]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/TocModel.h
* fix spelling in comments to please John.
[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://www.lyx.org/trac/ticket/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 updateItem(DocIterator const & dit);
57         ///
58         void clear();
59         ///
60         QAbstractItemModel * model();
61         ///
62         QAbstractItemModel const * model() const;
63         ///
64         void sort(bool sort_it);
65         ///
66         bool isSorted() const { return is_sorted_; }
67         ///
68         TocItem const & tocItem(QModelIndex const & index) const;
69         ///
70         QModelIndex modelIndex(DocIterator const & dit) const;
71         ///
72         int modelDepth() const;
73
74 private:
75         ///
76         void populate(unsigned int & index, QModelIndex const & parent);
77         ///
78         TocTypeModel * model_;
79         ///
80         QSortFilterProxyModel * sorted_model_;
81         ///
82         bool is_sorted_;
83         ///
84         Toc const * toc_;
85         ///
86         int maxdepth_;
87         ///
88         int mindepth_;
89 };
90
91
92 /// A container for the different TocModels.
93 class TocModels : public QObject
94 {
95         Q_OBJECT
96 public:
97         ///
98         TocModels();
99         ///
100         void reset(BufferView const * bv);
101         ///
102         int depth(QString const & type);
103         ///
104         QAbstractItemModel * model(QString const & type);
105         ///
106         QAbstractItemModel * nameModel();
107         ///
108         QModelIndex currentIndex(QString const & type) const;
109         ///
110         void goTo(QString const & type, QModelIndex const & index) const;
111         ///
112         void init(Buffer const & buffer);
113         ///
114         void updateBackend() const;
115         ///
116         void updateItem(QString const & type, DocIterator const & dit);
117         ///
118         void sort(QString const & type, bool sort_it);
119         ///
120         bool isSorted(QString const & type) const;
121         /// the item that is currently selected
122         TocItem const currentItem(QString const & type,
123                 QModelIndex const & index) const;
124
125 Q_SIGNALS:
126         /// Signal that the internal toc_models_ has been reset.
127         void modelReset();
128
129 private:
130         typedef QHash<QString, TocModel *>::const_iterator const_iterator;
131         typedef QHash<QString, TocModel *>::iterator iterator;
132         ///
133         void clear();
134         ///
135         BufferView const * bv_;
136         ///
137         QHash<QString, TocModel *> models_;
138         ///
139         TocTypeModel * names_;
140         ///
141         QSortFilterProxyModel * names_sorted_;
142 };
143
144 } // namespace frontend
145 } // namespace lyx
146
147 #endif // TOCMODEL_H