19#include "moc_qgsrangewidgetwrapper.cpp"
37 QWidget *editor =
nullptr;
39 if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Dial" ) )
43 else if (
config( QStringLiteral(
"Style" ) ).toString() == QLatin1String(
"Slider" ) )
45 editor =
new QgsSlider( Qt::Horizontal, parent );
51 case QMetaType::Type::Double:
54 case QMetaType::Type::LongLong:
58 static_cast<QgsDoubleSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
62 case QMetaType::Type::Int:
65 static_cast<QgsSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
74static void setupIntEditor(
const QVariant &min,
const QVariant &max,
const QVariant &step, T *slider,
QgsRangeWidgetWrapper *wrapper )
77 slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest() );
78 slider->setMaximum( max.isValid() ? max.toInt() : std::numeric_limits<int>::max() );
79 slider->setSingleStep( step.isValid() ? step.toInt() : 1 );
80 QObject::connect( slider, SIGNAL( valueChanged(
int ) ), wrapper, SLOT( emitValueChanged() ) );
85 mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor );
86 mIntSpinBox = qobject_cast<QSpinBox *>( editor );
88 mDial = qobject_cast<QDial *>( editor );
89 mSlider = qobject_cast<QSlider *>( editor );
90 mQgsDial = qobject_cast<QgsDial *>( editor );
91 mQgsSlider = qobject_cast<QgsSlider *>( editor );
93 const bool allowNull =
config( QStringLiteral(
"AllowNull" ),
true ).toBool();
95 QVariant min(
config( QStringLiteral(
"Min" ) ) );
96 QVariant max(
config( QStringLiteral(
"Max" ) ) );
97 QVariant step(
config( QStringLiteral(
"Step" ) ) );
100 if ( mDoubleSpinBox )
102 const double stepval = step.isValid() ? step.toDouble() : 1.0;
103 double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
104 const double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
110 mDoubleSpinBox->setDecimals( precisionval );
112 QgsDoubleSpinBox *qgsWidget = qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );
121 if ( precisionval > 0 )
123 decr = std::pow( 10, -precisionval );
131 mDoubleSpinBox->setMinimum( minval );
132 mDoubleSpinBox->setValue( minval );
133 QgsDoubleSpinBox *doubleSpinBox( qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ) );
139 mDoubleSpinBox->setMinimum( minval );
140 mDoubleSpinBox->setMaximum( maxval );
141 mDoubleSpinBox->setSingleStep( stepval );
142 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
143 mDoubleSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
145 connect( mDoubleSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
148 else if ( mIntSpinBox )
150 QgsSpinBox *qgsWidget = qobject_cast<QgsSpinBox *>( mIntSpinBox );
153 int minval = min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest();
154 const int maxval = max.isValid() ? max.toInt() : std::numeric_limits<int>::max();
155 const uint stepval = step.isValid() ? step.toUInt() : 1;
159 const int minvalOverflow = uint( minval ) - stepval;
160 if ( minvalOverflow < minval )
162 minval = minvalOverflow;
164 mIntSpinBox->setValue( minval );
165 QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
171 setupIntEditor( minval, maxval, stepval, mIntSpinBox,
this );
172 if (
config( QStringLiteral(
"Suffix" ) ).isValid() )
173 mIntSpinBox->setSuffix(
config( QStringLiteral(
"Suffix" ) ).toString() );
181 setupIntEditor( min, max, step, mQgsDial,
this );
182 else if ( mQgsSlider )
183 setupIntEditor( min, max, step, mQgsSlider,
this );
185 setupIntEditor( min, max, step, mDial,
this );
187 setupIntEditor( min, max, step, mSlider,
this );
193 return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
196void QgsRangeWidgetWrapper::valueChangedVariant(
const QVariant &v )
198 if ( v.userType() == QMetaType::Type::Int )
205 else if ( v.userType() == QMetaType::Type::LongLong )
212 else if ( v.userType() == QMetaType::Type::Double )
225 if ( mDoubleSpinBox )
227 const QMetaType::Type fieldType =
field().
type();
230 case QMetaType::Type::Double:
231 value = mDoubleSpinBox->value();
234 case QMetaType::Type::LongLong:
235 value =
static_cast< long long >( mDoubleSpinBox->value() );
242 if (
value == mDoubleSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
247 else if ( mIntSpinBox )
249 value = mIntSpinBox->value();
250 if (
value == mIntSpinBox->minimum() &&
config( QStringLiteral(
"AllowNull" ),
true ).toBool() )
259 else if ( mQgsSlider )
265 value = mDial->value();
269 value = mSlider->value();
275void QgsRangeWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList & )
277 if ( mDoubleSpinBox )
281 mDoubleSpinBox->setValue( mDoubleSpinBox->minimum() );
285 mDoubleSpinBox->setValue(
value.toDouble() );
293 mIntSpinBox->setValue( mIntSpinBox->minimum() );
297 mIntSpinBox->setValue(
value.toInt() );
305 else if ( mQgsSlider )
311 mDial->setValue(
value.toInt() );
315 mSlider->setValue(
value.toInt() );
321 if ( mDoubleSpinBox )
323 mDoubleSpinBox->setReadOnly( !enabled );
324 mDoubleSpinBox->setFrame( enabled );
326 else if ( mIntSpinBox )
328 mIntSpinBox->setReadOnly( !enabled );
329 mIntSpinBox->setFrame( enabled );
static QString nullRepresentation()
Returns the string 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, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
Represents a vector layer which manages a vector based data sets.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH