20 #include <QDialogButtonBox>
21 #include <QPushButton>
46 mMinSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
47 mMinSpinBox->setMaximum( std::numeric_limits<double>::max() );
48 mMinSpinBox->setValue( 0 );
49 mMinSpinBox->setDecimals( 6 );
51 mMaxSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
52 mMaxSpinBox->setMaximum( std::numeric_limits<double>::max() );
54 mMaxSpinBox->setValue( 100 );
55 mMaxSpinBox->setDecimals( 6 );
57 mMinInclusiveCheckBox->setChecked(
true );
58 mMaxInclusiveCheckBox->setChecked(
true );
73 mMinSpinBox->setValue( rangeDomain->
minimum().toDouble() );
74 mMaxSpinBox->setValue( rangeDomain->
maximum().toDouble() );
83 mMinSpinBox->value(), mMinInclusiveCheckBox->isChecked(),
84 mMaxSpinBox->value(), mMaxInclusiveCheckBox->isChecked() );
89 return mMinSpinBox->value() <= mMaxSpinBox->value();
110 mEditGlob->setText( globDomain->
glob() );
120 return !mEditGlob->text().trimmed().isEmpty();
133 mValuesTable->setModel( mModel );
135 connect( mButtonAddRow, &QToolButton::clicked,
this, [ = ]
137 mModel->insertRow( mModel->
rowCount() );
139 connect( mButtonRemoveRow, &QToolButton::clicked,
this, [ = ]
141 QItemSelectionModel *selectionModel = mValuesTable->selectionModel();
142 const QModelIndexList selectedRows = selectionModel->selectedIndexes();
143 if ( !selectedRows.empty() )
145 mModel->removeRow( selectedRows.first().row() );
179 : QAbstractTableModel( parent )
186 return mValues.count();
196 if ( index.row() < 0 || index.row() >= mValues.count()
197 || index.column() < 0 || index.column() >= 2 )
203 case Qt::DisplayRole:
205 case Qt::ToolTipRole:
207 switch ( index.column() )
212 return value.
value();
225 if ( index.row() < 0 || index.row() >= mValues.count()
226 || index.column() < 0 || index.column() >= 2 )
234 switch ( index.column() )
239 mValues.replace( index.row(), newValue );
240 emit dataChanged( index, index );
247 mValues.replace( index.row(), newValue );
248 emit dataChanged( index, index );
264 || index.row() >= mValues.size()
265 || index.column() < 0
267 return QAbstractTableModel::flags( index );
269 return Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsSelectable | Qt::ItemFlag::ItemIsEditable;
274 switch ( orientation )
279 case Qt::DisplayRole:
280 case Qt::ToolTipRole:
287 return tr(
"Value" );
306 if ( parent.isValid() )
309 beginInsertRows( QModelIndex(), row, row + count - 1 );
310 for (
int i = row; i < row + count; ++i )
320 if ( row < 0 || row >= mValues.count() )
323 if ( parent.isValid() )
326 for (
int i = row + count - 1; i >= row; --i )
328 beginRemoveRows( parent, i, i );
329 mValues.removeAt( i );
364 #if 0 // not supported by any formats yet...
374 mFieldTypeCombo->setCurrentIndex( mFieldTypeCombo->findData(
static_cast< int >( QVariant::String ) ) );
379 mFieldTypeCombo->setCurrentIndex( mFieldTypeCombo->findData(
static_cast< int >( QVariant::Double ) ) );
384 mFieldTypeCombo->setCurrentIndex( mFieldTypeCombo->findData(
static_cast< int >( QVariant::String ) ) );
388 mStackedWidget->addWidget( mDomainWidget );
389 mStackedWidget->setCurrentWidget( mDomainWidget );
391 connect( mNameEdit, &QLineEdit::textChanged,
this, [ = ]
407 mNameEdit->setText( domain->
name() );
408 mDescriptionEdit->setText( domain->
description() );
409 mComboMergePolicy->setCurrentIndex( mComboMergePolicy->findData(
static_cast< int >( domain->
mergePolicy() ) ) );
410 mComboSplitPolicy->setCurrentIndex( mComboSplitPolicy->findData(
static_cast< int >( domain->
splitPolicy() ) ) );
411 mFieldTypeCombo->setCurrentIndex( mFieldTypeCombo->findData(
static_cast< int >( domain->
fieldType() ) ) );
419 if ( !mDomainWidget )
422 std::unique_ptr< QgsFieldDomain > res( mDomainWidget->
createFieldDomain( mNameEdit->text(),
423 mDescriptionEdit->text(),
424 static_cast< QVariant::Type
>( mFieldTypeCombo->currentData().toInt() ) ) );
428 return res.release();
433 if ( mNameEdit->text().trimmed().isEmpty() )
436 return mDomainWidget && mDomainWidget->
isValid();
444 : QDialog( parent, flags )
446 setObjectName( QStringLiteral(
"QgsFieldDomainDialog" ) );
448 QVBoxLayout *vLayout =
new QVBoxLayout();
450 vLayout->addWidget( mWidget, 1 );
452 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
453 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
454 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
455 vLayout->addWidget( mButtonBox );
457 setLayout( vLayout );
459 validityChanged( mWidget->
isValid() );
482 void QgsFieldDomainDialog::validityChanged(
bool isValid )
484 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );