From: Vincent van Ravesteijn Date: Mon, 26 Apr 2010 01:36:24 +0000 (+0000) Subject: Make sure the Table of Contents is always on top in the model combobox of the TocWidget. X-Git-Tag: 2.0.0~3347 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=28b167bfff0257791673fa660eb3ec5b234ce3c4;p=features.git Make sure the Table of Contents is always on top in the model combobox of the TocWidget. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34290 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp index 86cf124396..508f333da8 100644 --- a/src/frontends/qt4/TocModel.cpp +++ b/src/frontends/qt4/TocModel.cpp @@ -246,7 +246,7 @@ TocModels::TocModels() : bv_(0) { names_ = new TocTypeModel(this); - names_sorted_ = new QSortFilterProxyModel(this); + names_sorted_ = new TocModelSortProxyModel(this); names_sorted_->setSourceModel(names_); #if QT_VERSION >= 0x040300 names_sorted_->setSortLocaleAware(true); diff --git a/src/frontends/qt4/TocModel.h b/src/frontends/qt4/TocModel.h index b41e1006b9..4e557ccbac 100644 --- a/src/frontends/qt4/TocModel.h +++ b/src/frontends/qt4/TocModel.h @@ -15,10 +15,9 @@ #include "qt_helpers.h" #include +#include #include -class QSortFilterProxyModel; - namespace lyx { class Buffer; @@ -80,6 +79,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 { @@ -129,7 +152,7 @@ private: /// TocTypeModel * names_; /// - QSortFilterProxyModel * names_sorted_; + TocModelSortProxyModel * names_sorted_; }; } // namespace frontend