#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)
+{
+ update();
+}
-void QToc::build_dialog()
+bool QToc::canOutline()
{
- dialog_.reset(new QTocDialog(this));
+ vector<string> const & types = getTypes();
- // Manage the cancel/close button
- bcview().setCancel(dialog_->closePB);
+ BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
+ return ControlToc::canOutline(types[type_]);
}
-void QToc::update_contents()
+QStandardItemModel * QToc::tocModel()
{
- dialog_->updateType();
- dialog_->updateToc();
+ lyxerr[Debug::GUI]
+ << "QToc: type_ " << type_
+ << " toc_models_.size() " << toc_models_.size()
+ << endl;
+
+ BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
+ return toc_models_[type_];
}
-void QToc::select(string const & text)
+QStandardItemModel * QToc::setTocModel(int type)
{
- toc::Toc::const_iterator iter = toclist.begin();
+ type_ = type;
+
+ lyxerr[Debug::GUI]
+ << "QToc: type_ " << type_
+ << " toc_models_.size() " << toc_models_.size()
+ << endl;
+
+ BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
+ return toc_models_[type_];
+}
+
- for (; iter != toclist.end(); ++iter) {
- if (iter->str == text)
- break;
+QModelIndex const QToc::getCurrentIndex()
+{
+ vector<string> const & types = getTypes();
+ TocIterator const it = getCurrentTocItem(types[type_]);
+ if (!it->isValid()) {
+ lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
+ return QModelIndex();
}
- if (iter == toclist.end()) {
- lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry: "
- << text << endl;
+ return toc_models_[type_]->modelIndex(it);
+}
+
+
+void QToc::goTo(QModelIndex const & index)
+{
+ if (!index.isValid()) {
+ lyxerr[Debug::GUI]
+ << "QToc::goTo(): QModelIndex is invalid!"
+ << endl;
return;
}
- controller().goTo(*iter);
+ TocIterator const it = toc_models_[type_]->tocIterator(index);
+
+ lyxerr[Debug::GUI]
+ << "QToc::goTo " << it->str()
+ << endl;
+
+ it->goTo(kernel().lyxview());
}
+
+void QToc::update()
+{
+ toc_models_.clear();
+
+ QStringList type_list;
+
+ type_ = 0;
+
+ vector<string> const & types = getTypes();
+ string const & selected_type = toc::getType(params().getCmdName());
+ lyxerr[Debug::GUI] << "selected_type " << selected_type << endl;
+
+ QString gui_names_;
+ for (size_t i = 0; i != types.size(); ++i) {
+ string const & type_str = types[i];
+ type_list.append(toqstr(getGuiName(type_str)));
+ if (type_str == selected_type)
+ type_ = i;
+
+ lyxerr[Debug::GUI]
+ << "QToc: new type " << type_str
+ << "\ttoc_models_.size() " << toc_models_.size()
+ << endl;
+
+ toc_models_.push_back(new TocModel(getContents(types[i])));
+ }
+ type_model_.setStringList(type_list);
+}
+
+
+void QToc::updateToc(int type)
+{
+ toc_models_[type] = new TocModel(getContents(getTypes()[type]));
+}
+
+
} // namespace frontend
} // namespace lyx