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