Verified Commit 1d5a9ea1 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Port 'Add To Addressbook' action to Akonadi::TagWidget

Summary:
They both look and behave the same, but Akonadi::TagWidget is the
"standard" widget used everywhere else.

Reviewers: mlaurent

Reviewed By: mlaurent

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D29252
parent 41cee314
......@@ -240,6 +240,7 @@ PUBLIC
KF5::PimCommonAkonadi
KF5::Completion
PRIVATE
KF5::AkonadiWidgets
KF5::TextWidgets
KF5::I18n
KF5::LibkdepimAkonadi
......
......@@ -22,8 +22,9 @@
#include <QLabel>
#include <KLineEdit>
#include <QComboBox>
#include <LibkdepimAkonadi/TagWidgets>
#include <AkonadiWidgets/CollectionComboBox>
#include <AkonadiWidgets/TagWidget>
FilterActionAddToAddressBookTest::FilterActionAddToAddressBookTest(QObject *parent)
: QObject(parent)
......@@ -45,7 +46,7 @@ void FilterActionAddToAddressBookTest::shouldHaveDefaultValue()
QLabel *label = w->findChild<QLabel *>(QStringLiteral("label_with_category"));
QVERIFY(label);
KPIM::TagWidget *categoryEdit = w->findChild<KPIM::TagWidget *>(QStringLiteral("CategoryEdit"));
auto categoryEdit = w->findChild<Akonadi::TagWidget *>(QStringLiteral("CategoryEdit"));
QVERIFY(categoryEdit);
label = w->findChild<QLabel *>(QStringLiteral("label_in_addressbook"));
......
......@@ -20,7 +20,9 @@
#include "filteractionaddtoaddressbook.h"
#include <LibkdepimAkonadi/AddContactJob>
#include <LibkdepimAkonadi/TagWidgets>
#include <AkonadiWidgets/TagSelectionDialog>
#include <AkonadiWidgets/TagWidget>
#include <CollectionComboBox>
#include <KContacts/Addressee>
......@@ -124,7 +126,7 @@ QWidget *FilterActionAddToAddressBook::createParamWidget(QWidget *parent) const
label->setObjectName(QStringLiteral("label_with_category"));
layout->addWidget(label, 0, 1);
KPIM::TagWidget *categoryEdit = new KPIM::TagWidget(widget);
auto categoryEdit = new Akonadi::TagWidget(widget);
categoryEdit->setObjectName(QStringLiteral("CategoryEdit"));
layout->addWidget(categoryEdit, 0, 2);
......@@ -142,14 +144,35 @@ QWidget *FilterActionAddToAddressBook::createParamWidget(QWidget *parent) const
layout->addWidget(collectionComboBox, 1, 2);
connect(headerCombo, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &FilterActionAddToAddressBook::filterActionModified);
connect(collectionComboBox, QOverload<int>::of(&Akonadi::CollectionComboBox::activated), this, &FilterActionAddToAddressBook::filterActionModified);
connect(categoryEdit, SIGNAL(selectionChanged(QStringList)),
this, SIGNAL(filterActionModified()));
connect(categoryEdit, &Akonadi::TagWidget::selectionChanged, this, &FilterActionAddToAddressBook::filterActionModified);
setParamWidgetValue(widget);
return widget;
}
namespace {
Akonadi::Tag::List namesToTags(const QStringList &names)
{
Akonadi::Tag::List tags;
tags.reserve(names.size());
std::transform(names.cbegin(), names.cend(), std::back_inserter(tags),
[](const QString &name) { return Akonadi::Tag{name}; });
return tags;
}
QStringList tagsToNames(const Akonadi::Tag::List &tags)
{
QStringList names;
names.reserve(tags.size());
std::transform(tags.cbegin(), tags.cend(), std::back_inserter(names),
std::bind(&Akonadi::Tag::name, std::placeholders::_1));
return names;
}
}
void FilterActionAddToAddressBook::setParamWidgetValue(QWidget *paramWidget) const
{
const auto headerCombo = paramWidget->findChild<KComboBox *>(QStringLiteral("HeaderComboBox"));
......@@ -162,9 +185,9 @@ void FilterActionAddToAddressBook::setParamWidgetValue(QWidget *paramWidget) con
headerCombo->setCurrentIndex(headerCombo->findData(mHeaderType));
KPIM::TagWidget *categoryEdit = paramWidget->findChild<KPIM::TagWidget *>(QStringLiteral("CategoryEdit"));
auto categoryEdit = paramWidget->findChild<Akonadi::TagWidget *>(QStringLiteral("CategoryEdit"));
Q_ASSERT(categoryEdit);
categoryEdit->setSelection(mCategory.split(QLatin1Char(';')));
categoryEdit->setSelection(namesToTags(mCategory.split(QLatin1Char(';'))));
Akonadi::CollectionComboBox *collectionComboBox = paramWidget->findChild<Akonadi::CollectionComboBox *>(QStringLiteral("AddressBookComboBox"));
Q_ASSERT(collectionComboBox);
......@@ -178,9 +201,9 @@ void FilterActionAddToAddressBook::applyParamWidgetValue(QWidget *paramWidget)
Q_ASSERT(headerCombo);
mHeaderType = static_cast<HeaderType>(headerCombo->itemData(headerCombo->currentIndex()).toInt());
const KPIM::TagWidget *categoryEdit = paramWidget->findChild<KPIM::TagWidget *>(QStringLiteral("CategoryEdit"));
const auto categoryEdit = paramWidget->findChild<Akonadi::TagWidget *>(QStringLiteral("CategoryEdit"));
Q_ASSERT(categoryEdit);
mCategory = categoryEdit->selection().join(QLatin1Char(';'));
mCategory = tagsToNames(categoryEdit->selection()).join(QLatin1Char(';'));
const Akonadi::CollectionComboBox *collectionComboBox = paramWidget->findChild<Akonadi::CollectionComboBox *>(QStringLiteral("AddressBookComboBox"));
Q_ASSERT(collectionComboBox);
......@@ -205,9 +228,9 @@ void FilterActionAddToAddressBook::clearParamWidget(QWidget *paramWidget) const
Q_ASSERT(headerCombo);
headerCombo->setCurrentIndex(0);
KPIM::TagWidget *categoryEdit = paramWidget->findChild<KPIM::TagWidget *>(QStringLiteral("CategoryEdit"));
auto categoryEdit = paramWidget->findChild<Akonadi::TagWidget *>(QStringLiteral("CategoryEdit"));
Q_ASSERT(categoryEdit);
categoryEdit->setSelection(mCategory.split(QLatin1Char(';')));
categoryEdit->setSelection(namesToTags(mCategory.split(QLatin1Char(';'))));
}
QString FilterActionAddToAddressBook::argsAsString() const
......
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