#include "CColumnModeDelegate.h" CColumnModeDelegate::CColumnModeDelegate() { } CColumnModeDelegate::~CColumnModeDelegate() { } QWidget* CColumnModeDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &index ) const { int nCol = index.column(); if ( nCol == 4 ) { QComboBox *pComboBox = new QComboBox(parent); pComboBox->addItem("db+rdb"); pComboBox->addItem("db"); pComboBox->addItem("rdb"); return pComboBox; } else if ( nCol == 5 || nCol == 9 || nCol == 10 || nCol == 13 || nCol ==19 || nCol == 20 ) { QComboBox *pComboBox = new QComboBox(parent); pComboBox->addItem("yes"); pComboBox->addItem("no"); return pComboBox; } else if ( nCol == 16 ) { QComboBox *pComboBox = new QComboBox(parent); pComboBox->addItem("char"); pComboBox->addItem("decimal"); pComboBox->addItem("int"); pComboBox->addItem("float"); pComboBox->addItem("double"); return pComboBox; } else if ( nCol == 7 || nCol == 8 || nCol == 17 ) { QSpinBox* pSpinBox = new QSpinBox(parent); pSpinBox->setMaximum( 100000000 ); return pSpinBox; } else if ( nCol == 11 ) { QComboBox *pComboBox = new QComboBox(parent); pComboBox->addItem(""); pComboBox->addItem("normal"); pComboBox->addItem("unique"); return pComboBox; } else if ( nCol == 12 ) { QComboBox *pComboBox = new QComboBox(parent); pComboBox->addItem("asc"); pComboBox->addItem("desc"); return pComboBox; } else if ( nCol == 15 ) { QComboBox *pComboBox = new QComboBox(parent); pComboBox->addItem("param"); pComboBox->addItem("data"); return pComboBox; } else if ( nCol == 6 ) { QComboBox *pComboBox = new QComboBox(parent); pComboBox->addItem("uchar"); pComboBox->addItem("char"); pComboBox->addItem("ushort"); pComboBox->addItem("short"); pComboBox->addItem("uint"); pComboBox->addItem("int"); pComboBox->addItem("ulong"); pComboBox->addItem("long"); pComboBox->addItem("float"); pComboBox->addItem("double"); pComboBox->addItem("string"); return pComboBox; } return NULL; } void CColumnModeDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const { int nCol = index.column(); if ( nCol == 7 || nCol == 8 || nCol == 17 ) { int nValue = index.model()->data(index).toInt(); QSpinBox* pSpinBox = static_cast(editor); pSpinBox->setValue( nValue ); } else if ( nCol == 4 || nCol == 5 || nCol == 9 || nCol == 10 || nCol == 13 || nCol == 19 || nCol == 20 || nCol == 6 || nCol == 11 || nCol == 12 || nCol == 15 || nCol == 16 ) { QString text = index.model()->data(index).toString(); QComboBox* pComboBox = static_cast(editor); int tindex = pComboBox->findText(text); pComboBox->setCurrentIndex(tindex); } } void CColumnModeDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const { int nCol = index.column(); if ( nCol == 7 || nCol == 8 || nCol == 17 ) { QSpinBox* pSpinBox = static_cast(editor); model->setData(index, pSpinBox->value()); } else if ( nCol == 4 || nCol == 5 || nCol == 9 || nCol == 10 || nCol == 13 || nCol == 19 || nCol == 20 || nCol == 6 || nCol == 11 || nCol == 12 || nCol == 15 || nCol == 16 ) { QComboBox* pComboBox = static_cast(editor); QString data = pComboBox->currentText(); model->setData(index, data); } }