void DoubleSpinBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { double value = index.data(Qt::DisplayRole).toDouble(); DoubleSpinBox *spinBox = static_cast<DoubleSpinBox*>(editor); spinBox->setValue(value); }
void FunctionDialog::setCurveToModify(Graph *g, int curve) { if (!g) return; graph = g; FunctionCurve *c = (FunctionCurve *)graph->curve(curve); if (!c) return; curveID = curve; QStringList formulas = c->formulas(); QMap<QString, double> constants = c->constants(); if (!constants.isEmpty()) { boxConstants->clearContents(); boxConstants->setRowCount(constants.size()); boxConstants->show(); ApplicationWindow *app = (ApplicationWindow *)parent(); QMapIterator<QString, double> i(constants); int row = 0; while (i.hasNext()) { i.next(); boxConstants->setItem(row, 0, new QTableWidgetItem(i.key())); DoubleSpinBox *sb = new DoubleSpinBox(); sb->setLocale(app->locale()); sb->setDecimals(app->fit_output_precision); sb->setValue(i.value()); boxConstants->setCellWidget(row, 1, sb); connect(sb, SIGNAL(valueChanged(double)), this, SLOT(acceptFunction())); row++; } }
void DoubleSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { DoubleSpinBox *spinBox = static_cast<DoubleSpinBox*>(editor); spinBox->interpretText(); double value = spinBox->value(); model->setData(index, value, Qt::EditRole); }
QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const { DoubleSpinBox *editor = new DoubleSpinBox(parent); editor->setFrame(false); editor->setMinimum(0.); editor->setMaximum(10000000.); return editor; }
KinematicsBarSetupDialog() { setWindowTitle(_("Kinematics Operation Setup")); QVBoxLayout* vbox = new QVBoxLayout(); setLayout(vbox); QHBoxLayout* hbox = new QHBoxLayout(); hbox->addWidget(new QLabel(_("Snap thresholds:"))); hbox->addSpacing(10); hbox->addWidget(new QLabel(_("distance"))); snapDistanceSpin.setAlignment(Qt::AlignCenter); snapDistanceSpin.setDecimals(3); snapDistanceSpin.setRange(0.0, 0.999); snapDistanceSpin.setSingleStep(0.001); snapDistanceSpin.setValue(0.025); hbox->addWidget(&snapDistanceSpin); hbox->addWidget(new QLabel(_("[m]"))); hbox->addSpacing(5); hbox->addWidget(new QLabel(_("angle"))); snapAngleSpin.setAlignment(Qt::AlignCenter); snapAngleSpin.setRange(0, 90); snapAngleSpin.setValue(30); hbox->addWidget(&snapAngleSpin); hbox->addWidget(new QLabel(_("[deg]"))); vbox->addLayout(hbox); hbox = new QHBoxLayout(); hbox->addWidget(new QLabel(_("Penetration block depth"))); penetrationBlockDepthSpin.setAlignment(Qt::AlignCenter); penetrationBlockDepthSpin.setDecimals(4); penetrationBlockDepthSpin.setRange(0.0, 0.0099); penetrationBlockDepthSpin.setSingleStep(0.0001); penetrationBlockDepthSpin.setValue(0.0005); hbox->addWidget(&penetrationBlockDepthSpin); hbox->addWidget(new QLabel(_("[m]"))); vbox->addLayout(hbox); hbox = new QHBoxLayout(); lazyCollisionDetectionModeCheck.setText(_("Lazy collision detection mode")); lazyCollisionDetectionModeCheck.setChecked(true); hbox->addWidget(&lazyCollisionDetectionModeCheck); vbox->addLayout(hbox); hbox = new QHBoxLayout(); okButton.setText(_("OK")); okButton.setDefault(true); hbox->addWidget(&okButton); vbox->addLayout(hbox); }
void ContourLinesEditor::updateContourLevels() { if (!d_spectrogram) return; int rows = table->rowCount(); QwtValueList levels; for (int i = 0; i < rows; i++) { DoubleSpinBox *spinBox = dynamic_cast<DoubleSpinBox *>(table->cellWidget(i, 0)); if (spinBox) levels << spinBox->value(); } d_spectrogram->setContourLevels(levels); }
void ContourLinesEditor::updateContents() { if (!d_spectrogram) return; QwtValueList levels = d_spectrogram->contourLevels (); int rows = (int)levels.size(); table->setRowCount(rows); table->blockSignals(true); QwtDoubleInterval range = d_spectrogram->data().range(); for (int i = 0; i < rows; i++){ DoubleSpinBox *sb = new DoubleSpinBox(); sb->setLocale(d_locale); sb->setDecimals(d_precision); sb->setValue(levels[i]); sb->setRange(range.minValue (), range.maxValue ()); connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *))); table->setCellWidget(i, 0, sb); QPen pen = d_spectrogram->defaultContourPen(); if (pen.style() == Qt::NoPen) pen = d_spectrogram->contourPen (levels[i]); int width = 80; int height = 20; QPixmap pix(width, height); pix.fill(Qt::white); QPainter paint(&pix); paint.setRenderHint(QPainter::Antialiasing); paint.setPen(pen); paint.drawLine(0, height/2, width, height/2); paint.end(); QLabel *lbl = new QLabel(); lbl->setPixmap(pix); table->setCellWidget(i, 1, lbl); d_pen_list << pen; } table->blockSignals(false); }
void ContourLinesEditor::insertLevel() { if (!d_spectrogram) return; int row = table->currentRow(); DoubleSpinBox *sb = (DoubleSpinBox*)table->cellWidget(row, 0); if (!sb) return; QwtDoubleInterval range = d_spectrogram->data().range(); double current_value = sb->value(); double previous_value = range.minValue (); sb = (DoubleSpinBox*)table->cellWidget(row - 1, 0); if (sb) previous_value = sb->value(); double val = 0.5*(current_value + previous_value); table->blockSignals(true); table->insertRow(row); sb = new DoubleSpinBox(); sb->setLocale(d_locale); sb->setDecimals(d_precision); sb->setValue(val); sb->setRange(range.minValue (), range.maxValue ()); connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *))); table->setCellWidget(row, 0, sb); QPen pen = d_spectrogram->defaultContourPen(); if (pen.style() == Qt::NoPen) pen = d_spectrogram->contourPen (val); int width = 80; int height = 20; QPixmap pix(width, height); pix.fill(Qt::white); QPainter paint(&pix); paint.setRenderHint(QPainter::Antialiasing); paint.setPen(pen); paint.drawLine(0, height/2, width, height/2); paint.end(); QLabel *lbl = new QLabel(); lbl->setPixmap(pix); table->setCellWidget(row, 1, lbl); table->blockSignals(false); enableButtons(table->currentRow()); d_pen_list.insert(row, pen); }
void ColorMapEditor::insertLevel() { int row = table->currentRow(); DoubleSpinBox *sb = (DoubleSpinBox*)table->cellWidget(row, 0); if (!sb) return; double current_value = sb->value(); double previous_value = min_val; sb = (DoubleSpinBox*)table->cellWidget(row - 1, 0); if (sb) previous_value = sb->value(); double val = 0.5*(current_value + previous_value); QwtDoubleInterval range = QwtDoubleInterval(min_val, max_val); double mapped_val = (val - min_val)/range.width(); QColor c = QColor(color_map.rgb(QwtDoubleInterval(0, 1), mapped_val)); table->blockSignals(true); table->insertRow(row); sb = new DoubleSpinBox(); sb->setLocale(d_locale); sb->setDecimals(d_precision); sb->setValue(val); sb->setRange(min_val, max_val); connect(sb, SIGNAL(valueChanged(double)), this, SLOT(updateColorMap())); connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *))); table->setCellWidget(row, 0, sb); QTableWidgetItem *it = new QTableWidgetItem(c.name()); // Avoid compiler warning //#ifdef Q_CC_MSVC it->setFlags(it->flags() & (~Qt::ItemIsEditable)); //#else // it->setFlags(!Qt::ItemIsEditable); //#endif it->setBackground(QBrush(c)); it->setForeground(QBrush(c)); table->setItem(row, 1, it); table->blockSignals(false); enableButtons(table->currentRow()); updateColorMap(); }
void ColorMapEditor::setColorMap(const QwtLinearColorMap& map) { scaleColorsBox->setChecked(map.mode() == QwtLinearColorMap::ScaledColors); QwtArray <double> colors = map.colorStops(); int rows = (int)colors.size(); table->setRowCount(rows); table->blockSignals(true); QwtDoubleInterval range = QwtDoubleInterval(min_val, max_val); for (int i = 0; i < rows; i++){ DoubleSpinBox *sb = new DoubleSpinBox(); sb->setLocale(d_locale); sb->setDecimals(d_precision); sb->setValue(min_val + colors[i] * range.width()); if (i == 0) sb->setRange(min_val, min_val); else if (i == rows -1) sb->setRange(max_val, max_val); else sb->setRange(min_val, max_val); connect(sb, SIGNAL(valueChanged(double)), this, SLOT(updateColorMap())); connect(sb, SIGNAL(activated(DoubleSpinBox *)), this, SLOT(spinBoxActivated(DoubleSpinBox *))); table->setCellWidget(i, 0, sb); QColor c = QColor(map.rgb(QwtDoubleInterval(0, 1), colors[i])); QTableWidgetItem *it = new QTableWidgetItem(c.name()); // Avoid compiler warning //#ifdef Q_CC_MSVC it->setFlags(it->flags() & (~Qt::ItemIsEditable)); //#else // it->setFlags(!Qt::ItemIsEditable); //#endif it->setBackground(QBrush(c)); it->setForeground(QBrush(c)); table->setItem(i, 1, it); } table->blockSignals(false); color_map = map; }
void SettingsDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const { // Get the setting type. int type = index.model()->data(index, SettingsModel::TypeRole).toInt(); // Set the editor data. QVariant value = index.model()->data(index, Qt::EditRole); switch (type) { case SettingsValue::INT: case SettingsValue::UNSIGNED_INT: case SettingsValue::INT_POSITIVE: { // Spin box editors. static_cast<QSpinBox*>(editor)->setValue(value.toInt()); break; } case SettingsValue::UNSIGNED_DOUBLE: case SettingsValue::DOUBLE: case SettingsValue::DOUBLE_RANGE: { // Double spin box editors. static_cast<DoubleSpinBox*>(editor)->setValue( value.toString()); break; } case SettingsValue::DOUBLE_RANGE_EXT: { DoubleSpinBox* e = static_cast<DoubleSpinBox*>(editor); QVariant v = index.model()->data(index, SettingsModel::ExtRangeRole); QList<QVariant> range = v.toList(); double min_ = range[0].toDouble(); QString ext_min_ = range[2].toString(); if (value.toString().toUpper() == ext_min_ || value.toDouble() < min_) e->setValue(e->rangeMin()); else e->setValue(value.toDouble()); break; } case SettingsValue::DATE_TIME: { // Date and time editors. static_cast<QLineEdit*>(editor)->setText(value.toString()); break; } case SettingsValue::TIME: { // Time editors. static_cast<QLineEdit*>(editor)->setText(value.toString()); break; } case SettingsValue::RANDOM_SEED: { // Random seed editors. if (value.toString().toUpper() == "TIME" || value.toInt() < 1) static_cast<QSpinBox*>(editor)->setValue(0); else static_cast<QSpinBox*>(editor)->setValue(value.toInt()); break; } case SettingsValue::INT_RANGE_EXT: // AXIS_RANGE { QVariant v = index.model()->data(index, SettingsModel::ExtRangeRole); QList<QVariant> range = v.toList(); int min_ = range[0].toInt(); QString ext_min_ = range[2].toString(); if (value.toString().toUpper() == ext_min_ || value.toInt() < min_) static_cast<QSpinBox*>(editor)->setValue(-1); else static_cast<QSpinBox*>(editor)->setValue(value.toInt()); break; } case SettingsValue::OPTION_LIST: { // Options list. QString str = value.toString(); int i = static_cast<QComboBox*>(editor)->findText(str, Qt::MatchFixedString); if (i < 0) i = 0; static_cast<QComboBox*>(editor)->setCurrentIndex(i); break; } default: { // Line editors. static_cast<QLineEdit*>(editor)->setText(value.toString()); break; } } }
void restoreState(const Archive& archive){ snapDistanceSpin.setValue(archive.get("snapDistance", snapDistanceSpin.value())); penetrationBlockDepthSpin.setValue(archive.get("penetrationBlockDepth", penetrationBlockDepthSpin.value())); lazyCollisionDetectionModeCheck.setChecked(archive.get("lazyCollisionDetectionMode", lazyCollisionDetectionModeCheck.isChecked())); }
void restoreState(const Archive& archive){ timeScaleRatioSpin.setValue(archive.get("timeScaleRatio", timeScaleRatioSpin.value())); preInitialDurationSpin.setValue(archive.get("preInitialDuration", preInitialDurationSpin.value())); postFinalDurationSpin.setValue(archive.get("postFinalDuration", postFinalDurationSpin.value())); onlyTimeBarRangeCheck.setChecked(archive.get("onlyTimeBarRange", onlyTimeBarRangeCheck.isChecked())); newBodyItemCheck.setChecked(archive.get("makeNewBodyItem", newBodyItemCheck.isChecked())); stealthyStepCheck.setChecked(archive.get("stealthyStepMode", stealthyStepCheck.isChecked())); stealthyHeightRatioThreshSpin.setValue(archive.get("stealthyHeightRatioThresh", stealthyHeightRatioThreshSpin.value())); flatLiftingHeightSpin.setValue(archive.get("flatLiftingHeight", flatLiftingHeightSpin.value())); flatLandingHeightSpin.setValue(archive.get("flatLandingHeight", flatLandingHeightSpin.value())); impactReductionHeightSpin.setValue(archive.get("impactReductionHeight", impactReductionHeightSpin.value())); impactReductionTimeSpin.setValue(archive.get("impactReductionTime", impactReductionTimeSpin.value())); autoZmpCheck.setChecked(archive.get("autoZmp", autoZmpCheck.isChecked())); minZmpTransitionTimeSpin.setValue(archive.get("minZmpTransitionTime", minZmpTransitionTimeSpin.value())); zmpCenteringTimeThreshSpin.setValue(archive.get("zmpCenteringTimeThresh", zmpCenteringTimeThreshSpin.value())); zmpTimeMarginBeforeLiftingSpin.setValue(archive.get("zmpTimeMarginBeforeLiftingSpin", zmpTimeMarginBeforeLiftingSpin.value())); se3Check.setChecked(archive.get("allLinkPositions", se3Check.isChecked())); lipSyncMixCheck.setChecked(archive.get("lipSyncMix", lipSyncMixCheck.isChecked())); }
BodyMotionGenerationSetupDialog() : QDialog(MainWindow::instance()){ setWindowTitle(_("Body Motion Generation Setup")); vbox = new QVBoxLayout(); QHBoxLayout* hbox = newRow(vbox); hbox->addWidget(new QLabel(_("Time scale"))); timeScaleRatioSpin.setDecimals(2); timeScaleRatioSpin.setRange(0.01, 9.99); timeScaleRatioSpin.setSingleStep(0.01); timeScaleRatioSpin.setValue(1.0); hbox->addWidget(&timeScaleRatioSpin); hbox->addSpacing(8); hbox->addWidget(new QLabel(_("Pre-initial"))); preInitialDurationSpin.setDecimals(1); preInitialDurationSpin.setRange(0.0, 9.9); preInitialDurationSpin.setSingleStep(0.1); preInitialDurationSpin.setValue(1.0); hbox->addWidget(&preInitialDurationSpin); hbox->addWidget(new QLabel(_("[s]"))); hbox->addSpacing(8); hbox->addWidget(new QLabel(_("Post-final"))); postFinalDurationSpin.setDecimals(1); postFinalDurationSpin.setRange(0.0, 9.9); postFinalDurationSpin.setSingleStep(0.1); postFinalDurationSpin.setValue(1.0); hbox->addWidget(&postFinalDurationSpin); hbox->addWidget(new QLabel(_("[s]"))); hbox->addStretch(); hbox = newRow(vbox); onlyTimeBarRangeCheck.setText(_("Time bar's range only")); onlyTimeBarRangeCheck.setChecked(false); hbox->addWidget(&onlyTimeBarRangeCheck); se3Check.setText(_("Put all link positions")); se3Check.setChecked(false); hbox->addWidget(&se3Check); hbox->addStretch(); hbox = newRow(vbox); newBodyItemCheck.setText(_("Make a new body item")); newBodyItemCheck.setChecked(true); hbox->addWidget(&newBodyItemCheck); hbox->addStretch(); addSeparator(vbox, &stealthyStepCheck); stealthyStepCheck.setText(_("Stealthy Step Mode")); stealthyStepCheck.setToolTip(_("This mode makes foot lifting / landing smoother to increase the stability")); stealthyStepCheck.setChecked(true); hbox = newRow(vbox); hbox->addWidget(new QLabel(_("Height ratio thresh"))); stealthyHeightRatioThreshSpin.setAlignment(Qt::AlignCenter); stealthyHeightRatioThreshSpin.setDecimals(2); stealthyHeightRatioThreshSpin.setRange(1.00, 9.99); stealthyHeightRatioThreshSpin.setSingleStep(0.01); stealthyHeightRatioThreshSpin.setValue(2.0); hbox->addWidget(&stealthyHeightRatioThreshSpin); hbox->addStretch(); hbox = newRow(vbox); hbox->addWidget(new QLabel(_("Flat Lifting Height"))); flatLiftingHeightSpin.setAlignment(Qt::AlignCenter); flatLiftingHeightSpin.setDecimals(3); flatLiftingHeightSpin.setRange(0.0, 0.0999); flatLiftingHeightSpin.setSingleStep(0.001); flatLiftingHeightSpin.setValue(0.005); hbox->addWidget(&flatLiftingHeightSpin); hbox->addWidget(new QLabel(_("[m]"))); hbox->addSpacing(8); hbox->addWidget(new QLabel(_("Flat Landing Height"))); flatLandingHeightSpin.setAlignment(Qt::AlignCenter); flatLandingHeightSpin.setDecimals(3); flatLandingHeightSpin.setRange(0.0, 0.0999); flatLandingHeightSpin.setSingleStep(0.001); flatLandingHeightSpin.setValue(0.005); hbox->addWidget(&flatLandingHeightSpin); hbox->addWidget(new QLabel(_("[m]"))); hbox->addStretch(); hbox = newRow(vbox); hbox->addWidget(new QLabel(_("Impact reduction height"))); impactReductionHeightSpin.setAlignment(Qt::AlignCenter); impactReductionHeightSpin.setDecimals(3); impactReductionHeightSpin.setRange(0.0, 0.099); impactReductionHeightSpin.setSingleStep(0.001); impactReductionHeightSpin.setValue(0.005); hbox->addWidget(&impactReductionHeightSpin); hbox->addWidget(new QLabel(_("[m]"))); hbox->addSpacing(8); hbox->addWidget(new QLabel(_("Impact reduction time"))); impactReductionTimeSpin.setAlignment(Qt::AlignCenter); impactReductionTimeSpin.setDecimals(3); impactReductionTimeSpin.setRange(0.001, 0.999); impactReductionTimeSpin.setSingleStep(0.001); impactReductionTimeSpin.setValue(0.04); hbox->addWidget(&impactReductionTimeSpin); hbox->addWidget(new QLabel(_("[s]"))); hbox->addStretch(); addSeparator(vbox, &autoZmpCheck); autoZmpCheck.setText(_("Auto ZMP Mode")); autoZmpCheck.setToolTip(_("Automatically insert ZMP and foot key poses for stable motion")); autoZmpCheck.setChecked(true); hbox = newRow(vbox); hbox->addWidget(new QLabel(_("Min. transtion time"))); minZmpTransitionTimeSpin.setDecimals(2); minZmpTransitionTimeSpin.setRange(0.01, 0.99); minZmpTransitionTimeSpin.setSingleStep(0.01); minZmpTransitionTimeSpin.setValue(0.1); hbox->addWidget(&minZmpTransitionTimeSpin); hbox->addWidget(new QLabel(_("[s]"))); hbox->addSpacing(8); hbox->addWidget(new QLabel(_("Centering time thresh"))); zmpCenteringTimeThreshSpin.setDecimals(3); zmpCenteringTimeThreshSpin.setRange(0.001, 0.999); zmpCenteringTimeThreshSpin.setSingleStep(0.001); zmpCenteringTimeThreshSpin.setValue(0.03); hbox->addWidget(&zmpCenteringTimeThreshSpin); hbox->addWidget(new QLabel(_("[s]"))); hbox->addStretch(); hbox = newRow(vbox); hbox->addWidget(new QLabel(_("Time margin before lifting"))); zmpTimeMarginBeforeLiftingSpin.setDecimals(3); zmpTimeMarginBeforeLiftingSpin.setRange(0.0, 0.999); zmpTimeMarginBeforeLiftingSpin.setSingleStep(0.001); zmpTimeMarginBeforeLiftingSpin.setValue(0.0); hbox->addWidget(&zmpTimeMarginBeforeLiftingSpin); hbox->addWidget(new QLabel(_("[s]"))); hbox->addStretch(); addSeparator(vbox); hbox = newRow(vbox); lipSyncMixCheck.setText(_("Mix lip-sync motion")); lipSyncMixCheck.setChecked(false); hbox->addWidget(&lipSyncMixCheck); hbox->addStretch(); QVBoxLayout* topVBox = new QVBoxLayout(); topVBox->addLayout(vbox); addSeparator(topVBox); QPushButton* okButton = new QPushButton(_("&Ok")); okButton->setDefault(true); QDialogButtonBox* buttonBox = new QDialogButtonBox(this); buttonBox->addButton(okButton, QDialogButtonBox::AcceptRole); connect(buttonBox,SIGNAL(accepted()), this, SLOT(accept())); topVBox->addWidget(buttonBox); setLayout(topVBox); }
void storeState(Archive& archive){ archive.write("snapDistance", snapDistanceSpin.value()); archive.write("penetrationBlockDepth", penetrationBlockDepthSpin.value()); archive.write("lazyCollisionDetectionMode", lazyCollisionDetectionModeCheck.isChecked()); }
QWidget* SettingsDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& index) const { // Get the setting type. int type = index.model()->data(index, SettingsModel::TypeRole).toInt(); // Create the appropriate editor. QWidget* editor = 0; switch (type) { case SettingsValue::INT: { // Spin box editors. QSpinBox* spinner = new QSpinBox(parent); spinner->setFrame(false); spinner->setRange(-INT_MAX, INT_MAX); editor = spinner; break; } case SettingsValue::UNSIGNED_INT: { // Spin box editors. QSpinBox* spinner = new QSpinBox(parent); spinner->setFrame(false); spinner->setRange(0, INT_MAX); editor = spinner; break; } case SettingsValue::INT_POSITIVE: { // Spin box editors. QSpinBox* spinner = new QSpinBox(parent); spinner->setFrame(false); spinner->setRange(1, INT_MAX); editor = spinner; break; } case SettingsValue::UNSIGNED_DOUBLE: { // Double spin box editors. DoubleSpinBox* spinner = new DoubleSpinBox(parent); spinner->setFrame(false); spinner->setRange(0, DBL_MAX); editor = spinner; break; } case SettingsValue::DOUBLE: { // Double spin box editors. DoubleSpinBox* spinner = new DoubleSpinBox(parent); spinner->setFrame(false); spinner->setRange(-DBL_MAX, DBL_MAX); editor = spinner; break; } case SettingsValue::DOUBLE_RANGE: { // Double spin box editors. DoubleSpinBox* spinner = new DoubleSpinBox(parent); QVariant v = index.model()->data(index, SettingsModel::RangeRole); QList<QVariant> range = v.toList(); double min_ = range[0].toDouble(); double max_ = range[1].toDouble(); spinner->setFrame(false); spinner->setRange(min_, max_); editor = spinner; break; } case SettingsValue::DOUBLE_RANGE_EXT: { QVariant v = index.model()->data(index, SettingsModel::ExtRangeRole); QList<QVariant> range = v.toList(); double min_ = range[0].toDouble(); double max_ = range[1].toDouble(); QString ext_min_ = range[2].toString(); DoubleSpinBox* spinner = new DoubleSpinBox(parent); spinner->setFrame(false); spinner->setRange(min_, max_); spinner->setMinText(ext_min_); editor = spinner; break; } case SettingsValue::DATE_TIME: { // Date and time editors. QLineEdit* line = new QLineEdit(parent); line->setFrame(false); editor = line; break; } case SettingsValue::TIME: { // Time editors. QLineEdit* line = new QLineEdit(parent); line->setFrame(false); editor = line; break; } case SettingsValue::RANDOM_SEED: { // Random seed editors. QSpinBox* spinner = new QSpinBox(parent); spinner->setFrame(false); spinner->setRange(0, INT_MAX); spinner->setSpecialValueText("time"); editor = spinner; break; } case SettingsValue::INT_RANGE_EXT: { QVariant v = index.model()->data(index, SettingsModel::ExtRangeRole); QList<QVariant> range = v.toList(); int min_ = range[0].toInt(); int max_ = range[1].toInt(); QString ext_min_ = range[2].toString(); QSpinBox* spinner = new QSpinBox(parent); spinner->setFrame(false); spinner->setRange(min_, max_); spinner->setSpecialValueText(ext_min_); editor = spinner; break; } case SettingsValue::OPTION_LIST: { // Options list. QComboBox* list = new QComboBox(parent); QVariant data = index.model()->data(index, SettingsModel::OptionsRole); QStringList options = data.toStringList(); list->setFrame(false); list->addItems(options); connect(list, SIGNAL(activated(int)), this, SLOT(commitAndCloseEditor(int))); editor = list; break; } case SettingsValue::DOUBLE_LIST: { // Floating-point arrays. QLineEdit* line = new QLineEdit(parent); QRegExp regex("^[+-]?\\d+(?:\\.\\d+)?(,[+-]?\\d+(?:\\.\\d+)?)*$"); QValidator* validator = new QRegExpValidator(regex, line); line->setFrame(false); line->setValidator(validator); editor = line; break; } default: { // Line editors. QLineEdit* line = new QLineEdit(parent); line->setFrame(false); editor = line; break; } } editor->setAutoFillBackground(true); return editor; }
void SettingsDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { // Get the setting type. int type = index.model()->data(index, SettingsModel::TypeRole).toInt(); // Get the editor data. QVariant value; switch (type) { case SettingsValue::INT: case SettingsValue::UNSIGNED_INT: case SettingsValue::INT_POSITIVE: { // Spin box editors. value = static_cast<QSpinBox*>(editor)->value(); break; } case SettingsValue::DOUBLE: case SettingsValue::UNSIGNED_DOUBLE: case SettingsValue::DOUBLE_RANGE: { // Double spin box editors. value = static_cast<DoubleSpinBox*>(editor)->cleanText(); break; } case SettingsValue::DOUBLE_RANGE_EXT: { // Double spin box editors. DoubleSpinBox* e = static_cast<DoubleSpinBox*>(editor); double v = e->value(); value = e->value(); if (v <= e->rangeMin()) value = e->minText(); else value = e->cleanText(); break; } case SettingsValue::DATE_TIME: { // Date and time editors. value = static_cast<QLineEdit*>(editor)->text(); // Validate these strings... // d-M-yyyy h:m:s.z // yyyy/M/d/h:m:s.z // yyyy-M-d h:m:s.z // yyyy-M-dTh:m:s.z // MJD.fraction QString h = "([01]?[0-9]|2[0-3])"; // 00-23 QString m = "[0-5]?[0-9]"; // 00-59 QString s = m; QString z = "(\\.\\d{1,3})?"; // 000-999 QString d = "(0?[1-9]|[12][0-9]|3[01])"; // 01-31 QString M = "(|1[0-2]|0?[1-9]|)"; // 01-12 QString y = "\\d{4,4}"; // yyyy QString rtime = h+":"+m+":"+s+z; // h:m:s.zzz QString rdate1 = "("+d+"-"+M+"-"+y+"\\s"+rtime+")"; QString rdate2 = "("+y+"/"+M+"/"+d+"/"+rtime+")"; QString rdate3 = "("+y+"-"+M+"-"+d+"\\s"+rtime+")"; QString rdate4 = "("+y+"-"+M+"-"+d+"T"+rtime+")"; QString rdate5 = "(\\d+\\.?\\d*)"; QString rdate6 = "(\\d+\\.?\\d*[e|E]-?\\d{1,2})"; QString rdatetime = rdate1+"|"+rdate2+"|"+rdate3+"|"+rdate4+ "|"+rdate5+"|"+rdate6; QRegExpValidator validator(QRegExp(rdatetime), 0); int pos = 0; QString v = value.toString(); if (validator.validate(v, pos) != QValidator::Acceptable && !v.isEmpty()) { cerr << "WARNING: DateTime value failed to validate." << endl; return; } break; } case SettingsValue::TIME: { // Time editors. value = static_cast<QLineEdit*>(editor)->text(); QString h = "(\\d+)"; // >= 0 QString m = "[0-5]?[0-9]"; // 00-59 QString s = m; QString z = "(\\.\\d{1,8})?"; // 000-99999999 QString rtime = h+":"+m+":"+s+z; // h:m:s.zzz QString sec = "(\\d+\\.?\\d*)"; QString exp_sec = "(\\d+\\.?\\d*[e|E]-?\\d{1,2})"; QRegExpValidator validator(QRegExp(rtime+"|"+sec+"|"+exp_sec), 0); int pos = 0; QString v = value.toString(); if (validator.validate(v, pos) != QValidator::Acceptable && !v.isEmpty()) { cerr << "WARNING: Time value failed to validate." << endl; return; } break; } case SettingsValue::RANDOM_SEED: { // Random seed editors. int val = static_cast<QSpinBox*>(editor)->value(); if (val < 1) value = static_cast<QSpinBox*>(editor)->specialValueText(); else value = val; break; } case SettingsValue::INT_RANGE_EXT: { // Random seed editors. int val = static_cast<QSpinBox*>(editor)->value(); if (val < 0) value = static_cast<QSpinBox*>(editor)->specialValueText(); else value = val; break; } case SettingsValue::OPTION_LIST: { // Options list. value = static_cast<QComboBox*>(editor)->currentText(); break; } default: { value = static_cast<QLineEdit*>(editor)->text(); break; } } model->setData(index, value, Qt::EditRole); }