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 void setString(TocItem const & item, QModelIndex index);
70 TocTypeModel * model_;
72 QSortFilterProxyModel * sorted_model_;
76 std::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
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