SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
qtDoubleLineEdit.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 
11 /*=========================================================================
12 
13  Program: ParaView
14  Module: pqDoubleLineEdit.h
15 
16  Copyright (c) 2005-2018 Sandia Corporation, Kitware Inc.
17  All rights reserved.
18 
19  ParaView is a free software; you can redistribute it and/or modify it
20  under the terms of the ParaView license version 1.2.
21 
22  See License_v1.2.txt for the full ParaView license.
23  A copy of this license can be obtained by contacting
24  Kitware Inc.
25  28 Corporate Drive
26  Clifton Park, NY 12065
27  USA
28 
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
33 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 
41 ========================================================================*/
42 #ifndef smtk_extension_qtDoubleLineEdit_h
43 #define smtk_extension_qtDoubleLineEdit_h
44 
45 #include "smtk/extension/qt/Exports.h"
46 #include "smtk/extension/qt/qtLineEdit.h"
47 
48 // Qt Includes.
49 #include <QScopedPointer> // for ivar
50 #include <QTextStream> // for formatDouble
51 
52 namespace smtk
53 {
54 namespace extension
55 {
75 class SMTKQTEXT_EXPORT qtDoubleLineEdit : public qtLineEdit
76 {
77  Q_OBJECT
78  Q_ENUMS(RealNumberNotation)
79  Q_PROPERTY(RealNumberNotation notation READ notation WRITE setNotation)
80  Q_PROPERTY(int precision READ precision WRITE setPrecision)
81  Q_PROPERTY(bool useGlobalPrecisionAndNotation READ useGlobalPrecisionAndNotation WRITE
82  setUseGlobalPrecisionAndNotation)
83  using Superclass = qtLineEdit;
84 
85 public:
86  qtDoubleLineEdit(QWidget* parent = nullptr);
87  ~qtDoubleLineEdit() override;
88 
93  {
94  MixedNotation = 0,
95  ScientificNotation,
96  FixedNotation
97  };
98 
103  RealNumberNotation notation() const;
104 
109  int precision() const;
110 
116  bool useGlobalPrecisionAndNotation() const;
117 
119 
124  static void setGlobalPrecisionAndNotation(int precision, RealNumberNotation notation);
125  static int globalPrecision();
126  static RealNumberNotation globalNotation();
128 
133  QString simplifiedText() const;
134 
136 
140  static QString
141  formatDouble(double value, QTextStream::RealNumberNotation notation, int precision);
142  static QString
143  formatDouble(double value, qtDoubleLineEdit::RealNumberNotation notation, int precision);
145 
147 
151  static QString formatDoubleUsingGlobalPrecisionAndNotation(double value);
153 
154 public Q_SLOTS:
159  void setNotation(RealNumberNotation _notation);
160 
165  void setPrecision(int precision);
166 
171  void setUseGlobalPrecisionAndNotation(bool value);
172 
173 protected:
174  void paintEvent(QPaintEvent* evt) override;
175  void resizeEvent(QResizeEvent* event) override;
176 
177 private:
178  Q_DISABLE_COPY(qtDoubleLineEdit)
179 
180  static int GlobalPrecision;
181  static RealNumberNotation GlobalNotation;
182 
183  class qtInternals;
184  QScopedPointer<qtInternals> Internals;
185 };
186 } // namespace extension
187 } // namespace smtk
188 #endif
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::extension::qtDoubleLineEdit
qtLineEdit subclass that supports a low precision view when inactive
Definition: qtDoubleLineEdit.h:75
smtk::extension::qtLineEdit
qtLineEdit is a specialization of QLineEdit which provide a new property 'text2'.
Definition: qtLineEdit.h:70
smtk::extension::qtDoubleLineEdit::RealNumberNotation
RealNumberNotation
This enum specifies which notations to use for displaying the value.
Definition: qtDoubleLineEdit.h:92