QWidget* NMGPropertyEditorDelegate::createEditor(QWidget* parent,
                                                 const QStyleOptionViewItem& option,
                                                 const QModelIndex& index) const
{
  Q_UNUSED(option);
  QWidget* editor = 0;
  if(index.column() == 1)
  {
    const QTreeWidgetItem* property = static_cast<QTreeWidgetItem*>(index.internalPointer());
    int valueType = property->data(1, Qt::EditRole).type();
    QString propertyName = property->text(0);
    switch(valueType)
    {
      case QVariant::Bool:
      {
        QComboBox* combo = new QComboBox(parent);
        combo->setFrame(FALSE);
        combo->addItems(QStringList() << QString::fromUtf8("false") << QString::fromUtf8("true"));
        QObject::connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(sync()));
        editor = combo;
        break;
      }
      
      case QVariant::String:
      {
        if(propertyName == "fontFamily")
        {
          QFontDatabase fdb;
          QStringList list = fdb.families(QFontDatabase::Latin);
          QStringList result;
          for(int i = 0; i < list.size(); i++) 
          {
            if(fdb.isScalable(list.at(i))) result += list.at(i);
          }
          QComboBox* combo = new QComboBox(parent);
          combo->setFrame(FALSE);
          combo->addItems(result);
          QObject::connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(sync()));
          editor = combo;
        }
        else if(propertyName == "representation")
        {
          QComboBox* combo = new QComboBox(parent);
          combo->setFrame(FALSE);
          QStringList list;
          list << LINE_TYPE << AREA_TYPE << POINTS_TYPE << BARS_TYPE;
          combo->addItems(list);
          QObject::connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(sync()));
          editor = combo;
        }
        else if(propertyName == "position")
QWidget *ComboboxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
{
  QComboBox *editor = new QComboBox(parent);
  editor->setFrame(false);
  editor->setModel(modelFromIndex(index));
  return editor;
}
QWidget *BoolProperty::createEditor(QWidget *parent, const QObject *target, const char *receiver) const
{
	QComboBox *combo = new QComboBox(parent);
	combo->view()->setTextElideMode(Qt::ElideLeft);
	combo->setFrame(0);
	combo->addItems(QStringList() << QString::fromUtf8("false") << QString::fromUtf8("true"));
	QObject::connect(combo, SIGNAL(activated(int)), target, receiver);

	return combo;
}
QWidget* DelegatDanych::createEditor(QWidget *parent,const QStyleOptionViewItem &option,const QModelIndex &index) const {
    QString field = index.model()->headerData(index.column(), Qt::Horizontal).toString();

    // te 3 nizej polaczyc w jedno : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if (field == "Wiek" ) {
        QSpinBox* editor = new QSpinBox(parent);
        editor->setFrame(true);
        editor->setMinimum(1);
        editor->setMaximum(100);
        return editor;
    }
    if (field == "Nr domu" ) {
        QSpinBox* editor = new QSpinBox(parent);
        editor->setFrame(true);
        editor->setMinimum(1);
        editor->setMaximum(100);
        return editor;
    }
    if(field == "ID psa" || field == "ID klienta") {
        QSpinBox* editor = new QSpinBox(parent);
        editor->setFrame(true);
        editor->setMinimum(1);
        editor->setMaximum(100);
        //editor->setSingleStep(100);
        return editor;
    }
    if (field == "Numer Telefonu ") {
        QLineEdit* editor = new QLineEdit(parent);
        QRegExp phoneFormat("([1-9]\\d\\d)-(\\d{3})-(\\d{3})");
        QRegExpValidator* phoneValid(new QRegExpValidator(phoneFormat));
        editor->setValidator(phoneValid);
        return editor;
    }
    if(field == "Kategoria") {
        QComboBox* editor = new QComboBox(parent);
        editor->setFrame(true);
        QStringList kategorie;
        kategorie << "Nieokreślony" << "Łagodny" << "Agresywny" << "Do domu" << "Na podwórko";
        editor->addItems(kategorie);
        return editor;
    }
    return QItemDelegate::createEditor(parent, option, index);
}
Example #5
0
QWidget *ComboBoxDelegate::createEditor(QWidget *parent,
		const QStyleOptionViewItem& option,
		const QModelIndex& index) const
{
	Position c = index.column();

	if (c >= 2) return QItemDelegate::createEditor(parent, option, index);

	QComboBox* editor = new QComboBox(parent);

	if (c == 0) editor->addItems(sl_modifier_);
	else 			 editor->addItems(sl_keys_);

	editor->setEditable(false);
	editor->setFrame(false);
	editor->setDuplicatesEnabled(false);

	editor->installEventFilter(const_cast<ComboBoxDelegate*>(this));
	editor->showPopup();
	return editor;
}
Example #6
0
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
    const QStyleOptionViewItem &/* option */,
    const QModelIndex &index ) const
{   srand(time(0));
    if(index.column() == 2){
        QComboBox *box = new QComboBox(parent);
        QStringList str;
        QString strpart("8-");
        for(unsigned int i(0); i < 10; i++){
            str << strpart +QString::number(rand() %888 + 111) + "-"+QString::number(rand() %888 + 111)+"-" + QString::number(rand() %88+11)+"-"+ QString::number(rand() %88+11);
        }
        box->addItems(str);
        box->setFrame(false);
        return box;
    }
    QLineEdit *editor = new QLineEdit(parent);
    editor->setFrame(false);
    //editor->setMinimum(0);
    //editor->setMaximum(1000);

    return editor;
}
Example #7
0
QWidget* ActionItemEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
					  const QModelIndex &index) const
{	
	QWidget* editor = NULL;
	switch(index.column())
	{
		case COLUMN_ACTION_TYPE:
		{
			QComboBox* combo = new QComboBox(parent);
			combo->setFrame(false);
			for(int i = 1; i < ACTION_NAME_COUNT - 1; ++i) //do not add sound aciton
			{
				combo->addItem(ACTION_TYPE_NAME[i]);
			}
			
			editor = combo;
			
			break;
		}
			
		case COLUMN_ENTITY_NAME:
		{
			DAVA::Entity* parentEntity = targetComponent->GetEntity();
			DAVA::Vector<DAVA::Entity*> allChildren;
			parentEntity->GetChildNodes(allChildren);

			DAVA::Vector<DAVA::String> childrenNames;
			childrenNames.push_back(parentEntity->GetName());
			for(int i = 0; i < allChildren.size(); ++i)
			{
				childrenNames.push_back(allChildren[i]->GetName());
			}
			
			std::sort(childrenNames.begin(), childrenNames.end());
			childrenNames.erase(std::unique(childrenNames.begin(), childrenNames.end()), childrenNames.end());
			
			QComboBox* combo = new QComboBox(parent);
			combo->setFrame(false);
			for(int i = 0; i < childrenNames.size(); ++i)
			{
				combo->addItem(childrenNames[i].c_str());
			}
			
			editor = combo;
			
			break;
		}
			
		case COLUMN_DELAY:
		{
			QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
			spinBox->setMinimum(0.0f);
			spinBox->setMaximum(3600.f);
			spinBox->setSingleStep(0.01f);
			
			editor = spinBox;
			
			break;
		}
			
		case COLUMN_SWITCH_INDEX:
		{
			QSpinBox* spinBox = new QSpinBox(parent);
			spinBox->setMinimum(-1);
			spinBox->setMaximum(128);
			spinBox->setSingleStep(1);
			
			editor = spinBox;

			break;
		}
			
		case COLUMN_STOPAFTERNREPEATS_INDEX:
		{
			QSpinBox* spinBox = new QSpinBox(parent);
			spinBox->setMinimum(-1);
			spinBox->setMaximum(100000);
			spinBox->setSingleStep(1);
			
			editor = spinBox;
			
			break;
		}

		case COLUMN_STOPWHENEMPTY_INDEX:
		{
			QComboBox* combo = new QComboBox(parent);
			combo->setFrame(false);
			combo->addItem("Yes");
			combo->addItem("No");
			
			editor = combo;
			break;
		}
	}

	DVASSERT(editor);
	return editor;
}
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;
}
QWidget* GCF::Components::EnumEditorCreator::createEditor(QWidget* parent)
{
    QComboBox* combo = new QComboBox(parent);
    combo->setFrame(false);
    return combo;
}
Example #10
0
QWidget* RelationDelegate::createEditor(QWidget *parent,
										const QStyleOptionViewItem &option,
										const QModelIndex &index) const
{
	QWidget* e;

	switch (index.column()) {
		case COLUMN_CATEGORY:
		{
			QComboBox *editor = new QComboBox(parent);
			editor->setFrame(false);

			QSqlQuery query;
			query.exec("SELECT id, name FROM category ORDER BY name ASC");
			while (query.next()) {
				int id = query.value(0).toInt();
				QString name = query.value(1).toString();
				editor->addItem(name, QVariant(id));
			}
			e = editor;
			break;
		}
		case COLUMN_FOOTPRINT:
		{
			QComboBox *editor = new QComboBox(parent);
			editor->setFrame(false);

			QSqlQuery query;
			query.exec("SELECT id, name FROM footprint ORDER BY name ASC");
			while (query.next()) {
				int id = query.value(0).toInt();
				QString name = query.value(1).toString();
				editor->addItem(name, QVariant(id));
			}
			e = editor;
			break;
		}
		case COLUMN_TEMP:
		{
			QComboBox *editor = new QComboBox(parent);
			editor->setFrame(false);

			QSqlQuery query;
			query.exec("SELECT id, name FROM temp ORDER BY name ASC");
			while (query.next()) {
				int id = query.value(0).toInt();
				QString name = query.value(1).toString();
				editor->addItem(name, QVariant(id));
			}
			e = editor;
			break;
		}
		case COLUMN_SUPPL:
		{
			QComboBox *editor = new QComboBox(parent);
			editor->setFrame(false);

			QSqlQuery query;
			query.exec("SELECT id, name FROM suppl ORDER BY name ASC");
			while (query.next()) {
				int id = query.value(0).toInt();
				QString name = query.value(1).toString();
				editor->addItem(name, QVariant(id));
			}
			e = editor;
			break;
		}
		case COLUMN_COUNT:
		case COLUMN_PRICE_VOL:
		{
			QSpinBox *editor = new QSpinBox(parent);
			editor->setFrame(false);
			editor->setRange(-1000000, 1000000);
			e = editor;
			break;
		}
		case COLUMN_PRICE:
		{
			QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
			editor->setFrame(false);
			editor->setRange(-1000000.0, 1000000.0);
			editor->setSingleStep(0.1);
			editor->setDecimals(6);
			e = editor;
			break;
		}
		default:
			e = QStyledItemDelegate::createEditor(parent, option, index);
	}

	return e;
}