#ifndef TOCMODEL_H
#define TOCMODEL_H
-#include "toc.h"
+#include "TocBackend.h"
#include "qt_helpers.h"
#include <QStandardItemModel>
#include <map>
-#include <string>
namespace lyx {
+
+class BufferView;
+
namespace frontend {
-class TocModel: public QStandardItemModel {
- Q_OBJECT
+class TocModel : public QStandardItemModel
+{
public:
///
TocModel() {}
///
- TocModel(toc::Toc const & toc_list);
- ///
- ~TocModel() {}
- ///
- TocModel const & operator=(toc::Toc const & toc_list);
+ TocModel(Toc const & toc) { populate(toc); }
///
void clear();
///
- void populate(toc::Toc const & toc_list);
+ void populate(Toc const & toc);
+ ///
+ TocIterator tocIterator(QModelIndex const & index) const;
///
- toc::TocItem const item(QModelIndex const & index) const;
+ QModelIndex modelIndex(TocIterator const & it) const;
///
- QModelIndex const index(std::string const & toc_str) const;
+ int modelDepth() const;
private:
///
- void populate(toc::Toc::const_iterator & iter,
- toc::Toc::const_iterator const & end,
+ void populate(TocIterator & it, TocIterator const & end,
QModelIndex const & parent);
+ ///
+ typedef std::map<QModelIndex, TocIterator> TocMap;
+ ///
+ typedef std::map<TocIterator, QModelIndex> ModelMap;
+ ///
+ TocMap toc_map_;
+ ///
+ ModelMap model_map_;
+ ///
+ int maxdepth_;
+ int mindepth_;
+};
+
+
+class TocModels: public QObject
+{
+ Q_OBJECT
+public:
+ ///
+ TocModels(): bv_(0) {}
+ ///
+ ~TocModels() { clear(); }
+ ///
+ void reset(BufferView const * bv);
+ ///
+ int depth(int type);
+ ///
+ QStandardItemModel * model(int type);
+ ///
+ QModelIndex currentIndex(int type) const;
+ ///
+ void goTo(int type, QModelIndex const & index) const;
+ ///
+ void init(Buffer const & buffer);
+ /// Test if outlining operation is possible
+ bool canOutline(int type) const;
+ /// Return the list of types available
+ QStringList const & typeNames() const { return type_names_; }
+ ///
+ void updateBackend() const;
+ ///
+ int decodeType(QString const & str) const;
- typedef std::map<QModelIndex, toc::TocItem> ItemMap;
+Q_SIGNALS:
+ /// Signal that the internal toc_models_ has been reset.
+ void modelReset();
+
+private:
+ ///
+ void clear();
+ ///
+ BufferView const * bv_;
+ ///
+ std::vector<TocModel *> models_;
///
- typedef std::map<std::string, QModelIndex> IndexMap;
+ QStringList types_;
///
- ItemMap item_map_;
- IndexMap index_map_;
+ QStringList type_names_;
};
} // namespace frontend