29 setMinimumSize( QSize( 50, 50 ) );
34 QDial::paintEvent( event );
35 QPainter painter(
this );
36 const QRect rect = geometry();
37 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
38 painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ),
75 if ( mMin.type() == QVariant::Int &&
76 mMax.type() == QVariant::Int &&
77 mStep.type() == QVariant::Int &&
78 mValue.type() == QVariant::Int )
80 QDial::setMinimum( mMin.toInt() );
81 QDial::setMaximum( mMax.toInt() );
82 QDial::setSingleStep( mStep.toInt() );
83 QDial::setValue( mValue.toInt() );
86 if ( mMin.type() == QVariant::Double &&
87 mMax.type() == QVariant::Double &&
88 mStep.type() == QVariant::Double &&
89 mValue.type() == QVariant::Double )
92 QDial::setMinimum( 0 );
94 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
95 if ( maximum() != max )
96 QDial::setMaximum( max );
98 if ( singleStep() != 1 )
99 QDial::setSingleStep( 1 );
101 QDial::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
104 connect(
this,
static_cast < void ( QDial::* )(
int )
> ( &QDial::valueChanged ),
this, &QgsDial::onValueChanged );
112void QgsDial::onValueChanged(
int value )
118 else if ( mMin.type() == QVariant::Int &&
119 mMax.type() == QVariant::Int &&
120 mStep.type() == QVariant::Int &&
121 mValue.type() == QVariant::Int )
125 else if ( mMin.type() == QVariant::Double &&
126 mMax.type() == QVariant::Double &&
127 mStep.type() == QVariant::Double &&
128 mValue.type() == QVariant::Double )
130 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)
Returns true if the specified variant should be considered a NULL value.