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