4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
15 #include "qt_helpers.h"
18 #include <QSortFilterProxyModel>
19 #include <QStandardItemModel>
33 /// A class that adapt the TocBackend of a Buffer into standard Qt models for
34 /// GUI visualisation.
35 /// There is one TocModel per list in the TocBackend.
40 TocModel(QObject * parent);
42 void reset(Toc const & toc);
46 void updateItem(DocIterator const & dit);
50 QAbstractItemModel * model();
52 QAbstractItemModel const * model() const;
54 void sort(bool sort_it);
56 bool isSorted() const { return is_sorted_; }
58 TocItem const & tocItem(QModelIndex const & index) const;
60 QModelIndex modelIndex(DocIterator const & dit) const;
62 int modelDepth() const;
66 void populate(unsigned int & index, QModelIndex const & parent);
68 TocTypeModel * model_;
70 QSortFilterProxyModel * sorted_model_;
82 /// A filter to sort the models alphabetically but with
83 /// the table of contents on top.
84 class TocModelSortProxyModel : public QSortFilterProxyModel
87 TocModelSortProxyModel(QObject * w)
88 : QSortFilterProxyModel(w)
91 bool lessThan (const QModelIndex & left, const QModelIndex & right) const
93 if (left.model()->data(left, Qt::UserRole).toString()
94 == QString("tableofcontents"))
96 else if (right.model()->data(right, Qt::UserRole).toString()
97 == QString("tableofcontents"))
100 return QSortFilterProxyModel::lessThan(left, right);
106 /// A container for the different TocModels.
107 class TocModels : public QObject
114 void reset(BufferView const * bv);
116 int depth(QString const & type);
118 QAbstractItemModel * model(QString const & type);
120 QAbstractItemModel * nameModel();
122 QModelIndex currentIndex(QString const & type) const;
124 void goTo(QString const & type, QModelIndex const & index) const;
126 void init(Buffer const & buffer);
128 void updateBackend() const;
130 void updateItem(QString const & type, DocIterator const & dit);
132 void sort(QString const & type, bool sort_it);
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;
140 /// Signal that the internal toc_models_ has been reset.
144 typedef QHash<QString, TocModel *>::const_iterator const_iterator;
145 typedef QHash<QString, TocModel *>::iterator iterator;
149 BufferView const * bv_;
151 QHash<QString, TocModel *> models_;
153 TocTypeModel * names_;
155 TocModelSortProxyModel * names_sorted_;
158 } // namespace frontend