/*! \reimp */
QRect QAccessibleDoubleSpinBox::rect(int child) const
{
    QRect rect;
    if (!doubleSpinBox()->isVisible())
        return rect;
    QStyleOptionSpinBox spinBoxOption;
    spinBoxOption.initFrom(doubleSpinBox());
    switch (child) {
    case Editor:
        rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption,
                                                 QStyle::SC_SpinBoxEditField, doubleSpinBox());
        break;
    case ValueUp:
        rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption,
                                                 QStyle::SC_SpinBoxUp, doubleSpinBox());
        break;
    case ValueDown:
        rect = doubleSpinBox()->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOption,
                                                 QStyle::SC_SpinBoxDown, doubleSpinBox());
        break;
    default:
        rect = spinBoxOption.rect;
        break;
    }
    const QPoint globalPos = doubleSpinBox()->mapToGlobal(QPoint(0, 0));
    return QRect(globalPos.x() + rect.x(), globalPos.y() + rect.y(), rect.width(), rect.height());
}
/*! \reimp */
QAccessible::State QAccessibleDoubleSpinBox::state(int child) const
{
    State state = QAccessibleWidgetEx::state(child);
    switch (child) {
    case ValueUp:
        if (doubleSpinBox()->value() >= doubleSpinBox()->maximum())
            state |= Unavailable;
        break;
    case ValueDown:
        if (doubleSpinBox()->value() <= doubleSpinBox()->minimum())
            state |= Unavailable;
        break;
    default:
        break;
    }
    return state;
}
/*! \reimp */
QString QAccessibleDoubleSpinBox::text(Text textType, int child) const
{
    if (!doubleSpinBox()->isVisible())
        return QString();
    switch (textType) {
    case Name:
        if (child == ValueUp)
            return QDoubleSpinBox::tr("More");
        else if (child == ValueDown)
            return QDoubleSpinBox::tr("Less");
        break;
    case Value:
        if (child == Editor || child == SpinBoxSelf)
            return doubleSpinBox()->textFromValue(doubleSpinBox()->value());
        break;
    default:
        break;
    }
    return QAccessibleWidgetEx::text(textType, 0);
}
/*! \reimp */
int QAccessibleDoubleSpinBox::childCount() const
{
    if (!doubleSpinBox()->isVisible())
        return 0;
    return ValueDown;
}
void QgsRangeWidgetWrapper::initWidget( QWidget *editor )
{
  mDoubleSpinBox = qobject_cast<QDoubleSpinBox *>( editor );
  mIntSpinBox = qobject_cast<QSpinBox *>( editor );

  mDial = qobject_cast<QDial *>( editor );
  mSlider = qobject_cast<QSlider *>( editor );
  mQgsDial = qobject_cast<QgsDial *>( editor );
  mQgsSlider = qobject_cast<QgsSlider *>( editor );

  bool allowNull = config( QStringLiteral( "AllowNull" ), true ).toBool();

  QVariant min( config( QStringLiteral( "Min" ) ) );
  QVariant max( config( QStringLiteral( "Max" ) ) );
  QVariant step( config( QStringLiteral( "Step" ) ) );
  QVariant precision( config( QStringLiteral( "Precision" ) ) );

  if ( mDoubleSpinBox )
  {
    double stepval = step.isValid() ? step.toDouble() : 1.0;
    double minval = min.isValid() ? min.toDouble() : std::numeric_limits<double>::lowest();
    double maxval  = max.isValid() ? max.toDouble() : std::numeric_limits<double>::max();
    int precisionval = precision.isValid() ? precision.toInt() : layer()->fields().at( fieldIdx() ).precision();

    mDoubleSpinBox->setDecimals( precisionval );

    QgsDoubleSpinBox *qgsWidget = qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox );


    if ( qgsWidget )
      qgsWidget->setShowClearButton( allowNull );
    // Make room for null value: lower the minimum to allow for NULL special values
    if ( allowNull )
    {
      double decr;
      if ( precisionval > 0 )
      {
        decr = std::pow( 10, -precisionval );
      }
      else
      {
        decr = stepval;
      }
      minval -= decr;
      // Note: call setMinimum here or setValue won't work
      mDoubleSpinBox->setMinimum( minval );
      mDoubleSpinBox->setValue( minval );
      QgsDoubleSpinBox *doubleSpinBox( qobject_cast<QgsDoubleSpinBox *>( mDoubleSpinBox ) );
      if ( doubleSpinBox )
        doubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
      else
        mDoubleSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
    }
    mDoubleSpinBox->setMinimum( minval );
    mDoubleSpinBox->setMaximum( maxval );
    mDoubleSpinBox->setSingleStep( stepval );
    if ( config( QStringLiteral( "Suffix" ) ).isValid() )
      mDoubleSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() );

    connect( mDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ),
    this, [ = ]( double ) { emitValueChanged(); } );
  }
  else if ( mIntSpinBox )
  {
    QgsSpinBox *qgsWidget = qobject_cast<QgsSpinBox *>( mIntSpinBox );
    if ( qgsWidget )
      qgsWidget->setShowClearButton( allowNull );
    int minval = min.toInt();
    if ( allowNull )
    {
      int stepval = step.isValid() ? step.toInt() : 1;
      minval -= stepval;
      mIntSpinBox->setValue( minval );
      QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
      if ( intSpinBox )
        intSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
      else
        mIntSpinBox->setSpecialValueText( QgsApplication::nullRepresentation() );
    }
    setupIntEditor( minval, max, step, mIntSpinBox, this );
    if ( config( QStringLiteral( "Suffix" ) ).isValid() )
      mIntSpinBox->setSuffix( config( QStringLiteral( "Suffix" ) ).toString() );
  }
  else
  {
    ( void )field().convertCompatible( min );
    ( void )field().convertCompatible( max );
    ( void )field().convertCompatible( step );
    if ( mQgsDial )
      setupIntEditor( min, max, step, mQgsDial, this );
    else if ( mQgsSlider )
      setupIntEditor( min, max, step, mQgsSlider, this );
    else if ( mDial )
      setupIntEditor( min, max, step, mDial, this );
    else if ( mSlider )
      setupIntEditor( min, max, step, mSlider, this );
  }
}
Beispiel #6
0
QString QAccessibleDoubleSpinBox::text(QAccessible::Text textType) const
{
    if (textType == QAccessible::Value)
        return doubleSpinBox()->textFromValue(doubleSpinBox()->value());
    return QAccessibleWidget::text(textType);
}