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 bool empty() { return toc_->empty(); }
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 void setString(TocItem const & item, QModelIndex index);
72 TocTypeModel * model_;
74 QSortFilterProxyModel * sorted_model_;
78 std::shared_ptr<Toc const> toc_;
86 /// A filter to sort the models alphabetically but with
87 /// the table of contents on top.
88 class TocModelSortProxyModel : public QSortFilterProxyModel
91 TocModelSortProxyModel(QObject * w)
92 : QSortFilterProxyModel(w)
95 bool lessThan(const QModelIndex & left, const QModelIndex & right) const override
97 if (left.model()->data(left, Qt::UserRole).toString()
98 == QString("tableofcontents"))
100 else if (right.model()->data(right, Qt::UserRole).toString()
101 == QString("tableofcontents"))
104 return QSortFilterProxyModel::lessThan(left, right);
110 /// A container for the different TocModels.
111 class TocModels : public QObject
119 void reset(BufferView const * bv);
121 int depth(QString const & type);
123 QAbstractItemModel * model(QString const & type);
125 QAbstractItemModel * nameModel();
127 QModelIndex currentIndex(QString const & type,
128 DocIterator const & dit) const;
130 FuncRequest goTo(QString const & type, QModelIndex const & index) const;
132 void updateItem(QString const & type, DocIterator const & dit);
134 void sort(QString const & type, bool sort_it);
136 bool isSorted(QString const & type) const;
137 /// the item that is currently selected
138 TocItem const currentItem(QString const & type,
139 QModelIndex const & index) const;
142 typedef QHash<QString, TocModel *>::const_iterator const_iterator;
143 typedef QHash<QString, TocModel *>::iterator iterator;
147 QHash<QString, TocModel *> models_;
149 TocTypeModel * names_;
151 TocModelSortProxyModel * names_sorted_;
154 } // namespace frontend