Skip to content

Commit

Permalink
Moved to proper QgsMapLayer subclass + icon + optional tile borders
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 27, 2020
1 parent 4b362b3 commit 5ec1890
Show file tree
Hide file tree
Showing 37 changed files with 163 additions and 18 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -513,6 +513,7 @@
<file>themes/default/mIconTimerPause.svg</file>
<file>themes/default/mIconTreeView.svg</file>
<file>themes/default/mIconVector.svg</file>
<file>themes/default/mIconVectorTileLayer.svg</file>
<file>themes/default/mIconVirtualLayer.svg</file>
<file>themes/default/mIconWcs.svg</file>
<file>themes/default/mIconWfs.svg</file>
Expand Down
4 changes: 3 additions & 1 deletion python/core/auto_additions/qgsmaplayer.py
Expand Up @@ -9,7 +9,9 @@
QgsMapLayer.PluginLayer.__doc__ = ""
QgsMapLayer.MeshLayer = QgsMapLayerType.MeshLayer
QgsMapLayer.MeshLayer.__doc__ = "Added in 3.2"
QgsMapLayerType.__doc__ = 'Types of layers that can be added to a map\n\n.. versionadded:: 3.8\n\n' + '* ``VectorLayer``: ' + QgsMapLayerType.VectorLayer.__doc__ + '\n' + '* ``RasterLayer``: ' + QgsMapLayerType.RasterLayer.__doc__ + '\n' + '* ``PluginLayer``: ' + QgsMapLayerType.PluginLayer.__doc__ + '\n' + '* ``MeshLayer``: ' + QgsMapLayerType.MeshLayer.__doc__
QgsMapLayer.VectorTileLayer = QgsMapLayerType.VectorTileLayer
QgsMapLayer.VectorTileLayer.__doc__ = "Added in 3.14"
QgsMapLayerType.__doc__ = 'Types of layers that can be added to a map\n\n.. versionadded:: 3.8\n\n' + '* ``VectorLayer``: ' + QgsMapLayerType.VectorLayer.__doc__ + '\n' + '* ``RasterLayer``: ' + QgsMapLayerType.RasterLayer.__doc__ + '\n' + '* ``PluginLayer``: ' + QgsMapLayerType.PluginLayer.__doc__ + '\n' + '* ``MeshLayer``: ' + QgsMapLayerType.MeshLayer.__doc__ + '\n' + '* ``VectorTileLayer``: ' + QgsMapLayerType.VectorTileLayer.__doc__
# --
QgsMapLayer.LayerFlag.baseClass = QgsMapLayer
QgsMapLayer.LayerFlags.baseClass = QgsMapLayer
Expand Down
7 changes: 6 additions & 1 deletion python/core/auto_generated/qgsdataitem.sip.in
Expand Up @@ -479,7 +479,8 @@ Item that represents a layer that can be opened with one of the providers
Database,
Table,
Plugin,
Mesh
Mesh,
VectorTile
};


Expand Down Expand Up @@ -573,6 +574,10 @@ Use QgsDataItemGuiProvider.deleteLayer instead
static QIcon iconMesh();
%Docstring
Returns icon for mesh layer type
%End
static QIcon iconVectorTile();
%Docstring
Returns icon for vector tile layer
%End

virtual QString layerName() const;
Expand Down
8 changes: 6 additions & 2 deletions python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -19,7 +19,8 @@ enum class QgsMapLayerType
VectorLayer,
RasterLayer,
PluginLayer,
MeshLayer
MeshLayer,
VectorTileLayer
};

class QgsMapLayer : QObject
Expand Down Expand Up @@ -53,6 +54,9 @@ This is the base class for all map layer types (vector, raster).
case QgsMapLayerType::MeshLayer:
sipType = sipType_QgsMeshLayer;
break;
case QgsMapLayerType::VectorTileLayer:
sipType = sipType_QgsVectorTileLayer;
break;
default:
sipType = nullptr;
break;
Expand Down Expand Up @@ -1419,7 +1423,7 @@ Sets the coordinate transform context to ``transformContext``

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider()->name() );
QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QString() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End

Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmaplayerproxymodel.sip.in
Expand Up @@ -34,6 +34,7 @@ The QgsMapLayerProxyModel class provides an easy to use model to display the lis
PluginLayer,
WritableLayer,
MeshLayer,
VectorTileLayer,
All
};
typedef QFlags<QgsMapLayerProxyModel::Filter> Filters;
Expand Down
13 changes: 11 additions & 2 deletions python/core/auto_generated/vectortile/qgsvectortilelayer.sip.in
Expand Up @@ -11,7 +11,7 @@



class QgsVectorTileLayer : QgsPluginLayer
class QgsVectorTileLayer : QgsMapLayer
{
%Docstring
Implements a map layer that is dedicated to rendering of vector tiles.
Expand Down Expand Up @@ -75,7 +75,7 @@ Constructs a new vector tile layer
~QgsVectorTileLayer();


virtual QgsPluginLayer *clone() const /Factory/;
virtual QgsVectorTileLayer *clone() const /Factory/;


virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) /Factory/;
Expand Down Expand Up @@ -123,6 +123,15 @@ Sets renderer for the map layer.
QgsVectorTileRenderer *renderer() const;
%Docstring
Returns currently assigned renderer
%End

void setTileBorderRenderingEnabled( bool enabled );
%Docstring
Sets whether to render also borders of tiles (useful for debugging)
%End
bool isTileBorderRenderingEnabled() const;
%Docstring
Returns whether to render also borders of tiles (useful for debugging)
%End

};
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_manager_plugin.py
Expand Up @@ -85,7 +85,7 @@ def unload(self):

def onLayerWasAdded(self, aMapLayer):
# Be able to update every Db layer from Postgres, Spatialite and Oracle
if hasattr(aMapLayer, 'dataProvider') and aMapLayer.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
if hasattr(aMapLayer, 'dataProvider') and aMapLayer.dataProvider() and aMapLayer.dataProvider().name() in ['postgres', 'spatialite', 'oracle']:
self.iface.addCustomActionForLayer(self.layerAction, aMapLayer)
# virtual has QUrl source
# url = QUrl(QUrl.fromPercentEncoding(l.source()))
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmfilterbygeometry.cpp
Expand Up @@ -303,6 +303,7 @@ QVariantMap QgsFilterByLayerTypeAlgorithm::processAlgorithm( const QVariantMap &

case QgsMapLayerType::PluginLayer:
case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
break;
}

Expand Down
6 changes: 6 additions & 0 deletions src/analysis/processing/qgsalgorithmpackage.cpp
Expand Up @@ -177,6 +177,12 @@ QVariantMap QgsPackageAlgorithm::processAlgorithm( const QVariantMap &parameters
feedback->pushDebugInfo( QObject::tr( "Packaging mesh layers is not supported." ) );
errored = true;
break;

case QgsMapLayerType::VectorTileLayer:
//not supported
feedback->pushDebugInfo( QObject::tr( "Packaging vector tile layers is not supported." ) );
errored = true;
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -404,6 +404,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/effects
${CMAKE_SOURCE_DIR}/src/core/validity
${CMAKE_SOURCE_DIR}/src/core/vectortile
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/attributeformconfig
${CMAKE_SOURCE_DIR}/src/gui/symbology
Expand Down
1 change: 1 addition & 0 deletions src/app/browser/qgsinbuiltdataitemproviders.cpp
Expand Up @@ -447,6 +447,7 @@ void QgsLayerItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *men

case QgsMapLayerType::PluginLayer:
case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
break;
}
} );
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -8325,6 +8325,7 @@ QString QgisApp::saveAsFile( QgsMapLayer *layer, const bool onlySelected, const
return saveAsVectorFileGeneral( qobject_cast<QgsVectorLayer *>( layer ), true, onlySelected, defaultToAddToMap );

case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::VectorTileLayer:
case QgsMapLayerType::PluginLayer:
return QString();
}
Expand Down Expand Up @@ -14006,6 +14007,10 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionIdentify->setEnabled( true );
break;

case QgsMapLayerType::VectorTileLayer:
// TODO
break;

case QgsMapLayerType::PluginLayer:
break;

Expand Down Expand Up @@ -14958,6 +14963,12 @@ void QgisApp::showLayerProperties( QgsMapLayer *mapLayer, const QString &page )
break;
}

case QgsMapLayerType::VectorTileLayer:
{
// TODO
break;
}

case QgsMapLayerType::PluginLayer:
{
QgsPluginLayer *pl = qobject_cast<QgsPluginLayer *>( mapLayer );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -497,6 +497,10 @@ void QgsIdentifyResultsDialog::addFeature( const QgsMapToolIdentify::IdentifyRes
addFeature( qobject_cast<QgsMeshLayer *>( result.mLayer ), result.mLabel, result.mAttributes, result.mDerivedAttributes );
break;

case QgsMapLayerType::VectorTileLayer:
// TODO
break;

case QgsMapLayerType::PluginLayer:
break;
}
Expand Down
15 changes: 15 additions & 0 deletions src/app/qgslayerstylingwidget.cpp
Expand Up @@ -225,6 +225,12 @@ void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer )
break;
}

case QgsMapLayerType::VectorTileLayer:
{
// TODO
break;
}

case QgsMapLayerType::PluginLayer:
break;
}
Expand Down Expand Up @@ -600,6 +606,12 @@ void QgsLayerStylingWidget::updateCurrentWidgetLayer()
break;
}

case QgsMapLayerType::VectorTileLayer:
{
// TODO
break;
}

case QgsMapLayerType::PluginLayer:
{
mStackedWidget->setCurrentIndex( mNotSupportedPage );
Expand Down Expand Up @@ -724,6 +736,9 @@ bool QgsLayerStyleManagerWidgetFactory::supportsLayer( QgsMapLayer *layer ) cons
case QgsMapLayerType::MeshLayer:
return true;

case QgsMapLayerType::VectorTileLayer:
return false; // TODO

case QgsMapLayerType::PluginLayer:
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/qgslayertreeviewtemporalindicator.cpp
Expand Up @@ -56,6 +56,7 @@ void QgsLayerTreeViewTemporalIndicatorProvider::onIndicatorClicked( const QModel
case QgsMapLayerType::VectorLayer:
case QgsMapLayerType::MeshLayer:
case QgsMapLayerType::PluginLayer:
case QgsMapLayerType::VectorTileLayer:
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -4697,6 +4697,8 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres
return QCoreApplication::translate( "expressions", "Raster" );
case QgsMapLayerType::MeshLayer:
return QCoreApplication::translate( "expressions", "Mesh" );
case QgsMapLayerType::VectorTileLayer:
return QCoreApplication::translate( "expressions", "Vector Tile" );
case QgsMapLayerType::PluginLayer:
return QCoreApplication::translate( "expressions", "Plugin" );
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -203,6 +203,9 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
case QgsMapLayerType::MeshLayer:
return QgsLayerItem::iconMesh();

case QgsMapLayerType::VectorTileLayer:
return QgsLayerItem::iconVectorTile();

case QgsMapLayerType::VectorLayer:
case QgsMapLayerType::PluginLayer:
break;
Expand Down
8 changes: 8 additions & 0 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -33,6 +33,7 @@
#include "qgsmeshlayer.h"
#include "qgsreferencedgeometry.h"
#include "qgsrasterfilewriter.h"
#include "qgsvectortilelayer.h"

QList<QgsRasterLayer *> QgsProcessingUtils::compatibleRasterLayers( QgsProject *project, bool sort )
{
Expand Down Expand Up @@ -152,6 +153,8 @@ QgsMapLayer *QgsProcessingUtils::mapLayerFromStore( const QString &string, QgsMa
return true;
case QgsMapLayerType::MeshLayer:
return !canUseLayer( qobject_cast< QgsMeshLayer * >( layer ) );
case QgsMapLayerType::VectorTileLayer:
return !canUseLayer( qobject_cast< QgsVectorTileLayer * >( layer ) );
}
return true;
} ), layers.end() );
Expand Down Expand Up @@ -404,6 +407,11 @@ bool QgsProcessingUtils::canUseLayer( const QgsMeshLayer *layer )
return layer && layer->dataProvider();
}

bool QgsProcessingUtils::canUseLayer( const QgsVectorTileLayer *layer )
{
return layer && layer->isValid();
}

bool QgsProcessingUtils::canUseLayer( const QgsRasterLayer *layer )
{
return layer && layer->isValid();
Expand Down
2 changes: 2 additions & 0 deletions src/core/processing/qgsprocessingutils.h
Expand Up @@ -34,6 +34,7 @@ class QgsMapLayerStore;
class QgsProcessingFeedback;
class QgsProcessingFeatureSource;
class QgsProcessingAlgorithm;
class QgsVectorTileLayer;

#include <QString>
#include <QVariant>
Expand Down Expand Up @@ -383,6 +384,7 @@ class CORE_EXPORT QgsProcessingUtils
private:
static bool canUseLayer( const QgsRasterLayer *layer );
static bool canUseLayer( const QgsMeshLayer *layer );
static bool canUseLayer( const QgsVectorTileLayer *layer );
static bool canUseLayer( const QgsVectorLayer *layer,
const QList< int > &sourceTypes = QList< int >() );

Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsdataitem.cpp
Expand Up @@ -80,6 +80,11 @@ QIcon QgsLayerItem::iconMesh()
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconMeshLayer.svg" ) );
}

QIcon QgsLayerItem::iconVectorTile()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconVectorTileLayer.svg" ) );
}

QIcon QgsLayerItem::iconDefault()
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconLayer.png" ) );
Expand Down Expand Up @@ -643,6 +648,9 @@ QgsMapLayerType QgsLayerItem::mapLayerType() const
case QgsLayerItem::Mesh:
return QgsMapLayerType::MeshLayer;

case QgsLayerItem::VectorTile:
return QgsMapLayerType::VectorTileLayer;

case QgsLayerItem::Plugin:
return QgsMapLayerType::PluginLayer;

Expand Down Expand Up @@ -693,6 +701,8 @@ QgsLayerItem::LayerType QgsLayerItem::typeFromMapLayer( QgsMapLayer *layer )
return Plugin;
case QgsMapLayerType::MeshLayer:
return Mesh;
case QgsMapLayerType::VectorTileLayer:
return VectorTile;
}
return Vector; // no warnings
}
Expand Down Expand Up @@ -778,6 +788,7 @@ QgsMimeDataUtils::Uri QgsLayerItem::mimeUri() const
case Raster:
case Plugin:
case Mesh:
case VectorTile:
break;
}
break;
Expand All @@ -787,6 +798,9 @@ QgsMimeDataUtils::Uri QgsLayerItem::mimeUri() const
case QgsMapLayerType::MeshLayer:
u.layerType = QStringLiteral( "mesh" );
break;
case QgsMapLayerType::VectorTileLayer:
u.layerType = QStringLiteral( "vector-tile" );
break;
case QgsMapLayerType::PluginLayer:
u.layerType = QStringLiteral( "plugin" );
break;
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsdataitem.h
Expand Up @@ -506,7 +506,8 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
Database,
Table,
Plugin, //!< Added in 2.10
Mesh //!< Added in 3.2
Mesh, //!< Added in 3.2
VectorTile //!< Added in 3.14
};

Q_ENUM( LayerType )
Expand Down Expand Up @@ -595,6 +596,8 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
static QIcon iconDefault();
//! Returns icon for mesh layer type
static QIcon iconMesh();
//! Returns icon for vector tile layer
static QIcon iconVectorTile();

//! \returns the layer name
virtual QString layerName() const { return name(); }
Expand Down

0 comments on commit 5ec1890

Please sign in to comment.