ACF $AcfVersion:0$
IDocumentMetaInfo.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// STL includes
6#include <optional>
7
8// Qt includes
9#include <QtCore/QDebug>
10#include <QtCore/QVariant>
11
12// ACF includes
13#include <istd/TInterfacePtr.h>
14#include <istd/IChangeable.h>
15
16
17namespace idoc
18{
19
20
70{
71public:
72
77 {
81 CF_METAINFO = 0xd83067d
82 };
83
139
140 typedef QSet<int> MetaInfoTypes;
141
147 virtual MetaInfoTypes GetMetaInfoTypes(bool allowReadOnly = true) const = 0;
148
152 virtual QVariant GetMetaInfo(int metaInfoType) const = 0;
153
157 virtual bool SetMetaInfo(int metaInfoType, const QVariant& metaInfo) = 0;
158
162 virtual void RemoveMetaInfo(int metaInfoType) = 0;
163
167 virtual QByteArray GetMetaInfoId(int metaInfoType) const = 0;
168
172 virtual QString GetMetaInfoName(int metaInfoType) const = 0;
173
177 virtual QString GetMetaInfoDescription(int metaInfoType) const = 0;
178
182 virtual bool IsMetaInfoWritable(int metaInfoType) const = 0;
183
214 template<class T>
215 static std::optional<T> GetMetaInfoT(const idoc::IDocumentMetaInfo& metaInfo, int key);
216};
217
218
220
221// inline methods
222template<class T>
223inline std::optional<T> IDocumentMetaInfo::GetMetaInfoT(const idoc::IDocumentMetaInfo& metaInfo, int key)
224{
225 QVariant metaData = metaInfo.GetMetaInfo(key);
226 if (!metaData.isValid()) {
227 return {};
228 }
229
230 const int metaTypeId =
231#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
232 metaData.typeId();
233#else
234 metaData.userType();
235#endif
236
237 if (metaTypeId != qMetaTypeId<T>()) {
238 I_IF_DEBUG(qWarning() << __FILE__ << __LINE__ << "Type mismatch for meta info key:" << key;)
239
240 return {};
241 }
242
243 return metaData.value<T>();
244}
245
246} // namespace idoc
247
248
Interface for document meta-information.
static std::optional< T > GetMetaInfoT(const idoc::IDocumentMetaInfo &metaInfo, int key)
Type-safe retrieval of metadata values.
virtual QByteArray GetMetaInfoId(int metaInfoType) const =0
Get an unique ID of the meta information.
virtual QString GetMetaInfoName(int metaInfoType) const =0
Get a human readable name for a given meta information type.
virtual QString GetMetaInfoDescription(int metaInfoType) const =0
Get a human readable description for a given meta information type.
MetaInfoType
Type of the meta information.
@ MIT_DOCUMENT_VERSION
Version of the document given as a QString.
@ MIT_DESCRIPTION
Document description.
@ MIT_TITLE
Title of the document.
@ MIT_CREATOR_VERSION
Version of the creation tool given as a QString.
@ MIT_CREATOR
Tool used for document creation.
@ MIT_MODIFICATION_TIME
Last document modification time.
@ MIT_CONTENT_CHECKSUM
Checksum of the document data.
@ MIT_AUTHOR
Person, who has created the document.
@ MIT_CREATION_TIME
Document creation time.
@ MIT_USER
Starting of user defined meta info types.
virtual bool IsMetaInfoWritable(int metaInfoType) const =0
Check if meta information can be changed.
virtual void RemoveMetaInfo(int metaInfoType)=0
Remove document's meta information for a given meta type.
virtual bool SetMetaInfo(int metaInfoType, const QVariant &metaInfo)=0
Set new document's meta information for a given meta type.
virtual QVariant GetMetaInfo(int metaInfoType) const =0
Get document's meta info.
virtual MetaInfoTypes GetMetaInfoTypes(bool allowReadOnly=true) const =0
Get list of contained meta info types.
ChangeFlags
Data model change notification flags.
@ CF_METAINFO
Meta information has been changed.
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
Shared ownership smart pointer for interface types.
#define I_IF_DEBUG(instructions)
Definition istd.h:59
Contains the system independent basic implementations of Document/View design pattern.
istd::TSharedInterfacePtr< IDocumentMetaInfo > MetaInfoPtr