]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/TocModel.h
Cleanup Toc dialog and GuiView interaction. The toc models are now part of GuiView...
[lyx.git] / src / frontends / qt4 / TocModel.h
1 // -*- C++ -*-
2 /**
3  * \file TocModel.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef TOCMODEL_H
13 #define TOCMODEL_H
14
15 #include "TocBackend.h"
16
17 #include "qt_helpers.h"
18
19 #include <QStandardItemModel>
20
21 #include <map>
22
23 namespace lyx {
24
25 class BufferView;
26
27 namespace frontend {
28
29 class TocModel : public QStandardItemModel
30 {
31 public:
32         ///
33         TocModel() {}
34         ///
35         TocModel(Toc const & toc) { populate(toc); }
36         ///
37         void clear();
38         ///
39         void populate(Toc const & toc);
40         ///
41         TocIterator tocIterator(QModelIndex const & index) const;
42         ///
43         QModelIndex modelIndex(TocIterator const & it) const;
44         ///
45         int modelDepth() const;
46
47 private:
48         ///
49         void populate(TocIterator & it, TocIterator const & end,
50                 QModelIndex const & parent);
51         ///
52         typedef std::map<QModelIndex, TocIterator> TocMap;
53         ///
54         typedef std::map<TocIterator, QModelIndex> ModelMap;
55         ///
56         TocMap toc_map_;
57         ///
58         ModelMap model_map_;
59         ///
60         int maxdepth_;
61         int mindepth_;
62 };
63
64
65 class TocModels: public QObject
66 {
67         Q_OBJECT
68 public:
69         ///
70         TocModels(): bv_(0) {}
71         ///
72         TocModels::~TocModels() { clear(); }
73         ///
74         void reset(BufferView const * bv);
75         ///
76         int depth(int type);
77         ///
78         QStandardItemModel * model(int type);
79         ///
80         QModelIndex TocModels::currentIndex(int type) const;
81         ///
82         void goTo(int type, QModelIndex const & index) const;
83         ///
84         void TocModels::init(Buffer const & buffer);
85         /// Test if outlining operation is possible
86         bool canOutline(int type) const;
87         /// Return the list of types available
88         QStringList const & typeNames() const { return type_names_; }
89         ///
90         void updateBackend() const;
91         ///
92         int decodeType(QString const & str) const;
93
94 Q_SIGNALS:
95         /// Signal that the internal toc_models_ has been reset.
96         void modelReset();
97
98 private:
99         ///
100         void clear();
101         /// Return the guiname from a given cmdName of the TOC param
102         QString guiName(std::string const & type) const;
103         ///
104         BufferView const * bv_;
105         ///
106         std::vector<TocModel *> models_;
107         ///
108         QStringList types_;
109         ///
110         QStringList type_names_;
111 };
112
113 } // namespace frontend
114 } // namespace lyx
115
116 #endif // TOCMODEL_H