]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/Validator.h
Remove a workaround that seems to be useless since Qt 4.8
[lyx.git] / src / frontends / qt / Validator.h
1 // -*- C++ -*-
2 /**
3  * \file Validator.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  * \author Richard Kimberly Heck
9  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * Validators are used to decide upon the legality of some input action.
13  * For example, a "line edit" widget might be used to input a "glue length".
14  * The correct syntax for such a length is "2em + 0.5em". The LengthValidator
15  * below will report whether the input text conforms to this syntax.
16  *
17  * This information is used in LyX primarily to give the user some
18  * feedback on the validity of the input data using the "checked_widget"
19  * concept. For example, if the data is invalid then the label of
20  * a "line edit" widget is changed in colour and the dialog's "Ok"
21  * and "Apply" buttons are disabled. See checked_widgets.[Ch] for
22  * further details.
23  */
24
25 #ifndef VALIDATOR_H
26 #define VALIDATOR_H
27
28 #include "support/Length.h"
29
30 #include <QValidator>
31
32 class QWidget;
33 class QLineEdit;
34
35 namespace lyx {
36
37 class LyXRC;
38
39 namespace frontend {
40
41 enum class KernelDocType : int;
42
43 /** A class to ascertain whether the data passed to the @c validate()
44  *  member function can be interpreted as a GlueLength.
45  */
46 class LengthValidator : public QValidator
47 {
48         Q_OBJECT
49 public:
50         /// Define a validator for widget @c parent.
51         LengthValidator(QWidget * parent);
52
53         /** @returns QValidator::Acceptable if @c data is a GlueLength.
54          *  If not, returns QValidator::Intermediate.
55          */
56         QValidator::State validate(QString & data, int &) const override;
57
58         /** @name Bottom
59          *  Set and retrieve the minimum allowed Length value.
60          */
61         //@{
62         void setBottom(Length const &);
63         void setBottom(GlueLength const &);
64         Length bottom() const { return bottom_; }
65         void setUnsigned(bool const u) { unsigned_ = u; }
66         void setPositive(bool const u) { positive_ = u; }
67         //@}
68
69 private:
70         Length bottom_;
71         GlueLength glue_bottom_;
72         bool no_bottom_ = true;
73         bool glue_length_ = false;
74         bool unsigned_ = false;
75         bool positive_ = false;
76 };
77
78
79 /// @returns a new @c LengthValidator that does not accept negative lengths.
80 LengthValidator * unsignedLengthValidator(QLineEdit *);
81
82
83 /** @returns a new @c LengthValidator that does not accept negative lengths.
84  *  but glue lengths.
85  */
86 LengthValidator * unsignedGlueLengthValidator(QLineEdit *);
87
88
89 /** A class to ascertain whether the data passed to the @c validate()
90  *  member function can be interpreted as a GlueLength or is @param autotext.
91  */
92 class LengthAutoValidator : public LengthValidator
93 {
94         Q_OBJECT
95 public:
96         /// Define a validator for widget @c parent.
97         LengthAutoValidator(QWidget * parent, QString const & autotext);
98
99         /** @returns QValidator::Acceptable if @c data is a GlueLength
100                 * or is "auto". If not, returns QValidator::Intermediate.
101          */
102         QValidator::State validate(QString & data, int &) const override;
103
104 private:
105         QString autotext_;
106 };
107
108 /// @returns a new @c LengthAutoValidator that does not accept negative lengths.
109 LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const & autotext);
110
111
112 /// @returns a new @c LengthAutoValidator that does not accept negative lengths.
113 LengthAutoValidator * positiveLengthAutoValidator(QLineEdit *, QString const & autotext);
114
115
116 /**
117  * A class to determine whether the passed is a double
118  * or is @param autotext.
119  *
120  */
121 class DoubleAutoValidator : public QDoubleValidator
122 {
123         Q_OBJECT
124 public:
125         DoubleAutoValidator(QWidget * parent, QString const & autotext);
126         DoubleAutoValidator(double bottom, double top, int decimals,
127                 QObject * parent);
128         QValidator::State validate(QString & input, int & pos) const override;
129
130 private:
131         QString autotext_;
132 };
133
134
135 // A class to ascertain that no newline characters are passed.
136 class NoNewLineValidator : public QValidator
137 {
138         Q_OBJECT
139 public:
140         // Define a validator.
141         NoNewLineValidator(QWidget *);
142         // Remove newline characters from input.
143         QValidator::State validate(QString &, int &) const override;
144 };
145
146
147 /** A class to ascertain whether the data passed to the @c validate()
148  *  member function is a valid file path.
149  *  The test is active only when the path is to be stored in a LaTeX
150  *  file, LaTeX being quite picky about legal names.
151  */
152 class PathValidator : public QValidator
153 {
154         Q_OBJECT
155 public:
156         /** Define a validator for widget @c parent.
157          *  If @c acceptable_if_empty is @c true then an empty path
158          *  is regarded as acceptable.
159          */
160         PathValidator(bool acceptable_if_empty, QWidget * parent);
161
162         /** @returns QValidator::Acceptable if @c data is a valid path.
163          *  If not, returns QValidator::Intermediate.
164          */
165         QValidator::State validate(QString &, int &) const override;
166
167         /** Define what checks that @c validate() will perform.
168          *  @param doc_type checks are activated only for @c LATEX docs.
169          *  @param lyxrc contains a @c tex_allows_spaces member that
170          *  is used to define what is legal.
171          */
172         void setChecker(KernelDocType const & doc_type, LyXRC const & lyxrc);
173
174 private:
175         bool acceptable_if_empty_;
176         bool latex_doc_;
177         bool tex_allows_spaces_;
178 };
179
180
181 /// @returns the PathValidator attached to the widget, or 0.
182 PathValidator * getPathValidator(QLineEdit *);
183
184 } // namespace frontend
185 } // namespace lyx
186
187 # endif // NOT VALIDATOR_H