Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 779e4804 authored by Laurent Montel's avatar Laurent Montel 😁

Use QSortFilterProxyModel + recursive filter

parent 4a9f4044
......@@ -33,7 +33,7 @@
#include <QInputDialog>
#include <KLocalizedString>
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
SearchFilterProxyModel::SearchFilterProxyModel(QObject *parent)
: KRecursiveFilterProxyModel(parent)
{
......@@ -57,6 +57,7 @@ bool SearchFilterProxyModel::acceptRow(int sourceRow, const QModelIndex &sourceP
return true;
}
}
#endif
SelectImapFolderWidget::SelectImapFolderWidget(const KSieveUi::SieveImapAccountSettings &account, QWidget *parent)
: QWidget(parent)
......@@ -77,9 +78,14 @@ SelectImapFolderWidget::SelectImapFolderWidget(const KSieveUi::SieveImapAccountS
mTreeView = new SelectImapFolderTreeView(this);
mTreeView->setObjectName(QStringLiteral("treeview"));
mTreeView->header()->hide();
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
mFilter = new SearchFilterProxyModel(this);
mFilter->setSourceModel(mModel);
#else
mFilter = new QSortFilterProxyModel(this);
mFilter->setRecursiveFiltering(true);
mFilter->setSourceModel(mModel);
#endif
mTreeView->setModel(mFilter);
connect(mTreeView, &QTreeView::doubleClicked, this, &SelectImapFolderWidget::slotDoubleClicked);
......@@ -103,7 +109,11 @@ void SelectImapFolderWidget::slotModelLoaded(QStandardItemModel *model, bool suc
void SelectImapFolderWidget::slotSearchPattern(const QString &pattern)
{
mTreeView->expandAll();
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
mFilter->setSearchPattern(pattern);
#else
mFilter->setFilterFixedString(pattern);
#endif
}
void SelectImapFolderWidget::slotDoubleClicked(const QModelIndex &index)
......
......@@ -23,12 +23,13 @@
#include <QWidget>
#include <QTreeView>
#include <KRecursiveFilterProxyModel>
#include <KSieveUi/SieveImapAccountSettings>
class QStandardItemModel;
class QLineEdit;
class SelectImapFolderTreeView;
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
#include <KRecursiveFilterProxyModel>
class SearchFilterProxyModel : public KRecursiveFilterProxyModel
{
Q_OBJECT
......@@ -44,6 +45,7 @@ protected:
private:
QString mPattern;
};
#endif
class SelectImapFolderWidget : public QWidget
{
......@@ -71,7 +73,11 @@ private:
QLineEdit *mSearchLineEdit;
SelectImapFolderTreeView *mTreeView;
QStandardItemModel *mModel;
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
SearchFilterProxyModel *mFilter;
#else
QSortFilterProxyModel *mFilter;
#endif
};
#endif // SELECTIMAPFOLDERWIDGET_H
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