Example #1
0
QWidget* OperationsDelegate::createEditor(QWidget *parent,
                                          const QStyleOptionViewItem &option,
                                          const QModelIndex &index) const
      {
      const QVariant value = index.data(Qt::EditRole);
      if (value.type() == QVariant::StringList) {     // list of possible values
            const QStringList list = qvariant_cast<QStringList>(value);
            if (!list.isEmpty()) {
                  QWidget *editor = nullptr;

                  if (list[0] == "__MultiValue__") {
                        MultiValueEditor *mv = new MultiValueEditor(list, parent);
                        connect(mv, SIGNAL(okClicked()),
                                this, SLOT(commitAndCloseEditor()));
                        editor = mv;
                        }
                  else if (list[0] == "__TimeSig__") {
                        TimeSigEditor *ts = new TimeSigEditor(list, parent);
                        connect(ts, SIGNAL(okClicked()),
                                this, SLOT(commitAndCloseEditor()));
                        editor = ts;
                        }
                  else {
                        QListWidget *lw = new QListWidget(parent);
                        for (const auto &item: list)
                              lw->addItem(item);
                        connect(lw, SIGNAL(itemClicked(QListWidgetItem*)),
                                this, SLOT(commitAndCloseEditor()));
                        editor = lw;
                        }
                  return editor;
                  }
            }
Example #2
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QWidget *USplata_zaborg_Delegate::createEditor(QWidget *parent,
        const QStyleOptionViewItem &option,
        const QModelIndex &index) const
{
	QSpinBox *spinbox;
    if (index.column() == durationColumn_1) {
        spinbox = new QSpinBox(parent);
        spinbox->setMaximum ( 999999 );
		spinbox->setMinimum ( 1 );
        connect(spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return spinbox;
    }
	else if (index.column() == durationColumn_2){
        QDoubleSpinBox *double_spinbox = new QDoubleSpinBox(parent);
        double_spinbox->setMaximum ( 99999 );
		double_spinbox->setMinimum ( 1 );
        connect(double_spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return double_spinbox;
    }
	else if ((index.column() == durationColumn_3) || (index.column() == durationColumn_5)) {
        spinbox = new QSpinBox(parent);
        spinbox->setMaximum ( 12 );
		spinbox->setMinimum ( 1 );
        connect(spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return spinbox;
    }
	else if ((index.column() == durationColumn_4) || (index.column() == durationColumn_6)) {
        spinbox = new QSpinBox(parent);
        spinbox->setMaximum ( 2100 );
		spinbox->setMinimum ( 2004 );
        connect(spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return spinbox;
    }
    else if (index.column() == durationColumn_7) {
        QSpinBox *spinbox = new QSpinBox(parent);
        spinbox->setMaximum ( 999999 );
		spinbox->setMinimum ( 1 );
        connect(spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return spinbox;
    }
	else{
        return QSqlRelationalDelegate::createEditor(parent, option, index);
    }
}
Example #3
0
//-----------------------------------------------------------------------------
// Function: LineEditDelegate::createEditor()
//-----------------------------------------------------------------------------
QWidget* LineEditDelegate::createEditor(QWidget* parent, QStyleOptionViewItem const&, QModelIndex const&) const
{
	QLineEdit* editor = new QLineEdit(parent);
	connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
	editor->setMinimumHeight(LineEditDelegate::MINIMUM_EDITOR_HEIGHT);
	return editor;
}
Example #4
0
QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
                                          const QStyleOptionViewItem &,
                                          const QModelIndex &index) const
{
    if (index.column() == 1) {
        QDateTimeEdit *editor = new QDateTimeEdit(parent);
        editor->setDisplayFormat("dd/M/yyyy");
        editor->setCalendarPopup(true);
        return editor;
    }

    QLineEdit *editor = new QLineEdit(parent);

    // create a completer with the strings in the column as model
    QStringList allStrings;
    for (int i = 1; i<index.model()->rowCount(); i++) {
        QString strItem(index.model()->data(index.sibling(i, index.column()),
            Qt::EditRole).toString());

        if (!allStrings.contains(strItem))
            allStrings.append(strItem);
    }

    QCompleter *autoComplete = new QCompleter(allStrings);
    editor->setCompleter(autoComplete);
    connect(editor, SIGNAL(editingFinished()),
        this, SLOT(commitAndCloseEditor()));
    return editor;
}
Example #5
0
QWidget* ComInterfacesDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const {
	switch (index.column()) {
		case NAME_COLUMN: 
		case DESCRIPTION_COLUMN: {
			QLineEdit* edit = new QLineEdit(parent);
			connect(edit, SIGNAL(editingFinished()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return edit;
								 }
		case COM_DEF_COLUMN: {
			Q_ASSERT(false);
			return NULL;
							 }
		case TRANSFER_TYPE_COLUMN: {
			QComboBox* combo = new QComboBox(parent);
			return combo;
								   }
		case DIRECTION_COLUMN: {
			QComboBox* combo = new QComboBox(parent);
			combo->addItem(tr("in"));
			combo->addItem(tr("out"));
			combo->addItem(tr("inout"));
			combo->setCurrentIndex(0);
			return combo;
							   }
		default: {
			return QStyledItemDelegate::createEditor(parent, option, index);
				 }
	}
}
Example #6
0
QWidget * AntennaDelegate::createEditor(QWidget * parent,
                                        const QStyleOptionViewItem &/*option*/,
                                        const QModelIndex &index) const
{
	// Are we editing the frequency?
	if(index.column() == frequencyColumn)
	{
		// We set the properties
		QDoubleSpinBox * frequencyEdit = new QDoubleSpinBox(parent);
		frequencyEdit->setAlignment(Qt::AlignRight);
		frequencyEdit->setDecimals(2);
		frequencyEdit->setMinimum(0.0);
		frequencyEdit->setSingleStep(0.01);
		frequencyEdit->setMaximum(20000000000.0);
		// When the editing is finished, changes must be commited
		connect(frequencyEdit,SIGNAL(editingFinished()),
		        this,SLOT(commitAndCloseEditor()));
		return frequencyEdit;
	}
	else
	/*
		If you happen to want the rest of the cells in the item to be editable,
		uncomment the following and comment the other return.
	*/
// 		return QItemDelegate::createEditor(parent,option,index);
		return 0;
}
QWidget *CalendarDelegate::createEditor(QWidget *parent,
                                    const QStyleOptionViewItem& /* option */,
                                    const QModelIndex& /* index */) const {
    QDateEdit *editor = new QDateEdit(parent);
    editor->setCalendarPopup(m_calpopup);
    editor->installEventFilter(const_cast<CalendarDelegate*>(this));
    connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
    return editor;
}
QWidget* EnvIdentifiersDelegate::createEditor( QWidget* parent, 
											  const QStyleOptionViewItem&,
											  const QModelIndex& ) const {

	QLineEdit* editor = new QLineEdit(parent);
	connect(editor, SIGNAL(editingFinished()),
	  this, SLOT(commitAndCloseEditor()));
	return editor;
}
QWidget *SpinDelegate::createEditor(QWidget *parent,
                                     const QStyleOptionViewItem& /* option */,
                                     const QModelIndex& /* index */) const {
    QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
    editor->setMinimum(m_min);
    editor->setMaximum(m_max);
    editor->setDecimals(m_precision);
    editor->setSingleStep(m_step);
    editor->installEventFilter(const_cast<SpinDelegate*>(this));
    QObject::connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
    return editor;
}
Example #10
0
QWidget* StarDelegate::createEditor(QWidget* parent,
                                    const QStyleOptionViewItem& option,
                                    const QModelIndex& index) const {
    // Populate the correct colors based on the styling
    QStyleOptionViewItemV4 newOption = option;
    initStyleOption(&newOption, index);

    StarEditor* editor = new StarEditor(parent, m_pTableView, index, newOption);
    connect(editor, SIGNAL(editingFinished()),
            this, SLOT(commitAndCloseEditor()));
    return editor;
}
 QWidget *Grid_filter_threshold_property_delegate::createEditor(QWidget *parent,
                                     const QStyleOptionViewItem &option,
                                     const QModelIndex &index) const

 {
   Grid_filter_threshold_property_editor* editor = new Grid_filter_threshold_property_editor(grid_, parent);
         connect(editor, SIGNAL(editingFinished()),
                 this, SLOT(commitAndCloseEditor()));

   return editor;

 }
AttributeEditor* AttributeDelegate::NewAttributeEditor(size_t n) const
{
    AttributeEditor* editor = new AttributeEditor(QString("List"));
    editor->SetListSize(n);

    connect(editor,SIGNAL(editingFinished()),
            this,SLOT(commitAndCloseEditor()));

    editor->Initialize();

    return editor;
}
QWidget* QgsComposerColumnSourceDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
  Q_UNUSED( option );
  Q_UNUSED( index );

  QgsFieldExpressionWidget *fieldExpression = new QgsFieldExpressionWidget( parent );
  fieldExpression->setLayer( mVectorLayer );

  //listen out for field changes
  connect( fieldExpression, SIGNAL( fieldChanged( QString ) ), this, SLOT( commitAndCloseEditor() ) );
  return fieldExpression;
}
//! [2]
QWidget *StarDelegate::createEditor(QWidget *parent,
                                    const QStyleOptionViewItem &option,
                                    const QModelIndex &index) const

{
    if (index.data().canConvert<StarRating>()) {
        StarEditor *editor = new StarEditor(parent);
        connect(editor, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return editor;
    } else {
        return QStyledItemDelegate::createEditor(parent, option, index);
    }
}
Example #15
0
QWidget *TrackDelegate::createEditor(QWidget *parent,
        const QStyleOptionViewItem &option,
        const QModelIndex &index) const
{
    if (index.column() == durationColumn) {
        QTimeEdit *timeEdit = new QTimeEdit(parent);
        timeEdit->setDisplayFormat("mm:ss");
        connect(timeEdit, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return timeEdit;
    } else {
        return QItemDelegate::createEditor(parent, option, index);
    }
}
Example #16
0
//-----------------------------------------------------------------------------
// Function: BusInterfacesDelegate::createEditor()
//-----------------------------------------------------------------------------
QWidget* BusInterfacesDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, 
    QModelIndex const& index) const
{
    if (index.column() == BusInterfaceColumns::NAME)
    {
        QLineEdit* edit = new QLineEdit(parent);
        connect(edit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
        return edit;
    }
    else if (index.column() == BusInterfaceColumns::BUSDEF ||
        index.column() == BusInterfaceColumns::ABSDEF) 
    {    		
        Q_ASSERT_X(false, "BusInterfacesDelegate::createEditor()", 
            "Attempting to create editor for non-editable index.");
        return 0;
    }
    else if (index.column() == BusInterfaceColumns::INTERFACE_MODE)
    {
        InterfaceModeSelector* selector = new InterfaceModeSelector(parent); 
        connect(selector, SIGNAL(currentIndexChanged(int)), 
            this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
        return selector;
    }
Example #17
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QWidget *UKvyt_Delegate::createEditor(QWidget *parent,
        const QStyleOptionViewItem &option,
        const QModelIndex &index) const
{
	QSpinBox *spinbox;
    if (index.column() == durationColumn_2) {
        QDoubleSpinBox *double_spinbox = new QDoubleSpinBox(parent);
        double_spinbox->setMaximum ( 999999999 );
		double_spinbox->setMinimum ( -999999999 );
        connect(double_spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return double_spinbox;
    } 
	else if ((index.column() == durationColumn_3) || (index.column() == durationColumn_4)){
        QDateEdit * dateEdit = new QDateEdit(parent);
		QDate date;
		date.setYMD( 2100, 12, 30 );
        dateEdit->setMaximumDate( date );
		date.setYMD( 2004, 1, 1 );
		dateEdit->setMinimumDate( date );
		dateEdit->setDisplayFormat( "d.MM.yyyy" );
        connect(dateEdit, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return dateEdit;
	}
	else if ((index.column() == durationColumn_5) || (index.column() == durationColumn_1)){
        spinbox = new QSpinBox(parent);
        spinbox->setMaximum ( 999999 );
		spinbox->setMinimum ( 1 );
        connect(spinbox, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()));
        return spinbox;
	}
	else{
        return QSqlRelationalDelegate::createEditor(parent, option, index);
    }
}
Example #18
0
QWidget *NotifyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*none*/,
                                            const QModelIndex& index) const
{
    if (eRepeatValue == index.column()) {
        QComboBox* editor = new QComboBox(parent);
        editor->clear();
        editor->addItems(NotificationItem::retryValues);
        return editor;
    } else {
        if (eExpireTimer == index.column()) {
            QSpinBox* editor = new QSpinBox(parent);
            connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
            return editor;
        } else {
            if (eTurnOn == index.column()) {
                QCheckBox* editor = new QCheckBox(parent);
                connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
                return editor;
            }
        }
    }
    QLineEdit *editor = new QLineEdit(parent);
    return editor;
}
QWidget *PhysObjectPropDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem &viewItem, const QModelIndex &index) const {
    //qDebug("PhysObjectPropDelegate::createEditor()");
    QLineEdit *pEdit = new QLineEdit(pParent);

    // create a completer with the strings in the column as model
    QStringList allStrings;
    for (int i = 1; i < index.model() -> rowCount(); i++) {
        QString strItem(index.model() -> data(index.sibling(i, index.column()), Qt::EditRole).toString());
        if (!allStrings.contains(strItem))
            allStrings.append(strItem);
    }
    QCompleter *pAutoComplete = new QCompleter(allStrings);
    pEdit -> setCompleter(pAutoComplete);
    connect(pEdit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
    return pEdit;
}
Example #20
0
QWidget* SystemViewsDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const {
	switch (index.column()) {
		case NAME_COLUMN:
		case DISPLAY_NAME_COLUMN:
		case DESCRIPTION_COLUMN: {
			QLineEdit* edit = new QLineEdit(parent);
			connect(edit, SIGNAL(editingFinished()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return edit;
								 }
		case HIER_REF_COLUMN: {
			Q_ASSERT(false);
			return NULL;
							  }
		default: {
			return QStyledItemDelegate::createEditor(parent, option, index);
				 }
	}
}
Example #21
0
QWidget* CpusDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const {

	switch (index.column()) {
		case CpusDelegate::NAME_COLUMN:
		case CpusDelegate::DISPLAY_NAME_COLUMN:
		case CpusDelegate::DESCRIPTION_COLUMN: {
			QLineEdit* edit = new QLineEdit(parent);
			connect(edit, SIGNAL(editingFinished()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return edit;
											   }
		case CpusDelegate::ADDRSPACE_COLUMN: {
            EnumCollectionEditor* editor = new EnumCollectionEditor(parent);
            return editor;
											 }
		default: {
			return QStyledItemDelegate::createEditor(parent, option, index);
				 }
	}
}
Example #22
0
QWidget* QmitkPropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option
  , const QModelIndex &index) const
{
  QVariant data = index.data(Qt::EditRole);
  QVariant displayData = index.data(Qt::DisplayRole);
  QString name = index.model()->data(index.model()->index(index.row(), index.column()-1)).value<QString>();

  if(data.isValid())
  {

    QWidget* editorWidget = NULL;

    if(data.type() == QVariant::Color)
    {
      QPushButton* colorBtn = new QPushButton(parent);
      QColor color = data.value<QColor>();

      QColor result = QColorDialog::getColor(color);
      if(result.isValid())
      {
        QPalette palette = colorBtn->palette();
        palette.setColor(QPalette::Button, result);
        colorBtn->setPalette(palette);
        colorBtn->setStyleSheet(QString("background-color: %1;foreground-color: %1; border-style: none;").arg(result.name()));
      }
      // QColorDialog closed by 'Cancel' button, use the old property color
      else
      {
        QPalette palette = colorBtn->palette();
        palette.setColor(QPalette::Button, color);
        colorBtn->setPalette(palette);
        colorBtn->setStyleSheet(QString("background-color: %1;foreground-color: %1; border-style: none;").arg(color.name()));

      }

      connect(colorBtn, SIGNAL(pressed()), this, SLOT(commitAndCloseEditor()));

      editorWidget = colorBtn;
    }

    else if(data.type() == QVariant::Int)
    {
      QSpinBox* spinBox = new QSpinBox(parent);
      spinBox->setSingleStep(1);
      spinBox->setMinimum(std::numeric_limits<int>::min());
      spinBox->setMaximum(std::numeric_limits<int>::max());
      editorWidget = spinBox;
    }
    // see qt documentation. cast is correct, it would be obsolete if we
    // store doubles
    else if(static_cast<QMetaType::Type>(data.type()) == QMetaType::Float)
    {
      QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
      spinBox->setDecimals(2);
      spinBox->setSingleStep(0.1);
      if(name == "opacity")
      {
        spinBox->setMinimum(0.0);
        spinBox->setMaximum(1.0);
      }
      else
      {
        spinBox->setMinimum(std::numeric_limits<float>::min());
        spinBox->setMaximum(std::numeric_limits<float>::max());
      }

      editorWidget = spinBox;
    }

    else if(data.type() == QVariant::StringList)
    {
      QStringList entries = data.value<QStringList>();
      QComboBox* comboBox = new QComboBox(parent);
      comboBox->setEditable(false);
      comboBox->addItems(entries);

      editorWidget = comboBox;
    }


    else
    {
      editorWidget = QStyledItemDelegate::createEditor(parent, option, index);
    }

    if ( editorWidget )
    {
      // install event filter
      editorWidget->installEventFilter( const_cast<QmitkPropertyDelegate*>(this) );
    }

    return editorWidget;

  }
  else
    return new QLabel(displayData.toString(), parent);

}
Example #23
0
QWidget *IrgaDelegate::createEditor(QWidget* parent,
                                     const QStyleOptionViewItem& option,
                                     const QModelIndex& index) const
{
    DEBUG_FUNC_NAME
    Q_UNUSED(option)

    QLabel *label;
    QComboBox *combo;
    QDoubleSpinBox *dspin;
    QLineEdit *ledit;
    QString currentManufacturer = index.model()->data(index.model()->index(IrgaModel::MANUFACTURER, index.column())).toString();
    QString currentModel = index.model()->data(index.model()->index(IrgaModel::MODEL, index.column())).toString();

//    qDebug() << "index.row()" << index.row();

    // can only edit name on blank column
    if (index.column() >= index.model()->columnCount()) return 0;

    // different kind of editor for each row
    switch (index.row())
    {
      case IrgaModel::MANUFACTURER:
          combo = new QComboBox(parent);
          combo->setEditable(false);
          combo->addItems(IrgaDesc::manufacturerStringList());
          combo->view()->setTextElideMode(Qt::ElideNone);
          connect(combo, SIGNAL(activated(int)),
                  this, SLOT(commitAndCloseEditor()));
          return combo;
      case IrgaModel::MODEL:
          combo = new QComboBox(parent);
          combo->setEditable(false);
          if (currentManufacturer.isEmpty())
          {
              combo->addItems(IrgaDesc::allModelStringList());
          }
          else if (currentManufacturer == IrgaDesc::getIRGA_MANUFACTURER_STRING_0())
          {
              combo->addItems(IrgaDesc::licorModelStringList());
          }
          else if (currentManufacturer == IrgaDesc::getIRGA_MANUFACTURER_STRING_1())
          {
              combo->addItems(IrgaDesc::otherModelStringList());
          }
          combo->view()->setTextElideMode(Qt::ElideNone);
          combo->setMaxVisibleItems(15);
          connect(combo, SIGNAL(activated(int)),
                  this, SLOT(commitAndCloseEditor()));
          return combo;
      case IrgaModel::SWVERSION:
            ledit = new QLineEdit(parent);
            ledit->setPlaceholderText(QStringLiteral("8.0.0"));
            connect(ledit, SIGNAL(editingFinished()),
                    this, SLOT(commitAndCloseEditor()));
            return ledit;
      case IrgaModel::ID:
            ledit = new QLineEdit(parent);
            ledit->setPlaceholderText(QStringLiteral("Alphanumeric ID"));
            connect(ledit, SIGNAL(editingFinished()),
                  this, SLOT(commitAndCloseEditor()));
            return ledit;
      case IrgaModel::TUBELENGTH:
            if (IrgaDesc::isOpenPathModel(currentModel))
            {
                label = new QLabel(parent);
                return label;
            }
            else
            {
                dspin = new QDoubleSpinBox(parent);
                dspin->setDecimals(1);
                dspin->setRange(0.0, 9999.0);
                dspin->setSingleStep(1.0);
                dspin->setAccelerated(true);
                dspin->setSuffix(QStringLiteral(" [cm]"));
                connect(dspin, SIGNAL(editingFinished()),
                      this, SLOT(commitAndCloseEditor()));
                return dspin;
            }
      case IrgaModel::TUBEDIAMETER:
            if (IrgaDesc::isOpenPathModel(currentModel))
            {
                label = new QLabel(parent);
                return label;
            }
            else
            {
              dspin = new QDoubleSpinBox(parent);
              dspin->setDecimals(1);
              dspin->setRange(0.0, 99.0);
              dspin->setSingleStep(1.0);
              dspin->setAccelerated(true);
              dspin->setSuffix(QStringLiteral(" [mm]"));
              connect(dspin, SIGNAL(editingFinished()),
                      this, SLOT(commitAndCloseEditor()));
              return dspin;
            }
      case IrgaModel::TUBEFLOWRATE:
            if (IrgaDesc::isOpenPathModel(currentModel))
            {
                label = new QLabel(parent);
                return label;
            }
            else
            {
              dspin = new QDoubleSpinBox(parent);
              dspin->setDecimals(1);
              dspin->setRange(0.0, 100.0);
              dspin->setSingleStep(1.0);
              dspin->setAccelerated(true);
              dspin->setSuffix(QStringLiteral(" [l/m]"));
              connect(dspin, SIGNAL(editingFinished()),
                      this, SLOT(commitAndCloseEditor()));
              return dspin;
            }
      case IrgaModel::TUBENSEPARATION:
      case IrgaModel::TUBEESEPARATION:
      case IrgaModel::TUBEVSEPARATION:
          dspin = new QDoubleSpinBox(parent);
          dspin->setDecimals(2);
          dspin->setRange(-1000.0, 1000.0);
          dspin->setSingleStep(1.0);
          dspin->setAccelerated(true);
          dspin->setSuffix(QStringLiteral(" [cm]"));
          connect(dspin, SIGNAL(editingFinished()),
                  this, SLOT(commitAndCloseEditor()));
          return dspin;
        case IrgaModel::VPATHLENGTH:
        case IrgaModel::HPATHLENGTH:
            if (currentModel != IrgaDesc::getIRGA_MODEL_STRING_6()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_7()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_8()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_9()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_10()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_11())
            {
                label = new QLabel(parent);
                return label;
            }
            else
            {
                dspin = new QDoubleSpinBox(parent);
                dspin->setDecimals(4);
                dspin->setRange(0.0001, 1000.0);
                dspin->setSingleStep(1.0);
                dspin->setAccelerated(true);
                dspin->setSuffix(QStringLiteral(" [cm]"));
                connect(dspin, SIGNAL(editingFinished()),
                        this, SLOT(commitAndCloseEditor()));
                return dspin;
            }
        case IrgaModel::TAU:
            if (currentModel != IrgaDesc::getIRGA_MODEL_STRING_6()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_7()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_8()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_9()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_10()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_11())
            {
                label = new QLabel(parent);
                return label;
            }
            else
            {
                dspin = new QDoubleSpinBox(parent);
                dspin->setDecimals(4);
                dspin->setRange(0.0001, 500.0);
                dspin->setSingleStep(1.0);
                dspin->setAccelerated(true);
                dspin->setSuffix(QStringLiteral(" [s]"));
                connect(dspin, SIGNAL(editingFinished()),
                        this, SLOT(commitAndCloseEditor()));
                return dspin;
            }
        case IrgaModel::KWATER:
        case IrgaModel::KOXYGEN:
            if (currentModel != IrgaDesc::getIRGA_MODEL_STRING_8()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_9()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_10()
                && currentModel != IrgaDesc::getIRGA_MODEL_STRING_11())
            {
                label = new QLabel(parent);
                return label;
            }
            else
            {
                dspin = new QDoubleSpinBox(parent);
                dspin->setDecimals(6);
                dspin->setRange(0.000001, 1.0);
                dspin->setSingleStep(1.0);
                dspin->setAccelerated(true);
                dspin->setSuffix(QStringLiteral(" [") + Defs::M3_G_CM_STRING + QStringLiteral("]"));
                connect(dspin, SIGNAL(editingFinished()),
                        this, SLOT(commitAndCloseEditor()));
                return dspin;
            }
          default:
              return QStyledItemDelegate::createEditor(parent, option, index);
    }
}
Example #24
0
QWidget *AnemDelegate::createEditor(QWidget* parent,
                                     const QStyleOptionViewItem& option,
                                     const QModelIndex& index) const
{
    Q_UNUSED(option)

    QLabel *label;
    QComboBox *combo;
    QDoubleSpinBox *dspin;
    QLineEdit *ledit;
    QString currentManufacturer = index.model()->data(index.model()->index(AnemModel::MANUFACTURER, index.column())).toString();
    QString currentModel = index.model()->data(index.model()->index(AnemModel::MODEL, index.column())).toString();

    // can only edit name on blank column
    if (index.column() >= index.model()->columnCount()) return 0;

    // different kind of editor for each row
    switch (index.row())
    {
      case AnemModel::MANUFACTURER:
          combo = new QComboBox(parent);
          combo->setEditable(false);
          combo->addItems(AnemDesc::manufacturerStringList());
          combo->view()->setTextElideMode(Qt::ElideNone);
          connect(combo, SIGNAL(activated(int)),
                  this, SLOT(commitAndCloseEditor()));
          return combo;
      case AnemModel::MODEL:
          combo = new QComboBox(parent);
          combo->setEditable(false);
          if (currentManufacturer.isEmpty())
          {
              combo->addItems(AnemDesc::allModelStringList());
          }
          else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_0())
          {
              combo->addItems(AnemDesc::campbellModelStringList());
          }
          else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_1())
          {
              combo->addItems(AnemDesc::gillModelStringList());
          }
          else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_2())
          {
              combo->addItems(AnemDesc::metekModelStringList());
          }
          else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_3())
          {
              combo->addItems(AnemDesc::youngModelStringList());
          }
          else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_4())
          {
              combo->addItems(AnemDesc::otherModelStringList());
          }
          combo->view()->setTextElideMode(Qt::ElideNone);
          combo->setMaxVisibleItems(15);
          connect(combo, SIGNAL(activated(int)),
                  this, SLOT(commitAndCloseEditor()));
          return combo;
      case AnemModel::ID:
          ledit = new QLineEdit(parent);
          connect(ledit, SIGNAL(editingFinished()),
                  this, SLOT(commitAndCloseEditor()));
          return ledit;
      case AnemModel::HEIGHT:
          dspin = new QDoubleSpinBox(parent);
          dspin->setDecimals(2);
          dspin->setRange(0.1, 500.0);
          dspin->setSingleStep(1.0);
          dspin->setAccelerated(true);
          dspin->setSuffix(QStringLiteral(" [m]"));
          connect(dspin, SIGNAL(editingFinished()),
                  this, SLOT(commitAndCloseEditor()));
          return dspin;
      case AnemModel::WINDFORMAT:
          combo = new QComboBox(parent);
          combo->setEditable(false);
          if (currentManufacturer.isEmpty()
              || currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_1())
          {
              combo->addItems(AnemDesc::allWindFormatStringList());
          }
          else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_0())
          {
              combo->addItems(AnemDesc::simplestWindFormatStringList());
          }
          else
          {
              combo->addItems(AnemDesc::commonWindFormatStringList());
          }
          combo->view()->setTextElideMode(Qt::ElideNone);
          connect(combo, SIGNAL(activated(int)),
                  this, SLOT(commitAndCloseEditor()));
          return combo;
      case AnemModel::NORTHALIGNMENT:
          combo = new QComboBox(parent);
          combo->setEditable(false);
          if (currentManufacturer.isEmpty())
          {
              combo->addItems(AnemDesc::allNorthAlignmentStringList());
          }
          // gill
          else if (currentManufacturer == AnemDesc::getANEM_MANUFACTURER_STRING_1())
          {
              combo->addItems(AnemDesc::gillNorthAlignmentStringList());
          }
          else
          {
              combo->addItems(AnemDesc::naNorthAlignmentStringList());
          }
          combo->view()->setTextElideMode(Qt::ElideNone);
          connect(combo, SIGNAL(activated(int)),
                  this, SLOT(commitAndCloseEditor()));
          return combo;
      case AnemModel::NORTHOFFSET:
          dspin = new QDoubleSpinBox(parent);
          dspin->setDecimals(1);
          dspin->setRange(0.0, 360.0);
          dspin->setSingleStep(1.0);
          dspin->setAccelerated(true);
          dspin->setSuffix(tr("  [%1]", "Degrees").arg(Defs::DEGREE));
          connect(dspin, SIGNAL(editingFinished()),
                  this, SLOT(commitAndCloseEditor()));
          return dspin;
      case AnemModel::NSEPARATION:
      case AnemModel::ESEPARATION:
      case AnemModel::VSEPARATION:
          if (index.column() == 0)
          {
              label = new QLabel(parent);
              return label;
          }
          else
          {
              dspin = new QDoubleSpinBox(parent);
              dspin->setDecimals(2);
              dspin->setRange(-1000.0, 1000.0);
              dspin->setSingleStep(1.0);
              dspin->setAccelerated(true);
              dspin->setSuffix(QStringLiteral(" [cm]"));
              connect(dspin, SIGNAL(editingFinished()),
                      this, SLOT(commitAndCloseEditor()));
              return dspin;
          }
      case AnemModel::VPATHLENGTH:
      case AnemModel::HPATHLENGTH:
        if (currentModel != AnemDesc::getANEM_MODEL_STRING_12())
        {
            label = new QLabel(parent);
            return label;
        }
        else
        {
          dspin = new QDoubleSpinBox(parent);
          dspin->setDecimals(4);
          dspin->setRange(0.0001, 1000.0);
          dspin->setSingleStep(1.0);
          dspin->setAccelerated(true);
          dspin->setSuffix(QStringLiteral(" [cm]"));
          connect(dspin, SIGNAL(editingFinished()),
                  this, SLOT(commitAndCloseEditor()));
          return dspin;
        }
      case AnemModel::TAU:
        if (currentModel != AnemDesc::getANEM_MODEL_STRING_12())
        {
            label = new QLabel(parent);
            return label;
        }
        else
        {
          dspin = new QDoubleSpinBox(parent);
          dspin->setDecimals(4);
          dspin->setRange(0.001, 1000.0);
          dspin->setSingleStep(1.0);
          dspin->setAccelerated(true);
          dspin->setSuffix(QStringLiteral(" [s]"));
          connect(dspin, SIGNAL(editingFinished()),
                  this, SLOT(commitAndCloseEditor()));
          return dspin;
        }
        default:
          return 0;
    }
}
Example #25
0
QWidget *QFRDRTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const {
    QVariant dat=index.data(Qt::DisplayRole);
    QString expression=index.data(QFRDRTable::TableExpressionRole).toString();
    if (expression.isEmpty()) {
        if (dat.type()==QVariant::Invalid) {
            dat=index.data(Qt::EditRole);
        }
         if ( dat.type() == QVariant::DateTime || dat.type() == QVariant::Time || dat.type() == QVariant::Date ) {
             QDateTimeEdit *editor = new QDateTimeEdit(parent);
             //editor->setDisplayFormat("dd/M/yyyy");
             editor->setCalendarPopup(true);
             return editor;
         }
         if ( !index.isValid() || dat.type() == QVariant::Double ) {
             QFDoubleEdit* editor=new QFDoubleEdit(parent);
             editor->setCheckBounds(false, false);
             editor->setShowUpDown(false);
             return editor;
         }
         if ( dat.type() == QVariant::Int || dat.type() == QVariant::LongLong ) {
             QSpinBox* editor=new QSpinBox(parent);
             editor->setRange(INT_MIN, INT_MAX);
             editor->setButtonSymbols(QAbstractSpinBox::NoButtons);
             return editor;
         }
         if ( dat.type() == QVariant::UInt || dat.type() == QVariant::ULongLong ) {
             QSpinBox* editor=new QSpinBox(parent);
             editor->setRange(0, UINT_MAX);
             editor->setButtonSymbols(QAbstractSpinBox::NoButtons);
             return editor;
         }
         if ( dat.type() == QVariant::Bool) {
             QCheckBox* editor=new QCheckBox(parent);
             return editor;
         }

         QLineEdit *editor = new QLineEdit(parent);

         // create a completer with the strings in the column as model
         QStringList allStrings;
         for (int i = 1; i<index.model()->rowCount(); i++) {
             QString strItem(index.model()->data(index.sibling(i, index.column()),
                 Qt::EditRole).toString());

             if (!allStrings.contains(strItem))
                 allStrings.append(strItem);
         }

         QCompleter *autoComplete = new QCompleter(allStrings);
         editor->setCompleter(autoComplete);
         connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
         return editor;
    } else {
        QWidget* widExpression=new QWidget(parent);
        widExpression->setFocusPolicy(Qt::StrongFocus);
        widExpression->setAutoFillBackground(true);
        QHBoxLayout* layout=new QHBoxLayout();
        layout->setContentsMargins(0,0,0,0);
        layout->setSpacing(1);
        widExpression->setLayout(layout);
        QLabel* label=new QLabel(widExpression);
        layout->addWidget(label, 1);
        label->setTextFormat(Qt::RichText);
        label->setText(tr("<b><font color=\"blue\">&Sigma;:</font> %1</b><i>&nbsp;&nbsp;= %2</i>").arg(expression).arg(dat.toString()));
        label->setAutoFillBackground(true);
        QFont f=label->font();
        f.setPointSizeF(f.pointSizeF()*0.9);
        label->setFont(f);
        QAction* actEdtExp;        
        QToolButton* btnEdtExp=createButtonAndAction(actEdtExp, QIcon(":/table/formula.png"), tr("edit expression ..."), widExpression);
        actEdtExp->setParent(widExpression);
        connect(actEdtExp, SIGNAL(triggered()), this, SLOT(doEditExpression()));
        layout->addWidget(btnEdtExp);
        QAction* actClearExp;
        QToolButton* btnClearExp=createButtonAndAction(actClearExp, QIcon(":/table/formulaclear.png"), tr("clear expression ..."), widExpression);
        actClearExp->setParent(widExpression);
        connect(actClearExp, SIGNAL(triggered()), this, SLOT(doClearExpression()));
        layout->addWidget(btnClearExp);
        widExpression->setFocus();
        return widExpression;
    }
}
Example #26
0
QWidget* BusPortsDelegate::createEditor( QWidget* parent, 
										const QStyleOptionViewItem& option,
										const QModelIndex& index ) const {

	switch (index.column()) {
		// name and comment need only normal QLineEdit
		case 0:
		case 8: {
			QLineEdit* line = new QLineEdit(parent);
			connect(line, SIGNAL(editingFinished()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return line;
			  }
		// qualifier
		case 1: {
			QComboBox* box = new QComboBox(parent);
			QStringList list;
			list.append(QString("address"));
			list.append(QString("data"));
			list.append(QString("clock"));
			list.append(QString("reset"));
			list.append(QString("any"));
			box->addItems(list);
			return box;
				}
		// width
		case 2: {
            QLineEdit* line = new QLineEdit(parent);

            // the validator for editor input
            QRegExpValidator* validator = new QRegExpValidator(QRegExp("[0-9]{0,5}"), line);

            line->setValidator(validator);

            connect(line, SIGNAL(editingFinished()),
                this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
            return line;
				}
		// default value
		case 3: {
			// the editor
			QLineEdit* line = new QLineEdit(parent);

			// the validator for editor input
			QIntValidator* validator = new QIntValidator(line);
			validator->setRange(0, 99999);

			line->setValidator(validator);

			connect(line, SIGNAL(editingFinished()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return line;
				}
		// mode
		case 4: {
			QComboBox* box = new QComboBox(parent);
			QStringList list;
			list.append(QString("master"));
			list.append(QString("slave"));
			list.append(QString("system"));
			list.append(QString("any"));
			box->addItems(list);
			connect(box, SIGNAL(destroyed()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return box;
				}
		// direction of the port
		case 5: {
			QComboBox* box = new QComboBox(parent);
			QStringList list;
			list.append(QString("in"));
			list.append(QString("out"));
			list.append(QString("inout"));
			box->addItems(list);
			connect(box, SIGNAL(destroyed()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return box;
				}
		// presence
		case 6: {
			QComboBox* box = new QComboBox(parent);
			QStringList list;
			list.append(QString("required"));
			list.append(QString("optional"));
			list.append(QString("illegal"));
			box->addItems(list);
			connect(box, SIGNAL(destroyed()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return box;
				}
		// driver
		case 7: {
			QComboBox* box = new QComboBox(parent);
			QStringList list;
			list.append(QString("none"));
			list.append(QString("any"));
			list.append(QString("clock"));
			list.append(QString("singleshot"));
			box->addItems(list);
			connect(box, SIGNAL(destroyed()),
				this, SLOT(commitAndCloseEditor()), Qt::UniqueConnection);
			return box;
				}
		
		default: {
			return QStyledItemDelegate::createEditor(parent, option, index);
				 }
	}
}