From f2672151c2bb42767936f5f20f6748a4abe50147 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 22 Oct 2016 18:39:33 +1000 Subject: [PATCH] Fix clazy qfileinfo-exists warnings From the clazy docs: Finds places using QFileInfo("foo").exists() instead of the faster version QFileInfo::exists("foo"). According to Qt's docs: "Using this function is faster than using QFileInfo(file).exists() for file system access." --- src/app/openstreetmap/qgsosmimportdialog.cpp | 2 +- src/app/qgisapp.cpp | 4 ++-- src/app/qgshandlebadlayers.cpp | 2 +- src/core/gps/qgsgpsdetector.cpp | 2 +- src/gui/qgscodeeditorpython.cpp | 4 ++-- src/gui/qgsprojectionselector.cpp | 10 +++++----- src/gui/symbology-ng/qgssymbollayerwidget.cpp | 4 ++-- .../delimitedtext/qgsdelimitedtextsourceselect.cpp | 2 +- src/providers/grass/qgsgrass.cpp | 6 +++--- src/providers/grass/qgsgrassimport.cpp | 2 +- src/providers/grass/qgsgrassvectormap.cpp | 2 +- src/providers/ogr/qgsogrdataitems.cpp | 2 +- tests/src/providers/testqgswcspublicservers.cpp | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/app/openstreetmap/qgsosmimportdialog.cpp b/src/app/openstreetmap/qgsosmimportdialog.cpp index 513f8530a32..b05ffe8fee7 100644 --- a/src/app/openstreetmap/qgsosmimportdialog.cpp +++ b/src/app/openstreetmap/qgsosmimportdialog.cpp @@ -84,7 +84,7 @@ void QgsOSMImportDialog::dbFileNameChanged( const QString& fileName ) void QgsOSMImportDialog::onOK() { // output file exists? - if ( QFileInfo( editDbFileName->text() ).exists() ) + if ( QFileInfo::exists( editDbFileName->text() ) ) { int res = QMessageBox::question( this, tr( "OpenStreetMap import" ), tr( "Output database file exists already. Overwrite?" ), QMessageBox::Yes | QMessageBox::No ); if ( res != QMessageBox::Yes ) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index fd2f7e85af9..c251b72e90c 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1765,7 +1765,7 @@ void QgisApp::createActions() mActionReportaBug->setShortcut( QString() ); #endif - mActionHelpContents->setEnabled( QFileInfo( QgsApplication::pkgDataPath() + "/doc/index.html" ).exists() ); + mActionHelpContents->setEnabled( QFileInfo::exists( QgsApplication::pkgDataPath() + "/doc/index.html" ) ); connect( mActionHelpContents, SIGNAL( triggered() ), this, SLOT( helpContents() ) ); connect( mActionHelpAPI, SIGNAL( triggered() ), this, SLOT( apiDocumentation() ) ); @@ -9185,7 +9185,7 @@ void QgisApp::helpContents() void QgisApp::apiDocumentation() { - if ( QFileInfo( QgsApplication::pkgDataPath() + "/doc/api/index.html" ).exists() ) + if ( QFileInfo::exists( QgsApplication::pkgDataPath() + "/doc/api/index.html" ) ) { openURL( "api/index.html" ); } diff --git a/src/app/qgshandlebadlayers.cpp b/src/app/qgshandlebadlayers.cpp index aa8c2d1335a..135009a6bbc 100644 --- a/src/app/qgshandlebadlayers.cpp +++ b/src/app/qgshandlebadlayers.cpp @@ -209,7 +209,7 @@ QString QgsHandleBadLayers::filename( int row ) void QgsHandleBadLayers::setFilename( int row, const QString& filename ) { - if ( !QFileInfo( filename ).exists() ) + if ( !QFileInfo::exists( filename ) ) return; QString type = mLayerList->item( row, 1 )->text(); diff --git a/src/core/gps/qgsgpsdetector.cpp b/src/core/gps/qgsgpsdetector.cpp index c57bb46396d..be80a44ef93 100644 --- a/src/core/gps/qgsgpsdetector.cpp +++ b/src/core/gps/qgsgpsdetector.cpp @@ -48,7 +48,7 @@ QList< QPair > QgsGPSDetector::availablePorts() { for ( int i = 0; i < 10; ++i ) { - if ( QFileInfo( linuxDev.arg( i ) ).exists() ) + if ( QFileInfo::exists( linuxDev.arg( i ) ) ) { devs << QPair( linuxDev.arg( i ), linuxDev.arg( i ) ); } diff --git a/src/gui/qgscodeeditorpython.cpp b/src/gui/qgscodeeditorpython.cpp index 6f6f1e5baf9..d13bf889231 100644 --- a/src/gui/qgscodeeditorpython.cpp +++ b/src/gui/qgscodeeditorpython.cpp @@ -74,7 +74,7 @@ void QgsCodeEditorPython::setSciLexerPython() } else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == "pap" ) { - if ( !QFileInfo( mAPISFilesList[0] ).exists() ) + if ( !QFileInfo::exists( mAPISFilesList[0] ) ) { QgsDebugMsg( QString( "The apis file %1 not found" ).arg( mAPISFilesList.at( 0 ) ) ); return; @@ -86,7 +86,7 @@ void QgsCodeEditorPython::setSciLexerPython() { for ( int i = 0; i < mAPISFilesList.size(); i++ ) { - if ( !QFileInfo( mAPISFilesList[i] ).exists() ) + if ( !QFileInfo::exists( mAPISFilesList[i] ) ) { QgsDebugMsg( QString( "The apis file %1 was not found" ).arg( mAPISFilesList.at( i ) ) ); return; diff --git a/src/gui/qgsprojectionselector.cpp b/src/gui/qgsprojectionselector.cpp index 859d986ee98..c5dbdb80087 100644 --- a/src/gui/qgsprojectionselector.cpp +++ b/src/gui/qgsprojectionselector.cpp @@ -308,7 +308,7 @@ QString QgsProjectionSelector::selectedProj4String() if ( srsId.toLong() >= USER_CRS_START_ID ) { databaseFileName = QgsApplication::qgisUserDbFilePath(); - if ( !QFileInfo( databaseFileName ).exists() ) //its unlikely that this condition will ever be reached + if ( !QFileInfo::exists( databaseFileName ) ) //its unlikely that this condition will ever be reached return QString(); } else //must be a system projection then @@ -372,7 +372,7 @@ QString QgsProjectionSelector::getSelectedExpression( const QString& expression if ( lvi->text( QGIS_CRS_ID_COLUMN ).toLong() >= USER_CRS_START_ID ) { databaseFileName = QgsApplication::qgisUserDbFilePath(); - if ( !QFileInfo( databaseFileName ).exists() ) + if ( !QFileInfo::exists( databaseFileName ) ) { return QString(); } @@ -483,7 +483,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet *crsFilter ) // if it doesnt exist we copy it in from the global resources dir //return straight away if the user has not created any custom projections - if ( !QFileInfo( databaseFileName ).exists() ) + if ( !QFileInfo::exists( databaseFileName ) ) { QgsDebugMsg( "Users qgis.db not found...skipping" ); mUserProjListDone = true; @@ -566,7 +566,7 @@ void QgsProjectionSelector::loadCrsList( QSet *crsFilter ) //read only filesystem because otherwise sqlite will try //to create the db file on the fly - if ( !QFileInfo( mSrsDatabaseFileName ).exists() ) + if ( !QFileInfo::exists( mSrsDatabaseFileName ) ) { mProjListDone = true; return; @@ -888,7 +888,7 @@ long QgsProjectionSelector::getLargestCrsIdMatch( const QString& theSql ) //check the db is available QString databaseFileName = QgsApplication::qgisUserDbFilePath(); - if ( QFileInfo( databaseFileName ).exists() ) //only bother trying to open if the file exists + if ( QFileInfo::exists( databaseFileName ) ) //only bother trying to open if the file exists { result = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, nullptr ); if ( result ) diff --git a/src/gui/symbology-ng/qgssymbollayerwidget.cpp b/src/gui/symbology-ng/qgssymbollayerwidget.cpp index 9d614b0a660..988d2750c33 100644 --- a/src/gui/symbology-ng/qgssymbollayerwidget.cpp +++ b/src/gui/symbology-ng/qgssymbollayerwidget.cpp @@ -2036,7 +2036,7 @@ void QgsSvgMarkerSymbolLayerWidget::on_mFileToolButton_clicked() void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_textEdited( const QString& text ) { - if ( !QFileInfo( text ).exists() ) + if ( !QFileInfo::exists( text ) ) { return; } @@ -2047,7 +2047,7 @@ void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_textEdited( const QString& void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_editingFinished() { - if ( !QFileInfo( mFileLineEdit->text() ).exists() ) + if ( !QFileInfo::exists( mFileLineEdit->text() ) ) { QUrl url( mFileLineEdit->text() ); if ( !url.isValid() ) diff --git a/src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp b/src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp index 3127c8f348a..39ef5e9fb88 100644 --- a/src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp +++ b/src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp @@ -670,7 +670,7 @@ bool QgsDelimitedTextSourceSelect::validate() { message = tr( "Please select an input file" ); } - else if ( ! QFileInfo( txtFilePath->text() ).exists() ) + else if ( ! QFileInfo::exists( txtFilePath->text() ) ) { message = tr( "File %1 does not exist" ).arg( txtFilePath->text() ); } diff --git a/src/providers/grass/qgsgrass.cpp b/src/providers/grass/qgsgrass.cpp index f23ecce0f34..eec0a98c53f 100644 --- a/src/providers/grass/qgsgrass.cpp +++ b/src/providers/grass/qgsgrass.cpp @@ -759,7 +759,7 @@ void QgsGrass::setMapsetSearchPathWatcher() QString searchFilePath = getDefaultMapsetPath() + "/SEARCH_PATH"; - if ( QFileInfo( searchFilePath ).exists() ) + if ( QFileInfo::exists( searchFilePath ) ) { QgsDebugMsg( "add watcher on SEARCH_PATH file " + searchFilePath ); mMapsetSearchPathWatcher->addPath( searchFilePath ); @@ -781,7 +781,7 @@ void QgsGrass::onSearchPathFileChanged( const QString & path ) { // changed or removed loadMapsetSearchPath(); - if ( !QFileInfo( searchFilePath ).exists() ) // removed + if ( !QFileInfo::exists( searchFilePath ) ) // removed { // reset watcher to mapset setMapsetSearchPathWatcher(); @@ -790,7 +790,7 @@ void QgsGrass::onSearchPathFileChanged( const QString & path ) else { // mapset directory changed - if ( QFileInfo( searchFilePath ).exists() ) // search path file added + if ( QFileInfo::exists( searchFilePath ) ) // search path file added { loadMapsetSearchPath(); setMapsetSearchPathWatcher(); diff --git a/src/providers/grass/qgsgrassimport.cpp b/src/providers/grass/qgsgrassimport.cpp index 83407760ffb..7ac3d3d5562 100644 --- a/src/providers/grass/qgsgrassimport.cpp +++ b/src/providers/grass/qgsgrassimport.cpp @@ -804,7 +804,7 @@ bool QgsGrassExternal::import() QString cmd = QgsGrass::gisbase() + "/bin/r.external"; QStringList arguments; - if ( QFileInfo( mSource ).exists() ) + if ( QFileInfo::exists( mSource ) ) { arguments << "input=" + mSource; } diff --git a/src/providers/grass/qgsgrassvectormap.cpp b/src/providers/grass/qgsgrassvectormap.cpp index 94cbe0ca26c..61969d6df02 100644 --- a/src/providers/grass/qgsgrassvectormap.cpp +++ b/src/providers/grass/qgsgrassvectormap.cpp @@ -504,7 +504,7 @@ bool QgsGrassVectorMap::mapOutdated() { // If the cidx file has been deleted, the map is currently being modified // by an external tool. Do not update until the cidx file has been recreated. - if ( !QFileInfo( dp + "/cidx" ).exists() ) + if ( !QFileInfo::exists( dp + "/cidx" ) ) { QgsDebugMsg( "The map is being modified and is unavailable : " + mGrassObject.toString() ); return false; diff --git a/src/providers/ogr/qgsogrdataitems.cpp b/src/providers/ogr/qgsogrdataitems.cpp index 0da7a69bb29..0cddf1b0024 100644 --- a/src/providers/ogr/qgsogrdataitems.cpp +++ b/src/providers/ogr/qgsogrdataitems.cpp @@ -298,7 +298,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem ) if ( suffix == "dbf" ) { QString pathShp = thePath.left( thePath.count() - 4 ) + ".shp"; - if ( QFileInfo( pathShp ).exists() ) + if ( QFileInfo::exists( pathShp ) ) return nullptr; } diff --git a/tests/src/providers/testqgswcspublicservers.cpp b/tests/src/providers/testqgswcspublicservers.cpp index 337ab794cae..a82e05607f0 100644 --- a/tests/src/providers/testqgswcspublicservers.cpp +++ b/tests/src/providers/testqgswcspublicservers.cpp @@ -374,7 +374,7 @@ void TestQgsWcsPublicServers::test() QString myPath = myVersionDirPath + '/' + myCoverage.identifier; QString myLogPath = myPath + ".log"; - if ( QFileInfo( myLogPath ).exists() && !mForce ) + if ( QFileInfo::exists( myLogPath ) && !mForce ) { //QMap log = readLog( myLogPath ); //if ( !log.value( "identifier" ).isEmpty() && log.value( "error" ).isEmpty() ) continue;