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.
18 #include <QSortFilterProxyModel>
30 /// A class that adapt the TocBackend of a Buffer into standard Qt models for
31 /// GUI visualisation.
32 /// There is one TocModel per list in the TocBackend.
36 TocModel(TocModel const &);
37 void operator=(TocModel const &);
40 TocModel(QObject * parent);
42 void reset(std::shared_ptr<Toc const>);
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_;
74 std::shared_ptr<Toc const> toc_;
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 updateItem(QString const & type, DocIterator const & dit);
130 void sort(QString const & type, bool sort_it);
132 bool isSorted(QString const & type) const;
133 /// the item that is currently selected
134 TocItem const currentItem(QString const & type,
135 QModelIndex const & index) const;
138 typedef QHash<QString, TocModel *>::const_iterator const_iterator;
139 typedef QHash<QString, TocModel *>::iterator iterator;
143 BufferView const * bv_;
145 QHash<QString, TocModel *> models_;
147 TocTypeModel * names_;
149 TocModelSortProxyModel * names_sorted_;
152 } // namespace frontend