* 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
This commit is contained in:
Abdelrazak Younes 2010-02-07 20:25:53 +00:00
parent 92fa10cc49
commit 1c188f022c
4 changed files with 89 additions and 12 deletions

View File

@ -27,8 +27,12 @@
#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_));

View File

@ -18,9 +18,11 @@
#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_;
};

View File

@ -24,24 +24,40 @@
#include "support/debug.h"
#include "support/lstrings.h"
using namespace std;
using namespace lyx::support;
namespace lyx {
namespace frontend {
/////////////////////////////////////////////////////////////////
//
// 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

View File

@ -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