equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
7 ** This file is part of the QtGui module of the Qt Toolkit. |
8 ** |
8 ** |
97 |
97 |
98 inline void init() { |
98 inline void init() { |
99 Q_Q(QDoubleSpinBox); |
99 Q_Q(QDoubleSpinBox); |
100 q->setInputMethodHints(Qt::ImhFormattedNumbersOnly); |
100 q->setInputMethodHints(Qt::ImhFormattedNumbersOnly); |
101 } |
101 } |
|
102 |
|
103 // When fiddling with the decimals property, we may lose precision in these properties. |
|
104 double actualMin; |
|
105 double actualMax; |
102 }; |
106 }; |
103 |
107 |
104 |
108 |
105 /*! |
109 /*! |
106 \class QSpinBox |
110 \class QSpinBox |
760 } |
764 } |
761 |
765 |
762 void QDoubleSpinBox::setMinimum(double minimum) |
766 void QDoubleSpinBox::setMinimum(double minimum) |
763 { |
767 { |
764 Q_D(QDoubleSpinBox); |
768 Q_D(QDoubleSpinBox); |
|
769 d->actualMin = minimum; |
765 const QVariant m(d->round(minimum)); |
770 const QVariant m(d->round(minimum)); |
766 d->setRange(m, (d->variantCompare(d->maximum, m) > 0 ? d->maximum : m)); |
771 d->setRange(m, (d->variantCompare(d->maximum, m) > 0 ? d->maximum : m)); |
767 } |
772 } |
768 |
773 |
769 /*! |
774 /*! |
790 } |
795 } |
791 |
796 |
792 void QDoubleSpinBox::setMaximum(double maximum) |
797 void QDoubleSpinBox::setMaximum(double maximum) |
793 { |
798 { |
794 Q_D(QDoubleSpinBox); |
799 Q_D(QDoubleSpinBox); |
|
800 d->actualMax = maximum; |
795 const QVariant m(d->round(maximum)); |
801 const QVariant m(d->round(maximum)); |
796 d->setRange((d->variantCompare(d->minimum, m) < 0 ? d->minimum : m), m); |
802 d->setRange((d->variantCompare(d->minimum, m) < 0 ? d->minimum : m), m); |
797 } |
803 } |
798 |
804 |
799 /*! |
805 /*! |
811 */ |
817 */ |
812 |
818 |
813 void QDoubleSpinBox::setRange(double minimum, double maximum) |
819 void QDoubleSpinBox::setRange(double minimum, double maximum) |
814 { |
820 { |
815 Q_D(QDoubleSpinBox); |
821 Q_D(QDoubleSpinBox); |
|
822 d->actualMin = minimum; |
|
823 d->actualMax = maximum; |
816 d->setRange(QVariant(d->round(minimum)), QVariant(d->round(maximum))); |
824 d->setRange(QVariant(d->round(minimum)), QVariant(d->round(maximum))); |
817 } |
825 } |
818 |
826 |
819 /*! |
827 /*! |
820 \property QDoubleSpinBox::decimals |
828 \property QDoubleSpinBox::decimals |
841 void QDoubleSpinBox::setDecimals(int decimals) |
849 void QDoubleSpinBox::setDecimals(int decimals) |
842 { |
850 { |
843 Q_D(QDoubleSpinBox); |
851 Q_D(QDoubleSpinBox); |
844 d->decimals = qBound(0, decimals, DBL_MAX_10_EXP + DBL_DIG); |
852 d->decimals = qBound(0, decimals, DBL_MAX_10_EXP + DBL_DIG); |
845 |
853 |
846 setRange(minimum(), maximum()); // make sure values are rounded |
854 setRange(d->actualMin, d->actualMax); // make sure values are rounded |
847 setValue(value()); |
855 setValue(value()); |
848 } |
856 } |
849 |
857 |
850 /*! |
858 /*! |
851 This virtual function is used by the spin box whenever it needs to |
859 This virtual function is used by the spin box whenever it needs to |
1049 Constructs a QSpinBoxPrivate object |
1057 Constructs a QSpinBoxPrivate object |
1050 */ |
1058 */ |
1051 |
1059 |
1052 QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate() |
1060 QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate() |
1053 { |
1061 { |
1054 minimum = QVariant(0.0); |
1062 actualMin = 0.0; |
1055 maximum = QVariant(99.99); |
1063 actualMax = 99.99; |
|
1064 minimum = QVariant(actualMin); |
|
1065 maximum = QVariant(actualMax); |
1056 value = minimum; |
1066 value = minimum; |
1057 singleStep = QVariant(1.0); |
1067 singleStep = QVariant(1.0); |
1058 decimals = 2; |
1068 decimals = 2; |
1059 type = QVariant::Double; |
1069 type = QVariant::Double; |
1060 } |
1070 } |