void HopDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QComboBox *combo; QSpinBox *spin; QDoubleSpinBox *dspin; int comboindex; QVariant value = index.model()->data(index, Qt::EditRole); // different kind of editor for each column switch (index.column()) { case HopModel::NAME: combo = static_cast<QComboBox*>(editor); if (!combo) return; comboindex = combo->findText(value.toString()); if (comboindex > 0) { combo->setCurrentIndex(comboindex); } else { combo->setEditText(value.toString()); } break; case HopModel::WEIGHT: case HopModel::ALPHA: dspin = static_cast<QDoubleSpinBox*>(editor); if (!dspin) return; dspin->setValue(value.toDouble()); break; case HopModel::TIME: spin = static_cast<QSpinBox*>(editor); if (!spin) return; spin->setValue(value.toUInt()); break; case HopModel::TYPE: combo = static_cast<QComboBox*>(editor); if (!combo) return; comboindex = combo->findText(value.toString()); if (comboindex > 0) { combo->setCurrentIndex(comboindex); } else { combo->setEditText(value.toString()); } break; default: QItemDelegate::setEditorData(editor, index); break; } }
void WidgetMOItem::updateWidgetValue(QWidget* curWidget, QVariant value) { QComboBox* combo = dynamic_cast<QComboBox*>(curWidget); if(combo) combo->setEditText(value.toString()); QSpinBox* spinBox = dynamic_cast<QSpinBox*>(curWidget); if(spinBox) spinBox->setValue(value.toInt()); QScienceSpinBox* doubleSpinBox = dynamic_cast<QScienceSpinBox*>(curWidget); if(doubleSpinBox) doubleSpinBox->setValue(value.toDouble()); QCheckBox* checkBox = dynamic_cast<QCheckBox*>(curWidget); if(checkBox) { if(value.toBool()) checkBox->setCheckState(Qt::Checked); else checkBox->setCheckState(Qt::Unchecked); } QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(curWidget); if(lineEdit) lineEdit->setText(value.toString()); }
//----------------------------------------------------------------------------- // Function: FileTypesDelegate::setEditorData() //----------------------------------------------------------------------------- void FileTypesDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const { switch (index.column()) { case FILE_TYPES_COL_NAME: { QComboBox* combo = qobject_cast<QComboBox*>(editor); Q_ASSERT_X(combo, "FileTypesDelegate::setEditorData", "Type conversion failed for QComboBox"); QString text = index.model()->data(index, Qt::DisplayRole).toString(); combo->setEditText(text); break; } case FILE_TYPES_COL_EXTENSIONS: { QLineEdit* line = qobject_cast<QLineEdit*>(editor); Q_ASSERT_X(line, "FileTypesDelegate::setEditorData", "Type conversion failed for QLineEdit"); QString text = index.model()->data(index, Qt::DisplayRole).toString(); line->setText(text); break; } default: { QStyledItemDelegate::setEditorData(editor, index); break; } } }
void MicroSelectWidget::updateFromAllowed() { QString oldFamily = m_pMicroFamily->currentText(); m_pMicroFamily->clear(); #define CHECK_ADD(family) \ if ( (m_allowedAsmSet & AsmInfo::family) \ && !MicroLibrary::self()->microIDs( AsmInfo::family, \ m_allowedGpsimSupport, m_allowedFlowCodeSupport, m_allowedMicrobeSupport ).isEmpty() ) { \ m_pMicroFamily->insertItem( m_pMicroFamily->count(), AsmInfo::setToString(AsmInfo::family) ); \ } CHECK_ADD(PIC12) CHECK_ADD(PIC14) CHECK_ADD(PIC16); #undef CHECK_ADD if ( m_pMicroFamily->contains(oldFamily) ) { //m_pMicroFamily->setCurrentText(oldFamily); // 2018.12.07 { QComboBox *c = m_pMicroFamily; QString text = oldFamily; int i = c->findText(text); if (i != -1) c->setCurrentIndex(i); else if (c->isEditable()) c->setEditText(text); else c->setItemText(c->currentIndex(), text); } } microFamilyChanged(oldFamily); }
void ActionDialog::setOutputTabs(const QStringList &tabs, const QString ¤tTabName) { QComboBox *w = ui->comboBoxOutputTab; w->clear(); w->addItem(""); w->addItems(tabs); w->setEditText(currentTabName); }
QComboBox *StManagerStudyListComp::createDirectoryComboBox ( const QString &text ) { QComboBox *comboBox = new QComboBox; comboBox->setEditable( true ); comboBox->setEditText( text ); return comboBox; }
void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const { QComboBox *c = qobject_cast<QComboBox*>(editor); QString data = index.model()->data(index, Qt::DisplayRole).toString(); int i = c->findText(data); if (i != -1) c->setCurrentIndex(i); else c->setEditText(data); }
//! Blocks disruptive characters from being entered in a column name field. //! This function directly changes the text in the GUI combobox controls. //! @param text The string to insert into the output CSV file after filtering //! @see dataRowCreate() void Window::filterColumnName(const QString &text) { QString filtered = text; // The following characters cause problems with CSV and so are banned: \", filtered.remove(QRegExp("[\\\\\\\",]")); if(text.length() != filtered.length()) { // To find out which combobox is being typed in, we have to request // the sender. It arrives as a QObject, which we cast to a QComboBox QComboBox * cBox = reinterpret_cast<QComboBox*>(QObject::sender()); cBox->setEditText(filtered); } }
void CustCharacteristicDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString value = index.model()->data(index, Qt::DisplayRole).toString(); QComboBox *comboBox = static_cast<QComboBox*>(editor); int curIdx = comboBox->findText(value); if(curIdx != -1) comboBox->setCurrentIndex(curIdx); else comboBox->setEditText(value); }
void Setting::lord(const QString& section, const QString& prefix, QComboBox& cmb, bool all) { cmb.clear(); QSettings& store = storage(); QStringList keys, vals; store.beginGroup(section); keys = store.childKeys(); qint32 n = keys.size(); if (n > 0) { QString tval; QString tkey = prefix + SET_PFX_CMBTXT; keys.sort(); while (n--) { QString k = keys[n]; if (k.startsWith(prefix)) { QString v = store.value(k).toString().trimmed(); if (k == tkey) tval = v; else if (all && !v.isEmpty()) vals.append(v); } } vals.removeDuplicates(); n = vals.count(); if (n > 0) { if (n > SET_MAX_CMBITM) n = SET_MAX_CMBITM; while (n--) cmb.addItem(vals[n]); } if (!tval.isEmpty()) cmb.setEditText(tval); } store.endGroup(); }
void QUDefaultDelegate::setEditorData( QWidget *editor, const QModelIndex &index) const { QString value = index.model()->data(index, Qt::DisplayRole).toString(); QComboBox *comboBox = static_cast<QComboBox*>(editor); if(QString::compare(value, N_A, Qt::CaseSensitive) == 0) value = ""; comboBox->setEditText(value); comboBox->lineEdit()->selectAll(); }
void MicroSelectWidget::setMicro( const QString & id ) { MicroInfo * info = MicroLibrary::self()->microInfoWithID(id); if (!info) return; m_pMicro->clear(); m_pMicro->insertItems( m_pMicro->count(), MicroLibrary::self()->microIDs( info->instructionSet()->set() ) ); //m_pMicro->setCurrentText(id); // 2018.12.07 { QComboBox *c = m_pMicro; QString text = id; int i = c->findText(text); if (i != -1) c->setCurrentIndex(i); else if (c->isEditable()) c->setEditText(text); else c->setItemText(c->currentIndex(), text); } //m_pMicroFamily->setCurrentText( AsmInfo::setToString( info->instructionSet()->set() ) ); // 2018.12.07 { QComboBox *c = m_pMicroFamily; QString text = AsmInfo::setToString( info->instructionSet()->set() ); int i = c->findText(text); if (i != -1) c->setCurrentIndex(i); else if (c->isEditable()) c->setEditText(text); else c->setItemText(c->currentIndex(), text); } }
void tst_QDataWidgetMapper::comboBox() { QDataWidgetMapper mapper; QAbstractItemModel *model = testModel(&mapper); mapper.setModel(model); mapper.setSubmitPolicy(QDataWidgetMapper::ManualSubmit); QComboBox readOnlyBox; readOnlyBox.setEditable(false); readOnlyBox.addItem("read only item 0"); readOnlyBox.addItem("read only item 1"); readOnlyBox.addItem("read only item 2"); QComboBox readWriteBox; readWriteBox.setEditable(true); readWriteBox.addItem("read write item 0"); readWriteBox.addItem("read write item 1"); readWriteBox.addItem("read write item 2"); // populat the combo boxes with data mapper.addMapping(&readOnlyBox, 0, "currentIndex"); mapper.addMapping(&readWriteBox, 1, "currentText"); mapper.toFirst(); QCOMPARE(readOnlyBox.currentText(), QString("read only item 0")); QCOMPARE(readWriteBox.currentText(), QString("read write item 0")); // set some new values on the boxes readOnlyBox.setCurrentIndex(1); readWriteBox.setEditText("read write item y"); mapper.submit(); // make sure the new values are in the model QCOMPARE(model->data(model->index(0, 0)).toInt(), 1); QCOMPARE(model->data(model->index(0, 1)).toString(), QString("read write item y")); // now test updating of the widgets model->setData(model->index(0, 0), 2, Qt::EditRole); model->setData(model->index(0, 1), QString("read write item z"), Qt::EditRole); QCOMPARE(readOnlyBox.currentIndex(), 2); QEXPECT_FAIL("", "See task 125493 and QTBUG-428", Abort); QCOMPARE(readWriteBox.currentText(), QString("read write item z")); }
void ShortcutDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString value = index.model()->data(index, Qt::EditRole).toString(); //menu shortcut key QComboBox *box = qobject_cast<QComboBox*>(editor); if (box) { QString normalized=QKeySequence(value).toString(QKeySequence::NativeText); int pos=box->findText(normalized); if (pos==-1) box->setEditText(value); else box->setCurrentIndex(pos); return; } //editor key replacement QLineEdit *le = qobject_cast<QLineEdit*>(editor); if (le) { le->setText(value); } }
//----------------------------------------------------------------------------- // Function: PortsDelegate::setEditorData() //----------------------------------------------------------------------------- void PortsDelegate::setEditorData(QWidget* editor, QModelIndex const& index) const { if (index.column() == PortColumns::DIRECTION) { QString text = index.data(Qt::DisplayRole).toString(); QComboBox* combo = qobject_cast<QComboBox*>(editor); int comboIndex = combo->findText(text); combo->setCurrentIndex(comboIndex); } else if (index.column() == PortColumns::TYPE_NAME || index.column() == PortColumns::TYPE_DEF) { QString text = index.data(Qt::DisplayRole).toString(); QComboBox* combo = qobject_cast<QComboBox*>(editor); int comboIndex = combo->findText(text); // if the text is not found if (comboIndex < 0) { combo->setEditText(text); } else { combo->setCurrentIndex(comboIndex); } } else if (index.column() == PortColumns::TAG_GROUP) { ListEditor* tagEditor = qobject_cast<ListEditor*>(editor); Q_ASSERT(tagEditor); QString portTagGroup = index.model()->data(index, Qt::DisplayRole).toString(); if (!portTagGroup.isEmpty()) { QStringList portTags = portTagGroup.split(", "); tagEditor->setItems(portTags); } } else { ExpressionDelegate::setEditorData(editor, index); } }
void ComboDelegate::setEditorData( QWidget* editor, const QModelIndex& index ) const { QString text = index.model()->data(index, Qt::DisplayRole).toString(); QComboBox* combo = qobject_cast<QComboBox*>(editor); Q_ASSERT(combo); int rowNumber = combo->findText(text); // if the current text was not found if (rowNumber < 0) { combo->setEditText(text); } // if text was found then select it else { combo->setCurrentIndex(rowNumber); } }
void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (QString(editor->metaObject()->className())==tr("QComboBox")){ QString text = index.model()->data(index, Qt::EditRole).toString(); QComboBox *cb = static_cast<QComboBox*>(editor); int i = 0; for(int j=1; j<=n_element; j++) { if( text.toStdString() == element_data[j-1].symbol ) { i = j-1; } } if (i != -1) cb->setCurrentIndex(i); else if (cb->isEditable()) cb->setEditText(text); else cb->setCurrentIndex(0); } else QItemDelegate::setEditorData(editor,index); }
void CustCharacteristicDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (editor->inherits("QComboBox")) { QString value = index.model()->data(index, Qt::DisplayRole).toString(); QComboBox *comboBox = static_cast<QComboBox*>(editor); int curIdx = comboBox->findText(value); if(curIdx != -1) comboBox->setCurrentIndex(curIdx); else comboBox->setEditText(value); } else if (editor->inherits("DLineEdit")) { QDate date = index.model()->data(index, Qt::UserRole).toDate(); DLineEdit *dlineedit = static_cast<DLineEdit*>(editor); dlineedit->setDate(date); } }
void ArchiveDelegate::setEditorData(QWidget *AEditor, const QModelIndex &AIndex) const { switch (AIndex.column()) { case COL_SAVE: case COL_OTR: case COL_EXACT: { QComboBox *comboBox = qobject_cast<QComboBox *>(AEditor); if (comboBox) comboBox->setCurrentIndex(comboBox->findData(AIndex.data(Qt::UserRole))); } break; case COL_EXPIRE: { QComboBox *comboBox = qobject_cast<QComboBox *>(AEditor); if (comboBox) comboBox->setEditText(QString::number(AIndex.data(Qt::UserRole).toInt()/ONE_DAY)); } break; default: break; } }
void CopyFilterGUIForm::setChannelNames(const vector<wstring>& channelNames) { inputChannelNames = channelNames; for (int row = 0; row < gridLayout->rowCount() - 1; row++) { QLayoutItem* item = gridLayout->itemAtPosition(row, 1); if (item != NULL) { QComboBox* targetComboBox = qobject_cast<QComboBox*>(item->widget()); targetComboBox->blockSignals(true); QString text = targetComboBox->currentText(); targetComboBox->clear(); for (wstring channelName : channelNames) targetComboBox->addItem(QString::fromStdWString(channelName)); targetComboBox->setEditText(text); targetComboBox->blockSignals(false); } QLayoutItem* summandItem = gridLayout->itemAtPosition(row, 3); CopyFilterGUIRow* summandWidget = qobject_cast<CopyFilterGUIRow*>(summandItem->widget()); summandWidget->setChannelNames(channelNames); } }
static mpdm_t kde4_drv_form(mpdm_t a, mpdm_t ctxt) { int n; mpdm_t widget_list; QWidget *qlist[100]; mpdm_t r; KDialog *dialog = new KDialog(window); dialog->setModal(true); dialog->setButtons(KDialog::Ok | KDialog::Cancel); widget_list = mpdm_aget(a, 0); KVBox *vb = new KVBox(dialog); dialog->setMainWidget(vb); for (n = 0; n < mpdm_size(widget_list); n++) { mpdm_t w = mpdm_aget(widget_list, n); wchar_t *type; mpdm_t t; KHBox *hb = new KHBox(vb); type = mpdm_string(mpdm_hget_s(w, L"type")); if ((t = mpdm_hget_s(w, L"label")) != NULL) { QLabel *ql = new QLabel(hb); ql->setText(str_to_qstring(mpdm_gettext(t))); } t = mpdm_hget_s(w, L"value"); if (wcscmp(type, L"text") == 0) { mpdm_t h; QComboBox *ql = new QComboBox(hb); ql->setEditable(true); ql->setMinimumContentsLength(30); ql->setMaxVisibleItems(8); if (t != NULL) ql->setEditText(str_to_qstring(t)); qlist[n] = ql; if ((h = mpdm_hget_s(w, L"history")) != NULL) { int i; /* has history; fill it */ h = mp_get_history(h); for (i = mpdm_size(h) - 1; i >= 0; i--) ql->addItem(str_to_qstring(mpdm_aget(h, i))); } } else if (wcscmp(type, L"password") == 0) { QLineEdit *ql = new QLineEdit(hb); ql->setEchoMode(QLineEdit::Password); qlist[n] = ql; } else if (wcscmp(type, L"checkbox") == 0) { QCheckBox *qc = new QCheckBox(hb); if (mpdm_ival(t)) qc->setCheckState(Qt::Checked); qlist[n] = qc; } else if (wcscmp(type, L"list") == 0) { int i; QListWidget *ql = new QListWidget(hb); ql->setMinimumWidth(480); /* use a monospaced font */ ql->setFont(QFont(QString("Mono"))); mpdm_t l = mpdm_hget_s(w, L"list"); for (i = 0; i < mpdm_size(l); i++) ql->addItem(str_to_qstring(mpdm_aget(l, i))); ql->setCurrentRow(mpdm_ival(t)); qlist[n] = ql; } if (n == 0) qlist[n]->setFocus(Qt::OtherFocusReason); } n = dialog->exec(); if (!n) return NULL; r = MPDM_A(mpdm_size(widget_list)); /* fill the return values */ for (n = 0; n < mpdm_size(widget_list); n++) { mpdm_t w = mpdm_aget(widget_list, n); mpdm_t v = NULL; wchar_t *type; type = mpdm_string(mpdm_hget_s(w, L"type")); if (wcscmp(type, L"text") == 0) { mpdm_t h; QComboBox *ql = (QComboBox *) qlist[n]; v = qstring_to_str(ql->currentText()); /* if it has history, add to it */ if ((h = mpdm_hget_s(w, L"history")) != NULL && v != NULL && mpdm_cmp_s(v, L"") != 0) { h = mp_get_history(h); if (mpdm_cmp(v, mpdm_aget(h, -1)) != 0) mpdm_push(h, v); } } else if (wcscmp(type, L"password") == 0) { QLineEdit *ql = (QLineEdit *) qlist[n]; v = qstring_to_str(ql->text()); } else if (wcscmp(type, L"checkbox") == 0) { QCheckBox *qb = (QCheckBox *) qlist[n]; v = MPDM_I(qb->checkState() == Qt::Checked); } else if (wcscmp(type, L"list") == 0) { QListWidget *ql = (QListWidget *) qlist[n]; v = MPDM_I(ql->currentRow()); } mpdm_aset(r, v, n); } return r; }
CProperties::CProperties( QWidget* parent, const char* name, HODBCINSTPROPERTY hTheFirstProperty ) : QMainWindow( parent, name, 0 ) { HODBCINSTPROPERTY hProperty; int nProperty; pMainWidget = new QWidget( this ); setCentralWidget( pMainWidget ); pTopLayout = new QVBoxLayout( pMainWidget ); // SETUP TOOLBAR toolbarMain = new QToolBar( this ); addToolBar( toolbarMain, tr( "ToolBar" ), Top, FALSE ); new QToolButton( QPixmap( checkOk_xpm ), QString(tr("Save and Exit")), QString(""), this, SLOT(pbOk_Clicked()), toolbarMain ); new QToolButton( QPixmap( checkCancel_xpm ), QString(tr("Cancel any changes and Exit")), QString(""), this, SLOT(pbCancel_Clicked()), toolbarMain ); QWhatsThis::whatsThisButton ( toolbarMain ); /* PROPERTIES */ hFirstProperty = hTheFirstProperty; for ( nProperties = 0, hProperty = hFirstProperty; hProperty != NULL; hProperty = hProperty->pNext ) { nProperties++; } pGridLayout = new QGridLayout( nProperties, 2, 2 ); pTopLayout->addLayout( pGridLayout ); pGridLayout->setColStretch ( 0, 0 ); pGridLayout->setColStretch ( 1, 1 ); for ( nProperty = 0, hProperty = hFirstProperty; hProperty != NULL; nProperty++, hProperty = hProperty->pNext ) { QLabel *pLabel = new QLabel( pMainWidget ); // 1ST COLUMN IS ALWAYS A LABEL CONTAINING THE PROPERTY NAME if ( hProperty->nPromptType != ODBCINST_PROMPTTYPE_HIDDEN ) { if ( hProperty->pszHelp ) QWhatsThis::add( pLabel, hProperty->pszHelp ); pLabel->setLineWidth( 1 ); pLabel->setText( hProperty->szName ); pLabel->setMinimumSize( pLabel->sizeHint() ); pLabel->setFixedHeight( pLabel->sizeHint().height() ); pGridLayout->addWidget( pLabel, nProperty, 0 ); } // 2ND COLUMN IS WHERE THE USER ENTERS DATA SO CREATE A WIDGET THAT IS MEANINGFULL switch ( hProperty->nPromptType ) { case ODBCINST_PROMPTTYPE_LABEL: { QLabel *pLabel2 = new QLabel( pMainWidget ); if ( hProperty->pszHelp ) QWhatsThis::add( pLabel2, hProperty->pszHelp ); pLabel2->setFrameStyle( QFrame::Box | QFrame::Sunken ); pLabel2->setLineWidth( 1 ); pLabel2->setText( hProperty->szValue ); pLabel2->setMinimumSize( pLabel2->sizeHint() ); pLabel2->setFixedHeight( pLabel2->sizeHint().height() ); pGridLayout->addWidget( pLabel2, nProperty, 1 ); hProperty->pWidget = pLabel2; if ( hProperty->pszHelp ) QToolTip::add( pLabel2, hProperty->pszHelp ); } break; case ODBCINST_PROMPTTYPE_LISTBOX: { QComboBox *pComboBox = new QComboBox( pMainWidget ); if ( hProperty->pszHelp ) QWhatsThis::add( pComboBox, hProperty->pszHelp ); pComboBox->insertStrList( (const char **)hProperty->aPromptData ); pComboBox->setMinimumSize( pComboBox->sizeHint() ); pComboBox->setFixedHeight( pComboBox->sizeHint().height() ); pGridLayout->addWidget( pComboBox, nProperty, 1 ); hProperty->pWidget = pComboBox; if ( hProperty->pszHelp ) QToolTip::add( pComboBox, hProperty->pszHelp ); setCurrentItem( pComboBox, hProperty->szValue ); } break; case ODBCINST_PROMPTTYPE_COMBOBOX: { QComboBox *pComboBox = new QComboBox( true, pMainWidget ); if ( hProperty->pszHelp ) QWhatsThis::add( pComboBox, hProperty->pszHelp ); pComboBox->insertStrList( (const char **)hProperty->aPromptData ); pComboBox->setEditText( hProperty->szValue ); pComboBox->setMinimumSize( pComboBox->sizeHint() ); pComboBox->setFixedHeight( pComboBox->sizeHint().height() ); pGridLayout->addWidget( pComboBox, nProperty, 1 ); hProperty->pWidget = pComboBox; if ( hProperty->pszHelp ) QToolTip::add( pComboBox, hProperty->pszHelp ); } break; case ODBCINST_PROMPTTYPE_FILENAME: { CFileSelector *pFileSelector = new CFileSelector( pMainWidget ); if ( hProperty->pszHelp ) QWhatsThis::add( pFileSelector, hProperty->pszHelp ); pFileSelector->pLineEdit->setText( hProperty->szValue ); pGridLayout->addWidget( pFileSelector, nProperty, 1 ); hProperty->pWidget = pFileSelector; if ( hProperty->pszHelp ) QToolTip::add( pFileSelector, hProperty->pszHelp ); } break; case ODBCINST_PROMPTTYPE_HIDDEN: delete pLabel; break; default: // PROMPTTYPE_TEXTEDIT and PROMPTTYPE_TEXTEDIT_PASSWORD { QLineEdit *pLineEdit = new QLineEdit( pMainWidget ); if ( hProperty->pszHelp ) QWhatsThis::add( pLineEdit, hProperty->pszHelp ); pLineEdit->setText( hProperty->szValue ); pLineEdit->setMinimumHeight( pLineEdit->sizeHint().height() ); pLineEdit->setFixedHeight( pLineEdit->sizeHint().height() ); if (hProperty->nPromptType == ODBCINST_PROMPTTYPE_TEXTEDIT_PASSWORD) pLineEdit->setEchoMode( QLineEdit::Password ) ; pGridLayout->addWidget( pLineEdit, nProperty, 1 ); pLabel->setBuddy( pLineEdit ); hProperty->pWidget = pLineEdit; if ( hProperty->pszHelp ) QToolTip::add( pLineEdit, hProperty->pszHelp ); } } } /* SPACER */ QLabel *pSpacer = new QLabel( pMainWidget ); pTopLayout->addWidget( pSpacer, 11 ); pTopLayout->activate(); pMainWidget->show(); }
void WidgetIOProperties::createIOProperties() { ui->mainLayout->setColumnMinimumWidth(0, 150); ui->optionLayout->setColumnMinimumWidth(0, 150); QString lang = Utils::GetLocale(); QString rsc = QString(":/doc/%1/io_doc.json").arg(lang); QFile f(rsc); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::warning(this, tr("Error"), tr("Failed to load IO documentation from %1").arg(rsc)); return; } QJsonParseError jerr; QJsonDocument jdoc = QJsonDocument::fromJson(f.readAll(), &jerr); if (jerr.error != QJsonParseError::NoError || !jdoc.isObject()) { QMessageBox::warning(this, tr("Error"), tr("Failed to parse JSON IO documentation from %1").arg(rsc)); return; } QString iotype = QString::fromUtf8(params["type"].c_str()); QJsonObject jobj = jdoc.object(); for (auto it = jobj.begin();it != jobj.end();it++) jobj.insert(it.key().toLower(), it.value()); QJsonObject jobjAlias; if (!jobj.contains(iotype)) { //Search in aliases bool aliasfound = false; for (auto it = jobj.constBegin();it != jobj.constEnd();it++) { QJsonObject o = it.value().toObject(); QJsonArray jalias = o["alias"].toArray(); for (int i = 0;i < jalias.size();i++) { if (jalias.at(i).toString() == iotype) { aliasfound = true; jobjAlias = o; } } } if (!aliasfound) { QMessageBox::warning(this, tr("Error"), tr("IO type %1 is not found in %2").arg(iotype).arg(rsc)); return; } } QJsonObject jioobj; if (jobjAlias.isEmpty()) jioobj = jobj[iotype].toObject(); else jioobj = jobjAlias; ui->labelTitle->setText(iotype); ui->labelDesc->setText(jioobj["description"].toString()); int rowMain = 0, rowOption = 0; QJsonArray jparams = jioobj["parameters"].toArray(); for (int i = 0;i < jparams.size();i++) { QJsonObject jparam = jparams[i].toObject(); QGridLayout *layout = jparam["mandatory"].toString() == "true"?ui->mainLayout:ui->optionLayout; int row = jparam["mandatory"].toBool()?rowMain:rowOption; QLabel *title = new QLabel(jparam["name"].toString()); layout->addWidget(title, row, 0); QPushButton *revert = new QPushButton(); revert->setIcon(QIcon(":/img/document-revert.png")); revert->setToolTip(tr("Revert modification")); layout->addWidget(revert, row, 1); hider.hide(revert); QString pvalue; string prop = jparam["name"].toString().toUtf8().constData(); if (params.Exists(prop)) pvalue = QString::fromUtf8(params[prop].c_str()); else pvalue = jparam["default"].toString(); if (jparam["type"].toString() == "string") { QLineEdit *w = new QLineEdit(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); w->setText(pvalue); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::LineEdit; uiObject.lineEdit = w; uiObjectMap[prop] = uiObject; connect(w, &QLineEdit::textChanged, [=]() { updateChangedParam(prop, w->text(), pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setText(pvalue); }); } else if (jparam["type"].toString() == "bool") { QCheckBox *w = new QCheckBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); w->setChecked(pvalue == "true"); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::CheckBox; uiObject.checkBox = w; uiObjectMap[prop] = uiObject; connect(w, &QCheckBox::stateChanged, [=]() { updateChangedParam(prop, w->isChecked()?"true":"false", pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setChecked(pvalue == "true"); }); } else if (jparam["type"].toString() == "int") { QSpinBox *w = new QSpinBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); if (!jparam["min"].toString().isEmpty()) w->setMinimum(jparam["min"].toString().toInt()); else w->setMinimum(-999999999); if (!jparam["max"].toString().isEmpty()) w->setMaximum(jparam["max"].toString().toInt()); else w->setMaximum(999999999); w->setValue(pvalue.toInt()); layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::SpinBox; uiObject.spinBox = w; uiObjectMap[prop] = uiObject; connect(w, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=]() { updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setValue(pvalue.toInt()); }); } else if (jparam["type"].toString() == "float") { QDoubleSpinBox *w = new QDoubleSpinBox(); w->setEnabled(jparam["readonly"].toString() != "true" && editable); if (!jparam["min"].toString().isEmpty()) w->setMinimum(jparam["min"].toString().toDouble()); else w->setMinimum(-999999999.0); if (!jparam["max"].toString().isEmpty()) w->setMaximum(jparam["max"].toString().toDouble()); else w->setMaximum(999999999.0); w->setValue(pvalue.toDouble()); layout->addWidget(w, row, 2); w->setDecimals(3); UiObject uiObject; uiObject.type = UiObjectType::DoubleSpinBox; uiObject.doubleSpinBox = w; uiObjectMap[prop] = uiObject; connect(w, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]() { updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert); }); connect(revert, &QPushButton::clicked, [=]() { w->setValue(pvalue.toDouble()); }); } else if (jparam["type"].toString() == "list") { QComboBox *w = new QComboBox(); int defIndex = 0; w->setEnabled(jparam["readonly"].toString() != "true" && editable); //fill combobox with values, if no value, set editable to true QJsonObject jvalues = jparam["list_value"].toObject(); if (jvalues.empty()) w->setEditable(true); else { w->setEditable(false); for (auto it = jvalues.begin();it != jvalues.end();it++) { w->addItem(it.value().toString(), it.key()); if (it.key() == pvalue) { defIndex = w->count() - 1; w->setCurrentIndex(defIndex); } } } layout->addWidget(w, row, 2); UiObject uiObject; uiObject.type = UiObjectType::ComboBox; uiObject.comboBox = w; uiObjectMap[prop] = uiObject; if (w->isEditable()) { connect(w, &QComboBox::currentTextChanged, [=]() { updateChangedParam(prop, w->currentText(), pvalue, title, revert); }); } else { connect(w, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=]() { updateChangedParam(prop, w->currentData().toString(), pvalue, title, revert); }); } connect(revert, &QPushButton::clicked, [=]() { if (w->isEditable()) w->setEditText(pvalue); else w->setCurrentIndex(defIndex); }); } QPushButton *help = new QPushButton(); help->setIcon(QIcon(":/img/icon_unkown.png")); help->setFlat(true); layout->addWidget(help, row, 3); if((i==0)&&(entryHelper != nullptr)) { QPushButton *entryHelperButton = new QPushButton(); entryHelperButton->setIcon(QIcon(":/img/icon_entry_helper.png")); entryHelperButton->setFlat(true); layout->addWidget(entryHelperButton, row, 4); connect(entryHelperButton, &QPushButton::clicked, [=]() { if (entryHelper->exec() == QDialog::Accepted) setValues(entryHelper->getParams()); }); } //avoid copy the QJsonObject in the lambda QString helpInfo = jparam["description"].toString(); connect(help, &QPushButton::clicked, [=]() { if (balloonTip) delete balloonTip; balloonTip = new BalloonTip(QPixmap(":/img/icon_unkown.png"), title->text(), helpInfo, 800, help); balloonTip->setArrowPosition(BalloonTip::TopLeft); balloonTip->move(QCursor::pos()); balloonTip->show(); }); if (jparam["mandatory"].toBool()) rowMain++; else rowOption++; } }
bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ) { if ( !editor ) return false; QgsVectorLayer::EditType editType = vl->editType( idx ); const QgsField &field = vl->pendingFields()[idx]; QVariant::Type myFieldType = field.type(); QSettings settings; QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString(); switch ( editType ) { case QgsVectorLayer::Classification: case QgsVectorLayer::UniqueValues: case QgsVectorLayer::Enumeration: case QgsVectorLayer::ValueMap: case QgsVectorLayer::ValueRelation: { QVariant v = value; QComboBox *cb = qobject_cast<QComboBox *>( editor ); if ( !cb ) return false; if ( v.isNull() ) { v = nullValue; } int idx = cb->findData( v ); if ( idx < 0 ) return false; cb->setCurrentIndex( idx ); } break; case QgsVectorLayer::DialRange: case QgsVectorLayer::SliderRange: case QgsVectorLayer::EditRange: { if ( myFieldType == QVariant::Int ) { if ( editType == QgsVectorLayer::EditRange ) { QSpinBox *sb = qobject_cast<QSpinBox *>( editor ); if ( !sb ) return false; sb->setValue( value.toInt() ); } else { QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor ); if ( !sl ) return false; sl->setValue( value.toInt() ); } break; } else if ( myFieldType == QVariant::Double ) { QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( editor ); if ( !dsb ) return false; dsb->setValue( value.toDouble() ); } } case QgsVectorLayer::CheckBox: { QGroupBox *gb = qobject_cast<QGroupBox *>( editor ); if ( gb ) { QPair<QString, QString> states = vl->checkedState( idx ); gb->setChecked( value == states.first ); break; } QCheckBox *cb = qobject_cast<QCheckBox *>( editor ); if ( cb ) { QPair<QString, QString> states = vl->checkedState( idx ); cb->setChecked( value == states.first ); break; } } // fall-through case QgsVectorLayer::LineEdit: case QgsVectorLayer::UniqueValuesEditable: case QgsVectorLayer::Immutable: case QgsVectorLayer::UuidGenerator: default: { QLineEdit *le = qobject_cast<QLineEdit *>( editor ); QComboBox *cb = qobject_cast<QComboBox *>( editor ); QTextEdit *te = qobject_cast<QTextEdit *>( editor ); QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( editor ); if ( !le && ! cb && !te && !pte ) return false; QString text; if ( value.isNull() ) { if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong ) text = ""; else if ( editType == QgsVectorLayer::UuidGenerator ) text = QUuid::createUuid().toString(); else text = nullValue; } else { text = value.toString(); } if ( le ) le->setText( text ); if ( cb && cb->isEditable() ) cb->setEditText( text ); if ( te ) te->setHtml( text ); if ( pte ) pte->setPlainText( text ); } break; case QgsVectorLayer::FileName: case QgsVectorLayer::Calendar: { QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor ); if ( cw ) { cw->setSelectedDate( value.toDate() ); break; } QLineEdit* le = qobject_cast<QLineEdit*>( editor ); if ( !le ) { le = editor->findChild<QLineEdit *>(); } if ( !le ) { return false; } le->setText( value.toString() ); } break; } return true; }
void ArchiveDelegate::onExpireIndexChanged(int AIndex) { QComboBox *comboBox = qobject_cast<QComboBox *>(sender()); if (comboBox) comboBox->setEditText(QString::number(comboBox->itemData(AIndex).toInt()/ONE_DAY)); }
void synthv1widget_controls_item_delegate::setEditorData ( QWidget *pEditor, const QModelIndex& index ) const { #ifdef CONFIG_DEBUG_0 qDebug("synthv1widget_controls_item_delegate::setEditorData(%p, %d, %d)", pEditor, index.row(), index.column()); #endif switch (index.column()) { case 0: // Channel. { const int iChannel = index.data().toInt(); // = index.model()->data(index, Qt::DisplayRole).toInt(); QSpinBox *pSpinBox = qobject_cast<QSpinBox *> (pEditor); if (pSpinBox) pSpinBox->setValue(iChannel); break; } case 1: // Type. { const QString& sText = index.data().toString(); // = index.model()->data(index, Qt::DisplayRole).toString(); QComboBox *pComboBox = qobject_cast<QComboBox *> (pEditor); if (pComboBox) { const int iIndex = pComboBox->findText(sText); if (iIndex >= 0) pComboBox->setCurrentIndex(iIndex); else pComboBox->setCurrentIndex(0); } break; } case 2: // Parameter. { const int iParam = index.data(Qt::UserRole).toInt(); // = index.model()->data(index, Qt::DisplayRole).toString(); QComboBox *pComboBox = qobject_cast<QComboBox *> (pEditor); if (pComboBox) { const int iIndex = pComboBox->findData(iParam); if (iIndex >= 0) pComboBox->setCurrentIndex(iIndex); else pComboBox->setEditText(index.data().toString()); } break; } case 3: // Subject. { const int iIndex = index.data(Qt::UserRole).toInt(); // = index.model()->data(index, Qt::DisplayRole).toInt(); QComboBox *pComboBox = qobject_cast<QComboBox *> (pEditor); if (pComboBox) pComboBox->setCurrentIndex(iIndex); break; } default: break; } }
void CopyFilterGUIForm::load(vector<Assignment> assignments) { if (gridLayout != NULL) delete gridLayout; for (QObject* object : children()) { QWidget* widget = qobject_cast<QWidget*>(object); if (widget != NULL) widget->setVisible(false); object->deleteLater(); } gridLayout = new QGridLayout(this); gridLayout->setContentsMargins(2, 2, 2, 2); gridLayout->setHorizontalSpacing(2); gridLayout->setVerticalSpacing(2); gridLayout->setColumnStretch(4, 1); gridLayout->setColumnStretch(5, 1); int row = 0; for (Assignment assignment : assignments) { QString oc = QString::fromStdWString(assignment.targetChannel); bool firstSummand = true; for (Assignment::Summand summand : assignment.sourceSum) { if (firstSummand) { gridLayout->addWidget(new QLabel(tr("Channel"), this), row, 0); QComboBox* targetComboBox = new QComboBox(this); targetComboBox->setEditable(true); for (wstring channelName : inputChannelNames) targetComboBox->addItem(QString::fromStdWString(channelName)); targetComboBox->setEditText(oc); connect(targetComboBox, SIGNAL(editTextChanged(QString)), this, SIGNAL(updateModel())); connect(targetComboBox, SIGNAL(editTextChanged(QString)), this, SIGNAL(updateChannels())); gridLayout->addWidget(targetComboBox, row, 1); gridLayout->addWidget(new QLabel("=", this), row, 2); firstSummand = false; } else { gridLayout->addWidget(new QLabel("+", this), row, 2); } CopyFilterGUIRow* rowWidget = new CopyFilterGUIRow(summand, inputChannelNames, this); connect(rowWidget, SIGNAL(updateModel()), this, SIGNAL(updateModel())); connect(rowWidget, SIGNAL(updateChannels()), this, SIGNAL(updateChannels())); gridLayout->addWidget(rowWidget, row, 3); QPushButton* addSummandButton = new QPushButton(this); addSummandButton->setText(tr("Add summand")); addSummandButton->setIcon(QIcon(":/icons/16x16/list-add-green.png")); gridLayout->addWidget(addSummandButton, row, 4); connect(addSummandButton, SIGNAL(pressed()), this, SLOT(addSummand())); QPushButton* removeButton = new QPushButton(this); if (assignment.sourceSum.size() == 1) removeButton->setText(tr("Remove assignment")); else removeButton->setText(tr("Remove summand")); removeButton->setIcon(QIcon(":/icons/16x16/list-remove-red.png")); gridLayout->addWidget(removeButton, row, 5); connect(removeButton, SIGNAL(pressed()), this, SLOT(remove())); QSpacerItem* spacerItem = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum); gridLayout->addItem(spacerItem, row, 6); row++; } } QPushButton* addAssignmentButton = new QPushButton(this); addAssignmentButton->setText(tr("Add assignment")); addAssignmentButton->setIcon(QIcon(":/icons/16x16/list-add-green.png")); gridLayout->addWidget(addAssignmentButton, row++, 0, 1, 4); connect(addAssignmentButton, SIGNAL(pressed()), this, SLOT(addAssignment())); }
void FinanceMgr::createToolbar() { QToolBar* toolBar = addToolBar(QString::fromLocal8Bit("系统工具")); QAction* calcAction = new QAction(QIcon(tr(":/Icon/Resources/calculator.png")), QString::fromLocal8Bit("计算器"), this); toolBar->addAction(calcAction); connect(calcAction, SIGNAL(triggered()), this, SLOT(openCalc())); ui.toolBar->addWidget(new QLabel(QString::fromLocal8Bit("年月: "), this)); QComboBox* yearMonth = new QComboBox(this); QStringList dateList; // find the most faraway month from the budget table Database_Result& dr = DatabaseHandler::instance()->getHandler()->from(BudgetTableName)->limit("1")->orderBy("budget_month ASC")->get(); int currentYear = QDate::currentDate().year(); QString strCurrentYear = QString("%1").arg(currentYear); int currentMonth = QDate::currentDate().month(); QString strCurrentMonth = QString("%1").arg(currentMonth); QString strYM = QString("%1%2").arg(strCurrentYear, strCurrentMonth); QDate databaseDate = QDate::currentDate(); if (dr.count() > 0) { Array record = *dr.resultArray().begin(); databaseDate = QDate::fromString(record[budgetMonthColumnName].c_str(), Qt::ISODate); } // create the year month list from the database time to current time bool loop = true; int year, month; year = databaseDate.year(); month = databaseDate.month(); do { QString strYear = QString("%1").arg(year); QString strMonth = QString("%1").arg(month); QString strYear2Month = QString("%1%2").arg(strYear, strMonth); dateList << strYear2Month; month++; if (month > 12) { month = 1; year++; } // add more than 2 month to the list int monthCount1 = year * 12 + month; int monthCount2 = QDate::currentDate().year() * 12 + QDate::currentDate().month(); if ((monthCount2 + 2) < monthCount1) { loop = false; } } while (loop); yearMonth->addItems(dateList); yearMonth->setEditable(true); QCompleter* ymCompleter = new QCompleter(dateList, this); yearMonth->setCompleter(ymCompleter); yearMonth->setEditText(strYM); ui.toolBar->addWidget(yearMonth); connect(yearMonth, SIGNAL(editTextChanged(const QString&)), this, SLOT(handleMonthChanged(const QString&))); }