Incidenceeditor

incidenceeditor-ng.h
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#pragma once
9
10#include "incidenceeditor_export.h"
11
12#include <Akonadi/Item>
13#include <KCalendarCore/Incidence>
14namespace IncidenceEditorNG
15{
16/**
17 * KCal Incidences are complicated objects. The user interfaces to create/modify
18 * are therefore complex too. The IncedenceEditor class is a divide and conquer
19 * approach to this complexity. An IncidenceEditor is an editor for a specific
20 * part(s) of an Incidence.
21 */
22class INCIDENCEEDITOR_EXPORT IncidenceEditor : public QObject
23{
24 Q_OBJECT
25public:
26 ~IncidenceEditor() override;
27
28 /**
29 * Load the values of @param incidence into the editor widgets. The passed
30 * incidence is kept for comparing with the current values of the editor.
31 */
32 virtual void load(const KCalendarCore::Incidence::Ptr &incidence) = 0;
33 /// This was introduced to replace categories with Akonadi::Tags
34 virtual void load(const Akonadi::Item &item);
35
36 /**
37 * Store the current values of the editor into @param incidence .
38 */
39 virtual void save(const KCalendarCore::Incidence::Ptr &incidence) = 0;
40 /// This was introduced to replace categories with Akonadi::Tags
41 virtual void save(Akonadi::Item &item);
42
43 /**
44 * Returns whether or not the current values in the editor differ from the
45 * initial values.
46 */
47 virtual bool isDirty() const = 0;
48
49 /**
50 * Returns whether or not the content of this editor is valid. The default
51 * implementation returns always true.
52 */
53 virtual bool isValid() const;
54
55 /**
56 Returns the last error, which is set in isValid() on error,
57 and cleared on success.
58 */
59 [[nodiscard]] QString lastErrorString() const;
60
61 /**
62 * Sets focus on the invalid field.
63 */
64 virtual void focusInvalidField();
65
66 /**
67 * Returns the type of the Incidence that is currently loaded.
68 */
69 [[nodiscard]] KCalendarCore::IncidenceBase::IncidenceType type() const;
70
71 /** Convenience method to get a pointer for a specific const Incidence Type. */
72 template<typename IncidenceT>
74 {
75 return mLoadedIncidence.dynamicCast<IncidenceT>();
76 }
77
78 /**
79 Re-implement this and print important member values and widget
80 enabled/disabled states that could have lead to isDirty() returning
81 true when the user didn't do any interaction with the editor.
82
83 This method is called in CombinedIncidenceEditor before crashing
84 due to assert( !editor->isDirty() )
85 */
86 virtual void printDebugInfo() const;
87
88Q_SIGNALS:
89 /**
90 * Signals whether the dirty status of this editor has changed. The new dirty
91 * status is passed as argument.
92 */
93 void dirtyStatusChanged(bool isDirty);
94
95public Q_SLOTS:
96 /**
97 * Checks if the dirty status has changed until last check and emits the
98 * dirtyStatusChanged signal if needed.
99 */
100 void checkDirtyStatus();
101
102protected:
103 /** Only subclasses can instantiate IncidenceEditors */
104 IncidenceEditor(QObject *parent = nullptr);
105
106 template<typename IncidenceT>
108 {
109 return inc.dynamicCast<IncidenceT>();
110 }
111
112protected:
113 KCalendarCore::Incidence::Ptr mLoadedIncidence;
114 mutable QString mLastErrorString;
115 bool mWasDirty = false;
116 bool mLoadingIncidence = false;
117};
118} // IncidenceEditorNG
KCal Incidences are complicated objects.
virtual bool isDirty() const =0
Returns whether or not the current values in the editor differ from the initial values.
void dirtyStatusChanged(bool isDirty)
Signals whether the dirty status of this editor has changed.
virtual void load(const KCalendarCore::Incidence::Ptr &incidence)=0
Load the values of.
QSharedPointer< IncidenceT > incidence() const
Convenience method to get a pointer for a specific const Incidence Type.
virtual void save(const KCalendarCore::Incidence::Ptr &incidence)=0
Store the current values of the editor into.
QSharedPointer< X > dynamicCast() 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.