35 QWidget *editor =
nullptr;
37 if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Dial" ) )
41 else if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Slider" ) )
43 editor =
new QgsSlider( Qt::Horizontal, parent );
49 case QVariant::Double:
52 static_cast<QgsDoubleSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
56 case QVariant::LongLong:
59 static_cast<QgsSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
68 static void setupIntEditor(
const QVariant &min,
const QVariant &max,
const QVariant &step, T *slider,
QgsRangeWidgetWrapper *wrapper )
71 slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest() );
72 slider->setMaximum( max.isValid() ? max.toInt() : std::numeric_limits<int>::max() );
73 slider->setSingleStep( step.isValid() ? step.toInt() : 1 );
79 mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor );
80 mIntSpinBox = qobject_cast<QSpinBox *>( editor );
82 mDial = qobject_cast<QDial *>( editor );
83 mSlider = qobject_cast<QSlider *>( editor );
84 mQgsDial = qobject_cast<
QgsDial *>( editor );
85 mQgsSlider = qobject_cast<
QgsSlider *>( editor );
87 bool allowNull =
config( QStringLiteral(
"AllowNull" ),
true ).toBool();
89 QVariant min(
config( QStringLiteral(
"Min" ) ) );
90 QVariant max(
config( QStringLiteral(
"Max" ) ) );
91 QVariant step(
config( QStringLiteral(
"Step" ) ) );
96 double stepval = step.isValid() ? step.toDouble() : 1.0;
97 double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
98 double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
101 mDoubleSpinBox->setDecimals( precisionval );
112 if ( precisionval > 0 )
114 decr = std::pow( 10, -precisionval );
122 mDoubleSpinBox->setMinimum( minval );
123 mDoubleSpinBox->setValue( minval );
124 QgsDoubleSpinBox *doubleSpinBox( qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ) );
130 mDoubleSpinBox->setMinimum( minval );
131 mDoubleSpinBox->setMaximum( maxval );
132 mDoubleSpinBox->setSingleStep( stepval );
133 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
134 mDoubleSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
136 connect( mDoubleSpinBox, static_cast <
void ( QDoubleSpinBox::* )(
double ) > ( &QDoubleSpinBox::valueChanged ),
139 else if ( mIntSpinBox )
144 int minval = min.toInt();
147 uint stepval = step.isValid() ? step.toUInt() : 1;
149 int minvalOverflow = uint( minval ) - stepval;
150 if ( minvalOverflow < minval )
152 minval = minvalOverflow;
154 mIntSpinBox->setValue( minval );
155 QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
161 setupIntEditor( minval, max, step, mIntSpinBox,
this );
162 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
163 mIntSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
171 setupIntEditor( min, max, step, mQgsDial,
this );
172 else if ( mQgsSlider )
173 setupIntEditor( min, max, step, mQgsSlider,
this );
175 setupIntEditor( min, max, step, mDial,
this );
177 setupIntEditor( min, max, step, mSlider,
this );
183 return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
186 void QgsRangeWidgetWrapper::valueChangedVariant(
const QVariant &v )
188 if ( v.type() == QVariant::Int )
190 if ( v.type() == QVariant::Double )
198 if ( mDoubleSpinBox )
200 value = mDoubleSpinBox->value();
201 if ( value == mDoubleSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
203 value = QVariant(
field().type() );
206 else if ( mIntSpinBox )
208 value = mIntSpinBox->value();
209 if ( value == mIntSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
211 value = QVariant(
field().type() );
218 else if ( mQgsSlider )
224 value = mDial->value();
228 value = mSlider->value();
236 if ( mDoubleSpinBox )
238 if ( value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
240 mDoubleSpinBox->setValue( mDoubleSpinBox->minimum() );
244 mDoubleSpinBox->setValue( value.toDouble() );
250 if ( value.isNull() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
252 mIntSpinBox->setValue( mIntSpinBox->minimum() );
256 mIntSpinBox->setValue( value.toInt() );
264 else if ( mQgsSlider )
270 mDial->setValue( value.toInt() );
274 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.
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.
QVariant variantValue() const
QVariant variantValue() const
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
void setValue(const QVariant &value)
bool convertCompatible(QVariant &v) const
Converts the provided variant to a compatible format.
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...
Represents a vector layer which manages a vector based data sets.