Incidenceeditor

attendeeeditor.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
3 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "attendeeeditor.h"
9
10using namespace IncidenceEditorNG;
11
12AttendeeEditor::AttendeeEditor(QWidget *parent)
13 : MultiplyingLineEditor(new AttendeeLineFactory(parent), parent)
14{
15 connect(this, &AttendeeEditor::lineAdded, this, &AttendeeEditor::slotLineAdded);
16
17 addData();
18}
19
20void AttendeeEditor::slotLineAdded(KPIM::MultiplyingLine *line)
21{
22 auto att = qobject_cast<AttendeeLine *>(line);
23 if (!att) {
24 return;
25 }
26
27 connect(att, qOverload<>(&AttendeeLine::changed), this, &AttendeeEditor::slotCalculateTotal);
28 connect(att, qOverload<const KCalendarCore::Attendee &, const KCalendarCore::Attendee &>(&AttendeeLine::changed), this, &AttendeeEditor::changed);
29 connect(att, &AttendeeLine::editingFinished, this, &AttendeeEditor::editingFinished);
30}
31
32void AttendeeEditor::slotCalculateTotal()
33{
34 int empty = 0;
35 int count = 0;
36
37 const QList<KPIM::MultiplyingLine *> listLines = lines();
38 for (KPIM::MultiplyingLine *line : listLines) {
39 auto att = qobject_cast<AttendeeLine *>(line);
40 if (att) {
41 if (att->isEmpty()) {
42 ++empty;
43 } else {
44 ++count;
45 }
46 }
47 }
48 Q_EMIT countChanged(count);
49 // We always want at least one empty line
50 if (empty == 0) {
51 addData();
52 }
53}
54
55AttendeeData::List AttendeeEditor::attendees() const
56{
58 AttendeeData::List attList; // clazy:exclude=inefficient-qlist
59 // qCDebug(INCIDENCEEDITOR_LOG) << "num attendees:" << dataList.size();
60 for (const KPIM::MultiplyingLineData::Ptr &datum : dataList) {
61 AttendeeData::Ptr att = qSharedPointerDynamicCast<AttendeeData>(datum);
62 if (!att) {
63 continue;
64 }
65 attList << att;
66 }
67 return attList;
68}
69
70void AttendeeEditor::addAttendee(const KCalendarCore::Attendee &attendee)
71{
72 addData(AttendeeData::Ptr(new AttendeeData(attendee)));
73}
74
75void AttendeeEditor::removeAttendee(const AttendeeData::Ptr &attendee)
76{
77 removeData(attendee);
78}
79
80void AttendeeEditor::setActions(AttendeeLine::AttendeeActions actions)
81{
82 const QList<KPIM::MultiplyingLine *> listLines = lines();
83 for (KPIM::MultiplyingLine *line : listLines) {
84 auto att = qobject_cast<AttendeeLine *>(line);
85 att->setActions(actions);
86 }
87}
88
89#include "moc_attendeeeditor.cpp"
QList< MultiplyingLineData::Ptr > allData() const
void removeData(const MultiplyingLineData::Ptr &data)
bool addData(const MultiplyingLineData::Ptr &data=MultiplyingLineData::Ptr(), bool showDialogBox=true)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QList< QAction * > actions() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.