Skip to content
Permalink
Browse files

Fixes after Nyall's review + doxygen fixes

  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent 3ccb6c3 commit 2aabad96e76bc810a87234f17c231c41180d8b3b
@@ -29,6 +29,8 @@ and registered in QgsProjectStorageRegistry.
{
%Docstring
Metadata associated with a project

.. versionadded:: 3.2
%End

%TypeHeaderCode
@@ -70,7 +72,7 @@ can read all data from it until it reaches its end.

virtual bool removeProject( const QString &uri ) = 0;
%Docstring
Removes and existing project at the given URI. Returns true if the removal
Removes an existing project at the given URI. Returns true if the removal
was successful.
%End

@@ -80,7 +82,7 @@ Rename an existing project at the given URI to a different URI. Returns true if
was successful.
%End

virtual bool readProjectMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata /Out/ );
virtual bool readProjectStorageMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata /Out/ );
%Docstring
Reads project metadata (e.g. last modified time) if this is supported by the storage implementation.
Returns true if the metadata were read with success.
@@ -13563,7 +13563,8 @@ QgsFeature QgisApp::duplicateFeatureDigitized( QgsMapLayer *mlayer, const QgsFea
void QgisApp::populateProjectStorageMenu( QMenu *menu, bool saving )
{
menu->clear();
for ( QgsProjectStorage *storage : QgsApplication::projectStorageRegistry()->projectStorages() )
const QList<QgsProjectStorage *> storages = QgsApplication::projectStorageRegistry()->projectStorages();
for ( QgsProjectStorage *storage : storages )
{
QString name = storage->visibleName();
if ( name.isEmpty() )
@@ -468,7 +468,7 @@ QDateTime QgsProject::lastModified() const
if ( storage )
{
QgsProjectStorage::Metadata metadata;
storage->readProjectMetadata( mFile.fileName(), metadata );
storage->readProjectStorageMetadata( mFile.fileName(), metadata );
return metadata.lastModified;
}
else
@@ -492,7 +492,7 @@ QString QgsProject::baseName() const
if ( storage )
{
QgsProjectStorage::Metadata metadata;
storage->readProjectMetadata( mFile.fileName(), metadata );
storage->readProjectStorageMetadata( mFile.fileName(), metadata );
return metadata.name;
}
else
@@ -14,8 +14,3 @@
***************************************************************************/

#include "qgsprojectstorage.h"


QgsProjectStorage::~QgsProjectStorage()
{
}
@@ -28,6 +28,7 @@ class QStringList;
class QgsReadWriteContext;

/**
* \ingroup core
* Abstract interface for project storage - to be implemented by various backends
* and registered in QgsProjectStorageRegistry.
*
@@ -37,7 +38,11 @@ class CORE_EXPORT QgsProjectStorage
{
public:

//! Metadata associated with a project
/**
* \ingroup core
* Metadata associated with a project
* \since QGIS 3.2
*/
class Metadata
{
public:
@@ -47,7 +52,7 @@ class CORE_EXPORT QgsProjectStorage
QDateTime lastModified;
};

virtual ~QgsProjectStorage();
virtual ~QgsProjectStorage() = default;

/**
* Unique identifier of the project storage type. If type() returns "memory", all project file names
@@ -75,7 +80,7 @@ class CORE_EXPORT QgsProjectStorage
virtual bool writeProject( const QString &uri, QIODevice *device, QgsReadWriteContext &context ) = 0;

/**
* Removes and existing project at the given URI. Returns true if the removal
* Removes an existing project at the given URI. Returns true if the removal
* was successful.
*/
virtual bool removeProject( const QString &uri ) = 0;
@@ -90,7 +95,7 @@ class CORE_EXPORT QgsProjectStorage
* Reads project metadata (e.g. last modified time) if this is supported by the storage implementation.
* Returns true if the metadata were read with success.
*/
virtual bool readProjectMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata SIP_OUT ) { Q_UNUSED( uri ); Q_UNUSED( metadata ); return false; }
virtual bool readProjectStorageMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata SIP_OUT ) { Q_UNUSED( uri ); Q_UNUSED( metadata ); return false; }

/**
* Returns human-readable name of the storage. Used as the menu item text in QGIS. Empty name
@@ -17,10 +17,6 @@

#include "qgsprojectstorage.h"

QgsProjectStorageRegistry::QgsProjectStorageRegistry()
{

}

QgsProjectStorageRegistry::~QgsProjectStorageRegistry()
{
@@ -37,7 +33,7 @@ QgsProjectStorage *QgsProjectStorageRegistry::projectStorageFromUri( const QStri
for ( auto it = mBackends.constBegin(); it != mBackends.constEnd(); ++it )
{
QgsProjectStorage *storage = it.value();
QString scheme = storage->type() + ":";
QString scheme = storage->type() + ':';
if ( uri.startsWith( scheme ) )
return storage;
}
@@ -24,6 +24,7 @@
class QgsProjectStorage;

/**
* \ingroup core
* Registry of storage backends that QgsProject may use.
* This is a singleton that should be accessed through QgsApplication::projectStorageRegistry().
*
@@ -32,7 +33,7 @@ class QgsProjectStorage;
class CORE_EXPORT QgsProjectStorageRegistry
{
public:
QgsProjectStorageRegistry();
QgsProjectStorageRegistry() = default;
~QgsProjectStorageRegistry();

//! Returns storage implementation if the storage type matches one. Returns null pointer otherwise (it is a normal file)
@@ -43,11 +43,6 @@ static bool _projectsTableExists( QgsPostgresConn &conn, const QString &schemaNa
}


QgsPostgresProjectStorage::QgsPostgresProjectStorage()
{
}


QStringList QgsPostgresProjectStorage::listProjects( const QString &uri )
{
QStringList lst;
@@ -193,7 +188,7 @@ bool QgsPostgresProjectStorage::removeProject( const QString &uri )
}


bool QgsPostgresProjectStorage::readProjectMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata )
bool QgsPostgresProjectStorage::readProjectStorageMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata )
{
QgsPostgresProjectUri projectUri = decodeUri( uri );
if ( !projectUri.valid )
@@ -23,7 +23,7 @@ typedef struct
class QgsPostgresProjectStorage : public QgsProjectStorage
{
public:
QgsPostgresProjectStorage();
QgsPostgresProjectStorage() = default;

virtual QString type() override { return QStringLiteral( "postgresql" ); }

@@ -35,7 +35,7 @@ class QgsPostgresProjectStorage : public QgsProjectStorage

virtual bool removeProject( const QString &uri ) override;

virtual bool readProjectMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata ) override;
virtual bool readProjectStorageMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata ) override;

#ifdef HAVE_GUI
// GUI support
@@ -29,7 +29,7 @@ class QgsPostgresProjectStorageDialog : public QDialog, private Ui::QgsPostgresP

private:

bool mSaving; //!< Whether using this dialog for loading or saving a project
bool mSaving = false; //!< Whether using this dialog for loading or saving a project
QAction *mActionRemoveProject = nullptr;
};

@@ -39,17 +39,17 @@
</widget>
<widget class="QMenu" name="mProjectFromTemplateMenu">
<property name="title">
<string>New From Template</string>
<string>New from Template</string>
</property>
</widget>
<widget class="QMenu" name="mProjectToStorageMenu">
<property name="title">
<string>Save To</string>
<string>Save to</string>
</property>
</widget>
<widget class="QMenu" name="mProjectFromStorageMenu">
<property name="title">
<string>Open From</string>
<string>Open from</string>
</property>
</widget>
<addaction name="mActionNewProject"/>
@@ -128,7 +128,7 @@ class MemoryStorage : public QgsProjectStorage
return true;
}

virtual bool readProjectMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata ) override
virtual bool readProjectStorageMetadata( const QString &uri, QgsProjectStorage::Metadata &metadata ) override
{
QStringList lst = uri.split( ":" );
Q_ASSERT( lst.count() == 2 );
@@ -194,13 +194,13 @@ void TestQgsProjectStorage::testMemoryStorage()
// test metadata access

QgsProjectStorage::Metadata meta1;
bool readMetaOk = memStorage->readProjectMetadata( "memory:project1", meta1 );
bool readMetaOk = memStorage->readProjectStorageMetadata( "memory:project1", meta1 );
QVERIFY( readMetaOk );
QCOMPARE( meta1.name, QString( "project1" ) );
QVERIFY( meta1.lastModified.secsTo( QDateTime::currentDateTime() ) < 1 );

QgsProjectStorage::Metadata metaX;
bool readMetaInvalidOk = memStorage->readProjectMetadata( "memory:projectXYZ", metaX );
bool readMetaInvalidOk = memStorage->readProjectStorageMetadata( "memory:projectXYZ", metaX );
QVERIFY( !readMetaInvalidOk );

// test removal
@@ -140,7 +140,7 @@ def testSaveLoadProject(self):

# try to see project's metadata

res, metadata = prj_storage.readProjectMetadata(project_uri)
res, metadata = prj_storage.readProjectStorageMetadata(project_uri)
self.assertTrue(res)
self.assertEqual(metadata.name, "abc")
time_project = metadata.lastModified

0 comments on commit 2aabad9

Please sign in to comment.
You can’t perform that action at this time.