Akonadi

tagselectwidget.cpp
1 /*
2  Copyright (c) 2015-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18  */
19 
20 #include "tagselectwidget.h"
21 #include "monitor.h"
22 #include "tagmodel.h"
23 #include "tageditwidget.h"
24 
25 #include "shared/akranges.h"
26 
27 #include <QHBoxLayout>
28 
29 using namespace Akonadi;
30 using namespace AkRanges;
31 
32 class Q_DECL_HIDDEN TagSelectWidget::Private
33 {
34 public:
35  QScopedPointer<TagEditWidget> mTagEditWidget;
36 };
37 
38 
39 TagSelectWidget::TagSelectWidget(QWidget *parent)
40  : QWidget(parent),
41  d(new Private())
42 {
43  QHBoxLayout *mainLayout = new QHBoxLayout(this);
44 
45  auto monitor = new Monitor(this);
46  monitor->setObjectName(QStringLiteral("TagSelectWidgetMonitor"));
47  monitor->setTypeMonitored(Monitor::Tags);
48 
49  auto model = new TagModel(monitor, this);
50  d->mTagEditWidget.reset(new TagEditWidget());
51  d->mTagEditWidget->setModel(model);
52  d->mTagEditWidget->setSelectionEnabled(true);
53  d->mTagEditWidget->setObjectName(QStringLiteral("tageditwidget"));
54 
55  mainLayout->addWidget(d->mTagEditWidget.get());
56 }
57 
58 TagSelectWidget::~TagSelectWidget() = default;
59 
60 void TagSelectWidget::setSelection(const Tag::List &tags)
61 {
62  d->mTagEditWidget->setSelection(tags);
63 }
64 
65 Tag::List TagSelectWidget::selection() const
66 {
67  return d->mTagEditWidget->selection();
68 }
69 
70 QStringList TagSelectWidget::tagToStringList() const
71 {
72  return selection() | Views::transform([](const auto &tag) { return tag.url().url(); }) | Actions::toQList;
73 }
74 
75 void TagSelectWidget::setSelectionFromStringList(const QStringList &lst)
76 {
77  setSelection(lst | Views::transform([](const auto &cat) { return Tag::fromUrl(QUrl{cat}); }) | Actions::toQVector);
78 }
79 
T * get() const const
void reset(T *other)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
A widget that offers facilities to add/remove tags and optionally provides a way to select tags...
Definition: tageditwidget.h:38
Monitors an item or collection for changes.
Definition: monitor.h:84
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.