21 #include <QPaintEvent>
28 setMinimumSize( QSize( 50, 50 ) );
33 QDial::paintEvent( event );
34 QPainter painter(
this );
35 const QRect rect = geometry();
36 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
37 painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ),
66 void QgsDial::update()
68 if ( mMin.isNull() || mMax.isNull() || mStep.isNull() )
71 if ( mValue.isNull() )
74 if ( mMin.type() == QVariant::Int &&
75 mMax.type() == QVariant::Int &&
76 mStep.type() == QVariant::Int &&
77 mValue.type() == QVariant::Int )
79 QDial::setMinimum( mMin.toInt() );
80 QDial::setMaximum( mMax.toInt() );
81 QDial::setSingleStep( mStep.toInt() );
82 QDial::setValue( mValue.toInt() );
85 if ( mMin.type() == QVariant::Double &&
86 mMax.type() == QVariant::Double &&
87 mStep.type() == QVariant::Double &&
88 mValue.type() == QVariant::Double )
91 QDial::setMinimum( 0 );
93 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
94 if ( maximum() != max )
95 QDial::setMaximum( max );
97 if ( singleStep() != 1 )
98 QDial::setSingleStep( 1 );
100 QDial::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
103 connect(
this,
static_cast < void ( QDial::* )(
int )
> ( &QDial::valueChanged ),
this, &QgsDial::onValueChanged );
111 void QgsDial::onValueChanged(
int value )
113 if ( mMin.isNull() || mMax.isNull() || mStep.isNull() )
117 else if ( mMin.type() == QVariant::Int &&
118 mMax.type() == QVariant::Int &&
119 mStep.type() == QVariant::Int &&
120 mValue.type() == QVariant::Int )
124 else if ( mMin.type() == QVariant::Double &&
125 mMax.type() == QVariant::Double &&
126 mStep.type() == QVariant::Double &&
127 mValue.type() == QVariant::Double )
129 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)