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.
16 #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.
37 TocModel(QObject * parent);
39 void reset(Toc const & toc);
43 void updateItem(DocIterator const & dit);
47 QAbstractItemModel * model();
49 QAbstractItemModel const * model() const;
51 void sort(bool sort_it);
53 bool isSorted() const { return is_sorted_; }
55 TocItem const & tocItem(QModelIndex const & index) const;
57 QModelIndex modelIndex(DocIterator const & dit) const;
59 int modelDepth() const;
63 void populate(unsigned int & index, QModelIndex const & parent);
65 TocTypeModel * model_;
67 QSortFilterProxyModel * sorted_model_;
79 /// A filter to sort the models alphabetically but with
80 /// the table of contents on top.
81 class TocModelSortProxyModel : public QSortFilterProxyModel
84 TocModelSortProxyModel(QObject * w)
85 : QSortFilterProxyModel(w)
88 bool lessThan (const QModelIndex & left, const QModelIndex & right) const
90 if (left.model()->data(left, Qt::UserRole).toString()
91 == QString("tableofcontents"))
93 else if (right.model()->data(right, Qt::UserRole).toString()
94 == QString("tableofcontents"))
97 return QSortFilterProxyModel::lessThan(left, right);
103 /// A container for the different TocModels.
104 class TocModels : public QObject
111 void reset(BufferView const * bv);
113 int depth(QString const & type);
115 QAbstractItemModel * model(QString const & type);
117 QAbstractItemModel * nameModel();
119 QModelIndex currentIndex(QString const & type) const;
121 void goTo(QString const & type, QModelIndex const & index) const;
123 void init(Buffer const & buffer);
125 void updateItem(QString const & type, DocIterator const & dit);
127 void sort(QString const & type, bool sort_it);
129 bool isSorted(QString const & type) const;
130 /// the item that is currently selected
131 TocItem const currentItem(QString const & type,
132 QModelIndex const & index) const;
135 /// Signal that the internal toc_models_ has been reset.
139 typedef QHash<QString, TocModel *>::const_iterator const_iterator;
140 typedef QHash<QString, TocModel *>::iterator iterator;
144 BufferView const * bv_;
146 QHash<QString, TocModel *> models_;
148 TocTypeModel * names_;
150 TocModelSortProxyModel * names_sorted_;
153 } // namespace frontend