diff --git a/src/pimcommonakonadi/folderdialog/checkedcollectionwidget.cpp b/src/pimcommonakonadi/folderdialog/checkedcollectionwidget.cpp index bfc1132..aeadd90 100644 --- a/src/pimcommonakonadi/folderdialog/checkedcollectionwidget.cpp +++ b/src/pimcommonakonadi/folderdialog/checkedcollectionwidget.cpp @@ -1,136 +1,134 @@ /* Copyright (c) 2013-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "checkedcollectionwidget.h" -#include #include #include #include -#include #include #include #include #include #include #include using namespace PimCommon; class PimCommon::CheckedCollectionWidgetPrivate { public: CheckedCollectionWidgetPrivate() : mFolderView(nullptr) , mSelectionModel(nullptr) , mCheckProxy(nullptr) , mCollectionFilter(nullptr) , mEntityTreeModel(nullptr) { } QTreeView *mFolderView = nullptr; QItemSelectionModel *mSelectionModel = nullptr; KCheckableProxyModel *mCheckProxy = nullptr; QSortFilterProxyModel *mCollectionFilter = nullptr; Akonadi::EntityTreeModel *mEntityTreeModel = nullptr; }; CheckedCollectionWidget::CheckedCollectionWidget(const QString &mimetype, QWidget *parent) : QWidget(parent) , d(new PimCommon::CheckedCollectionWidgetPrivate) { QVBoxLayout *vbox = new QVBoxLayout(this); vbox->setContentsMargins(0, 0, 0, 0); // Create a new change recorder. Akonadi::Monitor *monitor = new Akonadi::Monitor(this); monitor->setObjectName(QStringLiteral("CheckedCollectionWidgetMonitor")); monitor->fetchCollection(true); monitor->setAllMonitored(true); monitor->setMimeTypeMonitored(mimetype); connect(monitor, &Akonadi::Monitor::collectionAdded, this, &CheckedCollectionWidget::collectionAdded); connect(monitor, &Akonadi::Monitor::collectionRemoved, this, &CheckedCollectionWidget::collectionRemoved); d->mEntityTreeModel = new Akonadi::EntityTreeModel(monitor, this); // Set the model to show only collections, not items. d->mEntityTreeModel->setItemPopulationStrategy(Akonadi::EntityTreeModel::NoItemPopulation); Akonadi::CollectionFilterProxyModel *mimeTypeProxy = new Akonadi::CollectionFilterProxyModel(this); mimeTypeProxy->setExcludeVirtualCollections(true); mimeTypeProxy->addMimeTypeFilters(QStringList() << mimetype); mimeTypeProxy->setSourceModel(d->mEntityTreeModel); // Create the Check proxy model. d->mSelectionModel = new QItemSelectionModel(mimeTypeProxy); d->mCheckProxy = new KCheckableProxyModel(this); d->mCheckProxy->setSelectionModel(d->mSelectionModel); d->mCheckProxy->setSourceModel(mimeTypeProxy); d->mCollectionFilter = new QSortFilterProxyModel(this); d->mCollectionFilter->setRecursiveFilteringEnabled(true); d->mCollectionFilter->setSourceModel(d->mCheckProxy); d->mCollectionFilter->setFilterCaseSensitivity(Qt::CaseInsensitive); QLineEdit *searchLine = new QLineEdit(this); searchLine->setPlaceholderText(i18n("Search...")); searchLine->setClearButtonEnabled(true); connect(searchLine, &QLineEdit::textChanged, this, &CheckedCollectionWidget::slotSetCollectionFilter); vbox->addWidget(searchLine); d->mFolderView = new QTreeView; d->mFolderView->setEditTriggers(QAbstractItemView::NoEditTriggers); d->mFolderView->setAlternatingRowColors(true); d->mFolderView->setModel(d->mCollectionFilter); vbox->addWidget(d->mFolderView); } CheckedCollectionWidget::~CheckedCollectionWidget() { delete d; } Akonadi::EntityTreeModel *CheckedCollectionWidget::entityTreeModel() const { return d->mEntityTreeModel; } QTreeView *CheckedCollectionWidget::folderTreeView() const { return d->mFolderView; } QItemSelectionModel *CheckedCollectionWidget::selectionModel() const { return d->mSelectionModel; } KCheckableProxyModel *CheckedCollectionWidget::checkableProxy() const { return d->mCheckProxy; } void CheckedCollectionWidget::slotSetCollectionFilter(const QString &filter) { d->mCollectionFilter->setFilterWildcard(filter); d->mFolderView->expandAll(); } diff --git a/src/pimcommonakonadi/folderdialog/selectmulticollectionwidget.cpp b/src/pimcommonakonadi/folderdialog/selectmulticollectionwidget.cpp index dd35516..aae1b74 100644 --- a/src/pimcommonakonadi/folderdialog/selectmulticollectionwidget.cpp +++ b/src/pimcommonakonadi/folderdialog/selectmulticollectionwidget.cpp @@ -1,107 +1,103 @@ /* Copyright (c) 2013-2019 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "selectmulticollectionwidget.h" #include "folderdialog/checkedcollectionwidget.h" -#include #include - -#include #include -#include #include #include #include using namespace PimCommon; SelectMultiCollectionWidget::SelectMultiCollectionWidget(const QString &mimetype, QWidget *parent) : QWidget(parent) { initialize(mimetype); } SelectMultiCollectionWidget::SelectMultiCollectionWidget(const QString &mimetype, const QList &selectedCollection, QWidget *parent) : QWidget(parent) , mListCollection(selectedCollection) { initialize(mimetype); } SelectMultiCollectionWidget::~SelectMultiCollectionWidget() { } void SelectMultiCollectionWidget::initialize(const QString &mimetype) { QVBoxLayout *vbox = new QVBoxLayout(this); vbox->setContentsMargins(0, 0, 0, 0); mCheckedCollectionWidget = new PimCommon::CheckedCollectionWidget(mimetype); connect(mCheckedCollectionWidget, &PimCommon::CheckedCollectionWidget::collectionAdded, this, &SelectMultiCollectionWidget::slotCollectionsTreeFetched); connect(mCheckedCollectionWidget, &PimCommon::CheckedCollectionWidget::collectionRemoved, this, &SelectMultiCollectionWidget::slotCollectionsTreeFetched); connect(mCheckedCollectionWidget->entityTreeModel(), &Akonadi::EntityTreeModel::collectionTreeFetched, this, &SelectMultiCollectionWidget::slotCollectionsTreeFetched); vbox->addWidget(mCheckedCollectionWidget); } void SelectMultiCollectionWidget::updateStatus(const QModelIndex &parent) { const int nbCol = mCheckedCollectionWidget->checkableProxy()->rowCount(parent); for (int i = 0; i < nbCol; ++i) { const QModelIndex child = mCheckedCollectionWidget->checkableProxy()->index(i, 0, parent); const Akonadi::Collection col = mCheckedCollectionWidget->checkableProxy()->data(child, Akonadi::EntityTreeModel::CollectionRole).value(); if (mListCollection.contains(col.id())) { mCheckedCollectionWidget->checkableProxy()->setData(child, Qt::Checked, Qt::CheckStateRole); } updateStatus(child); } } void SelectMultiCollectionWidget::slotCollectionsTreeFetched() { if (!mListCollection.isEmpty()) { updateStatus(QModelIndex()); } mCheckedCollectionWidget->folderTreeView()->expandAll(); } QVector SelectMultiCollectionWidget::selectedCollection(const QModelIndex &parent) const { QVector lst; const int nbCol = mCheckedCollectionWidget->checkableProxy()->rowCount(parent); for (int i = 0; i < nbCol; ++i) { const QModelIndex child = mCheckedCollectionWidget->checkableProxy()->index(i, 0, parent); const Akonadi::Collection col = mCheckedCollectionWidget->checkableProxy()->data(child, Akonadi::EntityTreeModel::CollectionRole).value(); if (mCheckedCollectionWidget->checkableProxy()->data(child, Qt::CheckStateRole).value()) { lst << col; } lst << selectedCollection(child); } return lst; }