]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/TocModel.h
cosmetics
[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 <QStandardItemModel>
19
20 class QSortFilterProxyModel;
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);
37         ///
38         void reset();
39 };
40
41
42 class TocModel
43 {
44 public:
45         ///
46         TocModel(QObject * parent);
47         ///
48         void reset(Toc const & toc);
49         ///
50         void reset();
51         ///
52         void clear();
53         ///
54         QAbstractItemModel * model();
55         ///
56         QAbstractItemModel const * model() const;
57         ///
58         void sort(bool sort_it);
59         ///
60         bool isSorted() const { return is_sorted_; }
61         ///
62         TocItem const & tocItem(QModelIndex const & index) const;
63         ///
64         QModelIndex modelIndex(DocIterator const & dit) const;
65         ///
66         int modelDepth() const;
67
68 private:
69         ///
70         void populate(unsigned int & index, QModelIndex const & parent);
71         ///
72         TocTypeModel * model_;
73         ///
74         QSortFilterProxyModel * sorted_model_;
75         ///
76         bool is_sorted_;
77         ///
78         Toc const * toc_;
79         ///
80         int maxdepth_;
81         ///
82         int mindepth_;
83 };
84
85
86 class TocModels : public QObject
87 {
88         Q_OBJECT
89 public:
90         ///
91         TocModels();
92         ///
93         void reset(BufferView const * bv);
94         ///
95         int depth(QString const & type);
96         ///
97         QAbstractItemModel * model(QString const & type);
98         ///
99         QAbstractItemModel * nameModel();
100         ///
101         QModelIndex currentIndex(QString const & type) const;
102         ///
103         void goTo(QString const & type, QModelIndex const & index) const;
104         ///
105         void init(Buffer const & buffer);
106         ///
107         void updateBackend() const;
108         ///
109         void sort(QString const & type, bool sort_it);
110         ///
111         bool isSorted(QString const & type) const;
112
113 Q_SIGNALS:
114         /// Signal that the internal toc_models_ has been reset.
115         void modelReset();
116
117 private:
118         typedef QHash<QString, TocModel *>::const_iterator const_iterator;
119         typedef QHash<QString, TocModel *>::iterator iterator;
120         ///
121         void clear();
122         ///
123         BufferView const * bv_;
124         ///
125         QHash<QString, TocModel *> models_;
126         ///
127         TocTypeModel * names_;
128         ///
129         QSortFilterProxyModel * names_sorted_;
130 };
131
132 } // namespace frontend
133 } // namespace lyx
134
135 #endif // TOCMODEL_H