2006-03-05 17:24:44 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file Validator.h
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
2007-04-05 14:58:15 +00:00
|
|
|
* \author Richard Heck
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*
|
|
|
|
* Validators are used to decide upon the legality of some input action.
|
|
|
|
* For example, a "line edit" widget might be used to input a "glue length".
|
|
|
|
* The correct syntax for such a length is "2em + 0.5em". The LengthValidator
|
|
|
|
* below will report whether the input text conforms to this syntax.
|
|
|
|
*
|
|
|
|
* This information is used in LyX primarily to give the user some
|
|
|
|
* feedback on the validity of the input data using the "checked_widget"
|
|
|
|
* concept. For example, if the data is invalid then the label of
|
|
|
|
* a "line edit" widget is changed in colour and the dialog's "Ok"
|
|
|
|
* and "Apply" buttons are disabled. See checked_widgets.[Ch] for
|
|
|
|
* further details.
|
|
|
|
*/
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#ifndef VALIDATOR_H
|
|
|
|
#define VALIDATOR_H
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
#include "Length.h"
|
2007-11-14 00:21:31 +00:00
|
|
|
#include "Dialog.h" // KernelDocType
|
2006-08-17 09:03:26 +00:00
|
|
|
|
|
|
|
#include <QValidator>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
class QWidget;
|
|
|
|
class QLineEdit;
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2007-11-14 00:21:31 +00:00
|
|
|
class LyXRC;
|
|
|
|
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/** A class to ascertain whether the data passed to the @c validate()
|
2007-04-28 12:58:49 +00:00
|
|
|
* member function can be interpretted as a GlueLength.
|
2006-03-05 17:24:44 +00:00
|
|
|
*/
|
|
|
|
class LengthValidator : public QValidator
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
/// Define a validator for widget @c parent.
|
2006-08-17 09:03:26 +00:00
|
|
|
LengthValidator(QWidget * parent);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
/** @returns QValidator::Acceptable if @c data is a GlueLength.
|
2006-03-05 17:24:44 +00:00
|
|
|
* If not, returns QValidator::Intermediate.
|
|
|
|
*/
|
|
|
|
QValidator::State validate(QString & data, int &) const;
|
|
|
|
|
|
|
|
/** @name Bottom
|
2007-04-28 12:58:49 +00:00
|
|
|
* Set and retrieve the minimum allowed Length value.
|
2006-03-05 17:24:44 +00:00
|
|
|
*/
|
|
|
|
//@{
|
2007-04-28 12:58:49 +00:00
|
|
|
void setBottom(Length const &);
|
|
|
|
void setBottom(GlueLength const &);
|
|
|
|
Length bottom() const { return b_; }
|
2006-03-05 17:24:44 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
private:
|
2007-04-28 12:58:49 +00:00
|
|
|
Length b_;
|
|
|
|
GlueLength g_;
|
2006-03-05 17:24:44 +00:00
|
|
|
bool no_bottom_;
|
|
|
|
bool glue_length_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// @returns a new @c LengthValidator that does not accept negative lengths.
|
|
|
|
LengthValidator * unsignedLengthValidator(QLineEdit *);
|
|
|
|
|
2009-07-19 16:53:50 +00:00
|
|
|
|
|
|
|
/** @returns a new @c LengthValidator that does not accept negative lengths.
|
|
|
|
* but glue lengths.
|
|
|
|
*/
|
|
|
|
LengthValidator * unsignedGlueLengthValidator(QLineEdit *);
|
|
|
|
|
|
|
|
|
2007-04-05 14:58:15 +00:00
|
|
|
/** A class to ascertain whether the data passed to the @c validate()
|
2009-01-14 17:53:31 +00:00
|
|
|
* member function can be interpretted as a GlueLength or is @param autotext.
|
2007-04-05 14:58:15 +00:00
|
|
|
*/
|
|
|
|
class LengthAutoValidator : public LengthValidator
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2007-11-14 00:21:31 +00:00
|
|
|
public:
|
2007-04-05 14:58:15 +00:00
|
|
|
/// Define a validator for widget @c parent.
|
2009-01-14 17:53:31 +00:00
|
|
|
LengthAutoValidator(QWidget * parent, QString const autotext);
|
2007-04-05 14:58:15 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
/** @returns QValidator::Acceptable if @c data is a GlueLength
|
2007-04-05 14:58:15 +00:00
|
|
|
* or is "auto". If not, returns QValidator::Intermediate.
|
|
|
|
*/
|
2007-11-14 00:21:31 +00:00
|
|
|
QValidator::State validate(QString & data, int &) const;
|
2009-01-14 17:53:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QString autotext_;
|
2007-04-05 14:58:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// @returns a new @c LengthAutoValidator that does not accept negative lengths.
|
2009-01-14 17:53:31 +00:00
|
|
|
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const autotext);
|
2007-04-05 14:58:15 +00:00
|
|
|
|
2007-11-14 00:21:31 +00:00
|
|
|
|
2007-04-05 14:58:15 +00:00
|
|
|
/**
|
|
|
|
* A class to determine whether the passed is a double
|
2009-01-14 17:53:31 +00:00
|
|
|
* or is @param autotext.
|
2007-04-05 14:58:15 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-11-14 00:21:31 +00:00
|
|
|
class DoubleAutoValidator : public QDoubleValidator
|
|
|
|
{
|
2007-04-05 14:58:15 +00:00
|
|
|
Q_OBJECT
|
2007-11-14 00:21:31 +00:00
|
|
|
public:
|
2009-01-14 17:53:31 +00:00
|
|
|
DoubleAutoValidator(QWidget * parent, QString const autotext);
|
2007-11-14 00:21:31 +00:00
|
|
|
DoubleAutoValidator(double bottom, double top, int decimals,
|
|
|
|
QObject * parent);
|
|
|
|
QValidator::State validate(QString & input, int & pos) const;
|
2009-01-14 17:53:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QString autotext_;
|
2007-04-05 14:58:15 +00:00
|
|
|
};
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2011-09-24 16:39:17 +00:00
|
|
|
// A class to ascertain that no newline characters are passed.
|
|
|
|
class NoNewLineValidator : public QValidator
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
// Define a validator.
|
|
|
|
NoNewLineValidator(QWidget *);
|
|
|
|
// Remove newline characters from input.
|
|
|
|
QValidator::State validate(QString &, int &) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
/** A class to ascertain whether the data passed to the @c validate()
|
|
|
|
* member function is a valid file path.
|
|
|
|
* The test is active only when the path is to be stored in a LaTeX
|
|
|
|
* file, LaTeX being quite picky about legal names.
|
|
|
|
*/
|
|
|
|
class PathValidator : public QValidator
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
/** Define a validator for widget @c parent.
|
|
|
|
* If @c acceptable_if_empty is @c true then an empty path
|
|
|
|
* is regarded as acceptable.
|
|
|
|
*/
|
2006-08-17 09:03:26 +00:00
|
|
|
PathValidator(bool acceptable_if_empty, QWidget * parent);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/** @returns QValidator::Acceptable if @c data is a valid path.
|
|
|
|
* If not, returns QValidator::Intermediate.
|
|
|
|
*/
|
|
|
|
QValidator::State validate(QString &, int &) const;
|
|
|
|
|
|
|
|
/** Define what checks that @c validate() will perform.
|
|
|
|
* @param doc_type checks are activated only for @c LATEX docs.
|
|
|
|
* @param lyxrc contains a @c tex_allows_spaces member that
|
|
|
|
* is used to define what is legal.
|
|
|
|
*/
|
2007-11-14 00:21:31 +00:00
|
|
|
void setChecker(KernelDocType const & doc_type, LyXRC const & lyxrc);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool acceptable_if_empty_;
|
|
|
|
bool latex_doc_;
|
|
|
|
bool tex_allows_spaces_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// @returns the PathValidator attached to the widget, or 0.
|
|
|
|
PathValidator * getPathValidator(QLineEdit *);
|
|
|
|
|
2007-11-14 00:21:31 +00:00
|
|
|
} // namespace frontend
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
# endif // NOT VALIDATOR_H
|