OTB  6.7.0
Orfeo Toolbox
otbWrapperQtWidgetSpinBoxes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbWrapperQtWidgetSpinBoxes_h
22 #define otbWrapperQtWidgetSpinBoxes_h
23 
24 #include <QIcon>
25 #include <QLineEdit>
26 #include <QSpinBox>
27 
29 
30 namespace otb
31 {
32 namespace Wrapper
33 {
34 
35 // A QLineEdit with a built-in reset button
36 class OTBQtWidget_EXPORT QtWidgetLineEdit : public QLineEdit
37 {
38  Q_OBJECT
39 
40 public:
41  QtWidgetLineEdit( QWidget *parent = nullptr );
42 
43  // Show, hide or get state of the clear button
44  void EnableClearButton();
45  void DisableClearButton();
46 
47  static const int CLEAR_ICON_SIZE = 16;
48 
49 signals:
50  // Triggered when the clear button is pressed
51  void Cleared();
52 
53 private:
54 
55  QIcon m_ClearIcon;
56  QAction *m_ClearAction = nullptr;
57 };
58 
59 // A QSpinBox with QtWidgetLineEdit as a custom LineEdit
60 class OTBQtWidget_EXPORT QtWidgetSpinBox : public QSpinBox
61 {
62  Q_OBJECT
63 
64 public:
65  explicit QtWidgetSpinBox( QWidget* parent = nullptr);
66 
67  int valueFromText(const QString &text) const override;
68  QValidator::State validate( QString &input, int &pos ) const override;
69 
70  // Show, hide or get state of the clear button
71  void EnableClearButton();
72  void DisableClearButton();
73  bool IsClearButtonEnabled() const;
74 
75  void SetValueNoSignal(int);
76 
77 signals:
78  // Triggered when the clear button is pressed
79  void Cleared();
80 
81 private:
83 };
84 
85 // A QDoubleSpinBox with QtWidgetLineEdit as a custom LineEdit
86 // and custom handling of textFromValue / valueFromText for variable precision decimals
87 class OTBQtWidget_EXPORT QtWidgetDoubleSpinBox : public QDoubleSpinBox
88 {
89  Q_OBJECT
90 
91 public:
92  explicit QtWidgetDoubleSpinBox( QWidget* parent = nullptr);
93 
94  double valueFromText(const QString &text) const override;
95  QString textFromValue(double value) const override;
96  QValidator::State validate( QString &input, int &pos ) const override;
97 
98  // Show, hide or get state of the clear button
99  void EnableClearButton();
100  void DisableClearButton();
101  bool IsClearButtonEnabled() const;
102 
103  void SetValueNoSignal(double);
104 
105 signals:
106  // Triggered when the clear button is pressed
107  void Cleared();
108 
109 private:
111 };
112 
113 }
114 }
115 
116 #endif