4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
11 * Validators are used to decide upon the legality of some input action.
12 * For example, a "line edit" widget might be used to input a "glue length".
13 * The correct syntax for such a length is "2em + 0.5em". The LengthValidator
14 * below will report whether the input text conforms to this syntax.
16 * This information is used in LyX primarily to give the user some
17 * feedback on the validity of the input data using the "checked_widget"
18 * concept. For example, if the data is invalid then the label of
19 * a "line edit" widget is changed in colour and the dialog's "Ok"
20 * and "Apply" buttons are disabled. See checked_widgets.[Ch] for
27 #include "lyxlength.h"
28 #include "lyxgluelength.h"
36 /** A class to ascertain whether the data passed to the @c validate()
37 * member function can be interpretted as a LyXGlueLength.
39 class LengthValidator : public QValidator
43 /// Define a validator for widget @c parent.
44 LengthValidator(QWidget * parent);
46 /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
47 * If not, returns QValidator::Intermediate.
49 QValidator::State validate(QString & data, int &) const;
52 * Set and retrieve the minimum allowed LyXLength value.
55 void setBottom(LyXLength const &);
56 void setBottom(LyXGlueLength const &);
57 LyXLength bottom() const { return b_; }
61 #if defined(Q_DISABLE_COPY)
62 LengthValidator( const LengthValidator & );
63 LengthValidator& operator=( const LengthValidator & );
73 /// @returns a new @c LengthValidator that does not accept negative lengths.
74 LengthValidator * unsignedLengthValidator(QLineEdit *);
77 // Forward declarations
85 } // namespace frontend
89 /** A class to ascertain whether the data passed to the @c validate()
90 * member function is a valid file path.
91 * The test is active only when the path is to be stored in a LaTeX
92 * file, LaTeX being quite picky about legal names.
94 class PathValidator : public QValidator
98 /** Define a validator for widget @c parent.
99 * If @c acceptable_if_empty is @c true then an empty path
100 * is regarded as acceptable.
102 PathValidator(bool acceptable_if_empty, QWidget * parent);
104 /** @returns QValidator::Acceptable if @c data is a valid path.
105 * If not, returns QValidator::Intermediate.
107 QValidator::State validate(QString &, int &) const;
109 /** Define what checks that @c validate() will perform.
110 * @param doc_type checks are activated only for @c LATEX docs.
111 * @param lyxrc contains a @c tex_allows_spaces member that
112 * is used to define what is legal.
114 void setChecker(lyx::frontend::KernelDocType const & doc_type,
115 LyXRC const & lyxrc);
118 #if defined(Q_DISABLE_COPY)
119 PathValidator( const PathValidator & );
120 PathValidator& operator=( const PathValidator & );
123 bool acceptable_if_empty_;
125 bool tex_allows_spaces_;
129 /// @returns the PathValidator attached to the widget, or 0.
130 PathValidator * getPathValidator(QLineEdit *);
132 # endif // NOT VALIDATORS_H