Skip to content

Commit 585fa90

Browse files
committedMar 14, 2020
Fixes based on the feedback:
- dynamic_cast -> static_cast - QString -> QStringLiteral
1 parent bc23d86 commit 585fa90

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed
 

‎src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void QgsExpressionBuilderWidget::currentChanged( const QModelIndex &index, const
258258

259259
// Get the item
260260
QModelIndex idx = mProxyModel->mapToSource( index );
261-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
261+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
262262
if ( !item )
263263
return;
264264

@@ -355,8 +355,8 @@ void QgsExpressionBuilderWidget::updateFunctionFileList( const QString &path )
355355
{
356356
// Create default sample entry.
357357
newFunctionFile( "default" );
358-
txtPython->setText( QString( "'''\n#Sample custom function file\n "
359-
"(uncomment to use and customize or Add button to create a new file) \n%1 \n '''" ).arg( txtPython->text() ) );
358+
txtPython->setText( QStringLiteral( "'''\n#Sample custom function file\n "
359+
"(uncomment to use and customize or Add button to create a new file) \n%1 \n '''" ).arg( txtPython->text() ) );
360360
saveFunctionFile( "default" );
361361
}
362362
}
@@ -416,7 +416,7 @@ void QgsExpressionBuilderWidget::loadFunctionCode( const QString &code )
416416
void QgsExpressionBuilderWidget::expressionTree_doubleClicked( const QModelIndex &index )
417417
{
418418
QModelIndex idx = mProxyModel->mapToSource( index );
419-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
419+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
420420
if ( !item )
421421
return;
422422

@@ -1250,7 +1250,7 @@ void QgsExpressionBuilderWidget::showContextMenu( QPoint pt )
12501250
{
12511251
QModelIndex idx = expressionTree->indexAt( pt );
12521252
idx = mProxyModel->mapToSource( idx );
1253-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
1253+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
12541254
if ( !item )
12551255
return;
12561256

@@ -1272,7 +1272,7 @@ void QgsExpressionBuilderWidget::showContextMenu( QPoint pt )
12721272
void QgsExpressionBuilderWidget::loadSampleValues()
12731273
{
12741274
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
1275-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
1275+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
12761276
// TODO We should really return a error the user of the widget that
12771277
// the there is no layer set.
12781278
if ( !mLayer || !item )
@@ -1285,7 +1285,7 @@ void QgsExpressionBuilderWidget::loadSampleValues()
12851285
void QgsExpressionBuilderWidget::loadAllValues()
12861286
{
12871287
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
1288-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
1288+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
12891289
// TODO We should really return a error the user of the widget that
12901290
// the there is no layer set.
12911291
if ( !mLayer || !item )
@@ -1298,7 +1298,7 @@ void QgsExpressionBuilderWidget::loadAllValues()
12981298
void QgsExpressionBuilderWidget::loadSampleUsedValues()
12991299
{
13001300
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
1301-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
1301+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
13021302
// TODO We should really return a error the user of the widget that
13031303
// the there is no layer set.
13041304
if ( !mLayer || !item )
@@ -1311,7 +1311,7 @@ void QgsExpressionBuilderWidget::loadSampleUsedValues()
13111311
void QgsExpressionBuilderWidget::loadAllUsedValues()
13121312
{
13131313
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
1314-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
1314+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
13151315
// TODO We should really return a error the user of the widget that
13161316
// the there is no layer set.
13171317
if ( !mLayer || !item )
@@ -1367,7 +1367,7 @@ void QgsExpressionBuilderWidget::editSelectedUserExpression()
13671367
{
13681368
// Get the item
13691369
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
1370-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
1370+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
13711371
if ( !item )
13721372
return;
13731373

@@ -1390,7 +1390,7 @@ void QgsExpressionBuilderWidget::removeSelectedUserExpression()
13901390

13911391
// Get the item
13921392
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
1393-
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
1393+
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
13941394
if ( !item )
13951395
return;
13961396

@@ -1603,14 +1603,14 @@ void QgsExpressionBuilderWidget::loadExpressionsFromJson( const QJsonDocument &e
16031603
}
16041604

16051605
// we want to import only items of type expression for now
1606-
if ( expressionObj["type"].toString() != "expression" )
1606+
if ( expressionObj["type"].toString() != QStringLiteral( "expression" ) )
16071607
{
16081608
skippedExpressionLabels.append( expressionObj["name"].toString() );
16091609
continue;
16101610
}
16111611

16121612
// we want to import only items of type expression for now
1613-
if ( expressionObj["group"].toString() != "user" )
1613+
if ( expressionObj["group"].toString() != QStringLiteral( "user" ) )
16141614
{
16151615
skippedExpressionLabels.append( expressionObj["name"].toString() );
16161616
continue;
@@ -1621,7 +1621,7 @@ void QgsExpressionBuilderWidget::loadExpressionsFromJson( const QJsonDocument &e
16211621
const QString helpText = expressionObj["description"].toString();
16221622

16231623
// make sure they have valid name
1624-
if ( label.contains( "\\" ) || label.contains( "/" ) )
1624+
if ( label.contains( "\\" ) || label.contains( '/' ) )
16251625
{
16261626
skippedExpressionLabels.append( expressionObj["name"].toString() );
16271627
continue;
@@ -1657,11 +1657,11 @@ void QgsExpressionBuilderWidget::loadExpressionsFromJson( const QJsonDocument &e
16571657
{
16581658
QStringList skippedExpressionLabelsQuoted;
16591659
for ( const QString &skippedExpressionLabel : skippedExpressionLabels )
1660-
skippedExpressionLabelsQuoted.append( QString( "'%1'" ).arg( skippedExpressionLabel ) );
1660+
skippedExpressionLabelsQuoted.append( QStringLiteral( "'%1'" ).arg( skippedExpressionLabel ) );
16611661

16621662
QMessageBox::information( this,
16631663
tr( "Skipped Expression Imports" ),
1664-
QString( "%1\n%2" ).arg( tr( "The following expressions have been skipped:" ),
1664+
QStringLiteral( "%1\n%2" ).arg( tr( "The following expressions have been skipped:" ),
16651665
skippedExpressionLabelsQuoted.join( ", " ) ) );
16661666
}
16671667
}
@@ -1711,7 +1711,7 @@ const QList<QgsExpressionItem *> QgsExpressionBuilderWidget::findExpressions( co
17111711
const QList<QStandardItem *> found { mModel->findItems( label, Qt::MatchFlag::MatchRecursive ) };
17121712
for ( const auto &item : qgis::as_const( found ) )
17131713
{
1714-
result.push_back( dynamic_cast<QgsExpressionItem *>( item ) );
1714+
result.push_back( static_cast<QgsExpressionItem *>( item ) );
17151715
}
17161716
return result;
17171717
}

‎src/gui/qgsexpressionbuilderwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,14 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
416416
void operatorButtonClicked();
417417
void btnRun_pressed();
418418
void btnNewFile_pressed();
419+
419420
/**
420421
* Display a file dialog to choose where to store the exported expressions JSON file
421422
* and saves them to the selected destination.
422423
* \since QGIS 3.14
423424
*/
424425
void exportUserExpressions_pressed();
426+
425427
/**
426428
* Display a file dialog to choose where to load the expression JSON file from
427429
* and adds them to user expressions group.

0 commit comments

Comments
 (0)
Please sign in to comment.