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 "support/shared_ptr.h"
18 #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.
39 TocModel(QObject * parent);
41 void reset(shared_ptr<Toc const>);
45 void updateItem(DocIterator const & dit);
49 QAbstractItemModel * model();
51 QAbstractItemModel const * model() const;
53 void sort(bool sort_it);
55 bool isSorted() const { return is_sorted_; }
57 TocItem const & tocItem(QModelIndex const & index) const;
59 QModelIndex modelIndex(DocIterator const & dit) const;
61 int modelDepth() const;
65 void populate(unsigned int & index, QModelIndex const & parent);
67 TocTypeModel * model_;
69 QSortFilterProxyModel * sorted_model_;
73 shared_ptr<Toc const> toc_;
81 /// A filter to sort the models alphabetically but with
82 /// the table of contents on top.
83 class TocModelSortProxyModel : public QSortFilterProxyModel
86 TocModelSortProxyModel(QObject * w)
87 : QSortFilterProxyModel(w)
90 bool lessThan (const QModelIndex & left, const QModelIndex & right) const
92 if (left.model()->data(left, Qt::UserRole).toString()
93 == QString("tableofcontents"))
95 else if (right.model()->data(right, Qt::UserRole).toString()
96 == QString("tableofcontents"))
99 return QSortFilterProxyModel::lessThan(left, right);
105 /// A container for the different TocModels.
106 class TocModels : public QObject
113 void reset(BufferView const * bv);
115 int depth(QString const & type);
117 QAbstractItemModel * model(QString const & type);
119 QAbstractItemModel * nameModel();
121 QModelIndex currentIndex(QString const & type) const;
123 void goTo(QString const & type, QModelIndex const & index) const;
125 void init(Buffer const & buffer);
127 void updateItem(QString const & type, DocIterator const & dit);
129 void sort(QString const & type, bool sort_it);
131 bool isSorted(QString const & type) const;
132 /// the item that is currently selected
133 TocItem const currentItem(QString const & type,
134 QModelIndex const & index) const;
137 /// Signal that the internal toc_models_ has been reset.
141 typedef QHash<QString, TocModel *>::const_iterator const_iterator;
142 typedef QHash<QString, TocModel *>::iterator iterator;
146 BufferView const * bv_;
148 QHash<QString, TocModel *> models_;
150 TocTypeModel * names_;
152 TocModelSortProxyModel * names_sorted_;
155 } // namespace frontend