diff --git a/plugins/patchreview/patchreviewtoolview.h b/plugins/patchreview/patchreviewtoolview.h --- a/plugins/patchreview/patchreviewtoolview.h +++ b/plugins/patchreview/patchreviewtoolview.h @@ -22,7 +22,7 @@ #include namespace Sublime { class Area; } -namespace KDevelop { class IDocument; } +namespace KDevelop { class IDocument; class VcsFileChangesSortProxyModel; } namespace KParts { class Part; } namespace Purpose { class Menu; } @@ -98,6 +98,8 @@ Purpose::Menu* m_exportMenu; class PatchFilesModel* m_fileModel; + KDevelop::VcsFileChangesSortProxyModel* m_fileSortedModel; + public slots: void documentActivated( KDevelop::IDocument* ); void customContextMenuRequested(const QPoint& p); diff --git a/plugins/patchreview/patchreviewtoolview.cpp b/plugins/patchreview/patchreviewtoolview.cpp --- a/plugins/patchreview/patchreviewtoolview.cpp +++ b/plugins/patchreview/patchreviewtoolview.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -202,7 +203,11 @@ bool allowSelection = m_plugin->patch() && m_plugin->patch()->canSelectFiles(); m_fileModel = new PatchFilesModel( this, allowSelection ); - m_editPatch.filesList->setModel( m_fileModel ); + m_fileSortedModel = new KDevelop::VcsFileChangesSortProxyModel( this ); + m_fileSortedModel->setSourceModel( m_fileModel ); + m_fileSortedModel->sort(0); + connect(m_fileModel, &PatchFilesModel::itemChanged, m_fileSortedModel, &VcsFileChangesSortProxyModel::invalidate); + m_editPatch.filesList->setModel( m_fileSortedModel ); m_editPatch.filesList->header()->hide(); m_editPatch.filesList->setRootIsDecorated( false ); m_editPatch.filesList->setContextMenuPolicy(Qt::CustomContextMenu); diff --git a/vcs/CMakeLists.txt b/vcs/CMakeLists.txt --- a/vcs/CMakeLists.txt +++ b/vcs/CMakeLists.txt @@ -32,6 +32,7 @@ models/vcsannotationmodel.cpp models/vcseventmodel.cpp models/vcsfilechangesmodel.cpp + models/vcsfilechangessortproxymodel.cpp models/vcsitemeventmodel.cpp models/brancheslistmodel.cpp dvcs/dvcsjob.cpp diff --git a/vcs/models/vcsfilechangesmodel.h b/vcs/models/vcsfilechangesmodel.h --- a/vcs/models/vcsfilechangesmodel.h +++ b/vcs/models/vcsfilechangesmodel.h @@ -50,7 +50,8 @@ * @param isCheckable if true, model will show checkboxes on items. */ explicit VcsFileChangesModel(QObject *parent, bool isCheckable = false); - enum ItemRoles { VcsStatusInfoRole = Qt::UserRole+1, UrlRole, LastItemRole }; + enum ItemRoles { VcsStatusInfoRole = Qt::UserRole+1, UrlRole, StateRole, LastItemRole}; + enum ColumnsRoles { PathColumn = 0, StatusColumn = 1 }; QVariant data(const QModelIndex &index, int role) const override; diff --git a/vcs/models/vcsfilechangesmodel.cpp b/vcs/models/vcsfilechangesmodel.cpp --- a/vcs/models/vcsfilechangesmodel.cpp +++ b/vcs/models/vcsfilechangesmodel.cpp @@ -32,7 +32,6 @@ #include - namespace KDevelop { @@ -101,6 +100,8 @@ return QVariant::fromValue(m_info); case VcsFileChangesModel::UrlRole: return m_info.url(); + case VcsFileChangesModel::StateRole: + return int(m_info.state()); } return {}; } diff --git a/vcs/models/vcsfilechangessortproxymodel.h b/vcs/models/vcsfilechangessortproxymodel.h new file mode 100644 --- /dev/null +++ b/vcs/models/vcsfilechangessortproxymodel.h @@ -0,0 +1,40 @@ +/* This file is part of KDevelop + Copyright 2016 Artur Puzio + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDEVPLATFORM_VCSFILECHANGESSORTPROXYMODEL_H +#define KDEVPLATFORM_VCSFILECHANGESSORTPROXYMODEL_H + +#include + +#include + +namespace KDevelop +{ + +class KDEVPLATFORMVCS_EXPORT VcsFileChangesSortProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + VcsFileChangesSortProxyModel(QObject* parent); + bool lessThan(const QModelIndex& rLeft, const QModelIndex& rRight) const; +}; + +} + +#endif // KDEVPLATFORM_VCSFILECHANGESSORTPROXYMODEL_H diff --git a/vcs/models/vcsfilechangessortproxymodel.cpp b/vcs/models/vcsfilechangessortproxymodel.cpp new file mode 100644 --- /dev/null +++ b/vcs/models/vcsfilechangessortproxymodel.cpp @@ -0,0 +1,52 @@ +/* This file is part of KDevelop + Copyright 2016 Artur Puzio + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "vcsfilechangessortproxymodel.h" +#include "vcsfilechangesmodel.h" + +namespace KDevelop +{ + +VcsFileChangesSortProxyModel::VcsFileChangesSortProxyModel(QObject* parent) : QSortFilterProxyModel(parent) +{} + +bool VcsFileChangesSortProxyModel::lessThan(const QModelIndex& rLeft, const QModelIndex& rRight) const +{ + const int lRow = rLeft.row(); + const int rRow = rRight.row(); + + const QModelIndex leftStatusIndex = sourceModel()->index(lRow, VcsFileChangesModel::StatusColumn, QModelIndex()); + const QModelIndex rightStatusIndex = sourceModel()->index(rRow, VcsFileChangesModel::StatusColumn, QModelIndex()); + const int leftStatus = sourceModel()->data(leftStatusIndex, VcsFileChangesModel::StateRole).toInt(); + const int rightStatus = sourceModel()->data(rightStatusIndex, VcsFileChangesModel::StateRole).toInt(); + + if (leftStatusrightStatus) + return false; + + const QModelIndex leftPathIndex = sourceModel()->index(lRow, VcsFileChangesModel::PathColumn, QModelIndex()); + const QModelIndex rightPathIndex = sourceModel()->index(rRow, VcsFileChangesModel::PathColumn, QModelIndex()); + const QString leftPath = sourceModel()->data(leftPathIndex).toString(); + const QString rightPath = sourceModel()->data(rightPathIndex).toString(); + + return QString::localeAwareCompare(leftPath, rightPath)<0; +} + +} \ No newline at end of file