Skip to content

Commit 0ed1628

Browse files
committed
Modernize code
1 parent fe3e494 commit 0ed1628

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/gui/symbology/qgsstylemanagerdialog.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent )
4747
: QDialog( parent )
4848
, mStyle( style )
49-
, mModified( false )
5049
{
5150
setupUi( this );
5251
connect( tabItemType, &QTabWidget::currentChanged, this, &QgsStyleManagerDialog::tabItemType_currentChanged );
@@ -98,9 +97,6 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent )
9897
connect( importAction, &QAction::triggered, this, &QgsStyleManagerDialog::importItems );
9998
btnShare->setMenu( shareMenu );
10099

101-
// Set editing mode off by default
102-
mGrouppingMode = false;
103-
104100
QStandardItemModel *model = new QStandardItemModel( listItems );
105101
listItems->setModel( model );
106102
listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
@@ -150,7 +146,7 @@ QgsStyleManagerDialog::QgsStyleManagerDialog( QgsStyle *style, QWidget *parent )
150146
rampTypes << tr( "Gradient" ) << tr( "Color presets" ) << tr( "Random" ) << tr( "Catalog: cpt-city" );
151147
rampTypes << tr( "Catalog: ColorBrewer" );
152148
mMenuBtnAddItemColorRamp = new QMenu( this );
153-
Q_FOREACH ( const QString &rampType, rampTypes )
149+
for ( const QString &rampType : qgis::as_const( rampTypes ) )
154150
mMenuBtnAddItemColorRamp->addAction( new QAction( rampType, this ) );
155151
connect( mMenuBtnAddItemColorRamp, &QMenu::triggered,
156152
this, static_cast<bool ( QgsStyleManagerDialog::* )( QAction * )>( &QgsStyleManagerDialog::addColorRamp ) );
@@ -769,7 +765,7 @@ void QgsStyleManagerDialog::removeItem()
769765

770766
bool QgsStyleManagerDialog::removeSymbol()
771767
{
772-
QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
768+
const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
773769
if ( QMessageBox::Yes != QMessageBox::question( this, tr( "Remove Symbol" ),
774770
QString( tr( "Do you really want to remove %n symbol(s)?", nullptr, indexes.count() ) ),
775771
QMessageBox::Yes,
@@ -778,7 +774,7 @@ bool QgsStyleManagerDialog::removeSymbol()
778774

779775
QgsTemporaryCursorOverride override( Qt::WaitCursor );
780776

781-
Q_FOREACH ( const QModelIndex &index, indexes )
777+
for ( const QModelIndex &index : indexes )
782778
{
783779
QString symbolName = index.data().toString();
784780
// delete from style and update list
@@ -791,7 +787,7 @@ bool QgsStyleManagerDialog::removeSymbol()
791787

792788
bool QgsStyleManagerDialog::removeColorRamp()
793789
{
794-
QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
790+
const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
795791
if ( QMessageBox::Yes != QMessageBox::question( this, tr( "Remove Color Ramp" ),
796792
QString( tr( "Do you really want to remove %n ramp(s)?", nullptr, indexes.count() ) ),
797793
QMessageBox::Yes,
@@ -800,7 +796,7 @@ bool QgsStyleManagerDialog::removeColorRamp()
800796

801797
QgsTemporaryCursorOverride override( Qt::WaitCursor );
802798

803-
Q_FOREACH ( const QModelIndex &index, indexes )
799+
for ( const QModelIndex &index : indexes )
804800
{
805801
QString rampName = index.data().toString();
806802
// delete from style and update list
@@ -863,8 +859,8 @@ void QgsStyleManagerDialog::exportSelectedItemsImages( const QString &dir, const
863859
if ( dir.isEmpty() )
864860
return;
865861

866-
QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
867-
Q_FOREACH ( const QModelIndex &index, indexes )
862+
const QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
863+
for ( const QModelIndex &index : indexes )
868864
{
869865
QString name = index.data().toString();
870866
QString path = dir + '/' + name + '.' + format;
@@ -917,7 +913,7 @@ void QgsStyleManagerDialog::populateGroups()
917913
taggroup->setEditable( false );
918914
QStringList tags = mStyle->tags();
919915
tags.sort();
920-
Q_FOREACH ( const QString &tag, tags )
916+
for ( const QString &tag : qgis::as_const( tags ) )
921917
{
922918
QStandardItem *item = new QStandardItem( tag );
923919
item->setData( mStyle->tagId( tag ) );
@@ -1269,10 +1265,10 @@ void QgsStyleManagerDialog::regrouped( QStandardItem *item )
12691265
void QgsStyleManagerDialog::setSymbolsChecked( const QStringList &symbols )
12701266
{
12711267
QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
1272-
Q_FOREACH ( const QString &symbol, symbols )
1268+
for ( const QString &symbol : symbols )
12731269
{
1274-
QList<QStandardItem *> items = model->findItems( symbol );
1275-
Q_FOREACH ( QStandardItem *item, items )
1270+
const QList<QStandardItem *> items = model->findItems( symbol );
1271+
for ( QStandardItem *item : items )
12761272
item->setCheckState( Qt::Checked );
12771273
}
12781274
}
@@ -1381,7 +1377,7 @@ void QgsStyleManagerDialog::listitemsContextMenu( QPoint point )
13811377
QAction *a = nullptr;
13821378
QStringList tags = mStyle->tags();
13831379
tags.sort();
1384-
Q_FOREACH ( const QString &tag, tags )
1380+
for ( const QString &tag : qgis::as_const( tags ) )
13851381
{
13861382
a = new QAction( tag, mGroupListMenu );
13871383
a->setData( tag );
@@ -1411,8 +1407,8 @@ void QgsStyleManagerDialog::addFavoriteSelectedSymbols()
14111407
return;
14121408
}
14131409

1414-
QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1415-
Q_FOREACH ( const QModelIndex &index, indexes )
1410+
const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1411+
for ( const QModelIndex &index : indexes )
14161412
{
14171413
mStyle->addFavorite( type, index.data().toString() );
14181414
}
@@ -1428,8 +1424,8 @@ void QgsStyleManagerDialog::removeFavoriteSelectedSymbols()
14281424
return;
14291425
}
14301426

1431-
QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1432-
Q_FOREACH ( const QModelIndex &index, indexes )
1427+
const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1428+
for ( const QModelIndex &index : indexes )
14331429
{
14341430
mStyle->removeFavorite( type, index.data().toString() );
14351431
}
@@ -1464,8 +1460,8 @@ void QgsStyleManagerDialog::tagSelectedSymbols( bool newTag )
14641460
tag = selectedItem->data().toString();
14651461
}
14661462

1467-
QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1468-
Q_FOREACH ( const QModelIndex &index, indexes )
1463+
const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1464+
for ( const QModelIndex &index : indexes )
14691465
{
14701466
mStyle->tagSymbol( type, index.data().toString(), QStringList( tag ) );
14711467
}
@@ -1487,8 +1483,8 @@ void QgsStyleManagerDialog::detagSelectedSymbols()
14871483
QgsDebugMsg( QStringLiteral( "unknown entity type" ) );
14881484
return;
14891485
}
1490-
QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1491-
Q_FOREACH ( const QModelIndex &index, indexes )
1486+
const QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1487+
for ( const QModelIndex &index : indexes )
14921488
{
14931489
mStyle->detagSymbol( type, index.data().toString() );
14941490
}

src/gui/symbology/qgsstylemanagerdialog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
154154

155155
QString mStyleFilename;
156156

157-
bool mModified;
157+
bool mModified = false;
158158

159159
//! Mode to display the symbol list
160-
bool mGrouppingMode;
160+
bool mGrouppingMode = false;
161161

162162
//! space to store symbol tags
163163
QStringList mTagList;

0 commit comments

Comments
 (0)