#include <config.h>
#include "QToc.h"
-#include "QTocDialog.h"
+
+#include "TocModel.h"
#include "Qt2BC.h"
#include "qt_helpers.h"
#include "controllers/ControlToc.h"
+#include <algorithm>
+
using std::endl;
using std::pair;
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"