575,7 → 575,146 |
|
|
|
FilterValueDelegate::FilterValueDelegate(QObject *parent) |
: QItemDelegate(parent) |
{ |
} |
//! [0] |
|
void FilterValueDelegate::setClassID(QString newClassID){ |
class_id = newClassID; |
} |
|
|
|
//! [1] |
QWidget *FilterValueDelegate::createEditor(QWidget *parent, |
const QStyleOptionViewItem &/* option */, |
const QModelIndex &/* index */) const |
{ |
QStringList Name_list; |
|
Name_list = items; |
|
QComboBox *editor = new QComboBox(parent); |
|
/* |
editor->addItem("0"); |
editor->addItem("1"); |
editor->addItem("2"); |
editor->addItem("3"); |
editor->addItem("4"); |
editor->addItem("5"); |
editor->addItem("6"); |
editor->addItem("7"); |
editor->addItem("8"); |
editor->addItem("9"); |
*/ |
|
// editor->addItem("0"); |
|
// // // editor->addItems(Name_list); |
// editor->setEditable(false); |
return editor; |
} |
//! [1] |
|
//! [2] |
void FilterValueDelegate::setEditorData(QWidget *editor, |
const QModelIndex &index) const |
{ |
// int value = index.model()->data(index, Qt::EditRole).toInt(); |
|
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
// spinBox->setValue(value); |
|
|
const QAbstractItemModel * model = index.model(); |
|
|
QString value = index.model()->data(index, Qt::EditRole).toString(); |
QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString(); |
QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
//QStringList ID_list; |
//QStringList Name_list; |
int curr_index; |
|
//ID_list = items.keys(); |
//Name_list = items.values(); |
|
curr_index = items.indexOf(value); |
if (curr_index==-1) return; |
comboBox->setCurrentIndex(curr_index); |
/**************************************************** |
if (value == "0") comboBox->setCurrentIndex(0); |
if (value == "1") comboBox->setCurrentIndex(1); |
if (value == "2") comboBox->setCurrentIndex(2); |
if (value == "3") comboBox->setCurrentIndex(3); |
if (value == "4") comboBox->setCurrentIndex(4); |
if (value == "5") comboBox->setCurrentIndex(5); |
if (value == "6") comboBox->setCurrentIndex(6); |
if (value == "7") comboBox->setCurrentIndex(7); |
if (value == "8") comboBox->setCurrentIndex(8); |
if (value == "9") comboBox->setCurrentIndex(9); |
******************************************************/ |
comboBox->setEditable(false); |
|
|
//comboBox->setItemText(0, value); |
|
} |
//! [2] |
|
//! [3] |
void FilterValueDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
const QModelIndex &index) const |
{ |
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
// spinBox->interpretText(); |
// int value = spinBox->value(); |
|
// model->setData(index, value, Qt::EditRole); |
QStringList ID_list; |
QStringList Name_list; |
|
QComboBox *comboBox = static_cast<QComboBox*>(editor); |
int currIndex; |
currIndex = comboBox->currentIndex(); |
if (currIndex==-1) return; |
// QString value = comboBox->itemText(currIndex); |
|
// ID_list = items.keys(); |
// Name_list = items.values(); |
|
// QString value = ID_list.at(currIndex); |
QString value = items.at(currIndex); |
model->setData(index, value, Qt::EditRole); |
} |
//! [3] |
|
//! [4] |
void FilterValueDelegate::updateEditorGeometry(QWidget *editor, |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
{ |
editor->setGeometry(option.rect); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! [4] |
MyDEDelegate::MyDEDelegate( |
bool calpopup, |
QObject *parent) |