address review

This commit is contained in:
Denis Rouzaud 2020-05-14 22:24:33 +02:00
parent 8f9fbba391
commit 74c2ccc319
5 changed files with 57 additions and 6 deletions

View File

@ -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
@ -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;
@ -47,7 +53,8 @@ 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 );
@ -55,6 +62,8 @@ If ``place`` is given, the path is inserted at the given position in the list
Unregisters a basemap path
%End
private:
QgsBasemapPathRegistry( const QgsBasemapPathRegistry &other );
};
/************************************************************************

View File

@ -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
);

View File

@ -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();
@ -2329,6 +2330,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
mProfiler->end();
}
mPageSizeRegistry = new QgsPageSizeRegistry();
<<<<<<< HEAD
{
mProfiler->start( tr( "Setup layout item registry" ) );
mLayoutItemRegistry = new QgsLayoutItemRegistry();
@ -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()

View File

@ -18,6 +18,8 @@
#include "qgsbasemappathregistry.h"
#include "qgssettings.h"
#include "qgis.h"
#include "qgsreadwritelocker.h"
QgsBasemapPathRegistry::QgsBasemapPathRegistry()
{
@ -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 );
@ -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 );
@ -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();
@ -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 )
{
@ -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
@ -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();
}

View File

@ -20,6 +20,7 @@
#include <QDir>
#include <QList>
#include <QReadWriteLock>
#include "qgis_core.h"
#include "qgis_sip.h"
@ -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
@ -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
@ -52,7 +59,8 @@ 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 );
@ -60,10 +68,16 @@ class CORE_EXPORT QgsBasemapPathRegistry
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