QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
qgsabstractmetadatabase.h
Go to the documentation of this file.
1/***************************************************************************
2 QgsAbstractMetadataBase.h
3 -------------------
4 begin : March 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSABSTRACTMETADATABASE_H
19#define QGSABSTRACTMETADATABASE_H
20
21#include "qgis.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgsreadwritecontext.h"
25
26#include <QMap>
27#include <QMetaType>
28#include <QString>
29
30class QDomElement;
31class QDomDocument;
33
60class CORE_EXPORT QgsAbstractMetadataBase
61{
62 Q_GADGET
63
64#ifdef SIP_RUN
66 if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
67 sipType = sipType_QgsLayerMetadata;
68 else if ( dynamic_cast< QgsProjectMetadata * >( sipCpp ) != NULL )
69 sipType = sipType_QgsProjectMetadata;
70 else
71 sipType = NULL;
73#endif
74
75 Q_PROPERTY( QString type READ type )
76 Q_PROPERTY( QString title READ title )
77 Q_PROPERTY( QString abstract READ abstract )
78
79 public:
80 // NOTE - these really belong in a separate namespace, but SIP says no, I want to make you waste more time
81 // TODO: dump sip
82
86 typedef QMap< QString, QStringList > KeywordMap;
87
93 struct CORE_EXPORT Address
94 {
99 const QString &type = QString(),
100 const QString &address = QString(),
101 const QString &city = QString(),
102 const QString &administrativeArea = QString(),
103 const QString &postalCode = QString(),
104 const QString &country = QString()
105 )
106 : type( type )
107 , address( address )
108 , city( city )
111 , country( country )
112 {}
113
117 QString type;
118
122 QString address;
123
127 QString city;
128
133
137 QString postalCode;
138
142 QString country;
143
144 // TODO c++20 - replace with = default
145 bool operator==( const QgsAbstractMetadataBase::Address &other ) const;
146 };
147
153 struct CORE_EXPORT Contact
154 {
158 Contact( const QString &name = QString() )
159 : name( name )
160 {}
161
165 QString name;
166
171
175 QString position;
176
180 QList< QgsAbstractMetadataBase::Address > addresses;
181
185 QString voice;
186
190 QString fax;
191
196 QString email;
197
203 QString role;
204
205 // TODO c++20 - replace with = default
206 bool operator==( const QgsAbstractMetadataBase::Contact &other ) const;
207 };
208
214 typedef QList< QgsAbstractMetadataBase::Contact > ContactList;
215
216
222 struct CORE_EXPORT Link
223 {
227 Link( const QString &name = QString(), const QString &type = QString(), const QString &url = QString() )
228 : name( name )
229 , type( type )
230 , url( url )
231 {}
232
236 QString name;
237
242 QString type;
243
247 QString description;
248
252 QString url;
253
257 QString format;
258
262 QString mimeType;
263
267 QString size;
268
269 // TODO c++20 - replace with = default
270 bool operator==( const QgsAbstractMetadataBase::Link &other ) const;
271 };
272
278 typedef QList< QgsAbstractMetadataBase::Link > LinkList;
279
280 virtual ~QgsAbstractMetadataBase() = default;
281
287
292 QString identifier() const;
293
298 void setIdentifier( const QString &identifier );
299
305 QString parentIdentifier() const;
306
312 void setParentIdentifier( const QString &parentIdentifier );
313
321 QString language() const;
322
329 void setLanguage( const QString &language );
330
336 QString type() const;
337
343 void setType( const QString &type );
344
349 QString title() const;
350
355 void setTitle( const QString &title );
356
361 QString abstract() const;
362
367 void setAbstract( const QString &abstract );
368
373 QStringList history() const;
374
381 void setHistory( const QStringList &history );
382
388 void addHistoryItem( const QString &text );
389
402
416
427 void addKeywords( const QString &vocabulary, const QStringList &keywords );
428
435 bool removeKeywords( const QString &vocabulary );
436
445 QStringList keywordVocabularies() const;
446
457 QStringList keywords( const QString &vocabulary ) const;
458
465 QStringList categories() const;
466
473 void setCategories( const QStringList &categories );
474
480
488
494 void addContact( const QgsAbstractMetadataBase::Contact &contact );
495
501
509
515 void addLink( const QgsAbstractMetadataBase::Link &link );
516
523 QDateTime dateTime( Qgis::MetadataDateType type ) const;
524
531 void setDateTime( Qgis::MetadataDateType type, QDateTime date );
532
544 virtual bool readMetadataXml( const QDomElement &metadataElement, const QgsReadWriteContext &context = QgsReadWriteContext() );
545
558 virtual bool writeMetadataXml( QDomElement &metadataElement, QDomDocument &document, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
559
567 virtual void combine( const QgsAbstractMetadataBase *other );
568
574 virtual void registerTranslations( QgsTranslationContext *translationContext ) const;
575
576 protected:
583
584 /*
585 * IMPORTANT!!!!!!
586 *
587 * Do NOT add anything to this class without also updating the schema
588 * definition located at resources/qgis-resource-metadata.xsd
589 *
590 */
591
592 QString mIdentifier;
594 QString mLanguage;
595 QString mType;
596 QString mTitle;
597 QString mAbstract;
598 QStringList mHistory;
599
600 // IMPORTANT - look up before adding anything here!!
601
606
608
610
612 QMap< Qgis::MetadataDateType, QDateTime > mDates;
613
614 /*
615 * IMPORTANT!!!!!!
616 *
617 * Do NOT add anything to this class without also updating the schema
618 * definition located at resources/qgis-resource-metadata.xsd
619 *
620 */
621
622
631 bool equals( const QgsAbstractMetadataBase &other ) const;
632};
633
637
638#endif // QGSABSTRACTMETADATABASE_H
MetadataDateType
Date types for metadata.
Definition qgis.h:5062
QgsAbstractMetadataBase::ContactList mContacts
void setAbstract(const QString &abstract)
Sets a free-form abstract (description) of the resource.
void setType(const QString &type)
Sets the type (nature) of the resource.
void setParentIdentifier(const QString &parentIdentifier)
Sets a reference, URI, URL or some other mechanism to identify the parent resource that this resource...
QMap< QString, QStringList > KeywordMap
Map of vocabulary string to keyword list.
void addContact(const QgsAbstractMetadataBase::Contact &contact)
Adds an individual contact to the existing contacts.
void setTitle(const QString &title)
Sets the human readable title (name) of the resource, typically displayed in search results.
void setHistory(const QStringList &history)
Sets the freeform description of the history or lineage of the resource.
QgsAbstractMetadataBase::ContactList contacts() const
Returns a list of contact persons or entities associated with the resource.
virtual void combine(const QgsAbstractMetadataBase *other)
Combines the metadata from this object with the metadata from an other object.
void setLinks(const QgsAbstractMetadataBase::LinkList &links)
Sets the list of online resources associated with the resource.
void setIdentifier(const QString &identifier)
Sets the reference, URI, URL or some other mechanism to identify the resource.
QStringList categories() const
Returns categories of the resource.
QMap< Qgis::MetadataDateType, QDateTime > mDates
Metadata dates.
QStringList keywordVocabularies() const
Returns a list of keyword vocabularies contained in the metadata.
virtual bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Stores state in a DOM node.
void setContacts(const QgsAbstractMetadataBase::ContactList &contacts)
Sets the list of contacts or entities associated with the resource.
void setKeywords(const QgsAbstractMetadataBase::KeywordMap &keywords)
Sets the keywords map, which is a set of descriptive keywords associated with the resource.
QStringList history() const
Returns a freeform description of the history or lineage of the resource.
void setDateTime(Qgis::MetadataDateType type, QDateTime date)
Sets a date value for the specified date type.
QDateTime dateTime(Qgis::MetadataDateType type) const
Returns the date for the specified date type.
QgsAbstractMetadataBase::KeywordMap mKeywords
Keywords map.
QgsAbstractMetadataBase::KeywordMap keywords() const
Returns the keywords map, which is a set of descriptive keywords associated with the resource.
bool equals(const QgsAbstractMetadataBase &other) const
Tests whether the common metadata fields in this object are equal to other.
QgsAbstractMetadataBase::LinkList links() const
Returns a list of online resources associated with the resource.
void setLanguage(const QString &language)
Sets the human language associated with the resource.
virtual void registerTranslations(QgsTranslationContext *translationContext) const
Registers metadata translation strings.
virtual ~QgsAbstractMetadataBase()=default
QString parentIdentifier() const
A reference, URI, URL or some other mechanism to identify the parent resource that this resource is a...
QString language() const
Returns the human language associated with the resource.
void addKeywords(const QString &vocabulary, const QStringList &keywords)
Adds a list of descriptive keywords for a specified vocabulary.
void addLink(const QgsAbstractMetadataBase::Link &link)
Adds an individual link to the existing links.
bool removeKeywords(const QString &vocabulary)
Remove a vocabulary from the list.
QgsAbstractMetadataBase::LinkList mLinks
QString identifier() const
A reference, URI, URL or some other mechanism to identify the resource.
QgsAbstractMetadataBase()=default
Constructor for QgsAbstractMetadataBase.
virtual QgsAbstractMetadataBase * clone() const =0
Clones the metadata object.
void setCategories(const QStringList &categories)
Sets categories of the resource.
virtual bool readMetadataXml(const QDomElement &metadataElement, const QgsReadWriteContext &context=QgsReadWriteContext())
Sets state from DOM document.
void addHistoryItem(const QString &text)
Adds a single history text to the end of the existing history list.
A structured metadata store for a map layer.
A structured metadata store for a project.
A container for the context for various read/write operations on objects.
Used for the collecting of strings from projects for translation and creation of ts files.
QList< QgsAbstractMetadataBase::Link > LinkList
A list of links.
QList< QgsAbstractMetadataBase::Contact > ContactList
A list of contacts.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QString administrativeArea
Administrative area (state, province/territory, etc.).
QString address
Free-form physical address component, e.g.
QString city
City or locality name.
QString country
Free-form country string.
QString postalCode
Postal (or ZIP) code.
Address(const QString &type=QString(), const QString &address=QString(), const QString &city=QString(), const QString &administrativeArea=QString(), const QString &postalCode=QString(), const QString &country=QString())
Constructor for Address.
QString position
Position/title of contact.
QList< QgsAbstractMetadataBase::Address > addresses
List of addresses associated with this contact.
QString email
Electronic mail address.
QString organization
Organization contact belongs to/represents.
Contact(const QString &name=QString())
Constructor for Contact.