Navigation Menu

Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed May 19, 2020
1 parent 8f9fbba commit 74c2ccc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
13 changes: 11 additions & 2 deletions python/core/auto_generated/qgsbasemappathregistry.sip.in
Expand Up @@ -17,6 +17,12 @@ class QgsBasemapPathRegistry
A registry class to hold paths of basemaps
Paths are meant to be absolute paths and are stored by order of preference.

If a layer from one of the paths is loaded, it will be saved as basemap in the project file.
For instance, if you have C:\my_maps in your basemap paths,
C:\my_maps\my_country\ortho.tif will be save in your project as basemap:my_country\ortho.tif

The resolving of the file paths happens in QgsPathResolver.

.. versionadded:: 3.14
%End

Expand All @@ -35,7 +41,7 @@ Returns the full path if the file has been found in one of the paths, an empty s

QString relativePath( const QString &fullPath ) const;
%Docstring
Returns the relative path if the file has been found in one of the path, an emptry string otherwise
Returns the relative path if the file has been found in one of the path, an empty string otherwise
%End

QStringList paths() const;
Expand All @@ -47,14 +53,17 @@ Returns a list of registered basemap paths
void registerPath( const QString &path, int position = -1 );
%Docstring
Registers a basemap path
If ``place`` is given, the path is inserted at the given position in the list
If ``position`` is given, the path is inserted at the given position in the list
Since the paths are stored by order of preference, lower positions in the list take precedence.
%End

void unregisterPath( const QString &path );
%Docstring
Unregisters a basemap path
%End

private:
QgsBasemapPathRegistry( const QgsBasemapPathRegistry &other );
};

/************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsoptions.cpp
Expand Up @@ -2559,8 +2559,8 @@ void QgsOptions::addBasemapPath()
{
QString myDir = QFileDialog::getExistingDirectory(
this,
tr( "Choose a directory" ),
QDir::toNativeSeparators( QDir::homePath() ),
tr( "Choose a Directory" ),
QDir::homePath(),
QFileDialog::ShowDirsOnly
);

Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -2245,6 +2245,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
{
// don't use initializer lists or scoped pointers - as more objects are added here we
// will need to be careful with the order of creation/destruction
mBasemapPathRegistry = new QgsBasemapPathRegistry();
mMessageLog = new QgsMessageLog();
mProfiler = new QgsRuntimeProfiler();

Expand Down Expand Up @@ -2329,6 +2330,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
mProfiler->end();
}
mPageSizeRegistry = new QgsPageSizeRegistry();
<<<<<<< HEAD
{
mProfiler->start( tr( "Setup layout item registry" ) );
mLayoutItemRegistry = new QgsLayoutItemRegistry();
Expand Down Expand Up @@ -2376,6 +2378,18 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
mProfiler->end();
}
mBasemapPathRegistry = new QgsBasemapPathRegistry();
=======
mLayoutItemRegistry = new QgsLayoutItemRegistry();
mLayoutItemRegistry->populate();
mAnnotationRegistry = new QgsAnnotationRegistry();
m3DRendererRegistry = new Qgs3DRendererRegistry();
mProjectStorageRegistry = new QgsProjectStorageRegistry();
mNetworkContentFetcherRegistry = new QgsNetworkContentFetcherRegistry();
mValidityCheckRegistry = new QgsValidityCheckRegistry();
mClassificationMethodRegistry = new QgsClassificationMethodRegistry();
mBookmarkManager = new QgsBookmarkManager( nullptr );
mScaleBarRendererRegistry = new QgsScaleBarRendererRegistry();
>>>>>>> address review
}

QgsApplication::ApplicationMembers::~ApplicationMembers()
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsbasemappathregistry.cpp
Expand Up @@ -18,6 +18,8 @@
#include "qgsbasemappathregistry.h"
#include "qgssettings.h"
#include "qgis.h"
#include "qgsreadwritelocker.h"


QgsBasemapPathRegistry::QgsBasemapPathRegistry()
{
Expand All @@ -26,6 +28,8 @@ QgsBasemapPathRegistry::QgsBasemapPathRegistry()

QString QgsBasemapPathRegistry::fullPath( const QString &relativePath ) const
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );

for ( const QDir &basePath : qgis::as_const( mPaths ) )
if ( basePath.exists( relativePath ) )
return basePath.absoluteFilePath( relativePath );
Expand All @@ -35,6 +39,8 @@ QString QgsBasemapPathRegistry::fullPath( const QString &relativePath ) const

QString QgsBasemapPathRegistry::relativePath( const QString &fullPath ) const
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );

for ( const QDir &basePath : qgis::as_const( mPaths ) )
if ( fullPath.startsWith( basePath.absolutePath() ) )
return basePath.relativeFilePath( fullPath );
Expand All @@ -45,6 +51,8 @@ QString QgsBasemapPathRegistry::relativePath( const QString &fullPath ) const

QStringList QgsBasemapPathRegistry::paths() const
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Read );

QStringList paths;
for ( const QDir &dir : mPaths )
paths << dir.absolutePath();
Expand All @@ -53,6 +61,8 @@ QStringList QgsBasemapPathRegistry::paths() const

void QgsBasemapPathRegistry::setPaths( const QStringList &paths )
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );

mPaths.clear();
for ( const QString &path : paths )
{
Expand All @@ -70,6 +80,8 @@ void QgsBasemapPathRegistry::registerPath( const QString &path, int position )
if ( mPaths.contains( dir ) )
return;

QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );

if ( position >= 0 && position < mPaths.count() )
mPaths.insert( position, dir );
else
Expand All @@ -80,6 +92,8 @@ void QgsBasemapPathRegistry::registerPath( const QString &path, int position )

void QgsBasemapPathRegistry::unregisterPath( const QString &path )
{
QgsReadWriteLocker locker( mLock, QgsReadWriteLocker::Write );

mPaths.removeAll( QDir( path ) );
writeToSettings();
}
Expand Down
18 changes: 16 additions & 2 deletions src/core/qgsbasemappathregistry.h
Expand Up @@ -20,6 +20,7 @@

#include <QDir>
#include <QList>
#include <QReadWriteLock>

#include "qgis_core.h"
#include "qgis_sip.h"
Expand All @@ -29,6 +30,12 @@
* A registry class to hold paths of basemaps
* Paths are meant to be absolute paths and are stored by order of preference.
*
* If a layer from one of the paths is loaded, it will be saved as basemap in the project file.
* For instance, if you have C:\my_maps in your basemap paths,
* C:\my_maps\my_country\ortho.tif will be save in your project as basemap:my_country\ortho.tif
*
* The resolving of the file paths happens in QgsPathResolver.
*
* \since QGIS 3.14
*/
class CORE_EXPORT QgsBasemapPathRegistry
Expand All @@ -41,7 +48,7 @@ class CORE_EXPORT QgsBasemapPathRegistry
//! Returns the full path if the file has been found in one of the paths, an empty string otherwise
QString fullPath( const QString &relativePath ) const;

//! Returns the relative path if the file has been found in one of the path, an emptry string otherwise
//! Returns the relative path if the file has been found in one of the path, an empty string otherwise
QString relativePath( const QString &fullPath ) const;

//! Returns a list of registered basemap paths
Expand All @@ -52,18 +59,25 @@ class CORE_EXPORT QgsBasemapPathRegistry

/**
* Registers a basemap path
* If \a place is given, the path is inserted at the given position in the list
* If \a position is given, the path is inserted at the given position in the list
* Since the paths are stored by order of preference, lower positions in the list take precedence.
*/
void registerPath( const QString &path, int position = -1 );

//! Unregisters a basemap path
void unregisterPath( const QString &path );

private:
#ifdef SIP_RUN
QgsBasemapPathRegistry( const QgsBasemapPathRegistry &other )
{}
#endif

void readFromSettings();
void writeToSettings();

QList<QDir> mPaths;
mutable QReadWriteLock mLock;
};

#endif // QGSBASEMAPPATHREGISTRY_H

0 comments on commit 74c2ccc

Please sign in to comment.