QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
qgspercentagewidget.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgspercentagewidget.h
3
-----------------
4
Date : January 2024
5
Copyright : (C) 2024 Nyall Dawson
6
Email : nyall.dawson@gmail.com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgspercentagewidget.h
"
17
18
#include "
qgis.h
"
19
#include "
qgsdoublespinbox.h
"
20
21
#include <QHBoxLayout>
22
#include <QSlider>
23
24
#include "moc_qgspercentagewidget.cpp"
25
26
QgsPercentageWidget::QgsPercentageWidget
( QWidget *parent )
27
: QWidget( parent )
28
{
29
QHBoxLayout *layout =
new
QHBoxLayout();
30
layout->setContentsMargins( 0, 0, 0, 0 );
31
layout->setSpacing( 3 );
32
setLayout( layout );
33
34
mSlider =
new
QSlider();
35
mSlider->setMinimum( 0 );
36
mSlider->setMaximum( 1000 );
37
mSlider->setSingleStep( 10 );
38
mSlider->setPageStep( 100 );
39
mSlider->setValue( 1000 );
40
mSlider->setOrientation( Qt::Horizontal );
41
layout->addWidget( mSlider, 1 );
42
43
mSpinBox =
new
QgsDoubleSpinBox
();
44
mSpinBox->setMinimum( 0.0 );
45
mSpinBox->setMaximum( 100.0 );
46
mSpinBox->setValue( 100.0 );
47
mSpinBox->setClearValue( 100.0 );
48
mSpinBox->setMinimumSize( QSize( 100, 0 ) );
49
mSpinBox->setDecimals( 1 );
50
mSpinBox->setSuffix( tr(
" %"
) );
51
layout->addWidget( mSpinBox, 0 );
52
53
setFocusProxy( mSpinBox );
54
55
connect( mSlider, &QSlider::valueChanged,
this
, [
this
](
int
value
) { mSpinBox->setValue(
value
/ 10.0 ); } );
56
connect( mSpinBox,
static_cast<
void
(
QgsDoubleSpinBox
::* )(
double
)
>
( &QgsDoubleSpinBox::valueChanged ),
this
, [
this
](
double
value
) {
57
whileBlocking
( mSlider )->setValue(
static_cast<
int
>
( std::lround(
value
* 10 ) ) );
58
} );
59
connect( mSpinBox,
static_cast<
void
(
QgsDoubleSpinBox
::* )(
double
)
>
( &QgsDoubleSpinBox::valueChanged ),
this
, &QgsPercentageWidget::spinChanged );
60
}
61
62
double
QgsPercentageWidget::value
()
const
63
{
64
return
mSpinBox->value() / 100.0;
65
}
66
67
QgsDoubleSpinBox
*
QgsPercentageWidget::spinBox
()
68
{
69
return
mSpinBox;
70
}
71
72
void
QgsPercentageWidget::setValue
(
double
value
)
73
{
74
mSpinBox->setValue(
value
* 100.0 );
75
}
76
77
void
QgsPercentageWidget::spinChanged(
double
value )
78
{
79
emit
valueChanged
(
value
/ 100.0 );
80
}
QgsDoubleSpinBox
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
Definition
qgsdoublespinbox.h:46
QgsPercentageWidget::QgsPercentageWidget
QgsPercentageWidget(QWidget *parent=nullptr)
Constructor for QgsPercentageWidget.
Definition
qgspercentagewidget.cpp:26
QgsPercentageWidget::valueChanged
void valueChanged(double value)
Emitted when the value is changed in the widget, where value is a factor which ranges from 0....
QgsPercentageWidget::value
double value
Definition
qgspercentagewidget.h:36
QgsPercentageWidget::setValue
void setValue(double value)
Sets the current value to show in the widget, where value is a factor which ranges from 0....
Definition
qgspercentagewidget.cpp:72
QgsPercentageWidget::spinBox
QgsDoubleSpinBox * spinBox()
Returns the spin box part of the widget.
Definition
qgspercentagewidget.cpp:67
qgis.h
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition
qgis.h:7637
qgsdoublespinbox.h
qgspercentagewidget.h
Generated on
for QGIS API Documentation by
1.17.0