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 case QVariant::LongLong:
57 static_cast<QgsDoubleSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
64 static_cast<QgsSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
73static void setupIntEditor(
const QVariant &min,
const QVariant &max,
const QVariant &step, T *slider,
QgsRangeWidgetWrapper *wrapper )
76 slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest() );
77 slider->setMaximum( max.isValid() ? max.toInt() : std::numeric_limits<int>::max() );
78 slider->setSingleStep( step.isValid() ? step.toInt() : 1 );
79 QObject::connect( slider, SIGNAL( valueChanged(
int ) ), wrapper, SLOT( emitValueChanged() ) );
84 mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor );
85 mIntSpinBox = qobject_cast<QSpinBox *>( editor );
87 mDial = qobject_cast<QDial *>( editor );
88 mSlider = qobject_cast<QSlider *>( editor );
89 mQgsDial = qobject_cast<QgsDial *>( editor );
90 mQgsSlider = qobject_cast<QgsSlider *>( editor );
92 const bool allowNull =
config( QStringLiteral(
"AllowNull" ),
true ).toBool();
94 QVariant min(
config( QStringLiteral(
"Min" ) ) );
95 QVariant max(
config( QStringLiteral(
"Max" ) ) );
96 QVariant step(
config( QStringLiteral(
"Step" ) ) );
101 const double stepval = step.isValid() ? step.toDouble() : 1.0;
102 double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
103 const double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
109 mDoubleSpinBox->setDecimals( precisionval );
111 QgsDoubleSpinBox *qgsWidget = qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );
120 if ( precisionval > 0 )
122 decr = std::pow( 10, -precisionval );
130 mDoubleSpinBox->setMinimum( minval );
131 mDoubleSpinBox->setValue( minval );
132 QgsDoubleSpinBox *doubleSpinBox( qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ) );
138 mDoubleSpinBox->setMinimum( minval );
139 mDoubleSpinBox->setMaximum( maxval );
140 mDoubleSpinBox->setSingleStep( stepval );
141 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
142 mDoubleSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
144 connect( mDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
147 else if ( mIntSpinBox )
149 QgsSpinBox *qgsWidget = qobject_cast<QgsSpinBox *>( mIntSpinBox );
152 int minval = min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest();
153 const int maxval = max.isValid() ? max.toInt() : std::numeric_limits<int>::max();
154 const uint stepval = step.isValid() ? step.toUInt() : 1;
158 const int minvalOverflow = uint( minval ) - stepval;
159 if ( minvalOverflow < minval )
161 minval = minvalOverflow;
163 mIntSpinBox->setValue( minval );
164 QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
170 setupIntEditor( minval, maxval, stepval, mIntSpinBox,
this );
171 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
172 mIntSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
180 setupIntEditor( min, max, step, mQgsDial,
this );
181 else if ( mQgsSlider )
182 setupIntEditor( min, max, step, mQgsSlider,
this );
184 setupIntEditor( min, max, step, mDial,
this );
186 setupIntEditor( min, max, step, mSlider,
this );
192 return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
195void QgsRangeWidgetWrapper::valueChangedVariant(
const QVariant &v )
197 if ( v.type() == QVariant::Int )
204 else if ( v.type() == QVariant::LongLong )
211 else if ( v.type() == QVariant::Double )
224 if ( mDoubleSpinBox )
226 const QVariant::Type fieldType =
field().
type();
229 case QVariant::Double:
230 value = mDoubleSpinBox->value();
233 case QVariant::LongLong:
234 value =
static_cast< long long >( mDoubleSpinBox->value() );
241 if (
value == mDoubleSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
243 value = QVariant( fieldType );
246 else if ( mIntSpinBox )
248 value = mIntSpinBox->value();
249 if (
value == mIntSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
258 else if ( mQgsSlider )
264 value = mDial->value();
268 value = mSlider->value();
274void QgsRangeWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList & )
276 if ( mDoubleSpinBox )
280 mDoubleSpinBox->setValue( mDoubleSpinBox->minimum() );
284 mDoubleSpinBox->setValue(
value.toDouble() );
292 mIntSpinBox->setValue( mIntSpinBox->minimum() );
296 mIntSpinBox->setValue(
value.toInt() );
304 else if ( mQgsSlider )
310 mDial->setValue(
value.toInt() );
314 mSlider->setValue(
value.toInt() );
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
void setValue(const QVariant &value)
QVariant variantValue() const
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...
void setShowClearButton(bool showClearButton)
Sets whether the widget will show a clear button.
Encapsulate a field in an attribute table or data source.
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
void setValue(const QVariant &value)
QVariant variantValue() const
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.
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...
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH