From: Abdelrazak Younes Date: Sun, 7 Feb 2010 20:25:53 +0000 (+0000) Subject: * Dialog: X-Git-Tag: 2.0.0~4134 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1c188f022cf5f2bad4a088d60e87d86e4834fcf2;p=features.git * Dialog: - transfer ans simplify a bit the CheckedLineEdit class from ButtonController. * InsetDialog: - Pimpl private data - applyView(): now a slot, check widget before applying. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33350 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index 65d4a55981..d502ed2df9 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -27,8 +27,12 @@ #include "support/debug.h" #include "support/lassert.h" +#include +#include +#include #include #include +#include #include @@ -38,6 +42,16 @@ using namespace lyx::support; 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) @@ -48,6 +62,21 @@ Dialog::~Dialog() {} +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_)); diff --git a/src/frontends/qt4/Dialog.h b/src/frontends/qt4/Dialog.h index 57e63c1022..cc76f93c22 100644 --- a/src/frontends/qt4/Dialog.h +++ b/src/frontends/qt4/Dialog.h @@ -18,9 +18,11 @@ #include "support/strfwd.h" +#include #include class QWidget; +class QLineEdit; namespace lyx { @@ -44,6 +46,27 @@ enum KernelDocType 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 CheckedLineEdits; + /** \c Dialog collects the different parts of a Model-Controller-View * split of a generic dialog together. @@ -62,6 +85,9 @@ public: 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. @@ -256,6 +282,8 @@ protected: 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 @@ -271,6 +299,8 @@ private: Dialog(Dialog const &); void operator=(Dialog const &); + /// + CheckedLineEdits checked_line_edits_; }; diff --git a/src/frontends/qt4/InsetDialog.cpp b/src/frontends/qt4/InsetDialog.cpp index 38b543c165..5eee47a634 100644 --- a/src/frontends/qt4/InsetDialog.cpp +++ b/src/frontends/qt4/InsetDialog.cpp @@ -24,7 +24,6 @@ #include "support/debug.h" #include "support/lstrings.h" - using namespace std; using namespace lyx::support; @@ -33,15 +32,32 @@ namespace frontend { ///////////////////////////////////////////////////////////////// // -// InsetDialog +// InsetDialog::Private // ///////////////////////////////////////////////////////////////// +struct InsetDialog::Private +{ + Private(InsetCode code, FuncCode creation_code) + : inset_code_(code), creation_code_(creation_code) + { + } + + /// + InsetCode inset_code_; + /// + FuncCode creation_code_; +}; + +///////////////////////////////////////////////////////////////// +// +// InsetDialog +// +///////////////////////////////////////////////////////////////// InsetDialog::InsetDialog(GuiView & lv, InsetCode code, FuncCode creation_code, char const * name, char const * display_name) - : DialogView(lv, name, qt_(display_name)), inset_code_(code), - creation_code_(creation_code) + : DialogView(lv, name, qt_(display_name)), d(new Private(code, creation_code)) { } @@ -55,13 +71,16 @@ void InsetDialog::on_closePB_clicked() void InsetDialog::on_newPB_clicked() { docstring const argument = dialogToParams(); - dispatch(FuncRequest(creation_code_, argument)); + dispatch(FuncRequest(d->creation_code_, argument)); } void InsetDialog::applyView() { - Inset const * i = inset(inset_code_); + if (!checkWidgets()) + return; + + Inset const * i = inset(d->inset_code_); if (!i) return; @@ -75,7 +94,7 @@ void InsetDialog::applyView() void InsetDialog::updateView() { - Inset const * i = inset(inset_code_); + Inset const * i = inset(d->inset_code_); if (i) paramsToDialog(i); else diff --git a/src/frontends/qt4/InsetDialog.h b/src/frontends/qt4/InsetDialog.h index bf0336df0a..7a38f2521e 100644 --- a/src/frontends/qt4/InsetDialog.h +++ b/src/frontends/qt4/InsetDialog.h @@ -33,7 +33,6 @@ public: /// \name DialogView inherited methods //@{ - void applyView(); void updateView(); void dispatchParams() {} bool isBufferDependent() const { return true; } @@ -41,6 +40,7 @@ public: //@} protected Q_SLOTS: + void applyView(); void on_newPB_clicked(); void on_closePB_clicked(); @@ -51,10 +51,9 @@ protected: virtual docstring dialogToParams() const = 0; private: - /// - InsetCode inset_code_; - /// - FuncCode creation_code_; + /// pimpl + struct Private; + Private * d; }; } // namespace frontend