24 precisionSpinBox->setClearValue( 4 );
26 minimumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
27 minimumSpinBox->setMaximum( std::numeric_limits<int>::max() );
28 minimumSpinBox->setValue( std::numeric_limits<int>::lowest() );
30 maximumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
31 maximumSpinBox->setMaximum( std::numeric_limits<int>::max() );
32 maximumSpinBox->setValue( std::numeric_limits<int>::max() );
34 stepSpinBox->setMaximum( std::numeric_limits<int>::max() );
35 stepSpinBox->setValue( 1 );
36 stepSpinBox->setClearValue( 1 );
38 minimumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
39 minimumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
40 minimumDoubleSpinBox->setValue( std::numeric_limits<double>::min() );
42 maximumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
43 maximumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
44 maximumDoubleSpinBox->setValue( std::numeric_limits<double>::max() );
47 stepDoubleSpinBox->setMaximum( std::numeric_limits<int>::max() );
48 stepDoubleSpinBox->setValue( 1 );
49 stepDoubleSpinBox->setClearValue( 1 );
54 const QVariant::Type fieldType( vl->
fields().
at( fieldIdx ).
type() );
59 case QVariant::LongLong:
60 case QVariant::Double:
64 rangeStackedWidget->setCurrentIndex( fieldType == QVariant::Int ? 0 : 1 );
65 if ( fieldType == QVariant::LongLong )
67 minimumDoubleSpinBox->setDecimals( 0 );
68 maximumDoubleSpinBox->setDecimals( 0 );
69 stepDoubleSpinBox->setDecimals( 0 );
73 rangeWidget->addItem( tr(
"Editable" ), QStringLiteral(
"SpinBox" ) );
74 rangeWidget->addItem( tr(
"Slider" ), QStringLiteral(
"Slider" ) );
75 rangeWidget->addItem( tr(
"Dial" ), QStringLiteral(
"Dial" ) );
81 text = tr(
"Current minimum for this value is %1 and current maximum is %2." ).arg( min.toString(), max.toString() );
86 text = tr(
"Attribute has no integer or real type, therefore range is not usable." );
91 if ( fieldType != QVariant::Double )
93 precisionSpinBox->hide();
94 precisionLabel->hide();
97 valuesLabel->setText( text );
103 connect( minimumDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsEditorConfigWidget::changed );
104 connect( maximumDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsEditorConfigWidget::changed );
105 connect( stepDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsEditorConfigWidget::changed );
115 switch (
layer()->fields().at(
field() ).type() )
118 cfg.insert( QStringLiteral(
"Min" ), minimumSpinBox->value() );
119 cfg.insert( QStringLiteral(
"Max" ), maximumSpinBox->value() );
120 cfg.insert( QStringLiteral(
"Step" ), stepSpinBox->value() );
125 case QVariant::Double:
126 case QVariant::LongLong:
127 cfg.insert( QStringLiteral(
"Min" ), minimumDoubleSpinBox->value() );
128 cfg.insert( QStringLiteral(
"Max" ), maximumDoubleSpinBox->value() );
129 cfg.insert( QStringLiteral(
"Step" ), stepDoubleSpinBox->value() );
136 cfg.insert( QStringLiteral(
"Style" ), rangeWidget->currentData().toString() );
137 cfg.insert( QStringLiteral(
"AllowNull" ), allowNullCheckBox->isChecked() );
138 cfg.insert( QStringLiteral(
"Precision" ), precisionSpinBox->value() );
140 if ( !suffixLineEdit->text().isEmpty() )
142 cfg.insert( QStringLiteral(
"Suffix" ), suffixLineEdit->text() );
150 minimumDoubleSpinBox->setValue(
config.value( QStringLiteral(
"Min" ), std::numeric_limits<double>::lowest() ).toDouble( ) );
151 maximumDoubleSpinBox->setValue(
config.value( QStringLiteral(
"Max" ), std::numeric_limits<double>::max() ).toDouble( ) );
152 stepDoubleSpinBox->setValue(
config.value( QStringLiteral(
"Step" ), 1.0 ).toDouble() );
153 minimumSpinBox->setValue(
config.value( QStringLiteral(
"Min" ), std::numeric_limits<int>::lowest() ).toInt() );
154 maximumSpinBox->setValue(
config.value( QStringLiteral(
"Max" ), std::numeric_limits<int>::max() ).toInt() );
155 stepSpinBox->setValue(
config.value( QStringLiteral(
"Step" ), 1 ).toInt() );
156 rangeWidget->setCurrentIndex( rangeWidget->findData(
config.value( QStringLiteral(
"Style" ),
"SpinBox" ) ) );
157 suffixLineEdit->setText(
config.value( QStringLiteral(
"Suffix" ) ).toString() );
158 allowNullCheckBox->setChecked(
config.value( QStringLiteral(
"AllowNull" ),
true ).toBool() );
159 precisionSpinBox->setValue(
config.value( QStringLiteral(
"Precision" ),
layer()->fields().at(
field() ).
precision() ).toInt( ) );
164 QString style = rangeWidget->itemData( index ).toString();
165 allowNullCheckBox->setEnabled( style == QLatin1String(
"SpinBox" ) );
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
QVariantMap config() override
Create a configuration from the current GUI state.
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
QgsRangeConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)
void rangeWidgetChanged(int index)
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
void minimumAndMaximumValue(int index, QVariant &minimum, QVariant &maximum) const
Calculates both the minimum and maximum value for an attribute column.