33 QWidget *editor =
nullptr;
35 if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Dial" ) )
39 else if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Slider" ) )
41 editor =
new QgsSlider( Qt::Horizontal, parent );
47 case QVariant::Double:
50 static_cast<QgsDoubleSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
54 case QVariant::LongLong:
57 static_cast<QgsSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
66 static void setupIntEditor(
const QVariant &min,
const QVariant &max,
const QVariant &step, T *slider,
QgsRangeWidgetWrapper *wrapper )
69 slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest() );
70 slider->setMaximum( max.isValid() ? max.toInt() : std::numeric_limits<int>::max() );
71 slider->setSingleStep( step.isValid() ? step.toInt() : 1 );
77 mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor );
78 mIntSpinBox = qobject_cast<QSpinBox *>( editor );
80 mDial = qobject_cast<QDial *>( editor );
81 mSlider = qobject_cast<QSlider *>( editor );
82 mQgsDial = qobject_cast<
QgsDial *>( editor );
83 mQgsSlider = qobject_cast<
QgsSlider *>( editor );
85 bool allowNull =
config( QStringLiteral(
"AllowNull" ),
true ).toBool();
87 QVariant min(
config( QStringLiteral(
"Min" ) ) );
88 QVariant max(
config( QStringLiteral(
"Max" ) ) );
89 QVariant step(
config( QStringLiteral(
"Step" ) ) );
90 QVariant precision(
config( QStringLiteral(
"Precision" ) ) );
94 double stepval = step.isValid() ? step.toDouble() : 1.0;
95 double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
96 double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
99 mDoubleSpinBox->setDecimals( precisionval );
110 if ( precisionval > 0 )
112 decr = std::pow( 10, -precisionval );
120 mDoubleSpinBox->setMinimum( minval );
121 mDoubleSpinBox->setValue( minval );
124 mDoubleSpinBox->setMinimum( minval );
125 mDoubleSpinBox->setMaximum( maxval );
126 mDoubleSpinBox->setSingleStep( stepval );
127 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
128 mDoubleSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
130 connect( mDoubleSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
133 else if ( mIntSpinBox )
140 int minval = min.toInt();
141 int stepval = step.toInt();
143 mIntSpinBox->setValue( minval );
146 setupIntEditor( min, max, step, mIntSpinBox,
this );
147 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
148 mIntSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
156 setupIntEditor( min, max, step, mQgsDial,
this );
157 else if ( mQgsSlider )
158 setupIntEditor( min, max, step, mQgsSlider,
this );
160 setupIntEditor( min, max, step, mDial,
this );
162 setupIntEditor( min, max, step, mSlider,
this );
168 return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
171 void QgsRangeWidgetWrapper::valueChangedVariant(
const QVariant &v )
173 if ( v.type() == QVariant::Int )
175 if ( v.type() == QVariant::Double )
183 if ( mDoubleSpinBox )
185 value = mDoubleSpinBox->value();
186 if ( value == mDoubleSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
188 value = QVariant(
field().type() );
191 else if ( mIntSpinBox )
193 value = mIntSpinBox->value();
194 if ( value == mIntSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
196 value = QVariant(
field().type() );
203 else if ( mQgsSlider )
209 value = mDial->value();
213 value = mSlider->value();
221 if ( mDoubleSpinBox )
223 if ( value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
225 mDoubleSpinBox->setValue( mDoubleSpinBox->minimum() );
229 mDoubleSpinBox->setValue( value.toDouble() );
235 if ( value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
237 mIntSpinBox->setValue( mIntSpinBox->minimum() );
241 mIntSpinBox->setValue( value.toInt() );
249 else if ( mQgsSlider )
255 mDial->setValue( value.toInt() );
259 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...
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 setShowClearButton(const bool showClearButton)
Sets whether the widget will show a clear button.
QgsField at(int i) const
Get field at particular index (must be in range 0..N-1)
void setShowClearButton(const bool showClearButton)
Sets whether the widget will show a clear button.
QgsFields fields() const override
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)
QVariant variantValue() const
Represents a vector layer which manages a vector based data sets.
QVariant variantValue() const