]> git.lyx.org Git - features.git/commitdiff
* Migrate InsetFloat to InsetDialog
authorAbdelrazak Younes <younes@lyx.org>
Mon, 8 Feb 2010 22:09:40 +0000 (22:09 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 8 Feb 2010 22:09:40 +0000 (22:09 +0000)
* 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
src/frontends/qt4/FloatPlacement.cpp
src/frontends/qt4/FloatPlacement.h
src/frontends/qt4/GuiFloat.cpp
src/frontends/qt4/GuiFloat.h
src/frontends/qt4/ui/FloatPlacementUi.ui
src/frontends/qt4/ui/FloatUi.ui
src/insets/InsetFloat.cpp

index 91bce06e94540c4b8d7657477afbdd04d6a51d5c..7d344c87d7fae6ab22f48768c654019c7e7cb64c 100644 (file)
@@ -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: {
index 22fc1ac1d79d649ec1aeee9c8d5b81284e1f5ae0..33c66fd0f0298c51ca42f5a8d47da2b1f2489ed1 100644 (file)
@@ -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<InsetFloat const *>(inset);
+       InsetFloatParams const & params = fl->params();
+
+       floatType->setText(toqstr(params.type));
+
        set(params.placement);
 
        standardfloat_ = (params.type == "figure"
index f59eb39e55544725a4391a5043c235e6101d7874..be54db36bde6c66ded86abfc643c95a57196b567 100644 (file)
 #define FLOATPLACEMENT_H
 
 #include "ui_FloatPlacementUi.h"
-#include <QWidget>
 
-#include <string>
+#include <QWidget>
 
+#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();
 
index 773a7f0ba88dacb917789f8c568614f59adf8b4d..832ed8396fabb9f326329c5f899d8dc98d306221 100644 (file)
@@ -13,9 +13,8 @@
 #include "GuiFloat.h"
 
 #include "FloatPlacement.h"
-#include "FuncRequest.h"
 
-#include "insets/InsetFloat.h"
+#include "FuncRequest.h"
 
 #include <QPushButton>
 
@@ -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
 
index 76a73b834de35012f4f66f558e23803058eed566..b98ddb0ae65c123882dd2d3ac0f0171f831b8e50 100644 (file)
 #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
index 94f70692650bb6b4501efec6645df7b826015ea5..562fb0560fa28bb09ff11db7a6630df17b3f2ba0 100644 (file)
@@ -1,7 +1,8 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>FloatPlacementUi</class>
- <widget class="QWidget" name="FloatPlacementUi" >
-  <property name="geometry" >
+ <widget class="QWidget" name="FloatPlacementUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <height>295</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
-    <number>9</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
-   <item row="0" column="0" colspan="2" >
-    <widget class="QCheckBox" name="defaultsCB" >
-     <property name="text" >
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QSplitter" name="splitter">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <widget class="QLabel" name="floatTypeTitle">
+      <property name="text">
+       <string>Float Type:</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="floatType">
+      <property name="text">
+       <string>TextLabel</string>
+      </property>
+     </widget>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="2">
+    <spacer name="spacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="2" column="0">
+    <widget class="QCheckBox" name="defaultsCB">
+     <property name="text">
       <string>Use &amp;default placement</string>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" >
-    <widget class="QGroupBox" name="options" >
-     <property name="title" >
+   <item row="3" column="0">
+    <widget class="QGroupBox" name="options">
+     <property name="title">
       <string>Advanced Placement Options</string>
      </property>
-     <layout class="QGridLayout" >
-      <property name="margin" >
+     <layout class="QGridLayout">
+      <property name="margin">
        <number>9</number>
       </property>
-      <property name="spacing" >
+      <property name="spacing">
        <number>6</number>
       </property>
-      <item row="0" column="0" >
-       <widget class="QCheckBox" name="topCB" >
-        <property name="text" >
+      <item row="0" column="0">
+       <widget class="QCheckBox" name="topCB">
+        <property name="text">
          <string>&amp;Top of page</string>
         </property>
        </widget>
       </item>
-      <item row="5" column="0" >
-       <widget class="QCheckBox" name="ignoreCB" >
-        <property name="text" >
+      <item row="5" column="0">
+       <widget class="QCheckBox" name="ignoreCB">
+        <property name="text">
          <string>&amp;Ignore LaTeX rules</string>
         </property>
        </widget>
       </item>
-      <item row="4" column="0" >
-       <widget class="QCheckBox" name="heredefinitelyCB" >
-        <property name="text" >
+      <item row="4" column="0">
+       <widget class="QCheckBox" name="heredefinitelyCB">
+        <property name="text">
          <string>Here de&amp;finitely</string>
         </property>
        </widget>
       </item>
-      <item row="3" column="0" >
-       <widget class="QCheckBox" name="herepossiblyCB" >
-        <property name="text" >
+      <item row="3" column="0">
+       <widget class="QCheckBox" name="herepossiblyCB">
+        <property name="text">
          <string>&amp;Here if possible</string>
         </property>
        </widget>
       </item>
-      <item row="2" column="0" >
-       <widget class="QCheckBox" name="pageCB" >
-        <property name="text" >
+      <item row="2" column="0">
+       <widget class="QCheckBox" name="pageCB">
+        <property name="text">
          <string>&amp;Page of floats</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="0" >
-       <widget class="QCheckBox" name="bottomCB" >
-        <property name="text" >
+      <item row="1" column="0">
+       <widget class="QCheckBox" name="bottomCB">
+        <property name="text">
          <string>&amp;Bottom of page</string>
         </property>
        </widget>
      </layout>
     </widget>
    </item>
-   <item row="1" column="1" >
+   <item row="3" column="1">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>21</width>
        <height>20</height>
      </property>
     </spacer>
    </item>
-   <item row="2" column="0" colspan="2" >
-    <widget class="QCheckBox" name="spanCB" >
-     <property name="text" >
+   <item row="4" column="0">
+    <widget class="QCheckBox" name="spanCB">
+     <property name="text">
       <string>&amp;Span columns</string>
      </property>
     </widget>
    </item>
-   <item row="3" column="0" colspan="2" >
-    <widget class="QCheckBox" name="sidewaysCB" >
-     <property name="text" >
+   <item row="5" column="0">
+    <widget class="QCheckBox" name="sidewaysCB">
+     <property name="text">
       <string>&amp;Rotate sideways</string>
      </property>
     </widget>
    </item>
-   <item row="4" column="0" >
+   <item row="6" column="0">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>20</width>
        <height>20</height>
   </layout>
  </widget>
  <includes>
-  <include location="local" >qt_i18n.h</include>
+  <include location="local">qt_i18n.h</include>
  </includes>
  <resources/>
  <connections>
    <receiver>options</receiver>
    <slot>setDisabled(bool)</slot>
    <hints>
-    <hint type="sourcelabel" >
+    <hint type="sourcelabel">
      <x>51</x>
      <y>20</y>
     </hint>
-    <hint type="destinationlabel" >
+    <hint type="destinationlabel">
      <x>201</x>
      <y>47</y>
     </hint>
index 53a417fb3d46cee0b20406033b7bd54b81900d6c..0e812ea237410dd7ae4a921135cb1d2c2a151246 100644 (file)
@@ -1,10 +1,8 @@
-<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>FloatUi</class>
- <widget class="QDialog" name="FloatUi" >
-  <property name="geometry" >
+ <widget class="QDialog" name="FloatUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <height>336</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <property name="sizeGripEnabled" >
+  <property name="sizeGripEnabled">
    <bool>true</bool>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
-    <number>11</number>
-   </property>
-   <property name="spacing" >
+  <layout class="QVBoxLayout">
+   <property name="spacing">
     <number>6</number>
    </property>
+   <property name="margin">
+    <number>11</number>
+   </property>
    <item>
-    <widget class="lyx::FloatPlacement" name="floatFP" />
+    <widget class="lyx::FloatPlacement" name="floatFP" native="true"/>
    </item>
    <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <property name="spacing" >
+    <layout class="QHBoxLayout">
+     <property name="spacing">
       <number>6</number>
      </property>
-     <item>
-      <widget class="QPushButton" name="restorePB" >
-       <property name="text" >
-        <string>&amp;Restore</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>false</bool>
-       </property>
-      </widget>
-     </item>
+     <property name="margin">
+      <number>0</number>
+     </property>
      <item>
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>20</width>
          <height>20</height>
       </spacer>
      </item>
      <item>
-      <widget class="QPushButton" name="okPB" >
-       <property name="text" >
-        <string>&amp;OK</string>
+      <widget class="QPushButton" name="newPB">
+       <property name="toolTip">
+        <string/>
        </property>
-       <property name="default" >
-        <bool>true</bool>
+       <property name="text">
+        <string>&amp;New</string>
        </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="applyPB" >
-       <property name="text" >
-        <string>&amp;Apply</string>
+       <property name="autoDefault">
+        <bool>false</bool>
+       </property>
+       <property name="default">
+        <bool>false</bool>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="closePB" >
-       <property name="text" >
+      <widget class="QPushButton" name="closePB">
+       <property name="text">
         <string>&amp;Close</string>
        </property>
       </widget>
    </item>
   </layout>
  </widget>
- <pixmapfunction></pixmapfunction>
- <includes>
-  <include location="local" >qt_i18n.h</include>
- </includes>
  <customwidgets>
   <customwidget>
    <class>lyx::FloatPlacement</class>
    <extends></extends>
    <header>FloatPlacement.h</header>
    <container>1</container>
-   <pixmap></pixmap>
   </customwidget>
  </customwidgets>
  <tabstops>
-  <tabstop>restorePB</tabstop>
-  <tabstop>okPB</tabstop>
-  <tabstop>applyPB</tabstop>
   <tabstop>closePB</tabstop>
  </tabstops>
+ <includes>
+  <include location="local">qt_i18n.h</include>
+ </includes>
  <resources/>
  <connections/>
 </ui>
index 00cb7bd723fbd8109128437324a5d3ea5f2729bd..99175fd64b57797cf0a1c6ed8d38906619899536 100644 (file)
@@ -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<InsetFloat *>(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();
 }