21#include "moc_qgsdial.cpp"
31 setMinimumSize( QSize( 50, 50 ) );
36 QDial::paintEvent( event );
37 QPainter painter(
this );
38 const QRect rect = geometry();
39 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
40 painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ), Qt::AlignHCenter,
variantValue().toString(),
nullptr );
76 if ( mMin.userType() == QMetaType::Type::Int && mMax.userType() == QMetaType::Type::Int && mStep.userType() == QMetaType::Type::Int && mValue.userType() == QMetaType::Type::Int )
78 QDial::setMinimum( mMin.toInt() );
79 QDial::setMaximum( mMax.toInt() );
80 QDial::setSingleStep( mStep.toInt() );
81 QDial::setValue( mValue.toInt() );
84 if ( mMin.userType() == QMetaType::Type::Double && mMax.userType() == QMetaType::Type::Double && mStep.userType() == QMetaType::Type::Double && mValue.userType() == QMetaType::Type::Double )
87 QDial::setMinimum( 0 );
89 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
90 if ( maximum() != max )
91 QDial::setMaximum( max );
93 if ( singleStep() != 1 )
94 QDial::setSingleStep( 1 );
96 QDial::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
99 connect(
this,
static_cast<void ( QDial::* )(
int )
>( &QDial::valueChanged ),
this, &QgsDial::onValueChanged );
107void QgsDial::onValueChanged(
int value )
113 else if ( mMin.userType() == QMetaType::Type::Int && mMax.userType() == QMetaType::Type::Int && mStep.userType() == QMetaType::Type::Int && mValue.userType() == QMetaType::Type::Int )
117 else if ( mMin.userType() == QMetaType::Type::Double && mMax.userType() == QMetaType::Type::Double && mStep.userType() == QMetaType::Type::Double && mValue.userType() == QMetaType::Type::Double )
119 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.