Skip to content

Commit f52a9a0

Browse files
authored
Merge pull request #3468 from nyalldawson/spin_box_v2
Rework Qgs(Double)SpinBox clear handling
2 parents a90217d + f16b387 commit f52a9a0

File tree

11 files changed

+584
-127
lines changed

11 files changed

+584
-127
lines changed
Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1+
/** \ingroup gui
2+
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
3+
* The clear value can be either the minimum or the maiximum value of the spin box or a custom value.
4+
* This value can then be handled by a special value text.
5+
*/
6+
17
class QgsDoubleSpinBox : QDoubleSpinBox
28
{
39
%TypeHeaderCode
410
#include <qgsdoublespinbox.h>
511
%End
612

713
public:
14+
15+
//! Behaviour when widget is cleared.
816
enum ClearValueMode
917
{
10-
MinimumValue,
11-
MaximumValue,
12-
CustomValue
18+
MinimumValue, //!< Reset value to minimum()
19+
MaximumValue, //!< Reset value to maximum()
20+
CustomValue, //!< Reset value to custom value (see setClearValue() )
1321
};
1422

23+
/** Constructor for QgsDoubleSpinBox.
24+
* @param parent parent widget
25+
*/
1526
explicit QgsDoubleSpinBox( QWidget *parent /TransferThis/ = 0 );
1627

17-
//! determines if the widget will show a clear button
18-
//! @note the clear button will set the widget to its minimum value
28+
/** Sets whether the widget will show a clear button. The clear button
29+
* allows users to reset the widget to a default or empty state.
30+
* @param showClearButton set to true to show the clear button, or false to hide it
31+
* @see showClearButton()
32+
*/
1933
void setShowClearButton( const bool showClearButton );
34+
35+
/** Returns whether the widget is showing a clear button.
36+
* @see setShowClearButton()
37+
*/
2038
bool showClearButton() const;
2139

2240
/** Sets if the widget will allow entry of simple expressions, which are
@@ -25,6 +43,7 @@ class QgsDoubleSpinBox : QDoubleSpinBox
2543
* @note added in QGIS 2.7
2644
*/
2745
void setExpressionsEnabled( const bool enabled );
46+
2847
/** Returns whether the widget will allow entry of simple expressions, which are
2948
* evaluated and then discarded.
3049
* @returns true if spin box allows expression entry
@@ -36,26 +55,29 @@ class QgsDoubleSpinBox : QDoubleSpinBox
3655
virtual void clear();
3756

3857
/**
39-
* @brief setClearValue defines the clear value as a custom value and will automatically set the clear value mode to CustomValue
58+
* Defines the clear value as a custom value and will automatically set the clear value mode to CustomValue.
4059
* @param customValue defines the numerical value used as the clear value
4160
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
61+
* @see setClearValue()
4262
*/
4363
void setClearValue( double customValue, const QString& clearValueText = QString() );
64+
4465
/**
45-
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
66+
* Defines if the clear value should be the minimum or maximum values of the widget or a custom value.
4667
* @param mode mode to user for clear value
4768
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
4869
*/
4970
void setClearValueMode( ClearValueMode mode, const QString& clearValueText = QString() );
5071

51-
//! returns the value used when clear() is called.
72+
/** Returns the value used when clear() is called.
73+
* @see setClearValue()
74+
*/
5275
double clearValue() const;
5376

5477
virtual double valueFromText( const QString & text ) const;
5578
virtual QValidator::State validate( QString & input, int & pos ) const;
5679

5780
protected:
58-
virtual void resizeEvent( QResizeEvent* event );
5981
virtual void changeEvent( QEvent* event );
6082
virtual void paintEvent( QPaintEvent* event );
6183
};
Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1+
/** \ingroup gui
2+
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
3+
* The clear value can be either the minimum or the maiximum value of the spin box or a custom value.
4+
* This value can then be handled by a special value text.
5+
*/
6+
17
class QgsSpinBox : QSpinBox
28
{
39
%TypeHeaderCode
410
#include <qgsspinbox.h>
511
%End
612

713
public:
14+
15+
//! Behaviour when widget is cleared.
816
enum ClearValueMode
917
{
10-
MinimumValue,
11-
MaximumValue,
12-
CustomValue
18+
MinimumValue, //!< Reset value to minimum()
19+
MaximumValue, //!< Reset value to maximum()
20+
CustomValue, //!< Reset value to custom value (see setClearValue() )
1321
};
1422

23+
/** Constructor for QgsSpinBox.
24+
* @param parent parent widget
25+
*/
1526
explicit QgsSpinBox( QWidget *parent /TransferThis/ = 0 );
1627

17-
//! determines if the widget will show a clear button
18-
//! @note the clear button will set the widget to its minimum value
28+
/** Sets whether the widget will show a clear button. The clear button
29+
* allows users to reset the widget to a default or empty state.
30+
* @param showClearButton set to true to show the clear button, or false to hide it
31+
* @see showClearButton()
32+
*/
1933
void setShowClearButton( const bool showClearButton );
34+
35+
/** Returns whether the widget is showing a clear button.
36+
* @see setShowClearButton()
37+
*/
2038
bool showClearButton() const;
2139

2240
/** Sets if the widget will allow entry of simple expressions, which are
@@ -25,6 +43,7 @@ class QgsSpinBox : QSpinBox
2543
* @note added in QGIS 2.7
2644
*/
2745
void setExpressionsEnabled( const bool enabled );
46+
2847
/** Returns whether the widget will allow entry of simple expressions, which are
2948
* evaluated and then discarded.
3049
* @returns true if spin box allows expression entry
@@ -36,26 +55,30 @@ class QgsSpinBox : QSpinBox
3655
virtual void clear();
3756

3857
/**
39-
* @brief setClearValue defines the clear value for the widget and will automatically set the clear value mode to CustomValue
58+
* Defines the clear value as a custom value and will automatically set the clear value mode to CustomValue.
4059
* @param customValue defines the numerical value used as the clear value
4160
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
61+
* @see setClearValue()
4262
*/
4363
void setClearValue( int customValue, const QString& clearValueText = QString() );
64+
4465
/**
45-
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
66+
* Defines if the clear value should be the minimum or maximum values of the widget or a custom value.
4667
* @param mode mode to user for clear value
4768
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
4869
*/
4970
void setClearValueMode( ClearValueMode mode, const QString& clearValueText = QString() );
5071

51-
//! returns the value used when clear() is called.
72+
/** Returns the value used when clear() is called.
73+
* @see setClearValue()
74+
*/
5275
int clearValue() const;
5376

5477
virtual int valueFromText( const QString & text ) const;
5578
virtual QValidator::State validate( QString & input, int & pos ) const;
5679

5780
protected:
58-
virtual void resizeEvent( QResizeEvent* event );
81+
5982
virtual void changeEvent( QEvent* event );
6083
virtual void paintEvent( QPaintEvent* event );
6184
};

python/gui/qgsfilterlineedit.sip

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,138 @@
1-
2-
/** LineEdit with builtin clear button
3-
*/
1+
/** \class QgsFilterLineEdit
2+
* \ingroup gui
3+
* QLineEdit subclass with built in support for clearing the widget's value and
4+
* handling custom null value representations.
5+
*
6+
* When using QgsFilterLineEdit the value(), setValue() and clearValue() methods should be used
7+
* instead of QLineEdit's text(), setText() and clear() methods, and the valueChanged()
8+
* signal should be used instead of textChanged().
9+
**/
410
class QgsFilterLineEdit : QLineEdit
511
{
612
%TypeHeaderCode
713
#include <qgsfilterlineedit.h>
814
%End
915
public:
16+
17+
//! Behaviour when clearing value of widget
18+
enum ClearMode
19+
{
20+
ClearToNull, //!< Reset value to null
21+
ClearToDefault, //!< Reset value to default value (see defaultValue() )
22+
};
23+
24+
/** Constructor for QgsFilterLineEdit.
25+
* @param parent parent widget
26+
* @param nullValue string for representing null values
27+
*/
1028
QgsFilterLineEdit( QWidget* parent /TransferThis/ = 0, const QString& nullValue = QString::null );
1129

30+
/** Returns true if the widget's clear button is visible.
31+
* @see setShowClearButton()
32+
* @note added in QGIS 3.0
33+
*/
34+
bool showClearButton() const;
35+
36+
/** Sets whether the widget's clear button is visible.
37+
* @param visible set to false to hide the clear button
38+
* @see showClearButton()
39+
* @note added in QGIS 3.0
40+
*/
41+
void setShowClearButton( bool visible );
42+
43+
/** Returns the clear mode for the widget. The clear mode defines the behaviour of the
44+
* widget when its value is cleared. This defaults to ClearToNull.
45+
* @see setClearMode()
46+
* @note added in QGIS 3.0
47+
*/
48+
ClearMode clearMode() const;
49+
50+
/** Sets the clear mode for the widget. The clear mode defines the behaviour of the
51+
* widget when its value is cleared. This defaults to ClearToNull.
52+
* @see clearMode()
53+
* @note added in QGIS 3.0
54+
*/
55+
void setClearMode( ClearMode mode );
56+
57+
/** Sets the string representation for null values in the widget. This does not
58+
* affect the values returned for null values by value(), rather it only affects
59+
* the text that is shown to users when the widget's value is null.
60+
* @param nullValue string to show when widget's value is null
61+
* @see nullValue()
62+
*/
1263
void setNullValue( const QString& nullValue );
1364

65+
/** Returns the string used for representating null values in the widget.
66+
* @see setNullValue()
67+
* @see isNull()
68+
*/
1469
QString nullValue() const;
1570

71+
/** Sets the default value for the widget. The default value is a value
72+
* which the widget will be reset to if it is cleared and the clearMode()
73+
* is equal to ClearToDefault.
74+
* @param defaultValue default value
75+
* @see defaultValue()
76+
* @see clearMode()
77+
* @note added in QGIS 3.0
78+
*/
79+
void setDefaultValue( const QString& defaultValue );
80+
81+
/** Returns the default value for the widget. The default value is a value
82+
* which the widget will be reset to if it is cleared and the clearMode()
83+
* is equal to ClearToDefault.
84+
* @see setDefaultValue()
85+
* @see clearMode()
86+
* @note added in QGIS 3.0
87+
*/
88+
QString defaultValue() const;
89+
1690
/**
17-
* Sets the current text with NULL support
91+
* Sets the current text for the widget with support for handling null values.
1892
*
19-
* @param value The text to set. If a Null string is provided, the text will match the nullValue.
93+
* @param value The text to set. If a null string is provided, the text shown in the
94+
* widget will be set to the current nullValue().
95+
* @see value()
2096
*/
2197
void setValue( const QString& value );
2298

2399
/**
24-
* Returns the text of this edit with NULL support
100+
* Returns the text of this edit with support for handling null values. If the text
101+
* in the widget matches the current nullValue() then the returned value will be
102+
* a null string.
25103
*
26-
* @return Current text (Null string if it matches the nullValue property )
104+
* @return Current text (or null string if it matches the nullValue() property )
105+
* @see setValue()
27106
*/
28107
QString value() const;
29108

30109
/**
31-
* Determine if the current text represents Null.
110+
* Determine if the current text represents null.
32111
*
33-
* @return True if the value is Null.
112+
* @return True if the widget's value is null.
113+
* @see nullValue()
34114
*/
35115
bool isNull() const;
36116

117+
public slots:
118+
119+
/** Clears the widget and resets it to the null value.
120+
* @see nullValue()
121+
* @note added in QGIS 3.0
122+
*/
123+
virtual void clearValue();
124+
37125
signals:
126+
127+
/** Emitted when the widget is cleared
128+
* @see clearValue()
129+
*/
38130
void cleared();
39131

40132
/**
41-
* Same as textChanged(const QString& ) but with support for Null values.
133+
* Same as textChanged() but with support for null values.
42134
*
43-
* @param value The current text or Null string if it matches the nullValue property.
135+
* @param value The current text or null string if it matches the nullValue() property.
44136
*/
45137
void valueChanged( const QString& value );
46138

0 commit comments

Comments
 (0)