From 319be7eb0b764d6528a568fb95191d588ed2f474 Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Thu, 9 Mar 2017 23:06:10 +0100 Subject: [PATCH] order --- .../protein_list_view/proteinlistwindow.cpp | 1 + .../protein_list_view/proteintablemodel.cpp | 24 +++++++++++++++++++ src/gui/protein_list_view/proteintablemodel.h | 5 ++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp index 3b3b55d7..4069a466 100644 --- a/src/gui/protein_list_view/proteinlistwindow.cpp +++ b/src/gui/protein_list_view/proteinlistwindow.cpp @@ -57,6 +57,7 @@ ProteinListWindow::ProteinListWindow(QWidget *parent): _p_proxy_model->setSourceModel(_protein_table_model_p); _p_proxy_model->setDynamicSortFilter(true); ui->tableView->setModel( _p_proxy_model ); + ui->tableView->setSortingEnabled(true); } ProteinListWindow::~ProteinListWindow() diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp index b798a8e3..dac8ca49 100644 --- a/src/gui/protein_list_view/proteintablemodel.cpp +++ b/src/gui/protein_list_view/proteintablemodel.cpp @@ -35,6 +35,30 @@ bool ProteinTableProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { return true; } + +bool ProteinTableProxyModel::lessThan(const QModelIndex & left, const QModelIndex & right) const { + QVariant leftData = sourceModel()->data(left); + QVariant rightData = sourceModel()->data(right); + + return leftData.toString() < rightData.toString(); + //if (leftData.type() == QVariant::DateTime) { + // return leftData.toDateTime() < rightData.toDateTime(); + //} else { + // static QRegExp emailPattern("[\\w\\.]*@[\\w\\.]*)"); +/* + QString leftString = leftData.toString(); + if(left.column() == 1 && emailPattern.indexIn(leftString) != -1) + leftString = emailPattern.cap(1); + + QString rightString = rightData.toString(); + if(right.column() == 1 && emailPattern.indexIn(rightString) != -1) + rightString = emailPattern.cap(1); + + return QString::localeAwareCompare(leftString, rightString) < 0; + */ + // } +} + QVariant ProteinTableProxyModel::headerData(int section, Qt::Orientation orientation, int role) const { return sourceModel()->headerData(section, orientation, diff --git a/src/gui/protein_list_view/proteintablemodel.h b/src/gui/protein_list_view/proteintablemodel.h index eef8b80b..7b11abe6 100644 --- a/src/gui/protein_list_view/proteintablemodel.h +++ b/src/gui/protein_list_view/proteintablemodel.h @@ -35,9 +35,10 @@ class ProteinTableProxyModel : public QSortFilterProxyModel public: ProteinTableProxyModel(QObject* parent = 0); bool filterAcceptsRow(int source_row, - const QModelIndex &source_parent) const; + const QModelIndex &source_parent) const override; QVariant headerData(int section, Qt::Orientation orientation, - int role) const; + int role) const override; + bool lessThan(const QModelIndex & left, const QModelIndex & right) const override; public slots: //void setMinGravity(double minGravity); -- GitLab