24 precisionSpinBox->setClearValue( 4 );
27 minimumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
28 minimumSpinBox->setMaximum( std::numeric_limits<int>::max() );
29 minimumSpinBox->setValue( std::numeric_limits<int>::lowest() );
31 maximumSpinBox->setMinimum( std::numeric_limits<int>::lowest() );
32 maximumSpinBox->setMaximum( std::numeric_limits<int>::max() );
33 maximumSpinBox->setValue( std::numeric_limits<int>::max() );
35 stepSpinBox->setMaximum( std::numeric_limits<int>::max() );
36 stepSpinBox->setValue( 1 );
37 stepSpinBox->setClearValue( 1 );
39 minimumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
40 minimumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
41 minimumDoubleSpinBox->setValue( std::numeric_limits<double>::min() );
43 maximumDoubleSpinBox->setMinimum( std::numeric_limits<double>::lowest() );
44 maximumDoubleSpinBox->setMaximum( std::numeric_limits<double>::max() );
45 maximumDoubleSpinBox->setValue( std::numeric_limits<double>::max() );
48 stepDoubleSpinBox->setMaximum( std::numeric_limits<int>::max() );
49 stepDoubleSpinBox->setValue( 1 );
50 stepDoubleSpinBox->setClearValue( 1 );
55 const QVariant::Type fieldType( vl->
fields().
at( fieldIdx ).
type() );
60 case QVariant::LongLong:
61 case QVariant::Double:
65 rangeStackedWidget->setCurrentIndex( fieldType == QVariant::Int ? 0 : 1 );
66 if ( fieldType == QVariant::LongLong )
68 minimumDoubleSpinBox->setDecimals( 0 );
69 maximumDoubleSpinBox->setDecimals( 0 );
70 stepDoubleSpinBox->setDecimals( 0 );
74 rangeWidget->addItem( tr(
"Editable" ), QStringLiteral(
"SpinBox" ) );
75 rangeWidget->addItem( tr(
"Slider" ), QStringLiteral(
"Slider" ) );
76 rangeWidget->addItem( tr(
"Dial" ), QStringLiteral(
"Dial" ) );
82 text = tr(
"Current minimum for this value is %1 and current maximum is %2." ).arg( min.toString(), max.toString() );
87 text = tr(
"Attribute has no integer or real type, therefore range is not usable." );
92 if ( fieldType != QVariant::Double )
94 precisionSpinBox->hide();
95 precisionLabel->hide();
98 valuesLabel->setText( text );
104 connect( minimumDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsEditorConfigWidget::changed );
105 connect( maximumDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsEditorConfigWidget::changed );
106 connect( stepDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &
QgsEditorConfigWidget::changed );
117 switch (
layer()->fields().at(
field() ).type() )
120 cfg.insert( QStringLiteral(
"Min" ), minimumSpinBox->value() );
121 cfg.insert( QStringLiteral(
"Max" ), maximumSpinBox->value() );
122 cfg.insert( QStringLiteral(
"Step" ), stepSpinBox->value() );
127 case QVariant::Double:
128 case QVariant::LongLong:
129 cfg.insert( QStringLiteral(
"Min" ), minimumDoubleSpinBox->value() );
130 cfg.insert( QStringLiteral(
"Max" ), maximumDoubleSpinBox->value() );
131 cfg.insert( QStringLiteral(
"Step" ), stepDoubleSpinBox->value() );
138 cfg.insert( QStringLiteral(
"Style" ), rangeWidget->currentData().toString() );
139 cfg.insert( QStringLiteral(
"AllowNull" ), allowNullCheckBox->isChecked() );
140 cfg.insert( QStringLiteral(
"Precision" ), precisionSpinBox->value() );
142 if ( !suffixLineEdit->text().isEmpty() )
144 cfg.insert( QStringLiteral(
"Suffix" ), suffixLineEdit->text() );
152 minimumDoubleSpinBox->setValue(
config.value( QStringLiteral(
"Min" ), std::numeric_limits<double>::lowest() ).toDouble( ) );
153 maximumDoubleSpinBox->setValue(
config.value( QStringLiteral(
"Max" ), std::numeric_limits<double>::max() ).toDouble( ) );
154 stepDoubleSpinBox->setValue(
config.value( QStringLiteral(
"Step" ), 1.0 ).toDouble() );
155 minimumSpinBox->setValue(
config.value( QStringLiteral(
"Min" ), std::numeric_limits<int>::lowest() ).toInt() );
156 maximumSpinBox->setValue(
config.value( QStringLiteral(
"Max" ), std::numeric_limits<int>::max() ).toInt() );
157 stepSpinBox->setValue(
config.value( QStringLiteral(
"Step" ), 1 ).toInt() );
158 rangeWidget->setCurrentIndex( rangeWidget->findData(
config.value( QStringLiteral(
"Style" ),
"SpinBox" ) ) );
159 suffixLineEdit->setText(
config.value( QStringLiteral(
"Suffix" ) ).toString() );
160 allowNullCheckBox->setChecked(
config.value( QStringLiteral(
"AllowNull" ),
true ).toBool() );
161 precisionSpinBox->setValue(
config.value( QStringLiteral(
"Precision" ),
layer()->fields().at(
field() ).
precision() ).toInt( ) );
166 const QString style = rangeWidget->itemData( index ).toString();
167 allowNullCheckBox->setEnabled( style == QLatin1String(
"SpinBox" ) );
172 minimumDoubleSpinBox->setDecimals(
precision );
173 maximumDoubleSpinBox->setDecimals(
precision );
174 stepDoubleSpinBox->setDecimals(
precision );
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)
void setPrecision(int precision)
Sets the precision of minimum value, maximum value, step size UI elements.
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.