29#include "moc_qgsdial.cpp"
34 setMinimumSize( QSize( 50, 50 ) );
39 QDial::paintEvent( event );
40 QPainter painter(
this );
41 const QRect rect = geometry();
42 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
43 painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ), Qt::AlignHCenter,
variantValue().toString(),
nullptr );
79 if ( mMin.userType() == QMetaType::Type::Int && mMax.userType() == QMetaType::Type::Int && mStep.userType() == QMetaType::Type::Int && mValue.userType() == QMetaType::Type::Int )
81 QDial::setMinimum( mMin.toInt() );
82 QDial::setMaximum( mMax.toInt() );
83 QDial::setSingleStep( mStep.toInt() );
84 QDial::setValue( mValue.toInt() );
87 if ( mMin.userType() == QMetaType::Type::Double && mMax.userType() == QMetaType::Type::Double && mStep.userType() == QMetaType::Type::Double && mValue.userType() == QMetaType::Type::Double )
90 QDial::setMinimum( 0 );
92 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
93 if ( maximum() != max )
94 QDial::setMaximum( max );
96 if ( singleStep() != 1 )
97 QDial::setSingleStep( 1 );
99 QDial::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
102 connect(
this,
static_cast<void ( QDial::* )(
int )
>( &QDial::valueChanged ),
this, &QgsDial::onValueChanged );
110void QgsDial::onValueChanged(
int value )
116 else if ( mMin.userType() == QMetaType::Type::Int && mMax.userType() == QMetaType::Type::Int && mStep.userType() == QMetaType::Type::Int && mValue.userType() == QMetaType::Type::Int )
120 else if ( mMin.userType() == QMetaType::Type::Double && mMax.userType() == QMetaType::Type::Double && mStep.userType() == QMetaType::Type::Double && mValue.userType() == QMetaType::Type::Double )
122 mValue = QVariant( mMin.toDouble() + value * mStep.toDouble() );
QgsDial(QWidget *parent=nullptr)
Constructor for QgsDial.
void valueChanged(const QVariant &)
void setSingleStep(const QVariant &step)
void setValue(const QVariant &value)
QVariant variantValue() const
void paintEvent(QPaintEvent *event) override
void setMinimum(const QVariant &min)
void setMaximum(const QVariant &max)
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.