238,7 → 238,344 |
{ |
editor->setGeometry(option.rect); |
} |
|
|
|
|
|
|
|
|
|
|
|
//! [0] |
FilterSpinBoxDelegate::FilterSpinBoxDelegate(QObject *parent) |
: QItemDelegate(parent) |
{ |
} |
//! [0] |
|
void FilterSpinBoxDelegate::setClassID(QString newClassID){ |
class_id = newClassID; |
} |
|
void FilterSpinBoxDelegate::getItems(){ |
QMap <QString, QString> result_map; |
QSqlQuery q; |
QString query_str; |
bool ok; |
|
if (FilterSpinBoxDelegate::class_id.isEmpty()) |
{ |
items.clear(); |
return; |
} |
|
query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '"); |
query_str.append(class_id); |
query_str.append( tr("'")); |
|
q.prepare(query_str); |
|
|
ok = q.exec(); |
|
|
|
|
if (!ok) { |
/* |
QString error_str; |
error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû "); |
error_str.append(inctance); |
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
this, // Ðîäèòåëüñêèé âèäæåò. |
QObject::tr("Database Error"), // Çàãîëîâîê. |
q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
// tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ. |
|
*/ |
items.clear(); |
return; |
} |
|
|
// field_inctance = q.record().indexOf(tr("TableWhithInstance")); |
items.clear(); |
while(q.next()){ |
|
QString ID; |
QString Name; |
ID = q.value(0).toString(); // îïðåäåëÿåì ID |
Name = q.value(1).toString(); // îïðåäåëÿåì Name |
items.insert(ID, Name); |
} |
|
|
// return result_map; |
} |
|
|
//! [1] |
QWidget *FilterSpinBoxDelegate::createEditor(QWidget *parent, |
const QStyleOptionViewItem &/* option */, |
const QModelIndex &/* index */) const |
{ |
//QSpinBox *editor = new QSpinBox(parent); |
//editor->setMinimum(0); |
//editor->setMaximum(100); |
QStringList ID_list; |
QStringList Name_list; |
|
// getItems(); |
|
|
|
|
|
ID_list = items.keys(); |
Name_list = items.values(); |
|
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 FilterSpinBoxDelegate::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); |
QString value = index.model()->data(index, 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 = ID_list.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 FilterSpinBoxDelegate::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 = Name_list.at(currIndex); |
model->setData(index, value, Qt::EditRole); |
} |
//! [3] |
|
//! [4] |
void FilterSpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
{ |
editor->setGeometry(option.rect); |
} |
|
|
|
|
|
|
|
|
|
|
//! [0] |
FilterConditionDelegate::FilterConditionDelegate(QObject *parent) |
: QItemDelegate(parent) |
{ |
} |
//! [0] |
|
void FilterConditionDelegate::setClassID(QString newClassID){ |
class_id = newClassID; |
} |
|
|
|
//! [1] |
QWidget *FilterConditionDelegate::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 FilterConditionDelegate::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); |
QString value = index.model()->data(index, 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 FilterConditionDelegate::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 FilterConditionDelegate::updateEditorGeometry(QWidget *editor, |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
{ |
editor->setGeometry(option.rect); |
} |
|
|
|
|
|
|
|
|
|
|
//! [4] |
MyDEDelegate::MyDEDelegate( |
bool calpopup, |
QObject *parent) |