Commit de890bed authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

[Akonadi] Port to QSortFilterProxyModel from deprecated KRecursiveFilterProxyModel

Summary:
KRecursiveFilterProxyModel is dead. Port to QSortFilterProxyModel.

follow instructions in krecursivefilterproxymodel.h:
"If you can depend on Qt >= 5.10, then just use QSortFilterProxyModel::setRecursiveFilteringEnabled(true), and you don't need to use KRecursiveFilterProxyModel."
WARNING: merging this will break mailcommon build. working on a separate patch for mailcommon. perhaps others projects will also fail. don't know yet.

Reviewers: dvratil, winterz

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D25621
parent ad71b253
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.13.40")
set(PIM_VERSION "5.13.41")
project(Akonadi VERSION ${PIM_VERSION})
if (MSVC)
......
......@@ -19,20 +19,18 @@
#include <QTest>
#include <krecursivefilterproxymodel.h>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
class KRFPTestModel : public KRecursiveFilterProxyModel
class KRFPTestModel : public QSortFilterProxyModel
{
public:
KRFPTestModel(QObject *parent) : KRecursiveFilterProxyModel(parent) { }
bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const override
KRFPTestModel(QObject *parent) : QSortFilterProxyModel(parent) { }
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
{
const QModelIndex modelIndex = sourceModel()->index(sourceRow, 0, sourceParent);
return !modelIndex.data().toString().contains(QLatin1String("three"));
}
};
class ProxyModelsTest : public QObject
......@@ -48,7 +46,7 @@ private Q_SLOTS:
private:
QStandardItemModel m_model;
KRecursiveFilterProxyModel *m_krfp = nullptr;
QSortFilterProxyModel *m_krfp = nullptr;
KRFPTestModel *m_krfptest = nullptr;
};
......@@ -72,8 +70,9 @@ void ProxyModelsTest::init()
m_model.setData(m_model.index(4, 0, QModelIndex()), QStringLiteral("mystuff"), Qt::UserRole + 42);
m_krfp = new KRecursiveFilterProxyModel(this);
m_krfp = new QSortFilterProxyModel(this);
m_krfp->setSourceModel(&m_model);
m_krfp->setRecursiveFilteringEnabled(true);
m_krfptest = new KRFPTestModel(this);
m_krfptest->setSourceModel(m_krfp);
......
......@@ -39,7 +39,6 @@ public:
EntityOrderProxyModelPrivate(EntityOrderProxyModel *qq)
: q_ptr(qq)
{
}
void saveOrder(const QModelIndex &index);
......@@ -56,9 +55,10 @@ public:
using namespace Akonadi;
EntityOrderProxyModel::EntityOrderProxyModel(QObject *parent)
: KRecursiveFilterProxyModel(parent)
: QSortFilterProxyModel(parent)
, d_ptr(new EntityOrderProxyModelPrivate(this))
{
setRecursiveFilteringEnabled(true);
setDynamicSortFilter(true);
//setSortCaseSensitivity( Qt::CaseInsensitive );
}
......@@ -92,14 +92,14 @@ bool EntityOrderProxyModel::lessThan(const QModelIndex &left, const QModelIndex
Q_D(const EntityOrderProxyModel);
if (!d->m_orderConfig.isValid()) {
return KRecursiveFilterProxyModel::lessThan(left, right);
return QSortFilterProxyModel::lessThan(left, right);
}
const Collection col = parentCollection(left);
const QStringList list = d->m_orderConfig.readEntry(configKey(col), QStringList());
if (list.isEmpty()) {
return KRecursiveFilterProxyModel::lessThan(left, right);
return QSortFilterProxyModel::lessThan(left, right);
}
const QString leftValue = configString(left);
......@@ -109,7 +109,7 @@ bool EntityOrderProxyModel::lessThan(const QModelIndex &left, const QModelIndex
const int rightPosition = list.indexOf(rightValue);
if (leftPosition < 0 || rightPosition < 0) {
return KRecursiveFilterProxyModel::lessThan(left, right);
return QSortFilterProxyModel::lessThan(left, right);
}
return leftPosition < rightPosition;
......@@ -159,15 +159,15 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a
Q_D(EntityOrderProxyModel);
if (!d->m_orderConfig.isValid()) {
return KRecursiveFilterProxyModel::dropMimeData(data, action, row, column, parent);
return QSortFilterProxyModel::dropMimeData(data, action, row, column, parent);
}
if (!data->hasFormat(QStringLiteral("text/uri-list"))) {
return KRecursiveFilterProxyModel::dropMimeData(data, action, row, column, parent);
return QSortFilterProxyModel::dropMimeData(data, action, row, column, parent);
}
if (row == -1) {
return KRecursiveFilterProxyModel::dropMimeData(data, action, row, column, parent);
return QSortFilterProxyModel::dropMimeData(data, action, row, column, parent);
}
......@@ -182,7 +182,7 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a
parentCol = parent.data(EntityTreeModel::CollectionRole).value<Collection>();
} else {
if (!hasChildren(parent)) {
return KRecursiveFilterProxyModel::dropMimeData(data, action, row, column, parent);
return QSortFilterProxyModel::dropMimeData(data, action, row, column, parent);
}
const QModelIndex targetIndex = index(0, column, parent);
......@@ -195,7 +195,7 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a
// Dropping new favorite folders
if (droppedList.isEmpty()) {
const bool ok = KRecursiveFilterProxyModel::dropMimeData(data, action, row, column, parent);
const bool ok = QSortFilterProxyModel::dropMimeData(data, action, row, column, parent);
if (ok) {
droppedList = configStringsForDroppedUrls(urls, parentCol, &containsMove);
}
......@@ -224,7 +224,7 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a
d->m_orderConfig.writeEntry(configKey(parentCol), existingList);
if (containsMove) {
bool result = KRecursiveFilterProxyModel::dropMimeData(data, action, row, column, parent);
bool result = QSortFilterProxyModel::dropMimeData(data, action, row, column, parent);
invalidate();
return result;
}
......@@ -235,7 +235,7 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a
QModelIndexList EntityOrderProxyModel::match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const
{
if (role < Qt::UserRole) {
return KRecursiveFilterProxyModel::match(start, role, value, hits, flags);
return QSortFilterProxyModel::match(start, role, value, hits, flags);
}
QModelIndexList list;
......
......@@ -22,10 +22,10 @@
#ifndef AKONADI_ENTITYORDERPROXYMODEL_H
#define AKONADI_ENTITYORDERPROXYMODEL_H
#include <KRecursiveFilterProxyModel>
#include "akonadicore_export.h"
#include "collection.h"
#include "akonadicore_export.h"
#include <QSortFilterProxyModel>
class KConfigGroup;
......@@ -42,7 +42,7 @@ class EntityOrderProxyModelPrivate;
* @author Stephen Kelly <stephen@kdab.com>
* @since 4.6
*/
class AKONADICORE_EXPORT EntityOrderProxyModel : public KRecursiveFilterProxyModel
class AKONADICORE_EXPORT EntityOrderProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
......
......@@ -19,10 +19,8 @@
*/
#include "entityrightsfiltermodel.h"
#include "entitytreemodel.h"
using namespace Akonadi;
namespace Akonadi
......@@ -70,9 +68,10 @@ public:
}
EntityRightsFilterModel::EntityRightsFilterModel(QObject *parent)
: KRecursiveFilterProxyModel(parent)
: QSortFilterProxyModel(parent)
, d_ptr(new EntityRightsFilterModelPrivate(this))
{
setRecursiveFilteringEnabled(true);
}
EntityRightsFilterModel::~EntityRightsFilterModel()
......@@ -80,6 +79,16 @@ EntityRightsFilterModel::~EntityRightsFilterModel()
delete d_ptr;
}
bool EntityRightsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_D(const EntityRightsFilterModel);
const QModelIndex modelIndex = sourceModel()->index(sourceRow, 0, sourceParent);
return d->rightsMatches(modelIndex);
}
void EntityRightsFilterModel::setAccessRights(Collection::Rights rights)
{
Q_D(EntityRightsFilterModel);
......@@ -93,23 +102,14 @@ Collection::Rights EntityRightsFilterModel::accessRights() const
return d->mAccessRights;
}
bool EntityRightsFilterModel::acceptRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_D(const EntityRightsFilterModel);
const QModelIndex modelIndex = sourceModel()->index(sourceRow, 0, sourceParent);
return d->rightsMatches(modelIndex);
}
Qt::ItemFlags EntityRightsFilterModel::flags(const QModelIndex &index) const
{
Q_D(const EntityRightsFilterModel);
if (d->rightsMatches(index)) {
return KRecursiveFilterProxyModel::flags(index);
return QSortFilterProxyModel::flags(index);
} else {
return KRecursiveFilterProxyModel::flags(index) & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
return QSortFilterProxyModel::flags(index) & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
}
......
......@@ -20,11 +20,10 @@
#ifndef AKONADI_ENTITYRIGHTSFILTERMODEL_H
#define AKONADI_ENTITYRIGHTSFILTERMODEL_H
#include "akonadicore_export.h"
#include "entitytreemodel.h"
#include <krecursivefilterproxymodel.h>
#include "akonadicore_export.h"
#include <QSortFilterProxyModel>
namespace Akonadi
{
......@@ -58,7 +57,7 @@ class EntityRightsFilterModelPrivate;
* @author Tobias Koenig <tokoe@kde.org>
* @since 4.6
*/
class AKONADICORE_EXPORT EntityRightsFilterModel : public KRecursiveFilterProxyModel
class AKONADICORE_EXPORT EntityRightsFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
......@@ -100,7 +99,7 @@ public:
Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override;
protected:
bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
//@cond PRIVATE
......
......@@ -289,7 +289,7 @@ public:
*
* We use KSelectionProxyModel in order to make a flat list of selected folders from the folder tree.
*
* Attempts to use QSortFilterProxyModel / KRecursiveFilterProxyModel make code somewhat simpler,
* Attempts to use QSortFilterProxyModel make code somewhat simpler,
* but don't work since we then get a filtered tree, not a flat list. Stacking a KDescendantsProxyModel
* on top would likely remove explicitly selected parents when one of their child is selected too.
*/
......
......@@ -49,10 +49,10 @@ public:
}
RecursiveCollectionFilterProxyModel::RecursiveCollectionFilterProxyModel(QObject *parent)
: KRecursiveFilterProxyModel(parent)
: QSortFilterProxyModel(parent)
, d_ptr(new RecursiveCollectionFilterProxyModelPrivate(this))
{
setRecursiveFilteringEnabled(true);
}
RecursiveCollectionFilterProxyModel::~RecursiveCollectionFilterProxyModel()
......@@ -60,7 +60,7 @@ RecursiveCollectionFilterProxyModel::~RecursiveCollectionFilterProxyModel()
delete d_ptr;
}
bool RecursiveCollectionFilterProxyModel::acceptRow(int sourceRow, const QModelIndex &sourceParent) const
bool RecursiveCollectionFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_D(const RecursiveCollectionFilterProxyModel);
......@@ -85,6 +85,7 @@ bool RecursiveCollectionFilterProxyModel::acceptRow(int sourceRow, const QModelI
return collectionWanted;
}
void RecursiveCollectionFilterProxyModel::addContentMimeTypeInclusionFilter(const QString &mimeType)
{
Q_D(RecursiveCollectionFilterProxyModel);
......
......@@ -21,10 +21,10 @@
#ifndef AKONADI_RECURSIVECOLLECTIONFILTERPROXYMODEL_H
#define AKONADI_RECURSIVECOLLECTIONFILTERPROXYMODEL_H
#include <krecursivefilterproxymodel.h>
#include "akonadicore_export.h"
#include <QSortFilterProxyModel>
namespace Akonadi
{
......@@ -36,7 +36,7 @@ class RecursiveCollectionFilterProxyModelPrivate;
* @author Stephen Kelly <steveire@gmail.com>
* @since 4.6
*/
class AKONADICORE_EXPORT RecursiveCollectionFilterProxyModel : public KRecursiveFilterProxyModel
class AKONADICORE_EXPORT RecursiveCollectionFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
......@@ -99,9 +99,8 @@ public:
void setIncludeCheckedOnly(bool checked);
protected:
bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const override;
int columnCount(const QModelIndex &index) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
protected:
RecursiveCollectionFilterProxyModelPrivate *const d_ptr;
Q_DECLARE_PRIVATE(RecursiveCollectionFilterProxyModel)
......
......@@ -33,10 +33,10 @@ public:
};
TrashFilterProxyModel::TrashFilterProxyModel(QObject *parent)
: KRecursiveFilterProxyModel(parent)
: QSortFilterProxyModel(parent)
, d_ptr(new TrashFilterProxyModelPrivate())
{
setRecursiveFilteringEnabled(true);
}
TrashFilterProxyModel::~TrashFilterProxyModel()
......@@ -57,7 +57,7 @@ bool TrashFilterProxyModel::trashIsShown() const
return d->mTrashIsShown;
}
bool TrashFilterProxyModel::acceptRow(int sourceRow, const QModelIndex &sourceParent) const
bool TrashFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_D(const TrashFilterProxyModel);
const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
......
......@@ -22,7 +22,7 @@
#include "akonadicore_export.h"
#include <krecursivefilterproxymodel.h>
#include <QSortFilterProxyModel>
namespace Akonadi
{
......@@ -53,7 +53,7 @@ namespace Akonadi
* @author Christian Mollekopf <chrigi_1@fastmail.fm>
* @since 4.8
*/
class AKONADICORE_EXPORT TrashFilterProxyModel : public KRecursiveFilterProxyModel
class AKONADICORE_EXPORT TrashFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
......@@ -68,7 +68,7 @@ protected:
/**
* Sort filter criterias, according to how expensive the operation is
*/
bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
//@cond PRIVATE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment