File indexing completed on 2024-04-28 05:11:35
0001 /* 0002 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org> 0003 SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "incidenceeditor_export.h" 0011 0012 #include <Akonadi/Item> 0013 #include <KCalendarCore/Incidence> 0014 namespace IncidenceEditorNG 0015 { 0016 /** 0017 * KCal Incidences are complicated objects. The user interfaces to create/modify 0018 * are therefore complex too. The IncedenceEditor class is a divide and conquer 0019 * approach to this complexity. An IncidenceEditor is an editor for a specific 0020 * part(s) of an Incidence. 0021 */ 0022 class INCIDENCEEDITOR_EXPORT IncidenceEditor : public QObject 0023 { 0024 Q_OBJECT 0025 public: 0026 ~IncidenceEditor() override; 0027 0028 /** 0029 * Load the values of @param incidence into the editor widgets. The passed 0030 * incidence is kept for comparing with the current values of the editor. 0031 */ 0032 virtual void load(const KCalendarCore::Incidence::Ptr &incidence) = 0; 0033 /// This was introduced to replace categories with Akonadi::Tags 0034 virtual void load(const Akonadi::Item &item); 0035 0036 /** 0037 * Store the current values of the editor into @param incidence . 0038 */ 0039 virtual void save(const KCalendarCore::Incidence::Ptr &incidence) = 0; 0040 /// This was introduced to replace categories with Akonadi::Tags 0041 virtual void save(Akonadi::Item &item); 0042 0043 /** 0044 * Returns whether or not the current values in the editor differ from the 0045 * initial values. 0046 */ 0047 virtual bool isDirty() const = 0; 0048 0049 /** 0050 * Returns whether or not the content of this editor is valid. The default 0051 * implementation returns always true. 0052 */ 0053 virtual bool isValid() const; 0054 0055 /** 0056 Returns the last error, which is set in isValid() on error, 0057 and cleared on success. 0058 */ 0059 [[nodiscard]] QString lastErrorString() const; 0060 0061 /** 0062 * Sets focus on the invalid field. 0063 */ 0064 virtual void focusInvalidField(); 0065 0066 /** 0067 * Returns the type of the Incidence that is currently loaded. 0068 */ 0069 [[nodiscard]] KCalendarCore::IncidenceBase::IncidenceType type() const; 0070 0071 /** Convenience method to get a pointer for a specific const Incidence Type. */ 0072 template<typename IncidenceT> 0073 QSharedPointer<IncidenceT> incidence() const 0074 { 0075 return mLoadedIncidence.dynamicCast<IncidenceT>(); 0076 } 0077 0078 /** 0079 Re-implement this and print important member values and widget 0080 enabled/disabled states that could have lead to isDirty() returning 0081 true when the user didn't do any interaction with the editor. 0082 0083 This method is called in CombinedIncidenceEditor before crashing 0084 due to assert( !editor->isDirty() ) 0085 */ 0086 virtual void printDebugInfo() const; 0087 0088 Q_SIGNALS: 0089 /** 0090 * Signals whether the dirty status of this editor has changed. The new dirty 0091 * status is passed as argument. 0092 */ 0093 void dirtyStatusChanged(bool isDirty); 0094 0095 public Q_SLOTS: 0096 /** 0097 * Checks if the dirty status has changed until last check and emits the 0098 * dirtyStatusChanged signal if needed. 0099 */ 0100 void checkDirtyStatus(); 0101 0102 protected: 0103 /** Only subclasses can instantiate IncidenceEditors */ 0104 IncidenceEditor(QObject *parent = nullptr); 0105 0106 template<typename IncidenceT> 0107 QSharedPointer<IncidenceT> incidence(const KCalendarCore::Incidence::Ptr &inc) 0108 { 0109 return inc.dynamicCast<IncidenceT>(); 0110 } 0111 0112 protected: 0113 KCalendarCore::Incidence::Ptr mLoadedIncidence; 0114 mutable QString mLastErrorString; 0115 bool mWasDirty = false; 0116 bool mLoadingIncidence = false; 0117 }; 0118 } // IncidenceEditorNG