19#include "moc_qgsrangewidgetwrapper.cpp" 
   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 QMetaType::Type::Double:
 
   53      case QMetaType::Type::LongLong:
 
   56        static_cast<QgsDoubleSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
 
   60      case QMetaType::Type::Int:
 
   63        static_cast<QgsSpinBox *
>( editor )->setLineEditAlignment( Qt::AlignRight );
 
 
   72static void setupIntEditor( 
const QVariant &min, 
const QVariant &max, 
const QVariant &step, T *slider, 
QgsRangeWidgetWrapper *wrapper )
 
   75  slider->setMinimum( min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest() );
 
   76  slider->setMaximum( max.isValid() ? max.toInt() : std::numeric_limits<int>::max() );
 
   77  slider->setSingleStep( step.isValid() ? step.toInt() : 1 );
 
   78  QObject::connect( slider, SIGNAL( valueChanged( 
int ) ), wrapper, SLOT( emitValueChanged() ) );
 
   83  mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor );
 
   84  mIntSpinBox = qobject_cast<QSpinBox *>( editor );
 
   86  mDial = qobject_cast<QDial *>( editor );
 
   87  mSlider = qobject_cast<QSlider *>( editor );
 
   88  mQgsDial = qobject_cast<QgsDial *>( editor );
 
   89  mQgsSlider = qobject_cast<QgsSlider *>( editor );
 
   91  const bool allowNull = 
config( QStringLiteral( 
"AllowNull" ), 
true ).toBool();
 
   93  QVariant min( 
config( QStringLiteral( 
"Min" ) ) );
 
   94  QVariant max( 
config( QStringLiteral( 
"Max" ) ) );
 
   95  QVariant step( 
config( QStringLiteral( 
"Step" ) ) );
 
  100    const double stepval = step.isValid() ? step.toDouble() : 1.0;
 
  101    double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
 
  102    const double maxval = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
 
  108    mDoubleSpinBox->setDecimals( precisionval );
 
  110    QgsDoubleSpinBox *qgsWidget = qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );
 
  119      if ( precisionval > 0 )
 
  121        decr = std::pow( 10, -precisionval );
 
  129      mDoubleSpinBox->setMinimum( minval );
 
  130      mDoubleSpinBox->setValue( minval );
 
  131      QgsDoubleSpinBox *doubleSpinBox( qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ) );
 
  137    mDoubleSpinBox->setMinimum( minval );
 
  138    mDoubleSpinBox->setMaximum( maxval );
 
  139    mDoubleSpinBox->setSingleStep( stepval );
 
  140    if ( 
config( QStringLiteral( 
"Suffix" ) ).isValid() )
 
  141      mDoubleSpinBox->setSuffix( 
config( QStringLiteral( 
"Suffix" ) ).toString() );
 
  143    connect( mDoubleSpinBox, 
static_cast<void ( QDoubleSpinBox::* )( 
double )
>( &QDoubleSpinBox::valueChanged ), 
this, [
this]( 
double ) { 
emitValueChanged(); } );
 
  145  else if ( mIntSpinBox )
 
  147    QgsSpinBox *qgsWidget = qobject_cast<QgsSpinBox *>( mIntSpinBox );
 
  150    int minval = min.isValid() ? min.toInt() : std::numeric_limits<int>::lowest();
 
  151    const int maxval = max.isValid() ? max.toInt() : std::numeric_limits<int>::max();
 
  152    const uint stepval = step.isValid() ? step.toUInt() : 1;
 
  156      const int minvalOverflow = uint( minval ) - stepval;
 
  157      if ( minvalOverflow < minval )
 
  159        minval = minvalOverflow;
 
  161      mIntSpinBox->setValue( minval );
 
  162      QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
 
  168    setupIntEditor( minval, maxval, stepval, mIntSpinBox, 
this );
 
  169    if ( 
config( QStringLiteral( 
"Suffix" ) ).isValid() )
 
  170      mIntSpinBox->setSuffix( 
config( QStringLiteral( 
"Suffix" ) ).toString() );
 
  178      setupIntEditor( min, max, step, mQgsDial, 
this );
 
  179    else if ( mQgsSlider )
 
  180      setupIntEditor( min, max, step, mQgsSlider, 
this );
 
  182      setupIntEditor( min, max, step, mDial, 
this );
 
  184      setupIntEditor( min, max, step, mSlider, 
this );
 
 
  190  return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
 
 
  193void QgsRangeWidgetWrapper::valueChangedVariant( 
const QVariant &v )
 
  195  if ( v.userType() == QMetaType::Type::Int )
 
  202  else if ( v.userType() == QMetaType::Type::LongLong )
 
  209  else if ( v.userType() == QMetaType::Type::Double )
 
  222  if ( mDoubleSpinBox )
 
  224    const QMetaType::Type fieldType = 
field().
type();
 
  227      case QMetaType::Type::Double:
 
  228        value = mDoubleSpinBox->value();
 
  231      case QMetaType::Type::LongLong:
 
  232        value = 
static_cast<long long>( mDoubleSpinBox->value() );
 
  239    if ( 
value == mDoubleSpinBox->minimum() && 
config( QStringLiteral( 
"AllowNull" ), 
true ).toBool() )
 
  244  else if ( mIntSpinBox )
 
  246    value = mIntSpinBox->value();
 
  247    if ( 
value == mIntSpinBox->minimum() && 
config( QStringLiteral( 
"AllowNull" ), 
true ).toBool() )
 
  256  else if ( mQgsSlider )
 
  262    value = mDial->value();
 
  266    value = mSlider->value();
 
 
  272void QgsRangeWidgetWrapper::updateValues( 
const QVariant &value, 
const QVariantList & )
 
  274  if ( mDoubleSpinBox )
 
  278      mDoubleSpinBox->setValue( mDoubleSpinBox->minimum() );
 
  282      mDoubleSpinBox->setValue( 
value.toDouble() );
 
  290      mIntSpinBox->setValue( mIntSpinBox->minimum() );
 
  294      mIntSpinBox->setValue( 
value.toInt() );
 
  302  else if ( mQgsSlider )
 
  308    mDial->setValue( 
value.toInt() );
 
  312    mSlider->setValue( 
value.toInt() );
 
  318  if ( mDoubleSpinBox )
 
  320    mDoubleSpinBox->setReadOnly( !enabled );
 
  321    mDoubleSpinBox->setFrame( enabled );
 
  323  else if ( mIntSpinBox )
 
  325    mIntSpinBox->setReadOnly( !enabled );
 
  326    mIntSpinBox->setFrame( enabled );
 
 
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
 
A QDial subclass with additional refinements.
 
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).
 
A custom QSlider with additional refinements.
 
void setValue(const QVariant &value)
 
QVariant variantValue() const
 
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 dataset.
 
#define Q_NOWARN_DEPRECATED_POP
 
#define Q_NOWARN_DEPRECATED_PUSH