New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bugfix] Allow empty null representation in spinboxes #7943
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,13 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox | |
*/ | ||
void setLineEditAlignment( Qt::Alignment alignment ); | ||
|
||
/** | ||
* Set the special-value text to be \a txt | ||
* If set, the spin box will display this text instead of a numeric value whenever the current value | ||
* is equal to minimum(). Typical use is to indicate that this choice has a special (default) meaning. | ||
*/ | ||
void setSpecialValueText( const QString &txt ); | ||
|
||
double valueFromText( const QString &text ) const override; | ||
QValidator::State validate( QString &input, int &pos ) const override; | ||
void paintEvent( QPaintEvent *e ) override; | ||
|
@@ -156,6 +163,13 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox | |
bool mExpressionsEnabled = true; | ||
|
||
QString stripped( const QString &originalText ) const; | ||
|
||
// This is required because private implementation of | ||
// QAbstractSpinBoxPrivate checks for specialText emptiness | ||
// and skips specialText handling if it's empty | ||
static QString SPECIAL_TEXT_WHEN_EMPTY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any special reason to put this into the header? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the whole variable appears like an internal implementation detail that could only live isolated in the cpp on first look? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, besides that I'm using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't insist, I was just thinking out loud. Mostly I try to keep implementation details out of installed headers. |
||
|
||
friend class TestQgsRangeWidgetWrapper; | ||
}; | ||
|
||
#endif // QGSDOUBLESPINBOX_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No: the problem that is addressed here is that when the widget value is null and the user enters a text, the text gets appended/prepended to the invisible character and the value is not correctly converted to double/int, this is also checked in the tests, so we really want to replace any invisible char in any position in the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Sidenote: at some point I'll create a number-optimized QLineEdit with proper placeholder text and int/double properties. Noone needs the arrows on spinboxes anyway. And the only thing they reliably get right is data corruption because they grab the mouse wheel.
☠️ death to spinboxes ☠️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and they could even make copy/paste with thousand separators work as expected.