21#include "moc_qgsdial.cpp"
30 setMinimumSize( QSize( 50, 50 ) );
35 QDial::paintEvent( event );
36 QPainter painter(
this );
37 const QRect rect = geometry();
38 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
39 painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ),
76 if ( mMin.userType() == QMetaType::Type::Int &&
77 mMax.userType() == QMetaType::Type::Int &&
78 mStep.userType() == QMetaType::Type::Int &&
79 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 &&
88 mMax.userType() == QMetaType::Type::Double &&
89 mStep.userType() == QMetaType::Type::Double &&
90 mValue.userType() == QMetaType::Type::Double )
93 QDial::setMinimum( 0 );
95 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
96 if ( maximum() != max )
97 QDial::setMaximum( max );
99 if ( singleStep() != 1 )
100 QDial::setSingleStep( 1 );
102 QDial::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
105 connect(
this,
static_cast < void ( QDial::* )(
int )
> ( &QDial::valueChanged ),
this, &QgsDial::onValueChanged );
113void QgsDial::onValueChanged(
int value )
119 else if ( mMin.userType() == QMetaType::Type::Int &&
120 mMax.userType() == QMetaType::Type::Int &&
121 mStep.userType() == QMetaType::Type::Int &&
122 mValue.userType() == QMetaType::Type::Int )
126 else if ( mMin.userType() == QMetaType::Type::Double &&
127 mMax.userType() == QMetaType::Type::Double &&
128 mStep.userType() == QMetaType::Type::Double &&
129 mValue.userType() == QMetaType::Type::Double )
131 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.