Akonadi

tagselectwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "tagselectwidget.h"
8#include "monitor.h"
9#include "tageditwidget.h"
10#include "tagmodel.h"
11
12#include "shared/akranges.h"
13
14#include <QHBoxLayout>
15
16using namespace Akonadi;
17using namespace AkRanges;
18
19class Akonadi::TagSelectWidgetPrivate
20{
21public:
22 QScopedPointer<TagEditWidget> mTagEditWidget;
23};
24
25TagSelectWidget::TagSelectWidget(QWidget *parent)
26 : QWidget(parent)
27 , d(new TagSelectWidgetPrivate())
28{
29 auto mainLayout = new QHBoxLayout(this);
30
31 auto monitor = new Monitor(this);
32 monitor->setObjectName(QLatin1StringView("TagSelectWidgetMonitor"));
33 monitor->setTypeMonitored(Monitor::Tags);
34
35 auto model = new TagModel(monitor, this);
36 d->mTagEditWidget.reset(new TagEditWidget());
37 d->mTagEditWidget->setModel(model);
38 d->mTagEditWidget->setSelectionEnabled(true);
39 d->mTagEditWidget->setObjectName(QLatin1StringView("tageditwidget"));
40
41 mainLayout->addWidget(d->mTagEditWidget.get());
42}
43
44TagSelectWidget::~TagSelectWidget() = default;
45
46void TagSelectWidget::setSelection(const Tag::List &tags)
47{
48 d->mTagEditWidget->setSelection(tags);
49}
50
51Tag::List TagSelectWidget::selection() const
52{
53 return d->mTagEditWidget->selection();
54}
55
57{
58 return selection() | Views::transform([](const auto &tag) {
59 return tag.url().url();
60 })
61 | Actions::toQList;
62}
63
65{
66 setSelection(lst | Views::transform([](const auto &cat) {
67 return Tag::fromUrl(QUrl{cat});
68 })
69 | Actions::toQVector);
70}
71
72#include "moc_tagselectwidget.cpp"
Monitors an item or collection for changes.
Definition monitor.h:71
A widget that offers facilities to add/remove tags and optionally provides a way to select tags.
void setSelectionFromStringList(const QStringList &lst)
setSelectionFromStringList, convert a QStringList to Tag (converted from url)
QStringList tagToStringList() const
tagToStringList
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.