Branch data Line data Source code
1 : : /*************************************************************************** 2 : : qgsprojectstorage.h 3 : : -------------------------------------- 4 : : Date : March 2018 5 : : Copyright : (C) 2018 by Martin Dobias 6 : : Email : wonder dot sk at gmail dot com 7 : : *************************************************************************** 8 : : * * 9 : : * This program is free software; you can redistribute it and/or modify * 10 : : * it under the terms of the GNU General Public License as published by * 11 : : * the Free Software Foundation; either version 2 of the License, or * 12 : : * (at your option) any later version. * 13 : : * * 14 : : ***************************************************************************/ 15 : : 16 : : #ifndef QGSPROJECTSTORAGE_H 17 : : #define QGSPROJECTSTORAGE_H 18 : : 19 : : #include "qgis_core.h" 20 : : #include "qgis_sip.h" 21 : : 22 : : #include <QDateTime> 23 : : #include <QString> 24 : : 25 : : class QIODevice; 26 : : class QStringList; 27 : : 28 : : class QgsReadWriteContext; 29 : : 30 : : /** 31 : : * \ingroup core 32 : : * \brief Abstract interface for project storage - to be implemented by various backends 33 : : * and registered in QgsProjectStorageRegistry. 34 : : * 35 : : * \since QGIS 3.2 36 : : */ 37 : 3 : class CORE_EXPORT QgsProjectStorage 38 : : { 39 : : public: 40 : : 41 : : /** 42 : : * \ingroup core 43 : : * \brief Metadata associated with a project 44 : : * \since QGIS 3.2 45 : : */ 46 : 0 : class Metadata 47 : : { 48 : : public: 49 : : //! Name of the project - equivalent to a file's base name (i.e. without path and extension). 50 : : QString name; 51 : : //! Date and local time when the file was last modified. 52 : : QDateTime lastModified; 53 : : }; 54 : : 55 : 3 : virtual ~QgsProjectStorage() = default; 56 : : 57 : : /** 58 : : * Unique identifier of the project storage type. If type() returns "memory", all project file names 59 : : * starting with "memory:" will have read/write redirected through that storage implementation. 60 : : */ 61 : : virtual QString type() = 0; 62 : : 63 : : //! Returns list of all projects for given URI (specific to each storage backend) 64 : : virtual QStringList listProjects( const QString &uri ) = 0; 65 : : 66 : : /** 67 : : * Reads project file content stored in the backend at the specified URI to the given device 68 : : * (could be e.g. a temporary file or a memory buffer). The device is expected to be empty 69 : : * when passed to readProject() so that the method can write all data to it and then rewind 70 : : * it using seek(0) to make it ready for reading in QgsProject. 71 : : */ 72 : : virtual bool readProject( const QString &uri, QIODevice *device, QgsReadWriteContext &context ) = 0; 73 : : 74 : : /** 75 : : * Writes project file content stored in given device (could be e.g. a temporary file or a memory buffer) 76 : : * using the backend to the specified URI. The device is expected to contain all project file data 77 : : * and having position at the start of the content when passed to writeProject() so that the method 78 : : * can read all data from it until it reaches its end. 79 : : */ 80 : : virtual bool writeProject( const QString &uri, QIODevice *device, QgsReadWriteContext &context ) = 0; 81 : : 82 : : /** 83 : : * Removes an existing project at the given URI. Returns TRUE if the removal 84 : : * was successful. 85 : : */ 86 : : virtual bool removeProject( const QString &uri ) = 0; 87 : : 88 : : /** 89 : : * Rename an existing project at the given URI to a different URI. Returns TRUE if renaming 90 : : * was successful. 91 : : */ 92 : 0 : virtual bool renameProject( const QString &uri, const QString &uriNew ) { Q_UNUSED( uri ) Q_UNUSED( uriNew ); return false; } 93 : : 94 : : /** 95 : : * Reads project metadata (e.g. last modified time) if this is supported by the storage implementation. 96 : : * Returns TRUE if the metadata were read with success. 97 : : */ 98 : 0 : virtual bool readProjectStorageMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata SIP_OUT ) { Q_UNUSED( uri ) Q_UNUSED( metadata ); return false; } 99 : : 100 : : /** 101 : : * Extracts and returns the file path from a storage backend \a uri, filesystem-based storage 102 : : * backends should implement this method in order to support relative paths storage. 103 : : * The default implementation returns an empty string. 104 : : * \since QGIS 3.8.1 105 : : */ 106 : : virtual QString filePath( const QString &uri ); 107 : : 108 : : /** 109 : : * Returns human-readable name of the storage. Used as the menu item text in QGIS. Empty name 110 : : * indicates that the storage does not implement GUI support (showLoadGui() and showSaveGui()). 111 : : * The name may be translatable and ideally unique as well. 112 : : * \deprecated since QGIS 3.10 - use QgsProjectStorageGuiProvider for GUI-related project storage functionality 113 : : */ 114 : 0 : Q_DECL_DEPRECATED virtual QString visibleName() SIP_DEPRECATED { return QString(); } 115 : : 116 : : /** 117 : : * Opens GUI to allow user to select a project to be loaded (GUI specific to this storage type). 118 : : * Returns project URI if user has picked a project or empty string if the GUI was canceled. 119 : : * \deprecated since QGIS 3.10 - use QgsProjectStorageGuiProvider for GUI-related project storage functionality 120 : : */ 121 : 0 : Q_DECL_DEPRECATED virtual QString showLoadGui() SIP_DEPRECATED { return QString(); } 122 : : 123 : : /** 124 : : * Opens GUI to allow user to select where a project should be saved (GUI specific to this storage type). 125 : : * Returns project URI if user has picked a destination or empty string if the GUI was canceled. 126 : : * \deprecated since QGIS 3.10 - use QgsProjectStorageGuiProvider for GUI-related project storage functionality 127 : : */ 128 : 0 : Q_DECL_DEPRECATED virtual QString showSaveGui() SIP_DEPRECATED { return QString(); } 129 : : 130 : : }; 131 : : 132 : : #endif // QGSPROJECTSTORAGE_H