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"
38 /** A class to ascertain whether the data passed to the @c validate()
39 * member function can be interpretted as a LyXGlueLength.
41 class LengthValidator : public QValidator
45 /// Define a validator for widget @c parent.
46 LengthValidator(QWidget * parent);
48 /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
49 * If not, returns QValidator::Intermediate.
51 QValidator::State validate(QString & data, int &) const;
54 * Set and retrieve the minimum allowed LyXLength value.
57 void setBottom(LyXLength const &);
58 void setBottom(LyXGlueLength const &);
59 LyXLength bottom() const { return b_; }
63 #if defined(Q_DISABLE_COPY)
64 LengthValidator( const LengthValidator & );
65 LengthValidator& operator=( const LengthValidator & );
75 /// @returns a new @c LengthValidator that does not accept negative lengths.
76 LengthValidator * unsignedLengthValidator(QLineEdit *);
79 // Forward declarations
82 namespace frontend { class KernelDocType; }
85 /** A class to ascertain whether the data passed to the @c validate()
86 * member function is a valid file path.
87 * The test is active only when the path is to be stored in a LaTeX
88 * file, LaTeX being quite picky about legal names.
90 class PathValidator : public QValidator
94 /** Define a validator for widget @c parent.
95 * If @c acceptable_if_empty is @c true then an empty path
96 * is regarded as acceptable.
98 PathValidator(bool acceptable_if_empty, QWidget * parent);
100 /** @returns QValidator::Acceptable if @c data is a valid path.
101 * If not, returns QValidator::Intermediate.
103 QValidator::State validate(QString &, int &) const;
105 /** Define what checks that @c validate() will perform.
106 * @param doc_type checks are activated only for @c LATEX docs.
107 * @param lyxrc contains a @c tex_allows_spaces member that
108 * is used to define what is legal.
110 void setChecker(frontend::KernelDocType const & doc_type,
111 LyXRC const & lyxrc);
114 #if defined(Q_DISABLE_COPY)
115 PathValidator(const PathValidator &);
116 PathValidator & operator=(const PathValidator &);
119 bool acceptable_if_empty_;
121 bool tex_allows_spaces_;
125 /// @returns the PathValidator attached to the widget, or 0.
126 PathValidator * getPathValidator(QLineEdit *);
130 # endif // NOT VALIDATORS_H