本文整理汇总了C++中QComboBox::findData方法的典型用法代码示例。如果您正苦于以下问题:C++ QComboBox::findData方法的具体用法?C++ QComboBox::findData怎么用?C++ QComboBox::findData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QComboBox
的用法示例。
在下文中一共展示了QComboBox::findData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: populateCelestialBodyList
void AstroCalcDialog::populateCelestialBodyList()
{
Q_ASSERT(ui->celestialBodyComboBox);
QComboBox* planets = ui->celestialBodyComboBox;
QStringList planetNames(solarSystem->getAllPlanetEnglishNames());
const StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
//Save the current selection to be restored later
planets->blockSignals(true);
int index = planets->currentIndex();
QVariant selectedPlanetId = planets->itemData(index);
planets->clear();
//For each planet, display the localized name and store the original as user
//data. Unfortunately, there's no other way to do this than with a cycle.
foreach(const QString& name, planetNames)
{
if (name!="Solar System Observer" && name!="Sun" && name!=core->getCurrentPlanet()->getEnglishName())
planets->addItem(trans.qtranslate(name), name);
}
//Restore the selection
index = planets->findData(selectedPlanetId, Qt::UserRole, Qt::MatchCaseSensitive);
if (index<0)
index = planets->findData("Moon", Qt::UserRole, Qt::MatchCaseSensitive);;
planets->setCurrentIndex(index);
planets->model()->sort(0);
planets->blockSignals(false);
}
示例2: populateGroupCelestialBodyList
void AstroCalcDialog::populateGroupCelestialBodyList()
{
Q_ASSERT(ui->object2ComboBox);
QComboBox* groups = ui->object2ComboBox;
groups->blockSignals(true);
int index = groups->currentIndex();
QVariant selectedGroupId = groups->itemData(index);
groups->clear();
groups->addItem(q_("Solar system"), "0");
groups->addItem(q_("Planets"), "1");
groups->addItem(q_("Asteroids"), "2");
groups->addItem(q_("Plutinos"), "3");
groups->addItem(q_("Comets"), "4");
groups->addItem(q_("Dwarf planets"), "5");
groups->addItem(q_("Cubewanos"), "6");
groups->addItem(q_("Scattered disc objects"), "7");
groups->addItem(q_("Oort cloud objects"), "8");
index = groups->findData(selectedGroupId, Qt::UserRole, Qt::MatchCaseSensitive);
if (index<0)
index = groups->findData("1", Qt::UserRole, Qt::MatchCaseSensitive);
groups->setCurrentIndex(index);
groups->model()->sort(0);
groups->blockSignals(false);
}
示例3: populateMajorPlanetList
void AstroCalcDialog::populateMajorPlanetList()
{
Q_ASSERT(ui->object1ComboBox); // object 1 is always major planet
QComboBox* majorPlanet = ui->object1ComboBox;
QList<PlanetP> planets = solarSystem->getAllPlanets();
const StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
//Save the current selection to be restored later
majorPlanet->blockSignals(true);
int index = majorPlanet->currentIndex();
QVariant selectedPlanetId = majorPlanet->itemData(index);
majorPlanet->clear();
//For each planet, display the localized name and store the original as user
//data. Unfortunately, there's no other way to do this than with a cycle.
foreach(const PlanetP& planet, planets)
{
if (planet->getPlanetType()==Planet::isPlanet && planet->getEnglishName()!=core->getCurrentPlanet()->getEnglishName())
majorPlanet->addItem(trans.qtranslate(planet->getNameI18n()), planet->getEnglishName());
}
//Restore the selection
index = majorPlanet->findData(selectedPlanetId, Qt::UserRole, Qt::MatchCaseSensitive);
if (index<0)
index = majorPlanet->findData("Mercury", Qt::UserRole, Qt::MatchCaseSensitive);;
majorPlanet->setCurrentIndex(index);
majorPlanet->model()->sort(0);
majorPlanet->blockSignals(false);
}
示例4: NewWidget
QWidget *OBSPropertiesView::AddList(obs_property_t prop)
{
const char *name = obs_property_name(prop);
QComboBox *combo = new QComboBox();
obs_combo_type type = obs_property_list_type(prop);
obs_combo_format format = obs_property_list_format(prop);
size_t count = obs_property_list_item_count(prop);
int idx = -1;
for (size_t i = 0; i < count; i++)
AddComboItem(combo, prop, format, i);
if (type == OBS_COMBO_TYPE_EDITABLE)
combo->setEditable(true);
if (format == OBS_COMBO_FORMAT_INT) {
int val = (int)obs_data_getint(settings, name);
string valString = to_string(val);
idx = combo->findData(QT_UTF8(valString.c_str()));
} else if (format == OBS_COMBO_FORMAT_FLOAT) {
double val = obs_data_getdouble(settings, name);
string valString = to_string(val);
idx = combo->findData(QT_UTF8(valString.c_str()));
} else if (format == OBS_COMBO_FORMAT_STRING) {
const char *val = obs_data_getstring(settings, name);
if (type == OBS_COMBO_TYPE_EDITABLE)
combo->lineEdit()->setText(val);
else
idx = combo->findData(QT_UTF8(val));
}
if (type == OBS_COMBO_TYPE_EDITABLE)
return NewWidget(prop, combo,
SIGNAL(editTextChanged(const QString &)));
if (idx != -1)
combo->setCurrentIndex(idx);
WidgetInfo *info = new WidgetInfo(this, prop, combo);
connect(combo, SIGNAL(currentIndexChanged(int)), info,
SLOT(ControlChanged()));
children.push_back(std::move(unique_ptr<WidgetInfo>(info)));
/* trigger a settings update if the index was not found */
if (idx == -1)
info->ControlChanged();
return combo;
}
示例5: populateEphemerisTimeStepsList
void AstroCalcDialog::populateEphemerisTimeStepsList()
{
Q_ASSERT(ui->ephemerisStepComboBox);
QComboBox* steps = ui->ephemerisStepComboBox;
steps->blockSignals(true);
int index = steps->currentIndex();
QVariant selectedStepId = steps->itemData(index);
steps->clear();
steps->addItem(q_("10 minutes"), "1");
steps->addItem(q_("1 hour"), "2");
steps->addItem(q_("1 day"), "3");
steps->addItem(q_("5 days"), "4");
steps->addItem(q_("10 days"), "5");
steps->addItem(q_("15 days"), "6");
steps->addItem(q_("30 days"), "7");
steps->addItem(q_("60 days"), "8");
index = steps->findData(selectedStepId, Qt::UserRole, Qt::MatchCaseSensitive);
if (index<0)
index = 2;
steps->setCurrentIndex(index);
steps->blockSignals(false);
}
示例6: setValue
void WidgetParameters::setValue(QWidget* curWidget,QVariant value)
{
QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(curWidget);
if(lineEdit)
lineEdit->setText(value.toString());
QScienceSpinBox* dblspinbox = dynamic_cast<QScienceSpinBox*>(curWidget);
if(dblspinbox)
dblspinbox->setValue(value.toDouble());
QSpinBox* spinbox = dynamic_cast<QSpinBox*>(curWidget);
if(spinbox)
spinbox->setValue(value.toInt());
QCheckBox* checkbox = dynamic_cast<QCheckBox*>(curWidget);
if(checkbox)
checkbox->setChecked(value.toBool());
QComboBox* combo = dynamic_cast<QComboBox*>(curWidget);
if(combo)
{
combo->setCurrentIndex(combo->findData(value));
}
}
示例7: setEditorData
void QmitkPropertyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QVariant data = index.data(Qt::EditRole);
QVariant displayData = index.data(Qt::DisplayRole);
if(data.isValid())
{
if(data.type() == QVariant::Int)
{
QSpinBox* spinBox = qobject_cast<QSpinBox *>(editor);
spinBox->setValue(data.toInt());
}
// see qt documentation. cast is correct, it would be obsolete if we
// store doubles
else if(static_cast<QMetaType::Type>(data.type()) == QMetaType::Float)
{
QDoubleSpinBox* spinBox = qobject_cast<QDoubleSpinBox *>(editor);
spinBox->setValue(data.toDouble());
}
else if(data.type() == QVariant::StringList)
{
QComboBox* comboBox = qobject_cast<QComboBox *>(editor);
QString displayString = displayData.value<QString>();
comboBox->setCurrentIndex(comboBox->findData(displayString));
}
else
return QStyledItemDelegate::setEditorData(editor, index);
}
}
示例8: setEditorData
void Enums::setEditorData(QWidget * editor, const QModelIndex & /*index*/)
{
QComboBox * cb = dynamic_cast<QComboBox *>(editor);
int intValue = *reinterpret_cast<const int *>(value().constData());
int index = cb->findData(intValue);
cb->setCurrentIndex(index);
}
示例9: populateCoordinateSystemsList
void SearchDialog::populateCoordinateSystemsList()
{
Q_ASSERT(ui->coordinateSystemComboBox);
QComboBox* csys = ui->coordinateSystemComboBox;
//Save the current selection to be restored later
csys->blockSignals(true);
int index = csys->currentIndex();
QVariant selectedSystemId = csys->itemData(index);
csys->clear();
//For each coordinate system, display the localized name and store the key as user
//data. Unfortunately, there's no other way to do this than with a cycle.
csys->addItem(qc_("Equatorial (J2000.0)", "coordinate system"), "equatorialJ2000");
csys->addItem(qc_("Equatorial", "coordinate system"), "equatorial");
csys->addItem(qc_("Horizontal", "coordinate system"), "horizontal");
csys->addItem(qc_("Galactic", "coordinate system"), "galactic");
csys->addItem(qc_("Ecliptic", "coordinate system"), "ecliptic");
csys->addItem(qc_("Ecliptic (J2000.0)", "coordinate system"), "eclipticJ2000");
//Restore the selection
index = csys->findData(selectedSystemId, Qt::UserRole, Qt::MatchCaseSensitive);
csys->setCurrentIndex(index);
csys->blockSignals(false);
}
示例10: populateCoordinateSystemsList
void PointerCoordinatesWindow::populateCoordinateSystemsList()
{
Q_ASSERT(ui->coordinateSystemComboBox);
QComboBox* csys = ui->coordinateSystemComboBox;
//Save the current selection to be restored later
csys->blockSignals(true);
int index = csys->currentIndex();
QVariant selectedSystemId = csys->itemData(index);
csys->clear();
//For each algorithm, display the localized name and store the key as user
//data. Unfortunately, there's no other way to do this than with a cycle.
csys->addItem(q_("Right ascension/Declination (J2000.0)"), "RaDecJ2000");
csys->addItem(q_("Right ascension/Declination"), "RaDec");
csys->addItem(q_("Hour angle/Declination"), "HourAngle");
csys->addItem(q_("Ecliptic Longitude/Latitude"), "Ecliptic");
csys->addItem(q_("Ecliptic Longitude/Latitude (J2000.0)"), "EclipticJ2000");
csys->addItem(q_("Altitude/Azimuth"), "AltAzi");
csys->addItem(q_("Galactic Longitude/Latitude"), "Galactic");
//Restore the selection
index = csys->findData(selectedSystemId, Qt::UserRole, Qt::MatchCaseSensitive);
csys->setCurrentIndex(index);
csys->blockSignals(false);
}
示例11: setEditorData
void StatusDelegate::setEditorData(QWidget *AEditor, const QModelIndex &AIndex) const
{
switch (AIndex.data(STR_COLUMN).toInt())
{
case STC_STATUS:
{
QComboBox *comboBox = qobject_cast<QComboBox *>(AEditor);
if (comboBox)
{
int show = AIndex.data(STR_VALUE).toInt();
comboBox->setCurrentIndex(comboBox->findData(show));
}
break;
}
case STC_PRIORITY:
{
QSpinBox *spinBox = qobject_cast<QSpinBox *>(AEditor);
if (spinBox)
spinBox->setValue(AIndex.data(STR_VALUE).toInt());
break;
}
default:
QStyledItemDelegate::setEditorData(AEditor,AIndex);
}
}
示例12: setEditorData
bool VObjectProperty::setEditorData(QWidget *editor)
{
if (!editor)
{
return false;
}
QComboBox* tmpEditor = qobject_cast<QComboBox*>(editor);
if (tmpEditor)
{
quint32 objId = VProperty::d_ptr->VariantValue.toUInt();
qint32 tmpIndex = tmpEditor->findData(objId);
if (tmpIndex == -1)
{
tmpIndex = 0;
}
tmpEditor->blockSignals(true);
tmpEditor->setCurrentIndex(tmpIndex);
tmpEditor->blockSignals(false);
return true;
}
return false;
}
示例13: mFromSelectedPushButton_clicked
void QgsMergeAttributesDialog::mFromSelectedPushButton_clicked()
{
//find the selected feature
if ( !mVectorLayer )
{
return;
}
//find out feature id of selected row
QList<QTableWidgetItem *> selectionList = mTableWidget->selectedItems();
if ( selectionList.isEmpty() )
{
return;
}
//assume all selected items to be in the same row
QTableWidgetItem *selectedItem = selectionList[0];
int selectedRow = selectedItem->row();
QTableWidgetItem *selectedHeaderItem = mTableWidget->verticalHeaderItem( selectedRow );
if ( !selectedHeaderItem )
{
return;
}
bool conversionSuccess;
QgsFeatureId featureId = selectedHeaderItem->text().toLongLong( &conversionSuccess );
if ( !conversionSuccess )
{
return;
}
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
{
QComboBox *currentComboBox = qobject_cast<QComboBox *>( mTableWidget->cellWidget( 0, i ) );
if ( !currentComboBox )
continue;
if ( mVectorLayer->fields().at( i ).constraints().constraints() & QgsFieldConstraints::ConstraintUnique )
{
currentComboBox->setCurrentIndex( currentComboBox->findData( "skip" ) );
}
else
{
currentComboBox->setCurrentIndex( currentComboBox->findData( QStringLiteral( "f%1" ).arg( FID_TO_STRING( featureId ) ) ) );
}
}
}
示例14: setEditorData
void QgsComposerColumnAlignmentDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
{
Qt::AlignmentFlag alignment = ( Qt::AlignmentFlag )index.model()->data( index, Qt::EditRole ).toInt();
//set the value for the combobox
QComboBox *comboBox = static_cast<QComboBox *>( editor );
comboBox->setCurrentIndex( comboBox->findData( alignment ) );
}
示例15: setEditorData
void PriceFieldTableDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
if( index.column() == m_d->fieldTypeCol ){
QVariant value = index.model()->data( index, Qt::DisplayRole );
QComboBox * cBox = static_cast<QComboBox *>( editor );
cBox->setCurrentIndex( cBox->findData( value ) );
} else {
QStyledItemDelegate::setEditorData( editor, index );
}
}