Added comments.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 7 Dec 2010 21:55:20 +0000 (23:55 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 7 Dec 2010 21:55:20 +0000 (23:55 +0200)
src/delegates/comboboxdelegate.cpp
src/delegates/comboboxdelegate.h

index e060ae1..3f83f1d 100644 (file)
@@ -32,16 +32,19 @@ void ComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
     // get the item id from the hosting view's model
     int objid = index.model()->data(index,  Qt::DisplayRole).toInt();
 
-    // find matching object from QComboBox's model
+    // find a matching object from the editor's model
     QModelIndex startInd = cbmodel->index(0, cbmodelIdColumn);
     QModelIndexList indList = cbmodel->match(startInd, Qt::DisplayRole, objid);
+    // If an object was found in the editor's model create an index to the editor's model
     QModelIndex ind = indList.empty() ?
         QModelIndex() :
         cbmodel->index(indList.first().row(), cbmodelDisplayColumn);
 
+    // Get the name field of an object using the created index
     QString txt = ind.isValid() ?
         cbmodel->data(ind).toString() : "";
 
+    // Render the name text
     painter->save();
     painter->drawText(option.rect, txt);
     painter->restore();
index 68e78f5..920fe84 100644 (file)
 
 class QSqlQueryModel;
 
+/*
+* This delegate is for a certain column in a host view in which the model provides
+* an id of a data object. This delegate renders a name of that data object instead of id in the model.
+* In addition this delegate provides a QComboBox editor for selecting an object of featured type in
+* the column in question.
+*/
 class ComboBoxDelegate : public QStyledItemDelegate
 {
     Q_OBJECT
@@ -44,6 +50,7 @@ public:
 private slots:
     void commitAndCloseEditor(int);
 private:
+    // This model is for the editor data - objects in editor list (this is not a pointer to view's model)
     QSqlQueryModel *cbmodel;
     int cbmodelIdColumn;
     int cbmodelDisplayColumn;