]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/TocModel.h
Add missing initialization
[lyx.git] / src / frontends / qt4 / TocModel.h
index b41e1006b9ec1ad0dd8ceee2a271783568a73170..0c3c6b09dde61d52851f15e99c9a4319b892a575 100644 (file)
 #ifndef TOCMODEL_H
 #define TOCMODEL_H
 
-#include "qt_helpers.h"
+#include "Toc.h"
 
 #include <QHash>
-#include <QStandardItemModel>
-
-class QSortFilterProxyModel;
+#include <QSortFilterProxyModel>
 
 namespace lyx {
 
 class Buffer;
 class BufferView;
 class DocIterator;
-class Toc;
-class TocItem;
 
 namespace frontend {
 
@@ -36,11 +32,14 @@ class TocTypeModel;
 /// There is one TocModel per list in the TocBackend.
 class TocModel
 {
+       /// noncopyable
+       TocModel(TocModel const &);
+       void operator=(TocModel const &);
 public:
        ///
        TocModel(QObject * parent);
        ///
-       void reset(Toc const & toc);
+       void reset(std::shared_ptr<Toc const>);
        ///
        void reset();
        ///
@@ -66,13 +65,15 @@ private:
        ///
        void populate(unsigned int & index, QModelIndex const & parent);
        ///
+       void setString(TocItem const & item, QModelIndex index);
+       ///
        TocTypeModel * model_;
        ///
        QSortFilterProxyModel * sorted_model_;
        ///
        bool is_sorted_;
        ///
-       Toc const * toc_;
+       std::shared_ptr<Toc const> toc_;
        ///
        int maxdepth_;
        ///
@@ -80,6 +81,30 @@ private:
 };
 
 
+/// A filter to sort the models alphabetically but with
+/// the table of contents on top.
+class TocModelSortProxyModel : public QSortFilterProxyModel
+{
+public:
+       TocModelSortProxyModel(QObject * w) 
+               : QSortFilterProxyModel(w)
+       {}
+
+       bool lessThan (const QModelIndex & left, const QModelIndex & right) const
+       {
+               if (left.model()->data(left, Qt::UserRole).toString()
+                         == QString("tableofcontents"))
+                       return true;
+               else if (right.model()->data(right, Qt::UserRole).toString()
+                         == QString("tableofcontents"))
+                       return false;
+               else
+                       return QSortFilterProxyModel::lessThan(left, right);
+       }
+};
+
+
+
 /// A container for the different TocModels.
 class TocModels : public QObject
 {
@@ -96,14 +121,13 @@ public:
        ///
        QAbstractItemModel * nameModel();
        ///
-       QModelIndex currentIndex(QString const & type) const;
+       QModelIndex currentIndex(QString const & type,
+                                DocIterator const & dit) const;
        ///
        void goTo(QString const & type, QModelIndex const & index) const;
        ///
        void init(Buffer const & buffer);
        ///
-       void updateBackend() const;
-       ///
        void updateItem(QString const & type, DocIterator const & dit);
        ///
        void sort(QString const & type, bool sort_it);
@@ -113,23 +137,17 @@ public:
        TocItem const currentItem(QString const & type,
                QModelIndex const & index) const;
 
-Q_SIGNALS:
-       /// Signal that the internal toc_models_ has been reset.
-       void modelReset();
-
 private:
        typedef QHash<QString, TocModel *>::const_iterator const_iterator;
        typedef QHash<QString, TocModel *>::iterator iterator;
        ///
        void clear();
        ///
-       BufferView const * bv_;
-       ///
        QHash<QString, TocModel *> models_;
        ///
        TocTypeModel * names_;
        ///
-       QSortFilterProxyModel * names_sorted_;
+       TocModelSortProxyModel * names_sorted_;
 };
 
 } // namespace frontend