21 #include <QPaintEvent> 27 setMinimumSize( QSize( 50, 50 ) );
32 QDial::paintEvent( event );
33 QPainter painter(
this );
34 QRect rect = geometry();
35 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
36 painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ),
65 void QgsDial::update()
67 if ( mMin.isNull() || mMax.isNull() || mStep.isNull() )
70 if ( mValue.isNull() )
73 if ( mMin.type() == QVariant::Int &&
74 mMax.type() == QVariant::Int &&
75 mStep.type() == QVariant::Int &&
76 mValue.type() == QVariant::Int )
78 QDial::setMinimum( mMin.toInt() );
79 QDial::setMaximum( mMax.toInt() );
80 QDial::setSingleStep( mStep.toInt() );
81 QDial::setValue( mValue.toInt() );
84 if ( mMin.type() == QVariant::Double &&
85 mMax.type() == QVariant::Double &&
86 mStep.type() == QVariant::Double &&
87 mValue.type() == QVariant::Double )
90 QDial::setMinimum( 0 );
92 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 );
110 void QgsDial::onValueChanged(
int value )
112 if ( mMin.isNull() || mMax.isNull() || mStep.isNull() )
116 else if ( mMin.type() == QVariant::Int &&
117 mMax.type() == QVariant::Int &&
118 mStep.type() == QVariant::Int &&
119 mValue.type() == QVariant::Int )
123 else if ( mMin.type() == QVariant::Double &&
124 mMax.type() == QVariant::Double &&
125 mStep.type() == QVariant::Double &&
126 mValue.type() == QVariant::Double )
128 mValue = QVariant( mMin.toDouble() + value * mStep.toDouble() );
void setMaximum(const QVariant &max)
QgsDial(QWidget *parent=nullptr)
Constructor for QgsDial.
void paintEvent(QPaintEvent *event) override
void setMinimum(const QVariant &min)
void setSingleStep(const QVariant &step)
void valueChanged(const QVariant &)
void setValue(const QVariant &value)
QVariant variantValue() const