]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/TocModel.h
4bdbbbad2229c2f5e29f98d21412f0065731ac9d
[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 "qt_helpers.h"
16
17 #include <QHash>
18 #include <QList>
19 #include <QStandardItemModel>
20 #include <QStringList>
21
22 namespace lyx {
23
24 class Buffer;
25 class BufferView;
26 class DocIterator;
27 class Toc;
28 class TocItem;
29
30 namespace frontend {
31
32 class TocTypeModel : public QStandardItemModel
33 {
34 public:
35         ///
36         TocTypeModel(QObject * parent = 0);
37         ///
38         void reset();
39 };
40
41
42 class TocModel : public QStandardItemModel
43 {
44 public:
45         ///
46         TocModel(QObject * parent = 0);
47         ///
48         void reset(Toc const & toc);
49         ///
50         void reset();
51         ///
52         TocItem const & tocItem(QModelIndex const & index) const;
53         ///
54         QModelIndex modelIndex(DocIterator const & dit) const;
55         ///
56         int modelDepth() const;
57
58 private:
59         ///
60         void populate(unsigned int & index, QModelIndex const & parent);
61         ///
62         QList<QModelIndex> toc_indexes_;
63         ///
64         Toc const * toc_;
65         ///
66         int maxdepth_;
67         int mindepth_;
68 };
69
70
71 class TocModels: public QObject
72 {
73         Q_OBJECT
74 public:
75         ///
76         TocModels();
77         ///
78         void reset(BufferView const * bv);
79         ///
80         int depth(QString const & type);
81         ///
82         QStandardItemModel * model(QString const & type);
83         ///
84         QStandardItemModel * nameModel() { return names_; }
85         ///
86         QModelIndex currentIndex(QString const & type) const;
87         ///
88         void goTo(QString const & type, QModelIndex const & index) const;
89         ///
90         void init(Buffer const & buffer);
91         ///
92         void updateBackend() const;
93
94 Q_SIGNALS:
95         /// Signal that the internal toc_models_ has been reset.
96         void modelReset();
97
98 private:
99         typedef QHash<QString, TocModel *>::const_iterator const_iterator;
100         typedef QHash<QString, TocModel *>::iterator iterator;
101         ///
102         void clear();
103         ///
104         BufferView const * bv_;
105         ///
106         QHash<QString, TocModel *> models_;
107         ///
108         TocTypeModel * names_;
109 };
110
111 } // namespace frontend
112 } // namespace lyx
113
114 #endif // TOCMODEL_H