Skip to content
Permalink
Browse files

Make use of QgsProject::mapLayer<QgsVectorLayer *> template

  • Loading branch information
m-kuhn committed Jan 9, 2019
1 parent 468f25c commit e32c739b4760327975baf970ec839df1943ba255
@@ -720,6 +720,7 @@ Retrieve a pointer to a registered layer by layer ID.
.. seealso:: :py:func:`mapLayers`
%End


QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
%Docstring
Retrieve a list of matching registered layers by layer name.
@@ -317,7 +317,7 @@ void QgsActiveLayerFeaturesLocatorFilter::triggerResult( const QgsLocatorResult
QVariantList dataList = result.userData.toList();
QgsFeatureId id = dataList.at( 0 ).toLongLong();
QString layerId = dataList.at( 1 ).toString();
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
if ( !layer )
return;

@@ -431,7 +431,7 @@ void QgsAllLayersFeaturesLocatorFilter::triggerResultFromAction( const QgsLocato
QVariantList dataList = result.userData.toList();
QgsFeatureId fid = dataList.at( 0 ).toLongLong();
QString layerId = dataList.at( 1 ).toString();
QgsVectorLayer *layer = qobject_cast< QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
if ( !layer )
return;

@@ -682,7 +682,7 @@ void QgsAppLayerTreeViewMenuProvider::editVectorSymbol()
return;

QString layerId = action->property( "layerId" ).toString();
QgsVectorLayer *layer = dynamic_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
if ( !layer )
return;

@@ -712,7 +712,7 @@ void QgsAppLayerTreeViewMenuProvider::setVectorSymbolColor( const QColor &color
return;

QString layerId = action->property( "layerId" ).toString();
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
if ( !layer )
return;

@@ -805,7 +805,7 @@ void QgsAppLayerTreeViewMenuProvider::setSymbolLegendNodeColor( const QColor &co
std::unique_ptr< QgsSymbol > newSymbol( originalSymbol->clone() );
newSymbol->setColor( color );
node->setSymbol( newSymbol.release() );
if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) ) )
if ( QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId ) )
{
layer->emitStyleChanged();
}
@@ -93,7 +93,7 @@ void QgsLabelPropertyDialog::buttonBox_clicked( QAbstractButton *button )
void QgsLabelPropertyDialog::init( const QString &layerId, const QString &providerId, int featureId, const QString &labelText )
{
//get feature attributes
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *vlayer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
if ( !vlayer )
{
return;
@@ -690,7 +690,7 @@ bool QgsMapToolLabel::diagramCanShowHide( QgsVectorLayer *vlayer, int &showCol )
QgsMapToolLabel::LabelDetails::LabelDetails( const QgsLabelPosition &p )
: pos( p )
{
layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( pos.layerID ) );
layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( pos.layerID );
if ( layer && layer->labelsEnabled() && !p.isDiagram )
{
settings = layer->labeling()->settings( pos.providerID );
@@ -112,7 +112,7 @@ QgsValueRelationFieldFormatter::ValueRelationCache QgsValueRelationFieldFormatte
{
ValueRelationCache cache;

QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( config.value( QStringLiteral( "Layer" ) ).toString() ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( config.value( QStringLiteral( "Layer" ) ).toString() );

if ( !layer )
return cache;
@@ -85,7 +85,7 @@ QgsVectorLayer *QgsMimeDataUtils::Uri::vectorLayer( bool &owner, QString &error
return nullptr;
}
QString layerId = url.queryItemValue( QStringLiteral( "layerid" ) );
QgsVectorLayer *vectorLayer = qobject_cast< QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *vectorLayer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
if ( !vectorLayer )
{
error = QObject::tr( "Cannot get memory layer." );
@@ -68,7 +68,7 @@ QVariantMap QgsValueRelationConfigDlg::config()

void QgsValueRelationConfigDlg::setConfig( const QVariantMap &config )
{
QgsVectorLayer *lyr = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( config.value( QStringLiteral( "Layer" ) ).toString() ) );
QgsVectorLayer *lyr = QgsProject::instance()->mapLayer<QgsVectorLayer *>( config.value( QStringLiteral( "Layer" ) ).toString() );
mLayerName->setLayer( lyr );
mKeyColumn->setField( config.value( QStringLiteral( "Key" ) ).toString() );
mValueColumn->setField( config.value( QStringLiteral( "Value" ) ).toString() );
@@ -162,7 +162,7 @@ QList<QgsVectorLayer *> QgsGeometryCheckerSetupTab::getSelectedLayers()
if ( item->checkState() == Qt::Checked )
{
QString layerId = item->data( LayerIdRole ).toString();
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
if ( layer )
{
layers.append( layer );
@@ -253,8 +253,8 @@ void QgsGeometryCheckerSetupTab::runChecks()
}
}
}
QgsVectorLayer *lineLayerCheckLayer = ui.comboLineLayerIntersection->isEnabled() ? dynamic_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( ui.comboLineLayerIntersection->currentData().toString() ) ) : nullptr;
QgsVectorLayer *followBoundaryCheckLayer = ui.comboBoxFollowBoundaries->isEnabled() ? dynamic_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( ui.comboBoxFollowBoundaries->currentData().toString() ) ) : nullptr;
QgsVectorLayer *lineLayerCheckLayer = ui.comboLineLayerIntersection->isEnabled() ? QgsProject::instance()->mapLayer<QgsVectorLayer *>( ui.comboLineLayerIntersection->currentData().toString() ) : nullptr;
QgsVectorLayer *followBoundaryCheckLayer = ui.comboBoxFollowBoundaries->isEnabled() ? QgsProject::instance()->mapLayer<QgsVectorLayer *>( ui.comboBoxFollowBoundaries->currentData().toString() ) : nullptr;
if ( layers.contains( lineLayerCheckLayer ) || layers.contains( followBoundaryCheckLayer ) )
{
QMessageBox::critical( this, tr( "Check Geometries" ), tr( "The selected input layers cannot contain a layer also selected for a topology check." ) );
@@ -421,7 +421,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
// LineLayerIntersection check is enabled, make sure there is also a feature pool for that layer
if ( ui.checkLineLayerIntersection->isChecked() && !featurePools.keys().contains( ui.comboLineLayerIntersection->currentData().toString() ) )
{
QgsVectorLayer *layer = dynamic_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( ui.comboLineLayerIntersection->currentData().toString() ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( ui.comboLineLayerIntersection->currentData().toString() );
Q_ASSERT( layer );
featurePools.insert( layer->id(), new QgsVectorDataProviderFeaturePool( layer, selectedOnly ) );
}
@@ -271,7 +271,7 @@ template<> QgsGeometryCheck *QgsGeometryCheckFactoryT<QgsGeometryFollowBoundarie
QgsSettings().setValue( sSettingsGroup + "checkFollowBoundaries", ui.checkBoxFollowBoundaries->isChecked() );
if ( ui.checkBoxFollowBoundaries->isEnabled() && ui.checkBoxFollowBoundaries->isChecked() )
{
QgsVectorLayer *checkLayer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( ui.comboBoxFollowBoundaries->currentData().toString() ) );
QgsVectorLayer *checkLayer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( ui.comboBoxFollowBoundaries->currentData().toString() );
return new QgsGeometryFollowBoundariesCheck( context, QVariantMap(), checkLayer );
}
else
@@ -57,7 +57,7 @@ void QgsGlobeFeatureIdentifyCallback::onHit( osgEarth::ObjectID id )
std::string layerId;
if ( feature->getUserValue( "qgisLayerId", layerId ) )
{
QgsVectorLayer *lyr = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( QString::fromStdString( layerId ) ) );
QgsVectorLayer *lyr = QgsProject::instance()->mapLayer<QgsVectorLayer *>( QString::fromStdString( layerId ) );
#endif
if ( lyr )
{
@@ -151,7 +151,7 @@ void checkDock::deleteErrors()

void checkDock::parseErrorListByLayer( const QString &layerId )
{
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) );
QgsVectorLayer *layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( layerId );
QList<TopolError *>::Iterator it = mErrorList.begin();

while ( it != mErrorList.end() )
@@ -167,8 +167,8 @@ void TestQgsTranslateProject::translateProject()
QgsProject::instance()->read( projectFileName );

//with the qm file containing translation from en to de, the project should be in german and renamed with postfix .de
QgsVectorLayer *points_layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( "points_240d6bd6_9203_470a_994a_aae13cd9fa04" ) );
QgsVectorLayer *lines_layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( "lines_a677672a_bf5d_410d_98c9_d326a5719a1b" ) );
QgsVectorLayer *points_layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( "points_240d6bd6_9203_470a_994a_aae13cd9fa04" );
QgsVectorLayer *lines_layer = QgsProject::instance()->mapLayer<QgsVectorLayer *>( "lines_a677672a_bf5d_410d_98c9_d326a5719a1b" );

//LAYER NAMES
//lines -> Linien

0 comments on commit e32c739

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