-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1589 from opengisch/layerResolver
Add layer resolver
- Loading branch information
Showing
5 changed files
with
248 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/*************************************************************************** | ||
layerresolver.cpp | ||
------------------- | ||
begin : January 2021 | ||
copyright : (C) 2011 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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 "layerresolver.h" | ||
#include <qgsvectorlayerref.h> | ||
|
||
LayerResolver::LayerResolver( QObject *parent ) | ||
: QObject( parent ) | ||
{ | ||
|
||
} | ||
|
||
void LayerResolver::resolve() | ||
{ | ||
if ( !mProject ) | ||
{ | ||
setLayer( nullptr ); | ||
return; | ||
} | ||
|
||
QgsVectorLayerRef ref { mLayerId, | ||
mLayerName, | ||
mLayerSource, | ||
mLayerProviderName }; | ||
setLayer( ref.resolveByIdOrNameOnly( mProject ) ); | ||
} | ||
|
||
QString LayerResolver::layerId() const | ||
{ | ||
return mLayerId; | ||
} | ||
|
||
void LayerResolver::setLayerId( const QString &layerId ) | ||
{ | ||
if ( mLayerId == layerId ) | ||
return; | ||
|
||
mLayerId = layerId; | ||
resolve(); | ||
emit layerIdChanged(); | ||
} | ||
|
||
QString LayerResolver::layerName() const | ||
{ | ||
return mLayerName; | ||
} | ||
|
||
void LayerResolver::setLayerName( const QString &layerName ) | ||
{ | ||
if ( mLayerName == layerName ) | ||
return; | ||
|
||
mLayerName = layerName; | ||
resolve(); | ||
emit layerNameChanged(); | ||
} | ||
|
||
QString LayerResolver::layerSource() const | ||
{ | ||
return mLayerSource; | ||
} | ||
|
||
void LayerResolver::setLayerSource( const QString &layerSource ) | ||
{ | ||
if ( mLayerSource == layerSource ) | ||
return; | ||
|
||
mLayerSource = layerSource; | ||
emit layerSourceChanged(); | ||
} | ||
|
||
QString LayerResolver::layerProviderName() const | ||
{ | ||
return mLayerProviderName; | ||
} | ||
|
||
void LayerResolver::setLayerProviderName( const QString &layerProviderName ) | ||
{ | ||
if ( mLayerProviderName == layerProviderName ) | ||
return; | ||
|
||
mLayerProviderName = layerProviderName; | ||
resolve(); | ||
emit layerProviderNameChanged(); | ||
} | ||
|
||
QgsVectorLayer *LayerResolver::currentLayer() const | ||
{ | ||
return mLayer; | ||
} | ||
|
||
void LayerResolver::setLayer( QgsVectorLayer *layer ) | ||
{ | ||
if ( mLayer == layer ) | ||
return; | ||
|
||
mLayer = layer; | ||
emit currentLayerChanged(); | ||
} | ||
|
||
QgsProject *LayerResolver::project() const | ||
{ | ||
return mProject; | ||
} | ||
|
||
void LayerResolver::setProject( QgsProject *project ) | ||
{ | ||
if ( project == mProject ) | ||
return; | ||
|
||
mProject = project; | ||
resolve(); | ||
emit projectChanged(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/*************************************************************************** | ||
layerresolver.h | ||
------------------- | ||
begin : January 2021 | ||
copyright : (C) 2011 by Matthias Kuhn | ||
email : matthias@opengis.ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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 LAYERRESOLVER_H | ||
#define LAYERRESOLVER_H | ||
|
||
#include <QObject> | ||
|
||
class QgsVectorLayer; | ||
class QgsProject; | ||
|
||
/** | ||
* Helper class to resolve layers by id, name, source and provider. | ||
*/ | ||
class LayerResolver : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
/** | ||
* The layer id to resolve | ||
*/ | ||
Q_PROPERTY( QString layerId READ layerId WRITE setLayerId NOTIFY layerIdChanged ) | ||
|
||
/** | ||
* The layer name to resolve | ||
*/ | ||
Q_PROPERTY( QString layerName READ layerName WRITE setLayerName NOTIFY layerNameChanged ) | ||
|
||
/** | ||
* The layer source to resolve | ||
*/ | ||
Q_PROPERTY( QString layerSource READ layerSource WRITE setLayerSource NOTIFY layerSourceChanged ) | ||
|
||
/** | ||
* The layer provider name to resolve | ||
*/ | ||
Q_PROPERTY( QString layerProviderName READ layerProviderName WRITE setLayerProviderName NOTIFY layerProviderNameChanged ) | ||
|
||
/** | ||
* The qgis project from which layers will be acquired | ||
*/ | ||
Q_PROPERTY( QgsProject *project READ project WRITE setProject NOTIFY projectChanged ) | ||
|
||
/** | ||
* Contains the layer after a successful resolving process | ||
*/ | ||
Q_PROPERTY( QgsVectorLayer *currentLayer READ currentLayer NOTIFY currentLayerChanged ) | ||
|
||
public: | ||
explicit LayerResolver( QObject *parent = nullptr ); | ||
|
||
void resolve(); | ||
|
||
QString layerId() const; | ||
void setLayerId( const QString &layerId ); | ||
|
||
QString layerName() const; | ||
void setLayerName( const QString &layerName ); | ||
|
||
QString layerSource() const; | ||
void setLayerSource( const QString &layerSource ); | ||
|
||
QString layerProviderName() const; | ||
void setLayerProviderName( const QString &layerProviderName ); | ||
|
||
QgsVectorLayer *currentLayer() const; | ||
|
||
QgsProject *project() const; | ||
void setProject( QgsProject *project ); | ||
|
||
signals: | ||
void layerIdChanged(); | ||
void layerNameChanged(); | ||
void layerSourceChanged(); | ||
void layerProviderNameChanged(); | ||
void currentLayerChanged(); | ||
void projectChanged(); | ||
|
||
private: | ||
void setLayer( QgsVectorLayer *layer ); | ||
|
||
QString mLayerId; | ||
QString mLayerName; | ||
QString mLayerSource; | ||
QString mLayerProviderName; | ||
QgsProject *mProject = nullptr; | ||
QgsVectorLayer *mLayer = nullptr; | ||
}; | ||
|
||
#endif // LAYERRESOLVER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6ab5640
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Ta-daaa, freshly created APKs are available:
Other architectures: armv7, x86_64, x86