dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
basevalidatinglineedit.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef BASEVALIDATINGLINEEDIT_H
29 #define BASEVALIDATINGLINEEDIT_H
30 
31 #include "utils_global.h"
32 
33 #include <QLineEdit>
34 
35 namespace Utils {
36 
37 struct BaseValidatingLineEditPrivate;
38 
50 class QTCREATOR_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit
51 {
52  Q_OBJECT
53  Q_DISABLE_COPY(BaseValidatingLineEdit)
54  Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true)
55  Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor DESIGNABLE true)
56 
57 public:
58  enum State { Invalid, DisplayingInitialText, Valid };
59 
60  explicit BaseValidatingLineEdit(QWidget *parent = nullptr);
61  virtual ~BaseValidatingLineEdit();
62 
63 
64  State state() const;
65  bool isValid() const;
66  QString errorMessage() const;
67 
68  QString initialText() const;
69  void setInitialText(const QString &);
70 
71  QColor errorColor() const;
72  void setErrorColor(const QColor &);
73 
74  // Trigger an update (after changing settings)
75  void triggerChanged();
76 
77  static QColor textColor(const QWidget *w);
78  static void setTextColor(QWidget *w, const QColor &c);
79 
80 signals:
81  void validChanged();
82  void validChanged(bool validState);
83  void validReturnPressed();
84 
85 protected:
86  virtual bool validate(const QString &value, QString *errorMessage) const = 0;
87 
88 protected slots:
89  // Custom behaviour can be added here. The base implementation must
90  // be called.
91  virtual void slotReturnPressed();
92  virtual void slotChanged(const QString &t);
93 
94 private:
96 };
97 
98 } // namespace Utils
99 
100 #endif // BASEVALIDATINGLINEEDIT_H
const char t[]
Definition: coreconstants.h:40