36 QWidget *editor =
nullptr;
38 if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Dial" ) )
42 else if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Slider" ) )
44 editor =
new QgsSlider( Qt::Horizontal, parent );
50 case QVariant::Double:
53 static_cast<QgsDoubleSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
57 case QVariant::LongLong:
60 static_cast<QgsSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
69 static void setupIntEditor(
const QVariant &min,
const QVariant &max,
const QVariant &step, T *slider,
QgsRangeWidgetWrapper *wrapper )
72 slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest() );
73 slider->setMaximum( max.isValid() ? max.toInt() : std::numeric_limits<int>::max() );
74 slider->setSingleStep( step.isValid() ? step.toInt() : 1 );
80 mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor );
81 mIntSpinBox = qobject_cast<QSpinBox *>( editor );
83 mDial = qobject_cast<QDial *>( editor );
84 mSlider = qobject_cast<QSlider *>( editor );
85 mQgsDial = qobject_cast<
QgsDial *>( editor );
86 mQgsSlider = qobject_cast<
QgsSlider *>( editor );
88 bool allowNull =
config( QStringLiteral(
"AllowNull" ),
true ).toBool();
90 QVariant min(
config( QStringLiteral(
"Min" ) ) );
91 QVariant max(
config( QStringLiteral(
"Max" ) ) );
92 QVariant step(
config( QStringLiteral(
"Step" ) ) );
97 double stepval = step.isValid() ? step.toDouble() : 1.0;
98 double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
99 double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
102 mDoubleSpinBox->setDecimals( precisionval );
113 if ( precisionval > 0 )
115 decr = std::pow( 10, -precisionval );
123 mDoubleSpinBox->setMinimum( minval );
124 mDoubleSpinBox->setValue( minval );
125 QgsDoubleSpinBox *doubleSpinBox( qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ) );
131 mDoubleSpinBox->setMinimum( minval );
132 mDoubleSpinBox->setMaximum( maxval );
133 mDoubleSpinBox->setSingleStep( stepval );
134 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
135 mDoubleSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
137 connect( mDoubleSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
140 else if ( mIntSpinBox )
145 int minval = min.toInt();
148 uint stepval = step.isValid() ? step.toUInt() : 1;
150 int minvalOverflow = uint( minval ) - stepval;
151 if ( minvalOverflow < minval )
153 minval = minvalOverflow;
155 mIntSpinBox->setValue( minval );
156 QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
162 setupIntEditor( minval, max, step, mIntSpinBox,
this );
163 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
164 mIntSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
172 setupIntEditor( min, max, step, mQgsDial,
this );
173 else if ( mQgsSlider )
174 setupIntEditor( min, max, step, mQgsSlider,
this );
176 setupIntEditor( min, max, step, mDial,
this );
178 setupIntEditor( min, max, step, mSlider,
this );
184 return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
187 void QgsRangeWidgetWrapper::valueChangedVariant(
const QVariant &v )
189 if ( v.type() == QVariant::Int )
191 if ( v.type() == QVariant::Double )
199 if ( mDoubleSpinBox )
201 value = mDoubleSpinBox->value();
202 if ( value == mDoubleSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
204 value = QVariant(
field().type() );
207 else if ( mIntSpinBox )
209 value = mIntSpinBox->value();
210 if ( value == mIntSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
212 value = QVariant(
field().type() );
219 else if ( mQgsSlider )
225 value = mDial->value();
229 value = mSlider->value();
237 if ( mDoubleSpinBox )
239 if ( value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
241 mDoubleSpinBox->setValue( mDoubleSpinBox->minimum() );
245 mDoubleSpinBox->setValue( value.toDouble() );
251 if ( value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
253 mIntSpinBox->setValue( mIntSpinBox->minimum() );
257 mIntSpinBox->setValue( value.toInt() );
265 else if ( mQgsSlider )
271 mDial->setValue( value.toInt() );
275 mSlider->setValue( value.toInt() );
void setValue(const QVariant &value)
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
void setShowClearButton(bool showClearButton)
Sets whether the widget will show a clear button.
bool convertCompatible(QVariant &v) const
Converts the provided variant to a compatible format.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
void setSpecialValueText(const QString &txt)
Set the special-value text to be txt If set, the spin box will display this text instead of a numeric...
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
void setShowClearButton(bool showClearButton)
Sets whether the widget will show a clear button.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
void setValue(const QVariant &value)
void setSpecialValueText(const QString &txt)
Set the special-value text to be txt If set, the spin box will display this text instead of a numeric...
QVariant variantValue() const
Represents a vector layer which manages a vector based data sets.
QVariant variantValue() const