]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt4/QToc.C
Cleanup of the Toc model and controller: The objective is to let the View (TocWidget...
[features.git] / src / frontends / qt4 / QToc.C
index b43dbb124c4e65a4ba2ce8b1636e0c82a3b7fe11..fc683e9ff0413ba68410065fc2882ff55686dae6 100644 (file)
@@ -12,7 +12,8 @@
 #include <config.h>
 
 #include "QToc.h"
-#include "QTocDialog.h"
+
+#include "TocModel.h"
 #include "Qt2BC.h"
 #include "qt_helpers.h"
 
@@ -20,6 +21,8 @@
 
 #include "controllers/ControlToc.h"
 
+#include <algorithm>
+
 using std::endl;
 
 using std::pair;
@@ -29,71 +32,113 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
-typedef QController<ControlToc, QView<QTocDialog> > base_class;
 
 QToc::QToc(Dialog & parent)
-       : base_class(parent, _("Table of Contents"))
-{}
+       : ControlToc(parent)
+{
+}
 
 
-void QToc::build_dialog()
+bool QToc::canOutline(int type) const
 {
-       dialog_.reset(new QTocDialog(this));
+       if (type < 0) 
+               return false;
+
+       return ControlToc::canOutline(type);
 }
 
 
-void QToc::update_contents()
+int QToc::getTocDepth(int type)
 {
-       dialog_->updateType();
-       dialog_->updateToc();
+       if (type < 0)
+               return 0;
+       return toc_models_[type]->modelDepth();
 }
 
 
-void QToc::select(string const & text)
+QStandardItemModel * QToc::tocModel(int type)
 {
-       toc::Toc::const_iterator iter = toclist.begin();
+       if (type < 0)
+               return 0;
 
-       for (; iter != toclist.end(); ++iter) {
-               if (iter->str == text)
-                       break;
+       if (toc_models_.empty()) {
+               lyxerr[Debug::GUI] << "QToc::tocModel(): no types available " << endl;
+               return 0;
        }
 
-       if (iter == toclist.end()) {
-               lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry: "
-                       << text << endl;
-               return;
-       }
+       lyxerr[Debug::GUI]
+               << "QToc: type_ " << type
+               << "  toc_models_.size() " << toc_models_.size()
+               << endl;
 
-       controller().goTo(*iter);
+       BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
+       return toc_models_[type];
 }
 
-void QToc::moveUp()
+
+QModelIndex const QToc::getCurrentIndex(int type) const
 {
-       controller().outline(toc::UP);
-       update_contents();
+       if (type < 0)
+               return QModelIndex();
+
+       return toc_models_[type]->modelIndex(getCurrentTocItem(type));
 }
 
 
-void QToc::moveDown()
+void QToc::goTo(int type, QModelIndex const & index)
 {
-       controller().outline(toc::DOWN);
-       update_contents();
+       if (type < 0 || !index.isValid() 
+               || index.model() != toc_models_[type]) {
+               lyxerr[Debug::GUI]
+                       << "QToc::goTo(): QModelIndex is invalid!"
+                       << endl;
+               return;
+       }
+
+       BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
+
+       TocIterator const it = toc_models_[type]->tocIterator(index);
+       
+       lyxerr[Debug::GUI]
+               << "QToc::goTo " << lyx::to_utf8(it->str())
+               << endl;
+
+       ControlToc::goTo(*it);
+}
+
+
+void QToc::update()
+{
+       updateType();
+       updateToc();
+       modelReset();
 }
 
 
-void QToc::moveIn()
+void QToc::updateType()
 {
-       controller().outline(toc::IN);
-       update_contents();
+       QStringList type_list;
+
+       vector<docstring> const & type_names = typeNames();
+       BOOST_ASSERT(!type_names.empty());
+       for (size_t i = 0; i != type_names.size(); ++i)
+               type_list.append(toqstr(type_names[i]));
+
+       type_model_.setStringList(type_list);
 }
 
 
-void QToc::moveOut()
+void QToc::updateToc()
 {
-       controller().outline(toc::OUT);
-       update_contents();
+       toc_models_.clear();
+       TocList::const_iterator it = tocs().begin();
+       TocList::const_iterator end = tocs().end();
+       for (; it != end; ++it)
+               toc_models_.push_back(new TocModel(it->second));
 }
 
 
 } // namespace frontend
 } // namespace lyx
+
+#include "QToc_moc.cpp"