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>
31 /// A class that adapt the TocBackend of a Buffer into standard Qt models for
32 /// GUI visualisation.
33 /// There is one TocModel per list in the TocBackend.
37 TocModel(TocModel const &);
38 void operator=(TocModel const &);
41 TocModel(QObject * parent);
43 void reset(std::shared_ptr<Toc const>);
47 void updateItem(DocIterator const & dit);
51 QAbstractItemModel * model();
53 QAbstractItemModel const * model() const;
55 void sort(bool sort_it);
57 bool isSorted() const { return is_sorted_; }
59 TocItem const & tocItem(QModelIndex const & index) const;
61 QModelIndex modelIndex(DocIterator const & dit) const;
63 int modelDepth() const;
67 void populate(unsigned int & index, QModelIndex const & parent);
69 void setString(TocItem const & item, QModelIndex index);
71 TocTypeModel * model_;
73 QSortFilterProxyModel * sorted_model_;
77 std::shared_ptr<Toc const> toc_;
85 /// A filter to sort the models alphabetically but with
86 /// the table of contents on top.
87 class TocModelSortProxyModel : public QSortFilterProxyModel
90 TocModelSortProxyModel(QObject * w)
91 : QSortFilterProxyModel(w)
94 bool lessThan (const QModelIndex & left, const QModelIndex & right) const
96 if (left.model()->data(left, Qt::UserRole).toString()
97 == QString("tableofcontents"))
99 else if (right.model()->data(right, Qt::UserRole).toString()
100 == QString("tableofcontents"))
103 return QSortFilterProxyModel::lessThan(left, right);
109 /// A container for the different TocModels.
110 class TocModels : public QObject
117 void reset(BufferView const * bv);
119 int depth(QString const & type);
121 QAbstractItemModel * model(QString const & type);
123 QAbstractItemModel * nameModel();
125 QModelIndex currentIndex(QString const & type,
126 DocIterator const & dit) const;
128 FuncRequest goTo(QString const & type, QModelIndex const & index) 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 typedef QHash<QString, TocModel *>::const_iterator const_iterator;
141 typedef QHash<QString, TocModel *>::iterator iterator;
145 QHash<QString, TocModel *> models_;
147 TocTypeModel * names_;
149 TocModelSortProxyModel * names_sorted_;
152 } // namespace frontend