|
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 | + **/ |
4 | 10 | class QgsFilterLineEdit : QLineEdit |
5 | 11 | { |
6 | 12 | %TypeHeaderCode |
7 | 13 | #include <qgsfilterlineedit.h> |
8 | 14 | %End |
9 | 15 | 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 | + */ |
10 | 28 | QgsFilterLineEdit( QWidget* parent /TransferThis/ = 0, const QString& nullValue = QString::null ); |
11 | 29 |
|
| 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 | + */ |
12 | 63 | void setNullValue( const QString& nullValue ); |
13 | 64 |
|
| 65 | + /** Returns the string used for representating null values in the widget. |
| 66 | + * @see setNullValue() |
| 67 | + * @see isNull() |
| 68 | + */ |
14 | 69 | QString nullValue() const; |
15 | 70 |
|
| 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 | + |
16 | 90 | /** |
17 | | - * Sets the current text with NULL support |
| 91 | + * Sets the current text for the widget with support for handling null values. |
18 | 92 | * |
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() |
20 | 96 | */ |
21 | 97 | void setValue( const QString& value ); |
22 | 98 |
|
23 | 99 | /** |
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. |
25 | 103 | * |
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() |
27 | 106 | */ |
28 | 107 | QString value() const; |
29 | 108 |
|
30 | 109 | /** |
31 | | - * Determine if the current text represents Null. |
| 110 | + * Determine if the current text represents null. |
32 | 111 | * |
33 | | - * @return True if the value is Null. |
| 112 | + * @return True if the widget's value is null. |
| 113 | + * @see nullValue() |
34 | 114 | */ |
35 | 115 | bool isNull() const; |
36 | 116 |
|
| 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 | + |
37 | 125 | signals: |
| 126 | + |
| 127 | + /** Emitted when the widget is cleared |
| 128 | + * @see clearValue() |
| 129 | + */ |
38 | 130 | void cleared(); |
39 | 131 |
|
40 | 132 | /** |
41 | | - * Same as textChanged(const QString& ) but with support for Null values. |
| 133 | + * Same as textChanged() but with support for null values. |
42 | 134 | * |
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. |
44 | 136 | */ |
45 | 137 | void valueChanged( const QString& value ); |
46 | 138 |
|
|
0 commit comments