]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/TocModel.h
Remove unused forward declarations
[lyx.git] / src / frontends / qt / 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 "Toc.h"
16
17 #include <QHash>
18 #include <QSortFilterProxyModel>
19
20 namespace lyx {
21
22 class BufferView;
23 class DocIterator;
24 class FuncRequest;
25
26 namespace frontend {
27
28 class TocTypeModel;
29
30 /// A class that adapt the TocBackend of a Buffer into standard Qt models for
31 /// GUI visualisation.
32 /// There is one TocModel per list in the TocBackend.
33 class TocModel
34 {
35         /// noncopyable
36         TocModel(TocModel const &);
37         void operator=(TocModel const &);
38 public:
39         ///
40         TocModel(QObject * parent);
41         ///
42         void reset(std::shared_ptr<Toc const>);
43         ///
44         void reset();
45         ///
46         void updateItem(DocIterator const & dit);
47         ///
48         void clear();
49         ///
50         QAbstractItemModel * model();
51         ///
52         QAbstractItemModel const * model() const;
53         ///
54         void sort(bool sort_it);
55         ///
56         bool isSorted() const { return is_sorted_; }
57         ///
58         TocItem const & tocItem(QModelIndex const & index) const;
59         ///
60         QModelIndex modelIndex(DocIterator const & dit) const;
61         ///
62         int modelDepth() const;
63
64 private:
65         ///
66         void populate(unsigned int & index, QModelIndex const & parent);
67         ///
68         void setString(TocItem const & item, QModelIndex index);
69         ///
70         TocTypeModel * model_;
71         ///
72         QSortFilterProxyModel * sorted_model_;
73         ///
74         bool is_sorted_;
75         ///
76         std::shared_ptr<Toc const> toc_;
77         ///
78         int maxdepth_;
79         ///
80         int mindepth_;
81 };
82
83
84 /// A filter to sort the models alphabetically but with
85 /// the table of contents on top.
86 class TocModelSortProxyModel : public QSortFilterProxyModel
87 {
88 public:
89         TocModelSortProxyModel(QObject * w)
90                 : QSortFilterProxyModel(w)
91         {}
92
93         bool lessThan (const QModelIndex & left, const QModelIndex & right) const
94         {
95                 if (left.model()->data(left, Qt::UserRole).toString()
96                           == QString("tableofcontents"))
97                         return true;
98                 else if (right.model()->data(right, Qt::UserRole).toString()
99                           == QString("tableofcontents"))
100                         return false;
101                 else
102                         return QSortFilterProxyModel::lessThan(left, right);
103         }
104 };
105
106
107
108 /// A container for the different TocModels.
109 class TocModels : public QObject
110 {
111         Q_OBJECT
112 public:
113         ///
114         TocModels();
115         ~TocModels();
116         ///
117         void reset(BufferView const * bv);
118         ///
119         int depth(QString const & type);
120         ///
121         QAbstractItemModel * model(QString const & type);
122         ///
123         QAbstractItemModel * nameModel();
124         ///
125         QModelIndex currentIndex(QString const & type,
126                                  DocIterator const & dit) const;
127         ///
128         FuncRequest goTo(QString const & type, QModelIndex const & index) const;
129         ///
130         void updateItem(QString const & type, DocIterator const & dit);
131         ///
132         void sort(QString const & type, bool sort_it);
133         ///
134         bool isSorted(QString const & type) const;
135         /// the item that is currently selected
136         TocItem const currentItem(QString const & type,
137                 QModelIndex const & index) const;
138
139 private:
140         typedef QHash<QString, TocModel *>::const_iterator const_iterator;
141         typedef QHash<QString, TocModel *>::iterator iterator;
142         ///
143         void clear();
144         ///
145         QHash<QString, TocModel *> models_;
146         ///
147         TocTypeModel * names_;
148         ///
149         TocModelSortProxyModel * names_sorted_;
150 };
151
152 } // namespace frontend
153 } // namespace lyx
154
155 #endif // TOCMODEL_H