QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { QComboBox *comboDelegate = new QComboBox(parent); comboDelegate->setModel(model); comboDelegate->setEditable(true); comboDelegate->setAutoCompletion(true); comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion); comboDelegate->view()->setEditTriggers(QAbstractItemView::AllEditTriggers); comboDelegate->lineEdit()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this))); comboDelegate->view()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this))); connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString))); connect(comboDelegate->lineEdit(), SIGNAL(editingFinished()), this, SLOT(testActivation())); connect(comboDelegate, SIGNAL(activated(QString)), this, SLOT(fakeActivation())); currCombo.comboEditor = comboDelegate; currCombo.currRow = index.row(); currCombo.model = const_cast<QAbstractItemModel*>(index.model()); // Current display of things on Gnome3 looks like shit, so // let`s fix that. if (isGnome3Session()) { QPalette p; p.setColor(QPalette::Window, QColor(Qt::white)); p.setColor(QPalette::Base, QColor(Qt::white)); comboDelegate->lineEdit()->setPalette(p); comboDelegate->setPalette(p); } return comboDelegate; }
QWidget *BoolProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const { QComboBox *combo = new QComboBox(parent); combo->view()->setTextElideMode(Qt::ElideLeft); combo->setFrame(0); combo->addItems(QStringList() << QString::fromUtf8("false") << QString::fromUtf8("true")); QObject::connect(combo, SIGNAL(activated(int)), target, receiver); return combo; }
void AutohidingSplitter::addChild(QObject *pObject) { if (pObject && pObject->isWidgetType()) { pObject->installEventFilter(this); const QObjectList &childList = pObject->children(); for (QObject *obj: childList) { addChild(obj); } } QComboBox * combo = qobject_cast<QComboBox *>(pObject); if(combo){ popupsBlockingAutohiding.insert(combo->view()); // addChild(combo->view()); } }
QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { QComboBox *comboDelegate = new QComboBox(parent); comboDelegate->setModel(model); comboDelegate->setEditable(true); comboDelegate->setAutoCompletion(true); comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion); comboDelegate->lineEdit()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this))); comboDelegate->view()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this))); connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString))); currCombo.comboEditor = comboDelegate; currCombo.currRow = index.row(); currCombo.model = const_cast<QAbstractItemModel*>(index.model()); return comboDelegate; }
void tst_AddBookmarkDialog::addbookmarkdialog() { QFETCH(QString, url); QFETCH(QString, title); QFETCH(QDialogButtonBox::StandardButton, button); QFETCH(int, menuCount); QFETCH(int, toolbarCount); QFETCH(int, select); BookmarksManager *manager = BrowserApplication::bookmarksManager(); qRegisterMetaType<BookmarkNode *>("BookmarkNode *"); QSignalSpy spy(manager, SIGNAL(entryAdded(BookmarkNode *))); BookmarkNode *menu = manager->menu(); BookmarkNode *toolbar = manager->toolbar(); QCOMPARE(menu->children().count(), 0); QCOMPARE(toolbar->children().count(), 0); SubAddBookmarkDialog dialog(0, manager); dialog.setUrl(url); dialog.setTitle(title); QComboBox *combobox = dialog.findChild<QComboBox*>(); QVERIFY(combobox); if (select != -1) { combobox->setCurrentIndex(select); combobox->view()->setCurrentIndex(combobox->model()->index(select, 0)); } QDialogButtonBox *buttonBox = dialog.findChild<QDialogButtonBox*>(); QVERIFY(buttonBox); QPushButton *pushButton = buttonBox->button(button); pushButton->click(); QCOMPARE(spy.count(), menuCount + toolbarCount); QCOMPARE(menu->children().count(), menuCount); QCOMPARE(toolbar->children().count(), toolbarCount); BookmarkNode *node = 0; if (menuCount == 1) node = menu->children()[0]; if (toolbarCount == 1) node = toolbar->children()[0]; if (node) { QCOMPARE(node->title, title); QCOMPARE(node->url, url); } }
void setupCountryComboBox(QComboBox &comboBox, QStringList const &initiallySelected, bool withEmpty, QString const &emptyTitle) { if (withEmpty) comboBox.addItem(emptyTitle, Q("")); for (auto const &country : App::iso3166_1Alpha2Countries()) comboBox.addItem(country.first, country.second); auto &cfg = Settings::get(); if (!cfg.m_oftenUsedCountries.isEmpty()) comboBox.insertSeparator(cfg.m_oftenUsedCountries.count() + (withEmpty ? 1 : 0)); comboBox.view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); for (auto const &value : initiallySelected) if (setComboBoxTextByData(&comboBox, value)) return; }
void fixComboBoxViewWidth(QComboBox &comboBox) { comboBox.setSizeAdjustPolicy(QComboBox::AdjustToContents); comboBox.view()->setMinimumWidth(comboBox.sizeHint().width()); }
QWidget *AnemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { Q_UNUSED(option) QLabel *label; QComboBox *combo; QDoubleSpinBox *dspin; QLineEdit *ledit; QString currentManufacturer = index.model()->data(index.model()->index(AnemModel::MANUFACTURER, index.column())).toString(); QString currentModel = index.model()->data(index.model()->index(AnemModel::MODEL, index.column())).toString(); // can only edit name on blank column if (index.column() >= index.model()->columnCount()) return 0; // different kind of editor for each row switch (index.row()) { case AnemModel::MANUFACTURER: combo = new QComboBox(parent); combo->setEditable(false); combo->addItems(AnemDesc::manufacturerStringList()); combo->view()->setTextElideMode(Qt::ElideNone); connect(combo, SIGNAL(activated(int)), this, SLOT(commitAndCloseEditor())); return combo; case AnemModel::MODEL: combo = new QComboBox(parent); combo->setEditable(false); if (currentManufacturer.isEmpty()) { combo->addItems(AnemDesc::allModelStringList()); } else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_0()) { combo->addItems(AnemDesc::campbellModelStringList()); } else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_1()) { combo->addItems(AnemDesc::gillModelStringList()); } else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_2()) { combo->addItems(AnemDesc::metekModelStringList()); } else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_3()) { combo->addItems(AnemDesc::youngModelStringList()); } else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_4()) { combo->addItems(AnemDesc::otherModelStringList()); } combo->view()->setTextElideMode(Qt::ElideNone); combo->setMaxVisibleItems(15); connect(combo, SIGNAL(activated(int)), this, SLOT(commitAndCloseEditor())); return combo; case AnemModel::ID: ledit = new QLineEdit(parent); connect(ledit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return ledit; case AnemModel::HEIGHT: dspin = new QDoubleSpinBox(parent); dspin->setDecimals(2); dspin->setRange(0.1, 500.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [m]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; case AnemModel::WINDFORMAT: combo = new QComboBox(parent); combo->setEditable(false); if (currentManufacturer.isEmpty() || currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_1()) { combo->addItems(AnemDesc::allWindFormatStringList()); } else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_0()) { combo->addItems(AnemDesc::simplestWindFormatStringList()); } else { combo->addItems(AnemDesc::commonWindFormatStringList()); } combo->view()->setTextElideMode(Qt::ElideNone); connect(combo, SIGNAL(activated(int)), this, SLOT(commitAndCloseEditor())); return combo; case AnemModel::NORTHALIGNMENT: combo = new QComboBox(parent); combo->setEditable(false); if (currentManufacturer.isEmpty()) { combo->addItems(AnemDesc::allNorthAlignmentStringList()); } // gill else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_1()) { combo->addItems(AnemDesc::gillNorthAlignmentStringList()); } else { combo->addItems(AnemDesc::naNorthAlignmentStringList()); } combo->view()->setTextElideMode(Qt::ElideNone); connect(combo, SIGNAL(activated(int)), this, SLOT(commitAndCloseEditor())); return combo; case AnemModel::NORTHOFFSET: dspin = new QDoubleSpinBox(parent); dspin->setDecimals(1); dspin->setRange(0.0, 360.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(tr(" [%1]", "Degrees").arg(Defs::DEGREE)); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; case AnemModel::NSEPARATION: case AnemModel::ESEPARATION: case AnemModel::VSEPARATION: if (index.column() == 0) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(2); dspin->setRange(-1000.0, 1000.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [cm]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } case AnemModel::VPATHLENGTH: case AnemModel::HPATHLENGTH: if (currentModel != AnemDesc::getANEM_MODEL_STRING_12()) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(4); dspin->setRange(0.0001, 1000.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [cm]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } case AnemModel::TAU: if (currentModel != AnemDesc::getANEM_MODEL_STRING_12()) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(4); dspin->setRange(0.001, 1000.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [s]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } default: return 0; } }
QWidget *IrgaDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { DEBUG_FUNC_NAME Q_UNUSED(option) QLabel *label; QComboBox *combo; QDoubleSpinBox *dspin; QLineEdit *ledit; QString currentManufacturer = index.model()->data(index.model()->index(IrgaModel::MANUFACTURER, index.column())).toString(); QString currentModel = index.model()->data(index.model()->index(IrgaModel::MODEL, index.column())).toString(); // qDebug() << "index.row()" << index.row(); // can only edit name on blank column if (index.column() >= index.model()->columnCount()) return 0; // different kind of editor for each row switch (index.row()) { case IrgaModel::MANUFACTURER: combo = new QComboBox(parent); combo->setEditable(false); combo->addItems(IrgaDesc::manufacturerStringList()); combo->view()->setTextElideMode(Qt::ElideNone); connect(combo, SIGNAL(activated(int)), this, SLOT(commitAndCloseEditor())); return combo; case IrgaModel::MODEL: combo = new QComboBox(parent); combo->setEditable(false); if (currentManufacturer.isEmpty()) { combo->addItems(IrgaDesc::allModelStringList()); } else if (currentManufacturer == IrgaDesc::getIRGA_MANUFACTURER_STRING_0()) { combo->addItems(IrgaDesc::licorModelStringList()); } else if (currentManufacturer == IrgaDesc::getIRGA_MANUFACTURER_STRING_1()) { combo->addItems(IrgaDesc::otherModelStringList()); } combo->view()->setTextElideMode(Qt::ElideNone); combo->setMaxVisibleItems(15); connect(combo, SIGNAL(activated(int)), this, SLOT(commitAndCloseEditor())); return combo; case IrgaModel::SWVERSION: ledit = new QLineEdit(parent); ledit->setPlaceholderText(QStringLiteral("8.0.0")); connect(ledit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return ledit; case IrgaModel::ID: ledit = new QLineEdit(parent); ledit->setPlaceholderText(QStringLiteral("Alphanumeric ID")); connect(ledit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return ledit; case IrgaModel::TUBELENGTH: if (IrgaDesc::isOpenPathModel(currentModel)) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(1); dspin->setRange(0.0, 9999.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [cm]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } case IrgaModel::TUBEDIAMETER: if (IrgaDesc::isOpenPathModel(currentModel)) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(1); dspin->setRange(0.0, 99.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [mm]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } case IrgaModel::TUBEFLOWRATE: if (IrgaDesc::isOpenPathModel(currentModel)) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(1); dspin->setRange(0.0, 100.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [l/m]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } case IrgaModel::TUBENSEPARATION: case IrgaModel::TUBEESEPARATION: case IrgaModel::TUBEVSEPARATION: dspin = new QDoubleSpinBox(parent); dspin->setDecimals(2); dspin->setRange(-1000.0, 1000.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [cm]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; case IrgaModel::VPATHLENGTH: case IrgaModel::HPATHLENGTH: if (currentModel != IrgaDesc::getIRGA_MODEL_STRING_6() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_7() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_8() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_9() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_10() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_11()) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(4); dspin->setRange(0.0001, 1000.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [cm]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } case IrgaModel::TAU: if (currentModel != IrgaDesc::getIRGA_MODEL_STRING_6() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_7() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_8() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_9() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_10() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_11()) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(4); dspin->setRange(0.0001, 500.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [s]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } case IrgaModel::KWATER: case IrgaModel::KOXYGEN: if (currentModel != IrgaDesc::getIRGA_MODEL_STRING_8() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_9() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_10() && currentModel != IrgaDesc::getIRGA_MODEL_STRING_11()) { label = new QLabel(parent); return label; } else { dspin = new QDoubleSpinBox(parent); dspin->setDecimals(6); dspin->setRange(0.000001, 1.0); dspin->setSingleStep(1.0); dspin->setAccelerated(true); dspin->setSuffix(QStringLiteral(" [") + Defs::M3_G_CM_STRING + QStringLiteral("]")); connect(dspin, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return dspin; } default: return QStyledItemDelegate::createEditor(parent, option, index); } }