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
29 #include "Dialog.h" // KernelDocType
43 /** A class to ascertain whether the data passed to the @c validate()
44 * member function can be interpretted as a GlueLength.
46 class LengthValidator : public QValidator
50 /// Define a validator for widget @c parent.
51 LengthValidator(QWidget * parent);
53 /** @returns QValidator::Acceptable if @c data is a GlueLength.
54 * If not, returns QValidator::Intermediate.
56 QValidator::State validate(QString & data, int &) const;
59 * Set and retrieve the minimum allowed Length value.
62 void setBottom(Length const &);
63 void setBottom(GlueLength const &);
64 Length bottom() const { return b_; }
75 /// @returns a new @c LengthValidator that does not accept negative lengths.
76 LengthValidator * unsignedLengthValidator(QLineEdit *);
79 /** @returns a new @c LengthValidator that does not accept negative lengths.
82 LengthValidator * unsignedGlueLengthValidator(QLineEdit *);
85 /** A class to ascertain whether the data passed to the @c validate()
86 * member function can be interpretted as a GlueLength or is @param autotext.
88 class LengthAutoValidator : public LengthValidator
92 /// Define a validator for widget @c parent.
93 LengthAutoValidator(QWidget * parent, QString const autotext);
95 /** @returns QValidator::Acceptable if @c data is a GlueLength
96 * or is "auto". If not, returns QValidator::Intermediate.
98 QValidator::State validate(QString & data, int &) const;
104 /// @returns a new @c LengthAutoValidator that does not accept negative lengths.
105 LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const autotext);
109 * A class to determine whether the passed is a double
110 * or is @param autotext.
113 class DoubleAutoValidator : public QDoubleValidator
117 DoubleAutoValidator(QWidget * parent, QString const autotext);
118 DoubleAutoValidator(double bottom, double top, int decimals,
120 QValidator::State validate(QString & input, int & pos) const;
127 /** A class to ascertain whether the data passed to the @c validate()
128 * member function is a valid file path.
129 * The test is active only when the path is to be stored in a LaTeX
130 * file, LaTeX being quite picky about legal names.
132 class PathValidator : public QValidator
136 /** Define a validator for widget @c parent.
137 * If @c acceptable_if_empty is @c true then an empty path
138 * is regarded as acceptable.
140 PathValidator(bool acceptable_if_empty, QWidget * parent);
142 /** @returns QValidator::Acceptable if @c data is a valid path.
143 * If not, returns QValidator::Intermediate.
145 QValidator::State validate(QString &, int &) const;
147 /** Define what checks that @c validate() will perform.
148 * @param doc_type checks are activated only for @c LATEX docs.
149 * @param lyxrc contains a @c tex_allows_spaces member that
150 * is used to define what is legal.
152 void setChecker(KernelDocType const & doc_type, LyXRC const & lyxrc);
155 bool acceptable_if_empty_;
157 bool tex_allows_spaces_;
161 /// @returns the PathValidator attached to the widget, or 0.
162 PathValidator * getPathValidator(QLineEdit *);
164 } // namespace frontend
167 # endif // NOT VALIDATOR_H