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