Akonadi

tagselectwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2022 Laurent Montel <[email protected]>
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 
16 using namespace Akonadi;
17 using namespace AkRanges;
18 
19 class Akonadi::TagSelectWidgetPrivate
20 {
21 public:
22  QScopedPointer<TagEditWidget> mTagEditWidget;
23 };
24 
25 TagSelectWidget::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(QStringLiteral("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(QStringLiteral("tageditwidget"));
40 
41  mainLayout->addWidget(d->mTagEditWidget.get());
42 }
43 
44 TagSelectWidget::~TagSelectWidget() = default;
45 
46 void TagSelectWidget::setSelection(const Tag::List &tags)
47 {
48  d->mTagEditWidget->setSelection(tags);
49 }
50 
51 Tag::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 }
Monitors an item or collection for changes.
Definition: monitor.h:71
void setSelectionFromStringList(const QStringList &lst)
setSelectionFromStringList, convert a QStringList to Tag (converted from url)
A widget that offers facilities to add/remove tags and optionally provides a way to select tags.
Definition: tageditwidget.h:29
QStringList tagToStringList() const
tagToStringList
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.