Skip to content
Permalink
Browse files

A couple of for loop and naming improvements

  • Loading branch information
m-kuhn authored and nyalldawson committed Aug 18, 2020
1 parent 0e03c9f commit 2b6be6367a7275f8ac658fccbe95e457e7e07369
@@ -348,7 +348,7 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
{
if ( provider->doesStrictFeatureTypeCheck() )
{
for ( const auto &f : qgis::as_const( mAddedFeatures ) )
for ( const QgsFeature &f : qgis::as_const( mAddedFeatures ) )
{
if ( ( ! f.hasGeometry() ) ||
( f.geometry().wkbType() == provider->wkbType() ) )
@@ -581,8 +581,7 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
{
commitErrors << tr( "SUCCESS: %n feature(s) deleted.", "deleted features count", mDeletedFeatureIds.size() );
// TODO[MD]: we should not need this here
const auto constMDeletedFeatureIds = mDeletedFeatureIds;
for ( QgsFeatureId id : constMDeletedFeatureIds )
for ( QgsFeatureId id : qgis::as_const( mDeletedFeatureIds ) )
{
mChangedAttributeValues.remove( id );
mChangedGeometries.remove( id );
@@ -534,17 +534,16 @@ bool QgsVectorLayerJoinBuffer::addFeatures( QgsFeatureList &features, QgsFeature
return false;

// try to add/update a feature in each joined layer
const auto constVectorJoins = vectorJoins();
for ( const QgsVectorLayerJoinInfo &info : constVectorJoins )
const QgsVectorJoinList joins = vectorJoins();
for ( const QgsVectorLayerJoinInfo &info : joins )
{
QgsVectorLayer *joinLayer = info.joinLayer();

if ( joinLayer && joinLayer->isEditable() && info.isEditable() && info.hasUpsertOnEdit() )
{
QgsFeatureList joinFeatures;

const auto constFeatures = features;
for ( const QgsFeature &feature : constFeatures )
for ( const QgsFeature &feature : qgis::as_const( features ) )
{
const QgsFeature joinFeature = info.extractJoinedFeature( feature );

@@ -133,8 +133,7 @@ QgsRendererPropertiesDialog::QgsRendererPropertiesDialog( QgsVectorLayer *layer,

void QgsRendererPropertiesDialog::connectValueChanged( const QList<QWidget *> &widgets, const char *slot )
{
const auto constWidgets = widgets;
for ( QWidget *widget : constWidgets )
for ( QWidget *widget : widgets )
{
if ( QgsPropertyOverrideButton *w = qobject_cast<QgsPropertyOverrideButton *>( widget ) )
{
@@ -49,16 +49,16 @@ QgsSymbolLevelsWidget::QgsSymbolLevelsWidget( QgsFeatureRenderer *renderer, bool
for ( const QgsLegendSymbolItem &item : constLegendSymbolItems )
{
if ( item.symbol() )
mList << item;
mLegendSymbols << item;
}
}

const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
int maxLayers = 0;
tableLevels->setRowCount( mList.count() );
for ( int i = 0; i < mList.count(); i++ )
tableLevels->setRowCount( mLegendSymbols.count() );
for ( int i = 0; i < mLegendSymbols.count(); i++ )
{
QgsSymbol *sym = mList.at( i ).symbol();
QgsSymbol *sym = mLegendSymbols.at( i ).symbol();

// set icons for the rows
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( sym, QSize( iconSize, iconSize ) );
@@ -93,10 +93,10 @@ QgsSymbolLevelsWidget::QgsSymbolLevelsWidget( QgsFeatureRenderer *renderer, bool
void QgsSymbolLevelsWidget::populateTable()
{
const int iconSize = QgsGuiUtils::scaleIconSize( 16 );
for ( int row = 0; row < mList.count(); row++ )
for ( int row = 0; row < mLegendSymbols.count(); row++ )
{
QgsSymbol *sym = mList.at( row ).symbol();
QString label = mList.at( row ).label();
QgsSymbol *sym = mLegendSymbols.at( row ).symbol();
QString label = mLegendSymbols.at( row ).label();
QTableWidgetItem *itemLabel = new QTableWidgetItem( label );
itemLabel->setFlags( itemLabel->flags() ^ Qt::ItemIsEditable );
tableLevels->setItem( row, 0, itemLabel );
@@ -129,12 +129,12 @@ void QgsSymbolLevelsWidget::updateUi()

void QgsSymbolLevelsWidget::apply()
{
for ( int i = 0; i < mList.count(); i++ )
for ( const QgsLegendSymbolItem &legendSymbol : qgis::as_const( mLegendSymbols ) )
{
QgsSymbol *sym = mList.at( i ).symbol();
QgsSymbol *sym = legendSymbol.symbol();
for ( int layer = 0; layer < sym->symbolLayerCount(); layer++ )
{
mRenderer->setLegendSymbolItem( mList.at( i ).ruleKey(), sym->clone() );
mRenderer->setLegendSymbolItem( legendSymbol.ruleKey(), sym->clone() );
}
}

@@ -143,9 +143,9 @@ void QgsSymbolLevelsWidget::apply()

void QgsSymbolLevelsWidget::setDefaultLevels()
{
for ( int i = 0; i < mList.count(); i++ )
for ( int i = 0; i < mLegendSymbols.count(); i++ )
{
QgsSymbol *sym = mList.at( i ).symbol();
QgsSymbol *sym = mLegendSymbols.at( i ).symbol();
for ( int layer = 0; layer < sym->symbolLayerCount(); layer++ )
{
sym->symbolLayer( layer )->setRenderingPass( layer );
@@ -160,9 +160,9 @@ bool QgsSymbolLevelsWidget::usingLevels() const

void QgsSymbolLevelsWidget::renderingPassChanged( int row, int column )
{
if ( row < 0 || row >= mList.count() )
if ( row < 0 || row >= mLegendSymbols.count() )
return;
QgsSymbol *sym = mList.at( row ).symbol();
QgsSymbol *sym = mLegendSymbols.at( row ).symbol();
if ( column < 0 || column > sym->symbolLayerCount() )
return;
sym->symbolLayer( column - 1 )->setRenderingPass( tableLevels->item( row, column )->text().toInt() );
@@ -69,7 +69,7 @@ class GUI_EXPORT QgsSymbolLevelsWidget : public QgsPanelWidget, private Ui::QgsS
int mMaxLayers;

QgsFeatureRenderer *mRenderer = nullptr;
QgsLegendSymbolList mList;
QgsLegendSymbolList mLegendSymbols;

//! whether symbol layers always should be used (default FALSE)
bool mForceOrderingEnabled;

0 comments on commit 2b6be63

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