4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
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.
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
28 #include "Dialog.h" // KernelDocType
30 #include "support/Length.h"
44 /** A class to ascertain whether the data passed to the @c validate()
45 * member function can be interpreted as a GlueLength.
47 class LengthValidator : public QValidator
51 /// Define a validator for widget @c parent.
52 LengthValidator(QWidget * parent);
54 /** @returns QValidator::Acceptable if @c data is a GlueLength.
55 * If not, returns QValidator::Intermediate.
57 QValidator::State validate(QString & data, int &) const;
60 * Set and retrieve the minimum allowed Length value.
63 void setBottom(Length const &);
64 void setBottom(GlueLength const &);
65 Length bottom() const { return b_; }
66 void setUnsigned(bool const u) { unsigned_ = u; }
78 /// @returns a new @c LengthValidator that does not accept negative lengths.
79 LengthValidator * unsignedLengthValidator(QLineEdit *);
82 /** @returns a new @c LengthValidator that does not accept negative lengths.
85 LengthValidator * unsignedGlueLengthValidator(QLineEdit *);
88 /** A class to ascertain whether the data passed to the @c validate()
89 * member function can be interpreted as a GlueLength or is @param autotext.
91 class LengthAutoValidator : public LengthValidator
95 /// Define a validator for widget @c parent.
96 LengthAutoValidator(QWidget * parent, QString const & autotext);
98 /** @returns QValidator::Acceptable if @c data is a GlueLength
99 * or is "auto". If not, returns QValidator::Intermediate.
101 QValidator::State validate(QString & data, int &) const;
107 /// @returns a new @c LengthAutoValidator that does not accept negative lengths.
108 LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const & autotext);
112 * A class to determine whether the passed is a double
113 * or is @param autotext.
116 class DoubleAutoValidator : public QDoubleValidator
120 DoubleAutoValidator(QWidget * parent, QString const & autotext);
121 DoubleAutoValidator(double bottom, double top, int decimals,
123 QValidator::State validate(QString & input, int & pos) const;
130 // A class to ascertain that no newline characters are passed.
131 class NoNewLineValidator : public QValidator
135 // Define a validator.
136 NoNewLineValidator(QWidget *);
137 // Remove newline characters from input.
138 QValidator::State validate(QString &, int &) const;
142 /** A class to ascertain whether the data passed to the @c validate()
143 * member function is a valid file path.
144 * The test is active only when the path is to be stored in a LaTeX
145 * file, LaTeX being quite picky about legal names.
147 class PathValidator : public QValidator
151 /** Define a validator for widget @c parent.
152 * If @c acceptable_if_empty is @c true then an empty path
153 * is regarded as acceptable.
155 PathValidator(bool acceptable_if_empty, QWidget * parent);
157 /** @returns QValidator::Acceptable if @c data is a valid path.
158 * If not, returns QValidator::Intermediate.
160 QValidator::State validate(QString &, int &) const;
162 /** Define what checks that @c validate() will perform.
163 * @param doc_type checks are activated only for @c LATEX docs.
164 * @param lyxrc contains a @c tex_allows_spaces member that
165 * is used to define what is legal.
167 void setChecker(KernelDocType const & doc_type, LyXRC const & lyxrc);
170 bool acceptable_if_empty_;
172 bool tex_allows_spaces_;
176 /// @returns the PathValidator attached to the widget, or 0.
177 PathValidator * getPathValidator(QLineEdit *);
179 } // namespace frontend
182 # endif // NOT VALIDATOR_H