void BrainTreeDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
    const BrainTreeModel* pBrainTreeModel = static_cast<const BrainTreeModel*>(index.model());
    const AbstractTreeItem* pAbstractItem = static_cast<const AbstractTreeItem*>(pBrainTreeModel->itemFromIndex(index));

    switch(pAbstractItem->type()) {
        case BrainTreeModelItemTypes::SurfaceColorGyri: {
            QColor color = index.model()->data(index, BrainTreeItemRoles::SurfaceColorGyri).value<QColor>();
            QColorDialog* pColorDialog = static_cast<QColorDialog*>(editor);
            pColorDialog->setCurrentColor(color);
            break;
        }

        case BrainTreeModelItemTypes::SurfaceColorSulci: {
            QColor color = index.model()->data(index, BrainTreeItemRoles::SurfaceColorSulci).value<QColor>();
            QColorDialog* pColorDialog = static_cast<QColorDialog*>(editor);
            pColorDialog->setCurrentColor(color);
            break;
        }

        case BrainTreeModelItemTypes::SurfaceColorInfoOrigin: {
            QString colorOrigin = index.model()->data(index, BrainTreeItemRoles::SurfaceColorInfoOrigin).toString();
            QComboBox* pComboBox = static_cast<QComboBox*>(editor);
            pComboBox->setCurrentText(colorOrigin);
            break;
        }

        case BrainTreeModelItemTypes::RTDataColormapType: {
            QString colormap = index.model()->data(index, BrainTreeItemRoles::RTDataColormapType).toString();
            QComboBox* pComboBox = static_cast<QComboBox*>(editor);
            pComboBox->setCurrentText(colormap);
            break;
        }

        case BrainTreeModelItemTypes::RTDataNormalizationValue: {
            double value = index.model()->data(index, BrainTreeItemRoles::RTDataNormalizationValue).toDouble();
            QDoubleSpinBox* pDoubleSpinBox = static_cast<QDoubleSpinBox*>(editor);
            pDoubleSpinBox->setValue(value);
            break;
        }

        case BrainTreeModelItemTypes::RTDataTimeInterval: {
            int value = index.model()->data(index, BrainTreeItemRoles::RTDataTimeInterval).toInt();
            QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor);
            pSpinBox->setValue(value);
            break;
        }
    }

    QItemDelegate::setEditorData(editor, index);
}
void table_widget_delegate::setWidgetData(const QModelIndex &index, QWidget *editor, const QVariant& data) const
{
	if (!editor){
		return;
	}

	column_data_ptr cd = _column_datas[index.column()];
	if (!cd){
		return;
	}

	switch (cd->type)
	{
	case WIDGET_CHECKBOX:
        {
            QCheckBox *widget = qobject_cast<QCheckBox*>(editor);
            if(widget){
                widget->setChecked(data.toBool());
            }
        }
		break;
	case  WIDGET_COMBOBOX:
		{
			QComboBox *widget = qobject_cast<QComboBox*>(editor);
			switch (cd->data.type())
			{
			case QVariant::StringList:
				widget->setCurrentText(data.toString());
				break;
			case QVariant::Map:
				{
					  QVariantMap map = cd->data.toMap();
					  QString text;
					  for (auto it = map.begin(); it != map.end(); ++it){
						  if (data == it.value()){
							  text = it.key();
						  }
					  }

					  widget->setCurrentText(text);
				}
				break;
			default:
				break;
			}
		}
	default:
		break;
	}
}
Example #3
0
void EventDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    switch(index.column()) {
        case 0: {
            int value = index.model()->data(index, Qt::DisplayRole).toInt();
            QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
            spinBox->setValue(value);
            break;
        }

        case 1: {
            double value = index.model()->data(index, Qt::DisplayRole).toDouble();
            QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
            spinBox->setValue(value);
            break;
        }

        case 2: {
            int value = index.model()->data(index, Qt::DisplayRole).toInt();
            QComboBox *spinBox = static_cast<QComboBox*>(editor);
            spinBox->setCurrentText(QString().number(value));
            break;
        }
    }
}
Example #4
0
void UatDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    uat_field_t *field = indexToField(index);

    switch (field->mode) {
    case PT_TXTMOD_ENUM:
    {
        QComboBox *combobox = static_cast<QComboBox *>(editor);
        const QString &data = index.model()->data(index, Qt::EditRole).toString();
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        combobox->setCurrentText(data);
#else
        int new_index = combobox->findText(data);
        if (new_index >= 0) {
            combobox->setCurrentIndex(new_index);
        }
#endif

        break;
    }

    default:
        QStyledItemDelegate::setEditorData(editor, index);
    }
}
Example #5
0
void QuickEdit::VisibilityDelegateSetup()
{
    GenericDelegate* visibilityDelegate = new GenericDelegate(ui->tvEditor, false);
    visibilityDelegate->widgetCreator = [&](QWidget * parent)
    {
        QStringList visibilities = {"public" , "protected", "private", "package", "default"};
        QComboBox* box = new QComboBox(parent);
        QStringListModel* model = new QStringListModel;
        model->setStringList(visibilities);
        box->setModel(model);
        box->setEditable(false);
        return box;
    };
    visibilityDelegate->dataAccessor = [](QWidget * editor, const QModelIndex & index)
    {
        QString value = index.model()->data(index, Qt::EditRole).toString();
        QComboBox *box = static_cast<QComboBox*>(editor);
        box->setCurrentText(value);
    };
    visibilityDelegate->dataSetter = [](QWidget * editor,QAbstractItemModel* model, const QModelIndex &index)
    {
        QComboBox * box = static_cast<QComboBox*>(editor);
        QString value = box->currentText();
        model->setData(index, value, Qt::EditRole);
    };
    ui->tvEditor->setItemDelegateForColumn(columns.indexOf("visibility"), visibilityDelegate);
}
Example #6
0
void QuickEdit::DirectionDelegateSetup()
{
    GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false);

    delegate->widgetCreator = [](QWidget* parent)
    {
        QStringList visibilities;
        visibilities << "inout" << "in" << "out";
        QComboBox* box = new QComboBox(parent);
        QStringListModel* model = new QStringListModel;
        model->setStringList(visibilities);
        box->setModel(model);
        box->setEditable(false);
        return box;
    };
    
    delegate->dataAccessor = [](QWidget* editor, const QModelIndex& index)
    {
        QString value = index.model()->data(index, Qt::EditRole).toString();
        QComboBox* box = static_cast<QComboBox*>(editor);
        box->setCurrentText(value);
    };

    delegate->dataSetter = [](QWidget* editor, QAbstractItemModel* model, const QModelIndex& index)
    {
        QComboBox* box = static_cast<QComboBox*>(editor);
        QString value = box->currentText();
        model->setData(index, value, Qt::EditRole);
    };

    ui->tvEditor->setItemDelegateForColumn(columns.indexOf("direction"), delegate);
}
void ComboBoxItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
	const QString value = index.model()->data(index, Qt::EditRole).toString();

	QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
	comboBox->setCurrentText(value);
}
Example #8
0
void ObjektDelegate::setEditorData ( QWidget *editor, const QModelIndex &index ) const
{

  QComboBox *box = static_cast<QComboBox*> (editor);
  box->setCurrentText(index.data().toString());

}
Example #9
0
void QuickEdit::PrefixDelegateSetup()
{
    GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false);
    delegate->widgetCreator = [&](QWidget * parent)
    {
        QStringList list;
        list << " " << "const " << "volatile ";
        QCompleter *completer = new QCompleter(list, parent);
        completer->setCaseSensitivity(Qt::CaseSensitive);


        QComboBox* box = new QComboBox(parent);
        QStringListModel* model = new QStringListModel;
        model->setStringList(list);
        box->setModel(model);
        box->setEditable(true);
        box->setCompleter(completer);
        return box;
    };
    delegate->dataAccessor = [](QWidget * editor, const QModelIndex & index)
    {
        QString value = index.model()->data(index, Qt::EditRole).toString();
        QComboBox *box = static_cast<QComboBox*>(editor);
        box->setCurrentText(value);
    };
    delegate->dataSetter = [](QWidget * editor,QAbstractItemModel* model, const QModelIndex &index)
    {
        QComboBox * box = static_cast<QComboBox*>(editor);
        QString value = box->currentText();
        model->setData(index, value, Qt::EditRole);
    };
    ui->tvEditor->setItemDelegateForColumn(columns.indexOf("prefix"), delegate);
}
void VCMatrixPresetSelection::displayProperties(RGBScript *script)
{
    if (script == NULL)
        return;

    int gridRowIdx = 0;

    QList<RGBScriptProperty> properties = script->properties();
    if (properties.count() > 0)
        m_propertiesGroup->show();
    else
        m_propertiesGroup->hide();

    foreach(RGBScriptProperty prop, properties)
    {
        switch(prop.m_type)
        {
            case RGBScriptProperty::List:
            {
                QLabel *propLabel = new QLabel(prop.m_displayName);
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
                QComboBox *propCombo = new QComboBox(this);
                propCombo->addItems(prop.m_listValues);
                propCombo->setProperty("pName", prop.m_name);
                QString pValue = script->property(prop.m_name);
                if (!pValue.isEmpty())
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
                    propCombo->setCurrentText(pValue);
#else
                    propCombo->setCurrentIndex(propCombo->findText(pValue));
#endif
                connect(propCombo, SIGNAL(currentIndexChanged(QString)),
                        this, SLOT(slotPropertyComboChanged(QString)));
                m_propertiesLayout->addWidget(propCombo, gridRowIdx, 1);
                gridRowIdx++;
            }
            break;
            case RGBScriptProperty::Range:
            {
                QLabel *propLabel = new QLabel(prop.m_displayName);
                m_propertiesLayout->addWidget(propLabel, gridRowIdx, 0);
                QSpinBox *propSpin = new QSpinBox(this);
                propSpin->setRange(prop.m_rangeMinValue, prop.m_rangeMaxValue);
                propSpin->setProperty("pName", prop.m_name);
                QString pValue = script->property(prop.m_name);
                if (!pValue.isEmpty())
                    propSpin->setValue(pValue.toInt());
                connect(propSpin, SIGNAL(valueChanged(int)),
                        this, SLOT(slotPropertySpinChanged(int)));
                m_propertiesLayout->addWidget(propSpin, gridRowIdx, 1);
                gridRowIdx++;
            }
            break;
            default:
                qWarning() << "Type" << prop.m_type << "not handled yet";
            break;
        }
    }
}
void IntermodTraceDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
    QComboBox *combo = qobject_cast<QComboBox*>(editor);
    if (!combo) {
        QStyledItemDelegate::setEditorData(editor, index);
        return;
    }

    const QString text = index.data().toString();
    combo->setCurrentText(text);
}
Example #12
0
void ConfigPrintDialog::setRow(QTableWidget *table, int row, QStringList values)
{
    qDebug() << "ConfigPrintDialog::setRow()";
    //Imposta i valori della QStringList values nella riga con indice row
    //della QTableWidget table.
    for (int col=0; col<table->columnCount(); col++) {
        if (col == DESCR || col == ALIGN) {
            QComboBox *cb = qobject_cast<QComboBox *>(table->cellWidget(row, col));
            cb->setCurrentText(values[col]);
        }
        else {
            QLineEdit *le = qobject_cast<QLineEdit *>(table->cellWidget(row, col));
            le->setText(values[col]);
        }
    }
}
Example #13
0
QWidget* PreferencesDialog::getFontsPage() {
    QWidget* widget = new QWidget();

    //---------------------
    // Font
    //---------------------
    GroupContainer *fontGroup = new GroupContainer;
    fontGroup->setTitle("Font");

    //Font Size
    QSpinBox* fontSizeCombo = new QSpinBox;
    fontSizeCombo->setMinimum(8);
    fontSizeCombo->setMaximum(14);
    fontSizeCombo->setValue(QApplication::font().pointSize());

    connect(fontSizeCombo, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), 
            [=] (int i){UserPreferences().setFontSize(i);});

    //Font Weight
    QComboBox *fontWeightCombo = new QComboBox;
    fontWeightCombo->addItems(QStringList() << "0" << "25" << "50" << "75");
    fontWeightCombo->setCurrentText(QString::number(QApplication::font().weight()));

    connect(fontWeightCombo, static_cast<void(QComboBox::*)(const QString&)> (&QComboBox::currentTextChanged),
            [ = ] (const QString & value){UserPreferences().setFontWeight(value);});

    QFormLayout *fontLayout = new QFormLayout;
    fontLayout->setRowWrapPolicy(QFormLayout::WrapLongRows);
    fontLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
    fontLayout->setFormAlignment(Qt::AlignHCenter | Qt::AlignTop);
    fontLayout->setLabelAlignment(Qt::AlignRight);
    fontLayout->addRow("Font Size", fontSizeCombo);
    fontLayout->addRow("Font Weight", fontWeightCombo);

    fontGroup->setContainerLayout(fontLayout);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);
    mainLayout->addWidget(fontGroup);
    mainLayout->addStretch(1);
    widget->setLayout(mainLayout);
    return widget;
}
void EditEventDialog::addProperty(const EventAttribute &attribute) {
    assert(mEvent.mData.count(attribute.mID) <= 1);
    QString defaultValue;
    if (mEvent.mData.count(attribute.mID) == 1) {
        defaultValue = mEvent.mData.find(attribute.mID).value();
    }
    QWidget *pDataWidget = NULL;
    QFormLayout *pLayout = NULL;
    switch (attribute.mLayoutType) {
    case LAYOUT_EMITTER:
        pLayout = dynamic_cast<QFormLayout*>(ui->emitterGroupBox->layout());
        break;
    case LAYOUT_EVENT:
        pLayout = dynamic_cast<QFormLayout*>(ui->eventGroupBox->layout());
        break;
    case LAYOUT_CHILD_DATA:
        pLayout = ui->childDataLayout;
        break;
    }
    if (attribute.mPropertyType == SELECT_TYPE) {
        QComboBox *pCB = new QComboBox(this);
        pCB->addItems(attribute.mAllowedValues);
        pCB->setCurrentText(defaultValue);

        QObject::connect(pCB, SIGNAL(currentIndexChanged(QString)), this, SLOT(onComboBoxValueChanged(QString)));
        mEditingEvent.mData[attribute.mID] = defaultValue;

        pDataWidget = pCB;
    }
    else if (attribute.mPropertyType == STRING_TYPE) {
        QLineEdit *pLineEdit = new QLineEdit(this);
        pLineEdit->setText(defaultValue);
        QObject::connect(pLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onLineEditValueChanged(QString)));

        pDataWidget = pLineEdit;
    }
    else if (attribute.mPropertyType == BOOL_TYPE) {
        QCheckBox *pCB = new QCheckBox(this);
        pCB->setChecked(defaultValue.toLower() == "true");
        pDataWidget = pCB;

        QObject::connect(pCB, SIGNAL(toggled(bool)), this, SLOT(onCheckBoxValueChanged(bool)));
    }
Example #15
0
/**
 * Add elements to set additional column name and sort order
 */
void SortTableWorkspaceDialog::addColumn()
{
  m_form.lblColumnName->setText( "Column 1" );
  // create controls for setting new column
  auto newRow = m_sortColumns.size();
  assert( newRow <= m_columnNames.size() );
  QLabel *label = new QLabel( QString("Column %1").arg(newRow+1) );
  QComboBox *columnName = new QComboBox();
  columnName->addItems( m_columnNames );
  columnName->setToolTip( m_form.cbColumnName->toolTip() );
  connect( columnName, SIGNAL(currentIndexChanged(int)), this, SLOT(changedColumnName(int)) );
  QComboBox *ascending = new QComboBox();
  ascending->addItem("Ascending");
  ascending->addItem("Descending");
  ascending->setToolTip( m_form.cbAscending->toolTip() );
  // add them to the layout
  m_form.columnsLayout->addWidget(label,newRow,0);
  m_form.columnsLayout->addWidget(columnName,newRow,1);
  m_form.columnsLayout->addWidget(ascending,newRow,2);
  // correct the tab order
  QWidget::setTabOrder( m_form.columnsLayout->itemAtPosition( newRow - 1, 2 )->widget(), columnName );
  QWidget::setTabOrder( columnName, ascending );

  // suggest a name for the new column: one that hasn't been used in 
  // other sort columns
  QString newColumnName;
  foreach(QString name, m_columnNames)
  {
    if ( !m_sortColumns.contains(name) )
    {
      columnName->setCurrentText( name );
      break;
    }
  }
  // cache the column name
  m_sortColumns << columnName->currentText();
  // set the Add/Remove buttons into a correct state
  if ( m_sortColumns.size() == m_columnNames.size() )
  {
    m_form.btnAddColumn->setEnabled(false);
  }
  m_form.btnRemoveColumn->setEnabled(true);
}
Example #16
0
void QuickEdit::TypeDelegateSetup()
{
    GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false);

    delegate->widgetCreator = [](QWidget* parent)
    {
        BrowserNodeList result;
        QStringList classes;
        BrowserClass::instances(result);
        result.full_names(classes);

        QStringList basics = GenerationSettings::basic_types();
        classes+=basics;
        QCompleter* completer = new QCompleter(classes, parent);
        completer->setCaseSensitivity(Qt::CaseSensitive);

        QComboBox* box = new QComboBox(parent);
        QStringListModel* model = new QStringListModel;
        model->setStringList(classes);
        box->setModel(model);
        box->setEditable(true);
        box->setCompleter(completer);
        return box;
    };

    delegate->dataAccessor = [](QWidget* editor, const QModelIndex& index)
    {
        QString value = index.model()->data(index, Qt::EditRole).toString();
        QComboBox* box = static_cast<QComboBox*>(editor);
        box->setCurrentText(value);
    };

    delegate->dataSetter = [](QWidget* editor, QAbstractItemModel* model, const QModelIndex& index)
    {
        QComboBox* box = static_cast<QComboBox*>(editor);
        QString value = box->currentText();
        model->setData(index, value, Qt::EditRole);
    };

    ui->tvEditor->setItemDelegateForColumn(columns.indexOf("type"), delegate);
}
Example #17
0
void ComPortPicker::populate(QComboBox &box, const QString &settingsKey)
{
	const QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
	const QString defaultPortName = SettingsManager::value(settingsKey).toString();
	box.clear();

	for (const QextPortInfo &info : ports) {
		const QRegExp portNameRegexp("COM\\d+", Qt::CaseInsensitive);
		if (portNameRegexp.indexIn(info.portName) != -1) {
			const QString portName = portNameRegexp.cap();
			box.addItem(portName);
		}
	}

	const int defaultIndex = box.findText(defaultPortName);
	if (defaultIndex != -1) {
		box.setCurrentIndex(defaultIndex);
	} else if (box.isEditable()) {
		box.setCurrentText(defaultPortName);
	}
}
/**
 * Adds a row at the end of the files table.
 * @param folder
 *      The folder (relative the generated SCE file).
 * @param type
 *      The type of the file.
 * @param source
 *      The file source.
 */
void CreateSceFile::addTableRow(QString folder, QString type, QString source)
{
    if(!source.isEmpty())
    {
        ui->filesTableWidget->insertRow(ui->filesTableWidget->rowCount());
        int row = ui->filesTableWidget->rowCount() - 1;

        ui->filesTableWidget->setItem(row, COLUMN_SUBDIR,  new QTableWidgetItem(folder));
        ui->filesTableWidget->setItem(row, COLUMN_TYPE, new QTableWidgetItem());
        ui->filesTableWidget->setItem(row, COLUMN_SOURCE, new QTableWidgetItem(source));

        QComboBox* box = new QComboBox(ui->filesTableWidget);
        QStringList availTargets;
        availTargets << "script" << "execute script"  << "ui" << "lib" << "media" << "plugin" << "bin" << "etc";
        box->addItems(availTargets);
        box->setCurrentText(type);

        ui->filesTableWidget->setCellWidget(row, COLUMN_TYPE, box);
        connect(box, SIGNAL(currentTextChanged(QString)), this, SLOT(typeTextChangedSlot(QString)));
    }
}
QDockWidget* VisualizationWorkstationExtensionPlugin::getDockWidget() {
  _dockWidget = new QDockWidget("Cancer detection visualization");
  QUiLoader loader;
  QFile file(":/VisualizationWorkstationExtensionPlugin_ui/VisualizationWorkstationExtensionPlugin.ui");
  file.open(QFile::ReadOnly);
  QWidget* content = loader.load(&file, _dockWidget);
  file.close();
  _likelihoodCheckBox = content->findChild<QCheckBox*>("LikelihoodCheckBox");
  QDoubleSpinBox* spinBox = content->findChild<QDoubleSpinBox*>("OpacitySpinBox");
  spinBox->setValue(_opacity);
  QDoubleSpinBox* windowSpinBox = content->findChild<QDoubleSpinBox*>("WindowSpinBox");
  windowSpinBox->setValue(_window);
  QDoubleSpinBox* levelSpinBox = content->findChild<QDoubleSpinBox*>("LevelSpinBox");
  levelSpinBox->setValue(_level);
  QSpinBox* channelSpinBox = content->findChild<QSpinBox*>("ChannelSpinBox");
  channelSpinBox->setValue(_foregroundChannel);
  _segmentationCheckBox = content->findChild<QCheckBox*>("SegmentationCheckBox");
  QPushButton* openResultButton = content->findChild<QPushButton*>("OpenResultPushButton");
  QComboBox* LUTBox = content->findChild<QComboBox*>("LUTComboBox");
  LUTBox->setEditable(false);
  for (std::map<std::string, pathology::LUT>::const_iterator it = pathology::ColorLookupTables.begin(); it != pathology::ColorLookupTables.end(); ++it) {
    LUTBox->addItem(QString::fromStdString(it->first));
  }
  LUTBox->setCurrentText("Normal");
  connect(_likelihoodCheckBox, SIGNAL(toggled(bool)), this, SLOT(onEnableLikelihoodToggled(bool)));
  connect(_segmentationCheckBox, SIGNAL(toggled(bool)), this, SLOT(onEnableSegmentationToggled(bool)));
  connect(spinBox, SIGNAL(valueChanged(double)), this, SLOT(onOpacityChanged(double)));
  connect(windowSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onWindowValueChanged(double)));
  connect(levelSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onLevelValueChanged(double)));
  connect(channelSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onChannelChanged(int)));
  connect(openResultButton, SIGNAL(clicked()), this, SLOT(onOpenResultImageClicked()));
  connect(LUTBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onLUTChanged(const QString&)));
  _dockWidget->setEnabled(false);

  // Not used for know
  QGroupBox* segmentationGroupBox = content->findChild<QGroupBox*>("SegmentationGroupBox");
  segmentationGroupBox->setVisible(false);
  return _dockWidget;
}
Example #20
0
QWidget* PropertyEditor::createWidgetForEnum(const QString& name, const QVariant& value, QMetaEnum me, const QString &detail, QWidget* parent)
{
    mProperties[name] = value;
    QComboBox *box = new QComboBox(parent);
    if (!detail.isEmpty())
        box->setToolTip(detail);
    box->setObjectName(name);
    box->setEditable(false);
    for (int i = 0; i < me.keyCount(); ++i) {
        box->addItem(QString::fromLatin1(me.key(i)), me.value(i));
    }
    if (value.type() == QVariant::Int) {
        box->setCurrentIndex(box->findData(value));
    } else {
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
        box->setCurrentText(value.toString());
#else
        box->setCurrentIndex(box->findText(value.toString()));
#endif
    }
    connect(box, SIGNAL(currentIndexChanged(int)), SLOT(onEnumChange(int)));
    return box;
}
Example #21
0
void ModelMgrWidget::updateModels()
{
    //
    QLayoutItem *child;
    while (child = q_horiLayoutMain->takeAt(0)) {
        QWidget *widget = child->widget();
        if (widget) {
            widget->setParent(0);
            widget->deleteLater();
        }
        delete child;
    }

    //
    IconButton *buttonHome = new IconButton(QPixmap(":/application/image/home-1.png"), this);
    buttonHome->setObjectName("buttonHome");
    buttonHome->setFixedSize(25, 25);
    buttonHome->setToolTip(QStringLiteral("主页"));
    q_horiLayoutMain->addWidget(buttonHome);

    QComboBox *comboBoxModel = new QComboBox(this);
    comboBoxModel->addItem(QStringLiteral("数据管理"));
    comboBoxModel->addItem(QStringLiteral("数据查询"));
    comboBoxModel->addItem(QStringLiteral("数据分析"));
    comboBoxModel->setMinimumWidth(QFontMetrics(comboBoxModel->font())
                                   .width(comboBoxModel->itemText(0)) + 50);
    comboBoxModel->setToolTip(QStringLiteral("只切换模式界面,不初始化界面数据"));
    q_horiLayoutMain->addWidget(comboBoxModel);

    //
    connect(buttonHome, &QPushButton::clicked, [=](bool){
        setCurrentModel(QStringLiteral("数据管理"));
    });

    //
    QStringListIterator citerModelStack(q_modelStack);
    while (citerModelStack.hasNext()) {
        const QString &model = citerModelStack.next();
        //

        JClickableLabel *labelName = new JClickableLabel(model, this);
        labelName->setObjectName("labelName");
        labelName->setAlignment(Qt::AlignVCenter);
        labelName->setText(model);
        IconButton *buttonArrow = new IconButton(QPixmap(":/application/image/arrow-1.png"), this);
        buttonArrow->setObjectName("buttonArrow");
        buttonArrow->setFixedSize(20, 25);
        q_horiLayoutMain->addWidget(labelName);
        q_horiLayoutMain->addWidget(buttonArrow);

        //
        connect(labelName, &JClickableLabel::clicked, [=](){
            setCurrentModel(labelName->text());
        });
    }

    //
    comboBoxModel->setCurrentText(q_modelStack.last());

    //
    connect(comboBoxModel, &QComboBox::currentTextChanged, [=](const QString &text){
        setCurrentModel(text, false);
        Q_EMIT currentIndexChanged(text);
    });
}
void
MultiplayerDialog::buildPlayersList()
{
	boost::intrusive_ptr< Core::LandscapeModel::IModelLocker >
		locker = m_environment.lockModel();

	boost::intrusive_ptr< Core::LandscapeModel::ILandscape >
		landscape = locker->getLandscapeModel()->getLandscape();

	// Races

	Core::LandscapeModel::IStaticData::RacesCollection reces;
	m_environment.fetchRaces( reces );

	QStringList races;

	Core::LandscapeModel::IStaticData::RacesCollectionIterator
			beginRaces = reces.begin()
		,	endRaces = reces.end();

	for ( ; beginRaces != endRaces; ++beginRaces )
		races.push_back( beginRaces->first );

	// List

	Core::LandscapeModel::ILandscapeModel::PlayersCollection players;
	locker->getLandscapeModel()->fetchPlayers( players );

	Core::LandscapeModel::ILandscapeModel::PlayersCollectionIterator
			begin = players.begin()
		,	end = players.end();

	for ( ; begin != end; ++begin )
	{
		QHBoxLayout* playerLayout = new QHBoxLayout();

		QString palyerLabelText
			= QString( Resources::Views::PlayerByStartPointLabelFormat )
				.arg( ( *begin )->getStartPointId() )
				.arg( ( *begin )->getName() );

		QLabel* playerLabel = new QLabel( palyerLabelText );

		playerLayout->addWidget( playerLabel );

		QComboBox* playerComboBox = new QComboBox();
		playerComboBox->addItems( m_nonePlayerTypes );

		playerComboBox->setCurrentText( Core::LandscapeModel::PlayerType::toString( ( *begin )->getType() ) );

		QObject::connect( playerComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onPlayerTypeChanged() ) );

		playerLayout->addWidget( playerComboBox );
		playerLayout->addWidget( new QLabel( Resources::Views::RaceLabel ) );

		QComboBox* raceComboBox = new QComboBox();
		raceComboBox->addItems( races );

		raceComboBox->setCurrentText( ( *begin )->getRace() );

		QObject::connect( raceComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onPlayerRaceChanged() ) );

		playerLayout->addWidget( raceComboBox );
		playerLayout->addWidget( new QLabel( Resources::Views::ColorLabel ) );

		QComboBox* colorsComboBox = new QComboBox();

		playerLayout->addWidget( colorsComboBox );

		m_playersLayout->addLayout( playerLayout );

		m_playersData.insert(
			std::make_pair(
					( *begin )->getUniqueId()
				,	PlayerData( *playerLabel, *playerComboBox, *raceComboBox, *colorsComboBox, ( *begin )->getUniqueId() ) ) );
	}

	updatePlayersColors();

} // MultiplayerDialog::buildPlayersList
void MyCurrencyComboDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
    QString value = index.model()->data(index,Qt::EditRole).toString();
    QComboBox *cmbbox = static_cast<QComboBox*>(editor);
    cmbbox->setCurrentText(value);
}
Example #24
0
void EditIndexDialog::updateColumnLists()
{
    // Fill the table column list
    sqlb::FieldInfoList tableFields = pdb.getObjectByName(index.table()).dynamicCast<sqlb::Table>()->fieldInformation();
    ui->tableTableColumns->setRowCount(tableFields.size());
    int tableRows = 0;
    for(int i=0;i<tableFields.size();++i)
    {
        // When we're doing the initial loading and this field already is in the index to edit, then don't add it to the
        // list of table columns. It will be added to the list of index columns in the next step. When this is not the initial
        // loading, the index column list is empty, so this check will always be true.
        if(index.findColumn(tableFields.at(i).name) == -1)
        {
            // Put the name of the field in the first column
            QTableWidgetItem* name = new QTableWidgetItem(tableFields.at(i).name);
            name->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
            ui->tableTableColumns->setItem(tableRows, 0, name);

            // Put the data type in the second column
            QTableWidgetItem* type = new QTableWidgetItem(tableFields.at(i).type);
            type->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
            ui->tableTableColumns->setItem(tableRows, 1, type);

            tableRows++;
        }
    }

    // Set row count to actual count. This is needed for the intial loading, when some rows might have been omitted because they were used in the index
    ui->tableTableColumns->setRowCount(tableRows);

    // Fill the index column list. This is done separately from the table column to include expression columns (these are not found in the original
    // table) and to preserve the order of the index columns
    auto indexFields = index.columns();
    ui->tableIndexColumns->blockSignals(true);
    ui->tableIndexColumns->setRowCount(indexFields.size());
    for(int i=0;i<indexFields.size();++i)
    {
        // Put the name of the field in the first column
        QTableWidgetItem* name = new QTableWidgetItem(indexFields.at(i)->name());
        Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
        if(indexFields.at(i)->expression())
            flags |= Qt::ItemIsEditable;
        name->setFlags(flags);
        ui->tableIndexColumns->setItem(i, 0, name);

        // And put a combobox to select the order in which to index the field in the last column
        QComboBox* order = new QComboBox(this);
        order->addItem("");
        order->addItem("ASC");
        order->addItem("DESC");
        order->setCurrentText(indexFields.at(i)->order().toUpper());
        ui->tableIndexColumns->setCellWidget(i, 1, order);
        connect(order, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged),
                [=](QString new_order)
        {
            int colnum = index.findColumn(indexFields.at(i)->name());
            if(colnum != -1)
            {
                index.column(colnum)->setOrder(new_order);
                updateSqlText();
            }
        });
    }
    ui->tableIndexColumns->blockSignals(false);

    checkInput();
}
Example #25
0
void ComboBoxItemDelegate::setEditorData(QWidget *editor,
                                         const QModelIndex &index) const {
     QComboBox *combo = qobject_cast<QComboBox*>(editor);
     QString text = index.data(Qt::EditRole).toString();
     combo->setCurrentText(text);
}
Example #26
0
QString AddImagesDialog::getDirectory(const QStringList &fileNames, const QString &defaultDirectory)
{
    QDialog *dialog = new QDialog(Core::ICore::dialogParent());
    dialog->setMinimumWidth(480);

    QString result;
    QString directory = defaultDirectory;

    dialog->setModal(true);
    dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
    dialog->setWindowTitle(QCoreApplication::translate("AddImageToResources","Add Resources"));
    QTableWidget *table = createFilesTable(fileNames);
    table->setParent(dialog);
    QGridLayout *mainLayout = new QGridLayout(dialog);
    mainLayout->addWidget(table, 0, 0, 1, 4);

    QComboBox *directoryComboBox = createDirectoryComboBox(defaultDirectory);

    auto setDirectoryForComboBox = [directoryComboBox, &directory](const QString &newDir) {
        if (directoryComboBox->findText(newDir) < 0)
            directoryComboBox->addItem(newDir);

        directoryComboBox->setCurrentText(newDir);
        directory = newDir;
    };

    QObject::connect(directoryComboBox, &QComboBox::currentTextChanged, dialog, [&directory](const QString &text){
       directory = text;
    });

    QPushButton *browseButton = new QPushButton(QCoreApplication::translate("AddImageToResources", "&Browse..."), dialog);

    QObject::connect(browseButton, &QPushButton::clicked, dialog, [setDirectoryForComboBox, &directory]() {
        const QString newDir = QFileDialog::getExistingDirectory(Core::ICore::dialogParent(),
                                                              QCoreApplication::translate("AddImageToResources", "Target Directory"),
                                                              directory);
        if (!newDir.isEmpty())
            setDirectoryForComboBox(newDir);
    });

    mainLayout->addWidget(new QLabel(QCoreApplication::translate("AddImageToResources", "In directory:")), 1, 0);
    mainLayout->addWidget(directoryComboBox, 1, 0, 1, 3);
    mainLayout->addWidget(browseButton, 1, 3, 1 , 1);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                       | QDialogButtonBox::Cancel);

    mainLayout->addWidget(buttonBox, 3, 2, 1, 2);

    QObject::connect(buttonBox, &QDialogButtonBox::accepted, dialog, [dialog](){
        dialog->accept();
        dialog->deleteLater();
    });

    QObject::connect(buttonBox, &QDialogButtonBox::rejected, dialog, [dialog, &directory](){
        dialog->reject();
        dialog->deleteLater();
        directory = QString();
    });

    QObject::connect(dialog, &QDialog::accepted, [&directory, &result](){
        result = directory;
    });

    dialog->exec();

    return result;
}
void VisualizationWorkstationExtensionPlugin::setDefaultVisualizationParameters(std::shared_ptr<MultiResolutionImage> img) {
  if (_dockWidget) {
    double maxValue = img->getMaxValue(_foregroundChannel);
    double minValue = img->getMinValue(_foregroundChannel);
    if (_settings) {
      _settings->beginGroup("VisualizationWorkstationExtensionPlugin");
      pathology::DataType dtype = img->getDataType();
      if (dtype == pathology::Float) {
        _settings->beginGroup("VisualizationSettingsForFloatType");
      }
      else if (dtype == pathology::UChar) {
        _settings->beginGroup("VisualizationSettingsForUCharType");
      }
      else if (dtype == pathology::UInt16) {
        _settings->beginGroup("VisualizationSettingsForUInt16Type");
      }
      else if (dtype == pathology::UInt32) {
        _settings->beginGroup("VisualizationSettingsForUInt32Type");
      }
      _opacity = _settings->value("opacity", 0.5).toFloat();
      _foregroundChannel = _settings->value("foregroundchannel", 0).toUInt();
      if (_foregroundChannel >= img->getSamplesPerPixel()) {
        _foregroundChannel = 0;
      }
      _window = _settings->value("window", maxValue - minValue).toDouble();
      _level = _settings->value("level", (maxValue + minValue) / 2).toDouble();
      if (dtype == pathology::Float) {
        _currentLUT = _settings->value("lut", "Traffic Light").toString();
      }
      else {
        _currentLUT = _settings->value("lut", "Label").toString();
      }
      _renderingEnabled = _settings->value("visible", false).toBool();
      _settings->endGroup();
      _settings->endGroup();
    }
    else {
      _opacity = 0.5;
      _foregroundChannel = 0;
      _window = maxValue - minValue;
      _level = (maxValue + minValue) / 2;
      if (img->getDataType() == pathology::UChar || img->getDataType() == pathology::UInt32 || img->getDataType() == pathology::UInt16) {
        _currentLUT = "Label";
      }
      else {
        _currentLUT = "Traffic Light";
      }
    }
    QDoubleSpinBox* spinBox = _dockWidget->findChild<QDoubleSpinBox*>("OpacitySpinBox");
    spinBox->setValue(_opacity);
    _viewer->setForegroundOpacity(_opacity);
    QSpinBox* channelSpinBox = _dockWidget->findChild<QSpinBox*>("ChannelSpinBox");
    channelSpinBox->setMaximum(_foreground->getSamplesPerPixel() - 1);
    channelSpinBox->setValue(_foregroundChannel);
    _viewer->setForegroundChannel(_foregroundChannel);

    QDoubleSpinBox* windowSpinBox = _dockWidget->findChild<QDoubleSpinBox*>("WindowSpinBox");
    windowSpinBox->setValue(_window);
    QDoubleSpinBox* levelSpinBox = _dockWidget->findChild<QDoubleSpinBox*>("LevelSpinBox");
    levelSpinBox->setValue(_level);
    _viewer->setForegroundWindowAndLevel(_window, _level);
    QComboBox* LUTBox = _dockWidget->findChild<QComboBox*>("LUTComboBox");
    LUTBox->setCurrentText(_currentLUT);
    _viewer->setForegroundLUT(_currentLUT.toStdString());
  }
}
Example #28
0
File: main.cpp Project: tynn/H4KvT
int main(int argc, char **argv)
{
	Vals vals;

	/* the application */
	QApplication app(argc, argv);
	app.setApplicationName(APP_NAME);
	app.setWindowIcon(QIcon(":/icon"));
	Window window;

	/* translations */
	QTranslator qtr;
	if (qtr.load("qt_" + QLocale::system().name(), QTR_PATH))
		app.installTranslator(&qtr);

	QTranslator htr;
	if (htr.load("H4KvT_" + QLocale::system().name(), ":/"))
		app.installTranslator(&htr);

	/* display information */
	QTextEdit *text = new QTextEdit;
	text->setReadOnly(true);
	text->setLineWrapMode(QTextEdit::NoWrap);
	text->setToolTip(Window::tr("Drop any file for hashing"));
	QObject::connect(&window, &Window::idle, text, &QWidget::setEnabled);

	/* compare hash */
	QLineEdit *test = new QLineEdit;
	HexVal hexval;
	test->setValidator(&hexval);
	test->installEventFilter(&window);
	test->setToolTip(Window::tr("Compare hashes"));

	QObject::connect(test, &QLineEdit::textChanged,
		[&](const QString &newValue) { if (vals.name != "") {
			std::string hashVal = newValue.toStdString();
			std::transform(hashVal.begin(), hashVal.end(), hashVal.begin(), ::tolower);
			std::stringstream html;
			if (hashVal != "")
				html << "<style>.h" << hashVal << "{color:green}</style>";
			html << "<div style='margin-bottom:2; font-size:27px'><i><b>" << vals.name << "</b></i></div>";
			html << "<div style='margin-bottom:7; margin-left:23; font-size:13px'>" << vals.path << "</div>";
			if (!ALL(vals,"")) {
				html << "<div style='font-size:13px'><table>";
				if (vals.md5 != "")
					html << "<tr><td>md5: </td><td class='h" << vals.md5 << "'>" << vals.md5 << "</td</tr>";
				if (vals.sha1 != "")
					html << "<tr><td>sha1: </td><td class='h" << vals.sha1 << "'>" << vals.sha1 << "</td</tr>";
				if (vals.sha224 != "")
					html << "<tr><td>sha224: </td><td class='h" << vals.sha224 << "'>" << vals.sha224 << "</td</tr>";
				if (vals.sha256 != "")
					html << "<tr><td>sha256: </td><td class='h" << vals.sha256 << "'>" << vals.sha256 << "</td</tr>";
				if (vals.sha384 != "")
					html << "<tr><td>sha384: </td><td class='h" << vals.sha384 << "'>" << vals.sha384 << "</td</tr>";
				if (vals.sha512 != "")
					html << "<tr><td>sha512: </td><td class='h" << vals.sha512 << "'>" << vals.sha512 << "</td</tr>";
				html << "</table></div>";
			}
			int horizontal = text->horizontalScrollBar()->value();
			int vertical = text->verticalScrollBar()->value();
			text->setHtml(QString::fromStdString(html.str()));
			text->horizontalScrollBar()->setValue(horizontal);
			text->verticalScrollBar()->setValue(vertical);
			test->setStyleSheet(ANY(vals,hashVal) ? "color:green" : "");
		}});

	/* error messages */
	QLabel *error = new QLabel;
	error->setStyleSheet("color:red");

	/* test or error */
	QStackedWidget *stack = new QStackedWidget;
	delete stack->layout();
	stack->setLayout(new Stack);
	stack->addWidget(error);
	stack->addWidget(test);
	stack->setCurrentIndex(1);

	/* toggle test or error */
	QPushButton *hash = new QPushButton(QIcon(":/icon"), "");
	hash->setCheckable(true);
	hash->setChecked(true);
	hash->setToolTip(Window::tr("Compare hashes"));
	QObject::connect(hash, &QPushButton::toggled, stack, &QStackedWidget::setCurrentIndex);

	/* store method */
	QSettings settings("H4KvT", "H4KvT");

	/* more methods */
	bool more;
	try {
		settings.setValue("MoreHashingMethods", more = moreOrLess());
	} catch (...) {
		more = settings.value("MoreHashingMethods", false).toBool();
	}

	/* hashing method */
	QComboBox *meth = new QComboBox;
	meth->addItem("md5");
	meth->addItem("sha1");
	if (more) meth->addItem("sha224");
	meth->addItem("sha256");
	if (more) meth->addItem("sha384");
	meth->addItem("sha512");
	meth->setToolTip(Window::tr("Hashing method"));
	meth->setCurrentText(settings.value("HashingMethod", "md5").toString());
	QObject::connect(&window, &Window::idle, meth, &QWidget::setEnabled);

	QObject::connect(meth, &QComboBox::currentTextChanged,
		[&](const QString &text) { settings.setValue("HashingMethod", text); });

	/* toolbar */
	QHBoxLayout *pane = new QHBoxLayout;
	pane->addWidget(hash, 0, Qt::AlignLeft);
	pane->addWidget(stack);
	pane->addWidget(meth, 0, Qt::AlignRight);

	/* main layout */
	QVBoxLayout *layout = new QVBoxLayout;
	layout->addWidget(text);
	layout->addLayout(pane);

	/* the window */
	window.centralWidget()->setLayout(layout);
	window.show();

	/* future hashing */
	QFutureWatcher<Vals> zu;
	QObject::connect(&zu, &QFutureWatcher<Vals>::finished,
		[&]() {
			Vals valsi = zu.future().result();
			window.idle(true);
			if (valsi.path == "") {
				error->setText(QString::fromStdString(valsi.name));
				hash->setChecked(false);
			} else {
				error->clear();
				vals += valsi;
				test->textChanged(test->text());
			}
		});

	QObject::connect(meth, &QComboBox::currentTextChanged,
		[&](const QString &text) { if (vals.name != "") {
			window.idle(false);
			zu.setFuture(QtConcurrent::run(&update, text, vals));
		}});

	QObject::connect(&window, &Window::fileDroped,
		[&](const QString &name, const QString &path) {
			window.idle(false);
			zu.setFuture(QtConcurrent::run(&update, meth->currentText(), Vals(name, path)));
		});

	/* hashing info */
	QGraphicsBlurEffect blur;
	blur.setBlurHints(QGraphicsBlurEffect::AnimationHint);

	QPropertyAnimation anim(&blur, "blurRadius");
	anim.setDuration(2000);
	anim.setLoopCount(-1);
	anim.setKeyValueAt(0, 0);
	anim.setKeyValueAt(0.5, 3);
	anim.setKeyValueAt(1, 0);

	QLabel *hashing = new QLabel;
	hashing->setPixmap(QPixmap(":/icon"));
	hashing->setAttribute(Qt::WA_TransparentForMouseEvents);
	hashing->setGraphicsEffect(&blur);
	hashing->hide();
	(new QHBoxLayout(text))->addWidget(hashing, 0, Qt::AlignCenter);

	QObject::connect(&blur, &QGraphicsBlurEffect::blurRadiusChanged,
		hashing, static_cast<void(QWidget::*)()>(&QWidget::update));

	QObject::connect(&window, &Window::idle,
		[&](bool idle) {
			if (idle) {
				hashing->hide();
				anim.stop();
			} else {
				hashing->show();
				anim.start();
			}
		});

	/* about app */
	QMenu about;
	QAction *action = about.addAction(QIcon(":/icon"), Window::tr("About %1").arg(APP_NAME));
	action->setMenuRole(QAction::AboutRole);
	QObject::connect(action, &QAction::triggered, &window, &Window::about);

	error->setContextMenuPolicy(Qt::NoContextMenu);
	hash->setContextMenuPolicy(Qt::NoContextMenu);
	meth->setContextMenuPolicy(Qt::NoContextMenu);
	window.setContextMenuPolicy(Qt::CustomContextMenu);
	QObject::connect(&window, &QWidget::customContextMenuRequested,
		[&about, &window](const QPoint &pos) { about.popup(window.mapToGlobal(pos)); });

	text->setContextMenuPolicy(Qt::CustomContextMenu);
	QObject::connect(text, &QWidget::customContextMenuRequested,
		[action, text](const QPoint &pos) {
			if (QMenu *m = text->createStandardContextMenu()) {
				m->insertAction(m->insertSeparator(m->actions()[0]), action);
				m->popup(text->mapToGlobal(pos));
			}
		});

	test->setContextMenuPolicy(Qt::CustomContextMenu);
	QObject::connect(test, &QWidget::customContextMenuRequested,
		[action, test](const QPoint &pos) {
			if (QMenu *m = test->createStandardContextMenu()) {
				m->insertAction(m->insertSeparator(m->actions()[0]), action);
				m->popup(test->mapToGlobal(pos));
			}
		});

	return app.exec();
}
Example #29
0
EditorDialog::EditorDialog(QWidget * parent, osm::EditableMapObject & emo)
  : QDialog(parent), m_feature(emo)
{
  QGridLayout * grid = new QGridLayout();
  int row = 0;

  {  // Coordinates.
    ms::LatLon const ll = emo.GetLatLon();
    grid->addWidget(new QLabel("Latitude/Longitude:"), row, 0);
    QHBoxLayout * coords = new QHBoxLayout();
    coords->addWidget(new QLabel(QString::fromStdString(strings::to_string_dac(ll.lat, 7) + " " +
                                                        strings::to_string_dac(ll.lon, 7))));
    grid->addLayout(coords, row++, 1);
  }

  {  // Feature types.
    grid->addWidget(new QLabel("Type:"), row, 0);
    string localized = m_feature.GetLocalizedType();
    string const raw = DebugPrint(m_feature.GetTypes());
    if (!strings::EqualNoCase(localized, raw))
      localized += " (" + raw + ")";
    QLabel * label = new QLabel(QString::fromStdString(localized));
    label->setTextInteractionFlags(Qt::TextSelectableByMouse);
    grid->addWidget(label, row++, 1);
  }

  if (emo.IsNameEditable())
  {  // Names.
    char const * defaultLangStr =
        StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kDefaultCode);
    // Default name editor is always displayed, even if feature name is empty.
    grid->addWidget(new QLabel(QString("Name:")), row, 0);
    QLineEdit * defaultName = new QLineEdit();
    defaultName->setObjectName(defaultLangStr);
    QGridLayout * namesGrid = new QGridLayout();
    int namesRow = 0;
    namesGrid->addWidget(defaultName, namesRow++, 0, 1, 0);

    auto const namesDataSource = emo.GetNamesDataSource();

    for (auto const & ln : namesDataSource.names)
    {
      if (ln.m_code == StringUtf8Multilang::kDefaultCode)
      {
        defaultName->setText(QString::fromStdString(ln.m_name));
      }
      else
      {
        char const * langStr = StringUtf8Multilang::GetLangByCode(ln.m_code);
        namesGrid->addWidget(new QLabel(ln.m_lang), namesRow, 0);
        QLineEdit * lineEditName = new QLineEdit(QString::fromStdString(ln.m_name));
        lineEditName->setReadOnly(!emo.IsNameEditable());
        lineEditName->setObjectName(langStr);
        namesGrid->addWidget(lineEditName, namesRow++, 1);
      }
    }
    grid->addLayout(namesGrid, row++, 1);
  }

  if (emo.IsAddressEditable())
  {  // Address rows.
    auto nearbyStreets = emo.GetNearbyStreets();
    grid->addWidget(new QLabel(kStreetObjectName), row, 0);
    QComboBox * cmb = new QComboBox();
    cmb->setEditable(true);

    if (emo.GetStreet().m_defaultName.empty())
      cmb->addItem("");

    for (int i = 0; i < nearbyStreets.size(); ++i)
    {
      string street = nearbyStreets[i].m_defaultName;
      if (!nearbyStreets[i].m_localizedName.empty())
        street += " / " + nearbyStreets[i].m_localizedName;
      cmb->addItem(street.c_str());
      if (emo.GetStreet() == nearbyStreets[i])
        cmb->setCurrentIndex(i);
    }
    cmb->setObjectName(kStreetObjectName);
    grid->addWidget(cmb, row++, 1);

    grid->addWidget(new QLabel(kHouseNumberObjectName), row, 0);
    QLineEdit * houseLineEdit = new QLineEdit(emo.GetHouseNumber().c_str());
    houseLineEdit->setObjectName(kHouseNumberObjectName);
    grid->addWidget(houseLineEdit, row++, 1);

    grid->addWidget(new QLabel(kPostcodeObjectName), row, 0);
    QLineEdit * postcodeEdit = new QLineEdit(QString::fromStdString(emo.GetPostcode()));
    postcodeEdit->setObjectName(kPostcodeObjectName);
    grid->addWidget(postcodeEdit, row++, 1);
  }

  // Editable metadata rows.
  for (osm::Props const prop : emo.GetEditableProperties())
  {
    string v;
    switch (prop)
    {
    case osm::Props::Phone: v = emo.GetPhone(); break;
    case osm::Props::Fax: v = emo.GetFax(); break;
    case osm::Props::Email: v = emo.GetEmail(); break;
    case osm::Props::Website: v = emo.GetWebsite(); break;
    case osm::Props::Internet:
      {
        grid->addWidget(new QLabel(kInternetObjectName), row, 0);
        QComboBox * cmb = new QComboBox();
        string const values[] = {DebugPrint(osm::Internet::Unknown), DebugPrint(osm::Internet::Wlan),
                                 DebugPrint(osm::Internet::Wired), DebugPrint(osm::Internet::Yes),
                                 DebugPrint(osm::Internet::No)};
        for (auto const & v : values)
          cmb->addItem(v.c_str());
        cmb->setCurrentText(DebugPrint(emo.GetInternet()).c_str());
        cmb->setObjectName(kInternetObjectName);
        grid->addWidget(cmb, row++, 1);
      }
      continue;
    case osm::Props::Cuisine: v = strings::JoinStrings(emo.GetLocalizedCuisines(), ", "); break;
    case osm::Props::OpeningHours: v = emo.GetOpeningHours(); break;
    case osm::Props::Stars: v = strings::to_string(emo.GetStars()); break;
    case osm::Props::Operator: v = emo.GetOperator(); break;
    case osm::Props::Elevation:
      {
        double ele;
        if (emo.GetElevation(ele))
          v = strings::to_string_dac(ele, 2);
      }
      break;
    case osm::Props::Wikipedia: v = emo.GetWikipedia(); break;
    case osm::Props::Flats: v = emo.GetFlats(); break;
    case osm::Props::BuildingLevels: v = emo.GetBuildingLevels(); break;
    }
    QString const fieldName = QString::fromStdString(DebugPrint(prop));
    grid->addWidget(new QLabel(fieldName), row, 0);
    QLineEdit * lineEdit = new QLineEdit(QString::fromStdString(v));
    // Mark line editor to query it's text value when editing is finished.
    lineEdit->setObjectName(fieldName);
    grid->addWidget(lineEdit, row++, 1);
  }

  {  // Dialog buttons.
    QDialogButtonBox * buttonBox =
        new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Save);
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(OnSave()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    // Delete button should send custom int return value from dialog.
    QPushButton * deletePOIButton = new QPushButton("Delete POI");
    QSignalMapper * signalMapper = new QSignalMapper();
    connect(deletePOIButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
    signalMapper->setMapping(deletePOIButton, QDialogButtonBox::DestructiveRole);
    connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(done(int)));
    buttonBox->addButton(deletePOIButton, QDialogButtonBox::DestructiveRole);
    grid->addWidget(buttonBox, row++, 1);
  }

  setLayout(grid);
  setWindowTitle("OSM Editor");
}
Example #30
0
void Data3DTreeDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{
    const Data3DTreeModel* pData3DTreeModel = static_cast<const Data3DTreeModel*>(index.model());
    const AbstractTreeItem* pAbstractItem = static_cast<const AbstractTreeItem*>(pData3DTreeModel->itemFromIndex(index));

    switch(pAbstractItem->type()) {
        case MetaTreeItemTypes::SurfaceColorGyri: {
            QColor color = index.model()->data(index, MetaTreeItemRoles::SurfaceColorGyri).value<QColor>();
            QColorDialog* pColorDialog = static_cast<QColorDialog*>(editor);
            pColorDialog->setCurrentColor(color);
            break;
        }

        case MetaTreeItemTypes::SurfaceColorSulci: {
            QColor color = index.model()->data(index, MetaTreeItemRoles::SurfaceColorSulci).value<QColor>();
            QColorDialog* pColorDialog = static_cast<QColorDialog*>(editor);
            pColorDialog->setCurrentColor(color);
            break;
        }

        case MetaTreeItemTypes::RTDataColormapType: {
            QString colormap = index.model()->data(index, MetaTreeItemRoles::RTDataColormapType).toString();
            QComboBox* pComboBox = static_cast<QComboBox*>(editor);
            pComboBox->setCurrentText(colormap);
            break;
        }

        case MetaTreeItemTypes::RTDataNormalizationValue: {
            Spline* pSpline = static_cast<Spline*>(editor);
            int width = pSpline->size().width();
            int height = pSpline->size().height();
            if (pSpline->size().width() < 200 && pSpline->size().height() < 200)
            {
                pSpline->resize(600,400);   //resize histogram to be readable with default size
            }
            else
            {
                width = pSpline->size().width();   //keeps the size of the histogram
                height = pSpline->size().height();
                pSpline->resize(width,height);
            }
            return;
        }

        case MetaTreeItemTypes::RTDataTimeInterval: {
            int value = index.model()->data(index, MetaTreeItemRoles::RTDataTimeInterval).toInt();
            QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor);
            pSpinBox->setValue(value);
            break;
        }

        case MetaTreeItemTypes::RTDataVisualizationType: {
            QString visType = index.model()->data(index, MetaTreeItemRoles::RTDataVisualizationType).toString();
            QComboBox* pComboBox = static_cast<QComboBox*>(editor);
            pComboBox->setCurrentText(visType);
            break;
        }

        case MetaTreeItemTypes::SurfaceColor: {
            QColor color = index.model()->data(index, MetaTreeItemRoles::SurfaceColor).value<QColor>();
            QColorDialog* pColorDialog = static_cast<QColorDialog*>(editor);
            pColorDialog->setCurrentColor(color);
            break;
        }

        case MetaTreeItemTypes::PointColor: {
            QColor color = index.model()->data(index, MetaTreeItemRoles::PointColor).value<QColor>();
            QColorDialog* pColorDialog = static_cast<QColorDialog*>(editor);
            pColorDialog->setCurrentColor(color);
            break;
        }

        case MetaTreeItemTypes::RTDataNumberAverages: {
            int value = index.model()->data(index, MetaTreeItemRoles::RTDataNumberAverages).toInt();
            QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor);
            pSpinBox->setValue(value);
            break;
        }

        case MetaTreeItemTypes::SurfaceAlpha: {
            int value = index.model()->data(index, MetaTreeItemRoles::SurfaceAlpha).toDouble();
            QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor);
            pSpinBox->setValue(value);
            break;
        }

        case MetaTreeItemTypes::SurfaceTranslateX: {
            double value = index.model()->data(index, MetaTreeItemRoles::SurfaceTranslateX).toDouble();
            QDoubleSpinBox* pDoubleSpinBox = static_cast<QDoubleSpinBox*>(editor);
            pDoubleSpinBox->setValue(value);
            break;
        }

        case MetaTreeItemTypes::SurfaceTranslateY: {
            double value = index.model()->data(index, MetaTreeItemRoles::SurfaceTranslateY).toDouble();
            QDoubleSpinBox* pDoubleSpinBox = static_cast<QDoubleSpinBox*>(editor);
            pDoubleSpinBox->setValue(value);
            break;
        }

        case MetaTreeItemTypes::SurfaceTranslateZ: {
            double value = index.model()->data(index, MetaTreeItemRoles::SurfaceTranslateZ).toDouble();
            QDoubleSpinBox* pDoubleSpinBox = static_cast<QDoubleSpinBox*>(editor);
            pDoubleSpinBox->setValue(value);
            break;
        }        

        case MetaTreeItemTypes::NetworkThreshold: {
            Spline* pSpline = static_cast<Spline*>(editor);
            int width = pSpline->size().width();
            int height = pSpline->size().height();
            if (pSpline->size().width() < 200 && pSpline->size().height() < 200)   //pSpline initializes with size (137,15)
            {
                pSpline->resize(800,600);   //resize histogram to be readable with default size
            }
            else
            {
                width = pSpline->size().width();   //keeps the size of the histogram
                height = pSpline->size().height();
                pSpline->resize(width,height);
            }
            return;
        }

        default: // do nothing;
            break;
    }

    QItemDelegate::setEditorData(editor, index);
}