Incidenceeditor

combinedincidenceeditor.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
3 SPDX-FileCopyrightText: 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 "combinedincidenceeditor.h"
9
10#include "incidenceeditor_debug.h"
11
12using namespace IncidenceEditorNG;
13
14/// public methods
15
20
22{
23 qDeleteAll(mCombinedEditors);
24}
25
26void CombinedIncidenceEditor::combine(IncidenceEditor *other)
27{
28 Q_ASSERT(other);
29 mCombinedEditors.append(other);
30 connect(other, &IncidenceEditor::dirtyStatusChanged, this, &CombinedIncidenceEditor::handleDirtyStatusChange);
31}
32
34{
35 return mDirtyEditorCount > 0;
36}
37
39{
40 for (IncidenceEditor *editor : std::as_const(mCombinedEditors)) {
41 if (!editor->isValid()) {
42 const QString reason = editor->lastErrorString();
43 editor->focusInvalidField();
44 if (!reason.isEmpty()) {
45 Q_EMIT showMessage(reason, KMessageWidget::Warning);
46 }
47 return false;
48 }
49 }
50
51 return true;
52}
53
54void CombinedIncidenceEditor::handleDirtyStatusChange(bool isDirty)
55{
56 const int prevDirtyCount = mDirtyEditorCount;
57
58 Q_ASSERT(mDirtyEditorCount >= 0);
59
60 if (isDirty) {
61 ++mDirtyEditorCount;
62 } else {
63 --mDirtyEditorCount;
64 }
65
66 Q_ASSERT(mDirtyEditorCount >= 0);
67
68 if (prevDirtyCount == 0) {
70 }
71 if (mDirtyEditorCount == 0) {
73 }
74}
75
77{
78 mLoadedIncidence = incidence;
79 for (IncidenceEditor *editor : std::as_const(mCombinedEditors)) {
80 // load() may fire dirtyStatusChanged(), reset mDirtyEditorCount to make sure
81 // we don't end up with an invalid dirty count.
82 editor->blockSignals(true);
83 editor->load(incidence);
84 editor->blockSignals(false);
85
86 if (editor->isDirty()) {
87 // We are going to crash due to assert. Print some useful info before crashing.
88 qCWarning(INCIDENCEEDITOR_LOG) << "Faulty editor was " << editor->objectName();
89 qCWarning(INCIDENCEEDITOR_LOG) << "Incidence " << (incidence ? incidence->uid() : QStringLiteral("null"));
90
91 editor->printDebugInfo();
92
93 Q_ASSERT_X(false, "load", "editor shouldn't be dirty");
94 }
95 }
96
97 mWasDirty = false;
98 mDirtyEditorCount = 0;
100}
101
103{
104 for (IncidenceEditor *editor : std::as_const(mCombinedEditors)) {
105 // load() may fire dirtyStatusChanged(), reset mDirtyEditorCount to make sure
106 // we don't end up with an invalid dirty count.
107 editor->blockSignals(true);
108 editor->load(item);
109 editor->blockSignals(false);
110
111 if (editor->isDirty()) {
112 // We are going to crash due to assert. Print some useful info before crashing.
113 qCWarning(INCIDENCEEDITOR_LOG) << "Faulty editor was " << editor->objectName();
114 // qCWarning(INCIDENCEEDITOR_LOG) << "Incidence " << ( incidence ? incidence->uid() : "null" );
115
116 editor->printDebugInfo();
117
118 Q_ASSERT_X(false, "load", "editor shouldn't be dirty");
119 }
120 }
121
122 mWasDirty = false;
123 mDirtyEditorCount = 0;
125}
126
128{
129 for (IncidenceEditor *editor : std::as_const(mCombinedEditors)) {
130 editor->save(incidence);
131 }
132}
133
135{
136 for (IncidenceEditor *editor : std::as_const(mCombinedEditors)) {
137 editor->save(item);
138 }
139}
140
141#include "moc_combinedincidenceeditor.cpp"
void save(const KCalendarCore::Incidence::Ptr &incidence) override
Store the current values of the editor into.
void load(const KCalendarCore::Incidence::Ptr &incidence) override
Loads all data from.
~CombinedIncidenceEditor() override
Deletes this editor as well as all editors which are combined into this one.
bool isDirty() const override
Returns whether or not the current values in the editor differ from the initial values or if one of t...
CombinedIncidenceEditor(QWidget *parent=nullptr)
public methods
bool isValid() const override
Returns whether or not the content of this editor is valid.
KCal Incidences are complicated objects.
void dirtyStatusChanged(bool isDirty)
Signals whether the dirty status of this editor has changed.
QSharedPointer< IncidenceT > incidence() const
Convenience method to get a pointer for a specific const Incidence Type.
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.