diff options
author | Oto Magaldadze <omagaldadze@gmail.com> | 2013-09-17 14:02:49 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-29 12:12:16 +0100 |
commit | e913972d5268a2b1e5bfc12a0a72e4811e764d86 (patch) | |
tree | 93edbd28c651e9862fc4fd6b681d7a8d62f625bc /src | |
parent | fc5d07cee3c2d0f90badd24ddab0b220492f474f (diff) |
added QAbstractSpinBox::setGroupSeparatorShown function.
[ChangeLog][QtWidgets][QAbstractSpinBox] QTBUG-5142 - This will
allow a group (thousand) separator to be shown in QSpinBox
and QDoubleSpinBox widgets.
Task-number: QTBUG-5142
Change-Id: I2e23f5f83c93bb092a2dbd784e06d17d40d42909
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/widgets/qabstractspinbox.cpp | 27 | ||||
-rw-r--r-- | src/widgets/widgets/qabstractspinbox.h | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qabstractspinbox_p.h | 1 | ||||
-rw-r--r-- | src/widgets/widgets/qspinbox.cpp | 16 |
4 files changed, 40 insertions, 8 deletions
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 25369a01b6..af3a4d35f9 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -396,6 +396,30 @@ bool QAbstractSpinBox::isAccelerated() const } /*! + \property QAbstractSpinBox::showGroupSeparator + \since 5.3 + + + This property holds whether a thousands separator is enabled. By default this + property is false. +*/ +bool QAbstractSpinBox::isGroupSeparatorShown() const +{ + Q_D(const QAbstractSpinBox); + return d->showGroupSeparator; +} + +void QAbstractSpinBox::setGroupSeparatorShown(bool shown) +{ + Q_D(QAbstractSpinBox); + if (d->showGroupSeparator == shown) + return; + d->showGroupSeparator = shown; + d->setValue(d->value, EmitIfChanged); + updateGeometry(); +} + +/*! \enum QAbstractSpinBox::CorrectionMode This enum type describes the mode the spinbox will use to correct @@ -1316,7 +1340,8 @@ QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true), cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue), - acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0) + acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0), + showGroupSeparator(0) { } diff --git a/src/widgets/widgets/qabstractspinbox.h b/src/widgets/widgets/qabstractspinbox.h index 4f6aad0cde..7989000cc8 100644 --- a/src/widgets/widgets/qabstractspinbox.h +++ b/src/widgets/widgets/qabstractspinbox.h @@ -72,6 +72,7 @@ class Q_WIDGETS_EXPORT QAbstractSpinBox : public QWidget Q_PROPERTY(CorrectionMode correctionMode READ correctionMode WRITE setCorrectionMode) Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) Q_PROPERTY(bool keyboardTracking READ keyboardTracking WRITE setKeyboardTracking) + Q_PROPERTY(bool showGroupSeparator READ isGroupSeparatorShown WRITE setGroupSeparatorShown) public: explicit QAbstractSpinBox(QWidget *parent = 0); ~QAbstractSpinBox(); @@ -114,6 +115,9 @@ public: void setAccelerated(bool on); bool isAccelerated() const; + void setGroupSeparatorShown(bool shown); + bool isGroupSeparatorShown() const; + QSize sizeHint() const; QSize minimumSizeHint() const; void interpretText(); diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h index 0eeec02abc..da9f1d9757 100644 --- a/src/widgets/widgets/qabstractspinbox_p.h +++ b/src/widgets/widgets/qabstractspinbox_p.h @@ -150,6 +150,7 @@ public: QRect hoverRect; QAbstractSpinBox::ButtonSymbols buttonSymbols; QSpinBoxValidator *validator; + uint showGroupSeparator : 1; }; class QSpinBoxValidator : public QValidator diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index bf4e130d4e..a43b937951 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -463,8 +463,8 @@ void QSpinBox::setDisplayIntegerBase(int base) display the given \a value. The default implementation returns a string containing \a value printed in the standard way using QWidget::locale().toString(), but with the thousand separator - removed. Reimplementations may return anything. (See the example - in the detailed description.) + removed unless setGroupSeparatorShown() is set. Reimplementations may + return anything. (See the example in the detailed description.) Note: QSpinBox does not call this function for specialValueText() and that neither prefix() nor suffix() should be included in the @@ -487,7 +487,7 @@ QString QSpinBox::textFromValue(int value) const str.prepend('-'); } else { str = locale().toString(value); - if (qAbs(value) >= 1000 || value == INT_MIN) { + if (!d->showGroupSeparator && (qAbs(value) >= 1000 || value == INT_MIN)) { str.remove(locale().groupSeparator()); } } @@ -538,7 +538,8 @@ QValidator::State QSpinBox::validate(QString &text, int &pos) const */ void QSpinBox::fixup(QString &input) const { - input.remove(locale().groupSeparator()); + if (!isGroupSeparatorShown()) + input.remove(locale().groupSeparator()); } @@ -891,7 +892,8 @@ void QDoubleSpinBox::setDecimals(int decimals) display the given \a value. The default implementation returns a string containing \a value printed using QWidget::locale().toString(\a value, QLatin1Char('f'), decimals()) and will remove the thousand - separator. Reimplementations may return anything. + separator unless setGroupSeparatorShown() is set. Reimplementations may + return anything. Note: QDoubleSpinBox does not call this function for specialValueText() and that neither prefix() nor suffix() should @@ -908,9 +910,9 @@ QString QDoubleSpinBox::textFromValue(double value) const { Q_D(const QDoubleSpinBox); QString str = locale().toString(value, 'f', d->decimals); - if (qAbs(value) >= 1000.0) { + if (!d->showGroupSeparator && qAbs(value) >= 1000.0) str.remove(locale().groupSeparator()); - } + return str; } |