]> git.lyx.org Git - features.git/commitdiff
simplify GuiToc / TocWidget interaction. Much can still be simplified...
authorAbdelrazak Younes <younes@lyx.org>
Tue, 12 Feb 2008 07:47:16 +0000 (07:47 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 12 Feb 2008 07:47:16 +0000 (07:47 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22953 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiToc.cpp
src/frontends/qt4/GuiToc.h
src/frontends/qt4/TocWidget.cpp
src/frontends/qt4/TocWidget.h

index 2d746d80c1ab98d9d8797776876d621f3d38ff7c..0d7643f869dec289c59b33708358e8b28cae078a 100644 (file)
@@ -41,7 +41,7 @@ namespace lyx {
 namespace frontend {
 
 GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
-       : DockView(parent, "toc", qt_("Outline"), area, flags), params_(TOC_CODE)
+       : DockView(parent, "toc", qt_("Outline"), area, flags)
 {
        widget_ = new TocWidget(*this);
        setWidget(widget_);
@@ -139,7 +139,15 @@ TocList const & GuiToc::tocs() const
 
 bool GuiToc::initialiseParams(string const & data)
 {
-       InsetCommandMailer::string2params("toc", data, params_);
+       LYXERR(Debug::GUI, data);
+       QString str = QString::fromUtf8(data.c_str());
+       string new_type = "tableofcontents";
+       if (str.contains("floatlist")) {
+               if (str.contains("figure"))
+                       new_type = "figure";
+               else if (str.contains("table"))
+                       new_type = "table";
+       }
 
        types_.clear();
        type_names_.clear();
@@ -153,20 +161,16 @@ bool GuiToc::initialiseParams(string const & data)
                toc_models_.push_back(new TocModel(it->second));
        }
 
-       string selected_type ;
-       if (params_["type"].empty()) //Then plain toc...
-               selected_type = params_.getCmdName();
-       else
-               selected_type = to_ascii(params_["type"]);
-       selected_type_ = -1;
+       int selected_type = -1;
        for (size_t i = 0;  i != types_.size(); ++i) {
-               if (selected_type == types_[i]) {
-                       selected_type_ = i;
+               if (new_type == types_[i]) {
+                       selected_type = i;
                        break;
                }
        }
 
-       modelReset();
+       widget_->updateGui(selected_type);
+
        return true;
 }
 
@@ -237,9 +241,6 @@ docstring GuiToc::guiName(string const & type) const
 
 void GuiToc::dispatchParams()
 {
-       string const lfun = 
-               InsetCommandMailer::params2string("toc", params_);
-       dispatch(FuncRequest(getLfun(), lfun));
 }
 
 
index f73291f48f439433d0525cb16a31a2a34bccaedc..99e0e6dba737e883d5e4cd064fcbf5850e57653c 100644 (file)
@@ -83,9 +83,6 @@ public:
        std::vector<docstring> const & typeNames() const
        { return type_names_; }
 
-       ///
-       int selectedType() { return selected_type_; }
-
        /// Return the first TocItem before the cursor
        TocIterator currentTocItem(int type) const;
 
@@ -102,21 +99,16 @@ public:
 
        std::vector<std::string> types_;
        std::vector<docstring> type_names_;
-       int selected_type_;
 
        /// Return the guiname from a given cmdName of the TOC param
        docstring guiName(std::string const & type) const;
 
        /// clean-up on hide.
-       void clearParams() { params_.clear(); }
+       void clearParams() {}
        ///
        void dispatchParams();
        ///
        bool isBufferDependent() const { return true; }
-
-private:
-       ///
-       InsetCommandParams params_;
 };
 
 } // namespace frontend
index e90b53aeaf78c1be7e0affa05962032b72873f09..bdc968670b084cb9397bdbffd59b4a706ee65f7d 100644 (file)
@@ -32,8 +32,6 @@ TocWidget::TocWidget(GuiToc & form, QWidget * parent)
 {
        setupUi(this);
 
-       connect(&form_, SIGNAL(modelReset()), SLOT(updateGui()));
-
        moveOutTB->setIcon(QIcon(":/images/promote.png"));
        moveInTB->setIcon(QIcon(":/images/demote.png"));
        moveUpTB->setIcon(QIcon(":/images/up.png"));
@@ -212,7 +210,7 @@ void TocWidget::updateView()
 }
 
 
-void TocWidget::updateGui()
+void TocWidget::updateGui(int selected_type)
 {
        vector<docstring> const & type_names = form_.typeNames();
        if (type_names.empty()) {
@@ -224,20 +222,13 @@ void TocWidget::updateGui()
        }
 
        QString current_text = typeCO->currentText();
-       //lyxerr << "current_text " << fromqstr(current_text) << endl;
        typeCO->blockSignals(true);
        typeCO->clear();
-       int current_type = -1;
        for (size_t i = 0; i != type_names.size(); ++i) {
                QString item = toqstr(type_names[i]);
                typeCO->addItem(item);
-               if (item == current_text)
-                       current_type = i;
        }
-       if (current_type != -1)
-               typeCO->setCurrentIndex(current_type);
-       else
-               typeCO->setCurrentIndex(form_.selectedType());
+       typeCO->setCurrentIndex(selected_type);
        typeCO->blockSignals(false);
 
        setTocModel(typeCO->currentIndex());
index a4a41c6f1e83853fd6186848bf0451e9acdbee38..bad9da2c08c55571af9ecf9c986c5b51f18dfa84 100644 (file)
@@ -32,9 +32,10 @@ public:
        /// Update the display of the dialog whilst it is still visible.
        void updateView();
 
-protected Q_SLOTS:
        /// Update Gui of the display.
-       void updateGui();
+       void updateGui(int selected_type);
+
+protected Q_SLOTS:
        ///
        void setTocModel(size_t type);
        ///