Skip to content
Permalink
Browse files

introduce QgsBasemapPathRegistry to hold a list of paths where basema…

…ps can be located
  • Loading branch information
3nids committed May 14, 2020
1 parent 8499e09 commit b1920bb2879179268bd688737f7ca7004b57c64b
@@ -0,0 +1,66 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsbasemappathregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsBasemapPathRegistry
{
%Docstring
A registry class to hold paths of basemaps
Paths are meant to be absolute paths and are stored by order of preference.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsbasemappathregistry.h"
%End
public:
QgsBasemapPathRegistry();

~QgsBasemapPathRegistry();

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

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
%End

QStringList paths() const;
%Docstring
Returns a list of registered basemap paths
%End


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
%End

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

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsbasemappathregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -15,6 +15,7 @@
%Include auto_generated/qgsattributes.sip
%Include auto_generated/qgsattributetableconfig.sip
%Include auto_generated/qgsauxiliarystorage.sip
%Include auto_generated/qgsbasemappathregistry.sip
%Include auto_generated/qgsbearingutils.sip
%Include auto_generated/qgsblockingnetworkrequest.sip
%Include auto_generated/qgsbookmarkmanager.sip
@@ -224,6 +224,7 @@ SET(QGIS_CORE_SRCS
qgsattributetableconfig.cpp
qgsattributeeditorelement.cpp
qgsauxiliarystorage.cpp
qgsbasemappathregistry.cpp
qgsbearingutils.cpp
qgsblockingnetworkrequest.cpp
qgsbookmarkmanager.cpp
@@ -761,6 +762,7 @@ SET(QGIS_CORE_HDRS
qgsattributes.h
qgsattributetableconfig.h
qgsauxiliarystorage.h
qgsbasemappathregistry.h
qgsbearingutils.h
qgsblockingnetworkrequest.h
qgsbookmarkmanager.h
@@ -0,0 +1,80 @@
/***************************************************************************
qgsbasemappathregistry.cpp
--------------------------------------
Date : May 2020
Copyright : (C) 2020 by Denis Rouzaud
Email : denis.rouzaud
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <QDir>

#include "qgsbasemappathregistry.h"

#include "qgis.h"

QgsBasemapPathRegistry::QgsBasemapPathRegistry()
{

}

QString QgsBasemapPathRegistry::fullPath( const QString &relativePath ) const
{
for ( const QDir &basePath : qgis::as_const( mPaths ) )
if ( basePath.exists( relativePath ) )
return basePath.absoluteFilePath( relativePath );

return QString();
}

QString QgsBasemapPathRegistry::relativePath( const QString &fullPath ) const
{
for ( const QDir &basePath : qgis::as_const( mPaths ) )
if ( fullPath.startsWith( basePath.absolutePath() ) )
return basePath.relativeFilePath( fullPath );

return QString();

}

QStringList QgsBasemapPathRegistry::paths() const
{
QStringList paths;
for ( const QDir &dir : mPaths )
paths << dir.absolutePath();
return paths;
}

void QgsBasemapPathRegistry::setPaths( const QStringList &paths )
{
mPaths.clear();
for ( const QString &path : paths )
{
QDir dir( path );
if ( !mPaths.contains( dir ) )
mPaths << dir;
}
}

void QgsBasemapPathRegistry::registerPath( const QString &path, int position )
{
QDir dir( path );
if ( mPaths.contains( dir ) )
return;

if ( position > 0 && position < mPaths.count() )
mPaths.insert( position, dir );
else
mPaths.append( dir );
}

void QgsBasemapPathRegistry::unregisterPath( const QString &path )
{
mPaths.removeAll( QDir( path ) );
}
@@ -0,0 +1,65 @@
/***************************************************************************
qgsbasemappathregistry.h
--------------------------------------
Date : May 2020
Copyright : (C) 2020 by Denis Rouzaud
Email : denis.rouzaud
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/


#ifndef QGSBASEMAPPATHREGISTRY_H
#define QGSBASEMAPPATHREGISTRY_H


#include <QDir>
#include <QList>

#include "qgis_core.h"
#include "qgis_sip.h"

/**
* A registry class to hold paths of basemaps
* Paths are meant to be absolute paths and are stored by order of preference.
*
* \since QGIS 3.14
*/
class CORE_EXPORT QgsBasemapPathRegistry
{
public:
QgsBasemapPathRegistry();

~QgsBasemapPathRegistry() = default;

//! 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
QString relativePath( const QString &fullPath ) const;

//! Returns a list of registered basemap paths
QStringList paths() const;

//! Sets the complete list of basemap path
void setPaths( const QStringList &paths ) SIP_SKIP;

/**
* Registers a basemap path
* If \a place is given, the path is inserted at the given position in the list
*/
void registerPath( const QString &path, int position = -1 );

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

private:
QList<QDir> mPaths;
};

#endif // QGSBASEMAPPATHREGISTRY_H

0 comments on commit b1920bb

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