AnnotationObjectMgrDelegate.qt.C
00001 #include "NeovisionII/NeoAnnotate/AnnotationObjectMgrDelegate.qt.H"
00002
00003 AnnotationObjectMgrDelegate::AnnotationObjectMgrDelegate(QObject *parent)
00004 {
00005
00006 }
00007
00008 void AnnotationObjectMgrDelegate::paint(QPainter* painter,
00009 const QStyleOptionViewItem & option, const QModelIndex & index) const
00010 {
00011 QRect rect = option.rect;
00012 QString text;
00013
00014 switch(index.column())
00015 {
00016 case 0:
00017 case 1:
00018 text = index.data().toString();
00019 break;
00020 case 2:
00021 text = itsCategories[index.data().toInt()];
00022 break;
00023 }
00024
00025 painter->drawText(rect, Qt::AlignCenter, text);
00026 }
00027
00028 QSize AnnotationObjectMgrDelegate::sizeHint(const QStyleOptionViewItem & option,
00029 const QModelIndex & index) const
00030 {
00031 return QSize();
00032 }
00033
00034 QWidget* AnnotationObjectMgrDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
00035 {
00036 QRect rect = option.rect;
00037
00038 QLineEdit* lineEdit;
00039 QComboBox* comboBox;
00040
00041 switch(index.column())
00042 {
00043 case 0:
00044 return NULL;
00045 case 1:
00046 lineEdit = new QLineEdit(parent);
00047 lineEdit->setGeometry(rect);
00048 return lineEdit;
00049 case 2:
00050 comboBox = new QComboBox(parent);
00051 comboBox->setGeometry(rect);
00052 QMap<int, QString>::const_iterator catIt = itsCategories.constBegin();
00053 for(;catIt != itsCategories.constEnd(); ++catIt)
00054 comboBox->addItem(catIt.value(), catIt.key());
00055 return comboBox;
00056 }
00057 return 0;
00058 }
00059
00060 void AnnotationObjectMgrDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
00061 {
00062 }
00063
00064 void AnnotationObjectMgrDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
00065 {
00066 QLineEdit* lineEdit;
00067 QComboBox* comboBox;
00068 QString data;
00069
00070 switch(index.column())
00071 {
00072 case 1:
00073 lineEdit = static_cast<QLineEdit*>(editor);
00074 data = lineEdit->text();
00075
00076 break;
00077 case 2:
00078 comboBox = static_cast<QComboBox*>(editor);
00079 data = comboBox->itemData(comboBox->currentIndex()).toString();
00080 break;
00081 }
00082 qDebug() << "Setting Model Data: " << data;
00083 model->setData(index, data, Qt::EditRole);
00084 }