LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / libs / utils / basevalidatinglineedit.h
blobdde4c19830a48ed3b7d52ee4e7b2a24d5784d0e2
1 /**
2 ******************************************************************************
4 * @file basevalidatinglineedit.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @brief
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup
10 * @{
12 *****************************************************************************/
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.
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.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef BASEVALIDATINGLINEEDIT_H
30 #define BASEVALIDATINGLINEEDIT_H
32 #include "utils_global.h"
34 #include <QLineEdit>
36 namespace Utils {
37 struct BaseValidatingLineEditPrivate;
39 /**
40 * Base class for validating line edits that performs validation in a virtual
41 * validate() function to be implemented in derived classes.
42 * When invalid, the text color will turn red and a tooltip will
43 * contain the error message. This approach is less intrusive than a
44 * QValidator which will prevent the user from entering certain characters.
46 * The widget has a concept of an "initialText" which can be something like
47 * "<Enter name here>". This results in state 'DisplayingInitialText', which
48 * is not valid, but is not marked red.
50 class QTCREATOR_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit {
51 Q_OBJECT Q_DISABLE_COPY(BaseValidatingLineEdit)
52 Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true)
53 Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor DESIGNABLE true)
55 public:
56 enum State { Invalid, DisplayingInitialText, Valid };
58 explicit BaseValidatingLineEdit(QWidget *parent = 0);
59 virtual ~BaseValidatingLineEdit();
62 State state() const;
63 bool isValid() const;
64 QString errorMessage() const;
66 QString initialText() const;
67 void setInitialText(const QString &);
69 QColor errorColor() const;
70 void setErrorColor(const QColor &);
72 // Trigger an update (after changing settings)
73 void triggerChanged();
75 static QColor textColor(const QWidget *w);
76 static void setTextColor(QWidget *w, const QColor &c);
78 signals:
79 void validChanged();
80 void validChanged(bool validState);
81 void validReturnPressed();
83 protected:
84 virtual bool validate(const QString &value, QString *errorMessage) const = 0;
86 protected slots:
87 // Custom behaviour can be added here. The base implementation must
88 // be called.
89 virtual void slotReturnPressed();
90 virtual void slotChanged(const QString &t);
92 private:
93 BaseValidatingLineEditPrivate *m_bd;
95 } // namespace Utils
97 #endif // BASEVALIDATINGLINEEDIT_H