QWidget *CustCharacteristicDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /*style*/, const QModelIndex & index) const { if(index.column()!=1) return 0; QModelIndex idx = index.sibling(index.row(), 0); q.prepare("SELECT charass_value" " FROM charass, char" " WHERE ((charass_char_id=char_id)" " AND (charass_target_type='CT')" " AND (charass_target_id=:custtype_id)" " AND (char_id=:char_id) );"); q.bindValue(":char_id", idx.model()->data(idx, Qt::UserRole)); q.bindValue(":custtype_id", index.model()->data(index, Qt::UserRole)); q.exec(); QComboBox *editor = new QComboBox(parent); editor->setEditable(true); #ifdef Q_WS_MAC QFont boxfont = editor->font(); boxfont.setPointSize((boxfont.pointSize() == -1) ? boxfont.pixelSize() - 3 : boxfont.pointSize() - 3); editor->setFont(boxfont); #endif while(q.next()) editor->addItem(q.value("charass_value").toString()); editor->installEventFilter(const_cast<CustCharacteristicDelegate*>(this)); return editor; }
QWidget *CustCharacteristicDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /*style*/, const QModelIndex & index) const { if(index.column()!=1) return 0; QModelIndex idx = index.sibling(index.row(), 0); characteristic::Type chartype = characteristic::Text; // Determine what type we have XSqlQuery qry; qry.prepare("SELECT char_id, char_type " "FROM char " "WHERE (char_id=:char_id); "); qry.bindValue(":char_id", idx.model()->data(idx, Qt::UserRole)); qry.exec(); if (qry.first()) chartype = (characteristic::Type)qry.value("char_type").toInt(); if (chartype == characteristic::Text || chartype == characteristic::List) { q.prepare("SELECT charass_value " "FROM char, charass " " LEFT OUTER JOIN charopt ON ((charopt_char_id=charass_char_id) " " AND (charopt_value=charass_value)) " "WHERE ((charass_char_id=char_id)" " AND (charass_target_type='CT')" " AND (charass_target_id=:custtype_id)" " AND (char_id=:char_id) ) " "ORDER BY COALESCE(charopt_order,0), charass_value;"); q.bindValue(":char_id", idx.model()->data(idx, Qt::UserRole)); q.bindValue(":custtype_id", index.model()->data(index, Xt::IdRole)); q.exec(); QComboBox *editor = new QComboBox(parent); editor->setEditable(chartype == characteristic::Text); #ifdef Q_WS_MAC QFont boxfont = editor->font(); boxfont.setPointSize((boxfont.pointSize() == -1) ? boxfont.pixelSize() - 3 : boxfont.pointSize() - 3); editor->setFont(boxfont); #endif while(q.next()) editor->addItem(q.value("charass_value").toString()); editor->installEventFilter(const_cast<CustCharacteristicDelegate*>(this)); return editor; } else if (chartype == characteristic::Date) { DLineEdit *editor = new DLineEdit(parent); return editor; } return 0; }
void ModelMgrWidget::updateModels() { // QLayoutItem *child; while (child = q_horiLayoutMain->takeAt(0)) { QWidget *widget = child->widget(); if (widget) { widget->setParent(0); widget->deleteLater(); } delete child; } // IconButton *buttonHome = new IconButton(QPixmap(":/application/image/home-1.png"), this); buttonHome->setObjectName("buttonHome"); buttonHome->setFixedSize(25, 25); buttonHome->setToolTip(QStringLiteral("主页")); q_horiLayoutMain->addWidget(buttonHome); QComboBox *comboBoxModel = new QComboBox(this); comboBoxModel->addItem(QStringLiteral("数据管理")); comboBoxModel->addItem(QStringLiteral("数据查询")); comboBoxModel->addItem(QStringLiteral("数据分析")); comboBoxModel->setMinimumWidth(QFontMetrics(comboBoxModel->font()) .width(comboBoxModel->itemText(0)) + 50); comboBoxModel->setToolTip(QStringLiteral("只切换模式界面,不初始化界面数据")); q_horiLayoutMain->addWidget(comboBoxModel); // connect(buttonHome, &QPushButton::clicked, [=](bool){ setCurrentModel(QStringLiteral("数据管理")); }); // QStringListIterator citerModelStack(q_modelStack); while (citerModelStack.hasNext()) { const QString &model = citerModelStack.next(); // JClickableLabel *labelName = new JClickableLabel(model, this); labelName->setObjectName("labelName"); labelName->setAlignment(Qt::AlignVCenter); labelName->setText(model); IconButton *buttonArrow = new IconButton(QPixmap(":/application/image/arrow-1.png"), this); buttonArrow->setObjectName("buttonArrow"); buttonArrow->setFixedSize(20, 25); q_horiLayoutMain->addWidget(labelName); q_horiLayoutMain->addWidget(buttonArrow); // connect(labelName, &JClickableLabel::clicked, [=](){ setCurrentModel(labelName->text()); }); } // comboBoxModel->setCurrentText(q_modelStack.last()); // connect(comboBoxModel, &QComboBox::currentTextChanged, [=](const QString &text){ setCurrentModel(text, false); Q_EMIT currentIndexChanged(text); }); }