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