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 "lyxlength.h"
29 #include "lyxgluelength.h"
39 /** A class to ascertain whether the data passed to the @c validate()
40 * member function can be interpretted as a LyXGlueLength.
42 class LengthValidator : public QValidator
46 /// Define a validator for widget @c parent.
47 LengthValidator(QWidget * parent);
49 /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
50 * If not, returns QValidator::Intermediate.
52 QValidator::State validate(QString & data, int &) const;
55 * Set and retrieve the minimum allowed LyXLength value.
58 void setBottom(LyXLength const &);
59 void setBottom(LyXGlueLength const &);
60 LyXLength bottom() const { return b_; }
64 #if defined(Q_DISABLE_COPY)
65 LengthValidator( const LengthValidator & );
66 LengthValidator& operator=( const LengthValidator & );
76 /// @returns a new @c LengthValidator that does not accept negative lengths.
77 LengthValidator * unsignedLengthValidator(QLineEdit *);
79 //FIXME This should be generalized to take "text" as part of the
80 //constructor and so to set what text we check for, rather than
81 //hard-coding it as "auto". But see qt_helpers.h for reasons this
82 //is not so trivial and an idea about how to do it. (RGH)
83 /** A class to ascertain whether the data passed to the @c validate()
84 * member function can be interpretted as a LyXGlueLength or is "auto".
86 class LengthAutoValidator : public LengthValidator
90 /// Define a validator for widget @c parent.
91 LengthAutoValidator(QWidget * parent);
93 /** @returns QValidator::Acceptable if @c data is a LyXGlueLength
94 * or is "auto". If not, returns QValidator::Intermediate.
96 QValidator::State validate(QString & data, int &) const;
99 /// @returns a new @c LengthAutoValidator that does not accept negative lengths.
100 LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *);
102 //FIXME As above, this should really take a text argument.
104 * A class to determine whether the passed is a double
108 class DoubleAutoValidator : public QDoubleValidator {
111 DoubleAutoValidator(QWidget * parent);
112 DoubleAutoValidator(double bottom, double top, int decimals,
114 QValidator::State validate(QString & input, int & pos) const;
117 // Forward declarations
120 namespace frontend { class KernelDocType; }
123 /** A class to ascertain whether the data passed to the @c validate()
124 * member function is a valid file path.
125 * The test is active only when the path is to be stored in a LaTeX
126 * file, LaTeX being quite picky about legal names.
128 class PathValidator : public QValidator
132 /** Define a validator for widget @c parent.
133 * If @c acceptable_if_empty is @c true then an empty path
134 * is regarded as acceptable.
136 PathValidator(bool acceptable_if_empty, QWidget * parent);
138 /** @returns QValidator::Acceptable if @c data is a valid path.
139 * If not, returns QValidator::Intermediate.
141 QValidator::State validate(QString &, int &) const;
143 /** Define what checks that @c validate() will perform.
144 * @param doc_type checks are activated only for @c LATEX docs.
145 * @param lyxrc contains a @c tex_allows_spaces member that
146 * is used to define what is legal.
148 void setChecker(frontend::KernelDocType const & doc_type,
149 LyXRC const & lyxrc);
152 #if defined(Q_DISABLE_COPY)
153 PathValidator(const PathValidator &);
154 PathValidator & operator=(const PathValidator &);
157 bool acceptable_if_empty_;
159 bool tex_allows_spaces_;
163 /// @returns the PathValidator attached to the widget, or 0.
164 PathValidator * getPathValidator(QLineEdit *);
168 # endif // NOT VALIDATOR_H