From 52bd0268a3bd24fdeb277655d8fcedb6b52f6045 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 8 Feb 2010 22:09:40 +0000 Subject: [PATCH] * Migrate InsetFloat to InsetDialog * Bug fix and clean up InsetFloat parameter handling: this is still not very clean as the float type is not really a parameter still... The solution is to defer the float type reading to the actual inset reading, not its creation. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33370 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/factory.cpp | 11 +- src/frontends/qt4/FloatPlacement.cpp | 16 ++- src/frontends/qt4/FloatPlacement.h | 12 ++- src/frontends/qt4/GuiFloat.cpp | 54 ++-------- src/frontends/qt4/GuiFloat.h | 35 +++--- src/frontends/qt4/ui/FloatPlacementUi.ui | 131 ++++++++++++++--------- src/frontends/qt4/ui/FloatUi.ui | 88 ++++++--------- src/insets/InsetFloat.cpp | 16 +-- 8 files changed, 170 insertions(+), 193 deletions(-) diff --git a/src/factory.cpp b/src/factory.cpp index 91bce06e94..7d344c87d7 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -150,10 +150,13 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd) case LFUN_FLOAT_INSERT: { // check if the float type exists - string const argument = to_utf8(cmd.argument()); - if (params.documentClass().floats().typeExist(argument)) - return new InsetFloat(buf, argument); - lyxerr << "Non-existent float type: " << argument << endl; + string const type = cmd.getArg(0); + //FIXME: only the float type (the first argument) is transmitted + // because of the InsetFloat ctor. + if (params.documentClass().floats().typeExist(type)) + return new InsetFloat(buf, type); + lyxerr << "Non-existent float type: " << type << endl; + return 0; } case LFUN_FLOAT_WIDE_INSERT: { diff --git a/src/frontends/qt4/FloatPlacement.cpp b/src/frontends/qt4/FloatPlacement.cpp index 22fc1ac1d7..33c66fd0f0 100644 --- a/src/frontends/qt4/FloatPlacement.cpp +++ b/src/frontends/qt4/FloatPlacement.cpp @@ -45,6 +45,15 @@ FloatPlacement::FloatPlacement(QWidget *) } +docstring FloatPlacement::dialogToParams() const +{ + InsetFloatParams params; + params.type = fromqstr(floatType->text()); + params.placement = get(params.wide, params.sideways); + return from_ascii(InsetFloat::params2string(params)); +} + + void FloatPlacement::useWide() { spanCB->show(); @@ -108,8 +117,13 @@ void FloatPlacement::set(string const & placement) } -void FloatPlacement::set(lyx::InsetFloatParams const & params) +void FloatPlacement::paramsToDialog(Inset const * inset) { + InsetFloat const * fl = static_cast(inset); + InsetFloatParams const & params = fl->params(); + + floatType->setText(toqstr(params.type)); + set(params.placement); standardfloat_ = (params.type == "figure" diff --git a/src/frontends/qt4/FloatPlacement.h b/src/frontends/qt4/FloatPlacement.h index f59eb39e55..be54db36bd 100644 --- a/src/frontends/qt4/FloatPlacement.h +++ b/src/frontends/qt4/FloatPlacement.h @@ -14,13 +14,14 @@ #define FLOATPLACEMENT_H #include "ui_FloatPlacementUi.h" -#include -#include +#include +#include "support/docstring.h" namespace lyx { +class Inset; class InsetFloatParams; class FloatPlacement : public QWidget, public Ui::FloatPlacementUi { @@ -28,10 +29,15 @@ class FloatPlacement : public QWidget, public Ui::FloatPlacementUi { public: FloatPlacement(QWidget * parent = 0); + /// + void paramsToDialog(Inset const *); + /// + docstring dialogToParams() const; + /// void useWide(); + /// void useSideways(); - void set(lyx::InsetFloatParams const & params); void set(std::string const & placement); void checkAllowed(); diff --git a/src/frontends/qt4/GuiFloat.cpp b/src/frontends/qt4/GuiFloat.cpp index 773a7f0ba8..832ed8396f 100644 --- a/src/frontends/qt4/GuiFloat.cpp +++ b/src/frontends/qt4/GuiFloat.cpp @@ -13,9 +13,8 @@ #include "GuiFloat.h" #include "FloatPlacement.h" -#include "FuncRequest.h" -#include "insets/InsetFloat.h" +#include "FuncRequest.h" #include @@ -25,73 +24,38 @@ namespace lyx { namespace frontend { GuiFloat::GuiFloat(GuiView & lv) - : GuiDialog(lv, "float", qt_("Float Settings")) + : InsetDialog(lv, FLOAT_CODE, LFUN_FLOAT_INSERT, "float", "Float Settings") { setupUi(this); - connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - // enable span columns checkbox floatFP->useWide(); // enable sideways checkbox floatFP->useSideways(); - connect(floatFP, SIGNAL(changed()), this, SLOT(change_adaptor())); - - bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); - - bc().setCancel(closePB); - bc().setApply(applyPB); - bc().setOK(okPB); - bc().setRestore(restorePB); - - bc().addReadOnly(floatFP); -} - - -void GuiFloat::change_adaptor() -{ - changed(); -} - - -void GuiFloat::updateContents() -{ - floatFP->set(params_); -} - - -void GuiFloat::applyView() -{ - params_.placement = floatFP->get(params_.wide, params_.sideways); + connect(floatFP, SIGNAL(changed()), this, SLOT(applyView())); } -bool GuiFloat::initialiseParams(string const & data) +void GuiFloat::enableView(bool enable) { - InsetFloat::string2params(data, params_); - return true; + floatFP->setEnabled(enable); } -void GuiFloat::clearParams() +void GuiFloat::paramsToDialog(Inset const * inset) { - params_ = InsetFloatParams(); + floatFP->paramsToDialog(inset); } -void GuiFloat::dispatchParams() +docstring GuiFloat::dialogToParams() const { - dispatch(FuncRequest(getLfun(), InsetFloat::params2string(params_))); + return floatFP->dialogToParams(); } - Dialog * createGuiFloat(GuiView & lv) { return new GuiFloat(lv); } - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiFloat.h b/src/frontends/qt4/GuiFloat.h index 76a73b834d..b98ddb0ae6 100644 --- a/src/frontends/qt4/GuiFloat.h +++ b/src/frontends/qt4/GuiFloat.h @@ -12,41 +12,32 @@ #ifndef GUIFLOAT_H #define GUIFLOAT_H -#include "GuiDialog.h" +#include "InsetDialog.h" + #include "ui_FloatUi.h" -#include "insets/InsetFloat.h" namespace lyx { namespace frontend { -class GuiFloat : public GuiDialog, public Ui::FloatUi +class GuiFloat : public InsetDialog, public Ui::FloatUi { Q_OBJECT public: GuiFloat(GuiView & lv); -private Q_SLOTS: - void change_adaptor(); - -private: - /// Apply changes - void applyView(); - /// update - void updateContents(); - /// - bool initialiseParams(std::string const & data); - /// clean-up on hide. - void clearParams(); - /// clean-up on hide. - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } - private: - /// - InsetFloatParams params_; + /// \name Dialog inerited methods + //@{ + void enableView(bool enable); + //@} + + /// \name InsetDialog inherited methods + //@{ + void paramsToDialog(Inset const *); + docstring dialogToParams() const; + //@} }; } // namespace frontend diff --git a/src/frontends/qt4/ui/FloatPlacementUi.ui b/src/frontends/qt4/ui/FloatPlacementUi.ui index 94f7069265..562fb0560f 100644 --- a/src/frontends/qt4/ui/FloatPlacementUi.ui +++ b/src/frontends/qt4/ui/FloatPlacementUi.ui @@ -1,7 +1,8 @@ - + + FloatPlacementUi - - + + 0 0 @@ -9,73 +10,97 @@ 295 - + Form - - - 9 - - - 6 - - - - + + + + + Qt::Horizontal + + + + Float Type: + + + + + TextLabel + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + Use &default placement - - - + + + Advanced Placement Options - - + + 9 - + 6 - - - + + + &Top of page - - - + + + &Ignore LaTeX rules - - - + + + Here de&finitely - - - + + + &Here if possible - - - + + + &Page of floats - - - + + + &Bottom of page @@ -83,12 +108,12 @@ - + - + Qt::Horizontal - + 21 20 @@ -96,26 +121,26 @@ - - - + + + &Span columns - - - + + + &Rotate sideways - + - + Qt::Vertical - + 20 20 @@ -126,7 +151,7 @@ - qt_i18n.h + qt_i18n.h @@ -136,11 +161,11 @@ options setDisabled(bool) - + 51 20 - + 201 47 diff --git a/src/frontends/qt4/ui/FloatUi.ui b/src/frontends/qt4/ui/FloatUi.ui index 53a417fb3d..0e812ea237 100644 --- a/src/frontends/qt4/ui/FloatUi.ui +++ b/src/frontends/qt4/ui/FloatUi.ui @@ -1,10 +1,8 @@ - - - - + + FloatUi - - + + 0 0 @@ -12,49 +10,39 @@ 336 - + - + true - - - 11 - - + + 6 + + 11 + - + - - - 0 - - + + 6 - - - - &Restore - - - false - - - + + 0 + - + Qt::Horizontal - + QSizePolicy::Expanding - + 20 20 @@ -63,25 +51,24 @@ - - - &OK + + + - - true + + &New - - - - - - &Apply + + false + + + false - - + + &Close @@ -90,25 +77,20 @@ - - - qt_i18n.h - lyx::FloatPlacement
FloatPlacement.h
1 -
- restorePB - okPB - applyPB closePB + + qt_i18n.h +
diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 00cb7bd723..99175fd64b 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -110,7 +110,7 @@ namespace lyx { // // Lgb - +//FIXME: why do we set in stone the type here? InsetFloat::InsetFloat(Buffer * buf, string const & type) : InsetCollapsable(buf), name_(from_utf8(type)) { @@ -119,12 +119,6 @@ InsetFloat::InsetFloat(Buffer * buf, string const & type) } -InsetFloat::~InsetFloat() -{ - hideDialogs("float", this); -} - - docstring InsetFloat::name() const { return "Float:" + name_; @@ -229,7 +223,7 @@ void InsetFloat::updateLabels(ParIterator const & it, UpdateType utype) void InsetFloatParams::write(ostream & os) const { - os << "Float " << type << '\n'; + os << type << '\n'; if (!placement.empty()) os << "placement " << placement << "\n"; @@ -258,6 +252,7 @@ void InsetFloatParams::read(Lexer & lex) void InsetFloat::write(ostream & os) const { + os << "Float "; params_.write(os); InsetCollapsable::write(os); } @@ -426,8 +421,7 @@ bool InsetFloat::insetAllowed(InsetCode code) const bool InsetFloat::showInsetDialog(BufferView * bv) const { if (!InsetText::showInsetDialog(bv)) - bv->showDialog("float", params2string(params()), - const_cast(this)); + bv->showDialog("float"); return true; } @@ -503,7 +497,6 @@ void InsetFloat::string2params(string const & in, InsetFloatParams & params) Lexer lex; lex.setStream(data); lex.setContext("InsetFloat::string2params"); - lex >> "float" >> "Float"; lex >> params.type; // We have to read the type here! params.read(lex); } @@ -512,7 +505,6 @@ void InsetFloat::string2params(string const & in, InsetFloatParams & params) string InsetFloat::params2string(InsetFloatParams const & params) { ostringstream data; - data << "float" << ' '; params.write(data); return data.str(); } -- 2.39.2