#include "support/debug.h"
#include "support/lassert.h"
+#include <QLabel>
+#include <QLineEdit>
+#include <QList>
#include <QSettings>
#include <QString>
+#include <QValidator>
#include <string>
namespace lyx {
namespace frontend {
+bool CheckedLineEdit2::check() const
+{
+ bool const valid = input_->hasAcceptableInput();
+ // Visual feedback.
+ setValid(input_, valid);
+ if (label_)
+ setValid(label_, valid);
+ return valid;
+}
+
Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
: name_(name), title_(title), lyxview_(&lv)
{}
+void Dialog::addCheckedWidget(QLineEdit * input, QWidget * label)
+{
+ checked_line_edits_.append(CheckedLineEdit2(input, label));
+}
+
+
+bool Dialog::checkWidgets() const
+{
+ bool valid = true;
+ Q_FOREACH(CheckedLineEdit2 const & le, checked_line_edits_)
+ valid &= le.check();
+ return valid;
+}
+
+
bool Dialog::canApply() const
{
FuncRequest const fr(getLfun(), fromqstr(name_));
#include "support/strfwd.h"
+#include <QList>
#include <QString>
class QWidget;
+class QLineEdit;
namespace lyx {
DOCBOOK
};
+/// CheckedLineEdit
+// FIXME: Get rid of CheckedLineEdit in ButtonController and rename this one
+// to it.
+class CheckedLineEdit2
+{
+public:
+ CheckedLineEdit2(QLineEdit * input, QWidget * label = 0)
+ : input_(input), label_(label)
+ {}
+ ///
+ bool check() const;
+
+private:
+ // non-owned
+ QLineEdit * input_;
+ QWidget * label_;
+};
+
+
+typedef QList<CheckedLineEdit2> CheckedLineEdits;
+
/** \c Dialog collects the different parts of a Model-Controller-View
* split of a generic dialog together.
virtual QWidget * asQWidget() = 0;
virtual QWidget const * asQWidget() const = 0;
+ ///
+ void addCheckedWidget(QLineEdit * input, QWidget * label);
+
/// Session key.
/**
* This key must be used for any session setting.
void setTitle(QString const & title) { title_ = title; }
///
virtual void apply();
+ /// \return true if all CheckedWidgets are in a valid state.
+ bool checkWidgets() const;
private:
/** The Dialog's name is the means by which a dialog identifies
Dialog(Dialog const &);
void operator=(Dialog const &);
+ ///
+ CheckedLineEdits checked_line_edits_;
};
#include "support/debug.h"\r
#include "support/lstrings.h"\r
\r
-\r
using namespace std;\r
using namespace lyx::support;\r
\r
\r
/////////////////////////////////////////////////////////////////\r
//\r
-// InsetDialog\r
+// InsetDialog::Private\r
//\r
/////////////////////////////////////////////////////////////////\r
\r
+struct InsetDialog::Private\r
+{\r
+ Private(InsetCode code, FuncCode creation_code)\r
+ : inset_code_(code), creation_code_(creation_code)\r
+ {\r
+ }\r
+\r
+ ///\r
+ InsetCode inset_code_;\r
+ ///\r
+ FuncCode creation_code_;\r
+};\r
+\r
+/////////////////////////////////////////////////////////////////\r
+//\r
+// InsetDialog\r
+//\r
+/////////////////////////////////////////////////////////////////\r
\r
InsetDialog::InsetDialog(GuiView & lv, InsetCode code, FuncCode creation_code,\r
char const * name, char const * display_name)\r
- : DialogView(lv, name, qt_(display_name)), inset_code_(code),\r
- creation_code_(creation_code)\r
+ : DialogView(lv, name, qt_(display_name)), d(new Private(code, creation_code))\r
{\r
}\r
\r
void InsetDialog::on_newPB_clicked()\r
{\r
docstring const argument = dialogToParams();\r
- dispatch(FuncRequest(creation_code_, argument));\r
+ dispatch(FuncRequest(d->creation_code_, argument));\r
}\r
\r
\r
void InsetDialog::applyView()\r
{\r
- Inset const * i = inset(inset_code_);\r
+ if (!checkWidgets())\r
+ return;\r
+\r
+ Inset const * i = inset(d->inset_code_);\r
if (!i)\r
return;\r
\r
\r
void InsetDialog::updateView()\r
{\r
- Inset const * i = inset(inset_code_);\r
+ Inset const * i = inset(d->inset_code_);\r
if (i)\r
paramsToDialog(i);\r
else\r
\r
/// \name DialogView inherited methods\r
//@{\r
- void applyView();\r
void updateView();\r
void dispatchParams() {}\r
bool isBufferDependent() const { return true; }\r
//@}\r
\r
protected Q_SLOTS:\r
+ void applyView();\r
void on_newPB_clicked();\r
void on_closePB_clicked();\r
\r
virtual docstring dialogToParams() const = 0;\r
\r
private:\r
- ///\r
- InsetCode inset_code_;\r
- ///\r
- FuncCode creation_code_;\r
+ /// pimpl\r
+ struct Private;\r
+ Private * d;\r
};\r
\r
} // namespace frontend\r