]> git.lyx.org Git - features.git/commitdiff
* Dialog:
authorAbdelrazak Younes <younes@lyx.org>
Sun, 7 Feb 2010 20:25:53 +0000 (20:25 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 7 Feb 2010 20:25:53 +0000 (20:25 +0000)
- 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

src/frontends/qt4/Dialog.cpp
src/frontends/qt4/Dialog.h
src/frontends/qt4/InsetDialog.cpp
src/frontends/qt4/InsetDialog.h

index 65d4a5598141dbb3471e02af0c1471a2e638051c..d502ed2df9437aae5eb6c9048bf9fce098ec9e32 100644 (file)
 #include "support/debug.h"
 #include "support/lassert.h"
 
+#include <QLabel>
+#include <QLineEdit>
+#include <QList>
 #include <QSettings>
 #include <QString>
+#include <QValidator>
 
 #include <string>
 
@@ -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_));
index 57e63c1022bd1588f935bfd4b47af6cd88ebe076..cc76f93c22f1120b5e963f4269771b867d241039 100644 (file)
 
 #include "support/strfwd.h"
 
+#include <QList>
 #include <QString>
 
 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<CheckedLineEdit2> 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_;
 };
 
 
index 38b543c1659c5fdfb1ee1d97787e5e1547b51931..5eee47a6341235fea788d0d6c292de5d68a4ead3 100644 (file)
@@ -24,7 +24,6 @@
 #include "support/debug.h"\r
 #include "support/lstrings.h"\r
 \r
-\r
 using namespace std;\r
 using namespace lyx::support;\r
 \r
@@ -33,15 +32,32 @@ namespace frontend {
 \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
@@ -55,13 +71,16 @@ void InsetDialog::on_closePB_clicked()
 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
@@ -75,7 +94,7 @@ void InsetDialog::applyView()
 \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
index bf0336df0aabe146fc8e2bc1a7b59a71e09034cd..7a38f2521ee290a5e9152abf12b415bc6d70907a 100644 (file)
@@ -33,7 +33,6 @@ public:
 \r
        /// \name DialogView inherited methods\r
        //@{\r
-       void applyView();\r
        void updateView();\r
        void dispatchParams() {}\r
        bool isBufferDependent() const { return true; }\r
@@ -41,6 +40,7 @@ public:
        //@}\r
 \r
 protected Q_SLOTS:\r
+       void applyView();\r
        void on_newPB_clicked();\r
        void on_closePB_clicked();\r
 \r
@@ -51,10 +51,9 @@ protected:
        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