Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes based on the feedback:
- dynamic_cast -> static_cast
- QString -> QStringLiteral
  • Loading branch information
suricactus committed Mar 14, 2020
1 parent bc23d86 commit 585fa90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -258,7 +258,7 @@ void QgsExpressionBuilderWidget::currentChanged( const QModelIndex &index, const

// Get the item
QModelIndex idx = mProxyModel->mapToSource( index );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
if ( !item )
return;

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

Expand Down Expand Up @@ -1250,7 +1250,7 @@ void QgsExpressionBuilderWidget::showContextMenu( QPoint pt )
{
QModelIndex idx = expressionTree->indexAt( pt );
idx = mProxyModel->mapToSource( idx );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
if ( !item )
return;

Expand All @@ -1272,7 +1272,7 @@ void QgsExpressionBuilderWidget::showContextMenu( QPoint pt )
void QgsExpressionBuilderWidget::loadSampleValues()
{
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer || !item )
Expand All @@ -1285,7 +1285,7 @@ void QgsExpressionBuilderWidget::loadSampleValues()
void QgsExpressionBuilderWidget::loadAllValues()
{
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer || !item )
Expand All @@ -1298,7 +1298,7 @@ void QgsExpressionBuilderWidget::loadAllValues()
void QgsExpressionBuilderWidget::loadSampleUsedValues()
{
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer || !item )
Expand All @@ -1311,7 +1311,7 @@ void QgsExpressionBuilderWidget::loadSampleUsedValues()
void QgsExpressionBuilderWidget::loadAllUsedValues()
{
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer || !item )
Expand Down Expand Up @@ -1367,7 +1367,7 @@ void QgsExpressionBuilderWidget::editSelectedUserExpression()
{
// Get the item
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
if ( !item )
return;

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

// Get the item
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
QgsExpressionItem *item = static_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
if ( !item )
return;

Expand Down Expand Up @@ -1603,14 +1603,14 @@ void QgsExpressionBuilderWidget::loadExpressionsFromJson( const QJsonDocument &e
}

// we want to import only items of type expression for now
if ( expressionObj["type"].toString() != "expression" )
if ( expressionObj["type"].toString() != QStringLiteral( "expression" ) )
{
skippedExpressionLabels.append( expressionObj["name"].toString() );
continue;
}

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

// make sure they have valid name
if ( label.contains( "\\" ) || label.contains( "/" ) )
if ( label.contains( "\\" ) || label.contains( '/' ) )
{
skippedExpressionLabels.append( expressionObj["name"].toString() );
continue;
Expand Down Expand Up @@ -1657,11 +1657,11 @@ void QgsExpressionBuilderWidget::loadExpressionsFromJson( const QJsonDocument &e
{
QStringList skippedExpressionLabelsQuoted;
for ( const QString &skippedExpressionLabel : skippedExpressionLabels )
skippedExpressionLabelsQuoted.append( QString( "'%1'" ).arg( skippedExpressionLabel ) );
skippedExpressionLabelsQuoted.append( QStringLiteral( "'%1'" ).arg( skippedExpressionLabel ) );

QMessageBox::information( this,
tr( "Skipped Expression Imports" ),
QString( "%1\n%2" ).arg( tr( "The following expressions have been skipped:" ),
QStringLiteral( "%1\n%2" ).arg( tr( "The following expressions have been skipped:" ),
skippedExpressionLabelsQuoted.join( ", " ) ) );
}
}
Expand Down Expand Up @@ -1711,7 +1711,7 @@ const QList<QgsExpressionItem *> QgsExpressionBuilderWidget::findExpressions( co
const QList<QStandardItem *> found { mModel->findItems( label, Qt::MatchFlag::MatchRecursive ) };
for ( const auto &item : qgis::as_const( found ) )
{
result.push_back( dynamic_cast<QgsExpressionItem *>( item ) );
result.push_back( static_cast<QgsExpressionItem *>( item ) );
}
return result;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsexpressionbuilderwidget.h
Expand Up @@ -416,12 +416,14 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
void operatorButtonClicked();
void btnRun_pressed();
void btnNewFile_pressed();

/**
* Display a file dialog to choose where to store the exported expressions JSON file
* and saves them to the selected destination.
* \since QGIS 3.14
*/
void exportUserExpressions_pressed();

/**
* Display a file dialog to choose where to load the expression JSON file from
* and adds them to user expressions group.
Expand Down

0 comments on commit 585fa90

Please sign in to comment.