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.
17 #include "support/shared_ptr.h"
20 #include <QSortFilterProxyModel>
32 /// A class that adapt the TocBackend of a Buffer into standard Qt models for
33 /// GUI visualisation.
34 /// There is one TocModel per list in the TocBackend.
38 TocModel(TocModel const &);
39 void operator=(TocModel const &);
42 TocModel(QObject * parent);
44 void reset(shared_ptr<Toc const>);
48 void updateItem(DocIterator const & dit);
52 QAbstractItemModel * model();
54 QAbstractItemModel const * model() const;
56 void sort(bool sort_it);
58 bool isSorted() const { return is_sorted_; }
60 TocItem const & tocItem(QModelIndex const & index) const;
62 QModelIndex modelIndex(DocIterator const & dit) const;
64 int modelDepth() const;
68 void populate(unsigned int & index, QModelIndex const & parent);
70 TocTypeModel * model_;
72 QSortFilterProxyModel * sorted_model_;
76 shared_ptr<Toc const> toc_;
84 /// A filter to sort the models alphabetically but with
85 /// the table of contents on top.
86 class TocModelSortProxyModel : public QSortFilterProxyModel
89 TocModelSortProxyModel(QObject * w)
90 : QSortFilterProxyModel(w)
93 bool lessThan (const QModelIndex & left, const QModelIndex & right) const
95 if (left.model()->data(left, Qt::UserRole).toString()
96 == QString("tableofcontents"))
98 else if (right.model()->data(right, Qt::UserRole).toString()
99 == QString("tableofcontents"))
102 return QSortFilterProxyModel::lessThan(left, right);
108 /// A container for the different TocModels.
109 class TocModels : public QObject
116 void reset(BufferView const * bv);
118 int depth(QString const & type);
120 QAbstractItemModel * model(QString const & type);
122 QAbstractItemModel * nameModel();
124 QModelIndex currentIndex(QString const & type) const;
126 void goTo(QString const & type, QModelIndex const & index) const;
128 void init(Buffer const & buffer);
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