itom
Loading...
Searching...
No Matches
doubleSpinBox_p.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom and its software development toolkit (SDK).
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 In addition, as a special exception, the Institut für Technische
15 Optik (ITO) gives you certain additional rights.
16 These rights are described in the ITO LGPL Exception version 1.0,
17 which can be found in the file LGPL_EXCEPTION.txt in this package.
18
19 itom is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22 General Public Licence for more details.
23
24 You should have received a copy of the GNU Library General Public License
25 along with itom. If not, see <http://www.gnu.org/licenses/>.
26
27 This file is a port and modified version of the
28 CTK Common Toolkit (http://www.commontk.org)
29*********************************************************************** */
30
31// includes
32#include "doubleSpinBox.h"
33
34// Qt includes
35#include <QDoubleSpinBox>
36#include <QPointer>
38class ValueProxy;
39class QFocusEvent;
40
41//-----------------------------------------------------------------------------
42class itomQDoubleSpinBox: public QDoubleSpinBox
43{
44 Q_OBJECT
50 Q_PROPERTY(bool invertedControls READ invertedControls WRITE setInvertedControls)
51public:
52 typedef QDoubleSpinBox Superclass;
53 itomQDoubleSpinBox(DoubleSpinBoxPrivate* pimpl, QWidget* widget);
54 void setInvertedControls(bool invertedControls);
55 bool invertedControls() const;
56
59 virtual void stepBy(int steps);
60
63 virtual QLineEdit* lineEdit()const;
64
65 virtual double valueFromText(const QString &text) const;
66 virtual QString textFromValue(double value) const;
67 virtual int decimalsFromText(const QString &text) const;
68 virtual QValidator::State validate(QString& input, int& pos)const;
69
71 void initStyleOptionSpinBox(QStyleOptionSpinBox* option);
72protected:
73 DoubleSpinBoxPrivate* const d_ptr;
74
75 void focusOutEvent(QFocusEvent * event);
76
81 virtual StepEnabled stepEnabled () const;
82
83 bool InvertedControls;
84private:
85 Q_DECLARE_PRIVATE(DoubleSpinBox);
86 Q_DISABLE_COPY(itomQDoubleSpinBox);
87};
88
89//-----------------------------------------------------------------------------
90class DoubleSpinBoxPrivate: public QObject
91{
92 Q_OBJECT
93 Q_DECLARE_PUBLIC(DoubleSpinBox);
94protected:
95 DoubleSpinBox* const q_ptr;
96public:
98
99 itomQDoubleSpinBox* SpinBox;
101 int DefaultDecimals;
102 DoubleSpinBox::DecimalsOptions DOption;
103 bool InvertedControls;
104 DoubleSpinBox::SizeHintPolicy SizeHintPolicy;
105
106 double InputValue;
107 double InputRange[2];
108
109 mutable QString CachedText;
110 mutable double CachedValue;
111 mutable QValidator::State CachedState;
112 mutable int CachedDecimals;
113 mutable QSize CachedSizeHint;
114 mutable QSize CachedMinimumSizeHint;
115 bool ForceInputValueUpdate;
116
117 QPointer<ValueProxy> Proxy;
118
119 void init();
121 bool compare(double x1, double x2) const;
123 double round(double value, int decimals)const;
124
126 QString stripped(const QString& text, int* pos)const;
127
131 int boundDecimals(int decimals)const;
135 int decimalsForValue(double value)const;
138 void setDecimals(int dec);
141 void setValue(double value, int dec = -1);
142
146 double validateAndInterpret(QString &input, int &pos,
147 QValidator::State &state, int &decimals) const;
148
149 void connectSpinBoxValueChanged();
150 void disconnectSpinBoxValueChanged();
151
152public slots:
153 void editorTextChanged(const QString& text);
154 void onValueChanged();
155
156 void onValueProxyAboutToBeModified();
157 void onValueProxyModified();
158};
Custom SpinBox The DoubleSpinBox internally uses a QDoubleSpinBox while it retain controls over it.
Definition doubleSpinBox.h:55
SetMode
Definition doubleSpinBox.h:113
Definition doubleSpinBox_p.h:91
void setValue(double value, int dec=-1)
Definition doubleSpinBox.cpp:302
int decimalsForValue(double value) const
Definition doubleSpinBox.cpp:291
int boundDecimals(int decimals) const
Definition doubleSpinBox.cpp:276
QString stripped(const QString &text, int *pos) const
Remove prefix and suffix.
Definition doubleSpinBox.cpp:254
bool compare(double x1, double x2) const
Compare two double previously rounded according to the number of decimals.
Definition doubleSpinBox.cpp:241
double validateAndInterpret(QString &input, int &pos, QValidator::State &state, int &decimals) const
Definition doubleSpinBox.cpp:376
void setDecimals(int dec)
Definition doubleSpinBox.cpp:339
double round(double value, int decimals) const
Return a value rounded with the number of decimals.
Definition doubleSpinBox.cpp:248
Base class for value proxies. Value proxy allows to decouple the displayed value from the values acce...
Definition valueProxy.h:46
Definition doubleSpinBox_p.h:43
bool invertedControls
Definition doubleSpinBox_p.h:50
void initStyleOptionSpinBox(QStyleOptionSpinBox *option)
Expose publicly QAbstractSpinBox::initStyleOption()
Definition doubleSpinBox.cpp:66
virtual StepEnabled stepEnabled() const
Definition doubleSpinBox.cpp:102
virtual QLineEdit * lineEdit() const
Definition doubleSpinBox.cpp:61
virtual void stepBy(int steps)
Definition doubleSpinBox.cpp:84