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.isValid() ? min.toInt() : std::numeric_limits<int>::lowest();
146 int maxval = max.isValid() ? max.toInt() : std::numeric_limits<int>::max();
147 uint stepval = step.isValid() ? step.toUInt() : 1;
151 int minvalOverflow = uint( minval ) - stepval;
152 if ( minvalOverflow < minval )
154 minval = minvalOverflow;
156 mIntSpinBox->setValue( minval );
157 QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
163 setupIntEditor( minval, maxval, stepval, mIntSpinBox,
this );
164 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
165 mIntSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
173 setupIntEditor( min, max, step, mQgsDial,
this );
174 else if ( mQgsSlider )
175 setupIntEditor( min, max, step, mQgsSlider,
this );
177 setupIntEditor( min, max, step, mDial,
this );
179 setupIntEditor( min, max, step, mSlider,
this );
185 return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
188 void QgsRangeWidgetWrapper::valueChangedVariant(
const QVariant &v )
190 if ( v.type() == QVariant::Int )
197 if ( v.type() == QVariant::Double )
210 if ( mDoubleSpinBox )
212 value = mDoubleSpinBox->value();
213 if ( value == mDoubleSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
215 value = QVariant(
field().type() );
218 else if ( mIntSpinBox )
220 value = mIntSpinBox->value();
221 if ( value == mIntSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
223 value = QVariant(
field().type() );
230 else if ( mQgsSlider )
236 value = mDial->value();
240 value = mSlider->value();
246 void QgsRangeWidgetWrapper::updateValues(
const QVariant &
value,
const QVariantList & )
248 if ( mDoubleSpinBox )
250 if (
value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
252 mDoubleSpinBox->setValue( mDoubleSpinBox->minimum() );
256 mDoubleSpinBox->setValue(
value.toDouble() );
262 if (
value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
264 mIntSpinBox->setValue( mIntSpinBox->minimum() );
268 mIntSpinBox->setValue(
value.toInt() );
276 else if ( mQgsSlider )
282 mDial->setValue(
value.toInt() );
286 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.
#define Q_NOWARN_DEPRECATED_PUSH
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)
#define Q_NOWARN_DEPRECATED_POP
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