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."
This commit is contained in:
Nyall Dawson 2016-10-22 18:39:33 +10:00
parent ef5110732b
commit f2672151c2
13 changed files with 22 additions and 22 deletions

View File

@ -84,7 +84,7 @@ void QgsOSMImportDialog::dbFileNameChanged( const QString& fileName )
void QgsOSMImportDialog::onOK() void QgsOSMImportDialog::onOK()
{ {
// output file exists? // 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 ); int res = QMessageBox::question( this, tr( "OpenStreetMap import" ), tr( "Output database file exists already. Overwrite?" ), QMessageBox::Yes | QMessageBox::No );
if ( res != QMessageBox::Yes ) if ( res != QMessageBox::Yes )

View File

@ -1765,7 +1765,7 @@ void QgisApp::createActions()
mActionReportaBug->setShortcut( QString() ); mActionReportaBug->setShortcut( QString() );
#endif #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( mActionHelpContents, SIGNAL( triggered() ), this, SLOT( helpContents() ) );
connect( mActionHelpAPI, SIGNAL( triggered() ), this, SLOT( apiDocumentation() ) ); connect( mActionHelpAPI, SIGNAL( triggered() ), this, SLOT( apiDocumentation() ) );
@ -9185,7 +9185,7 @@ void QgisApp::helpContents()
void QgisApp::apiDocumentation() 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" ); openURL( "api/index.html" );
} }

View File

@ -209,7 +209,7 @@ QString QgsHandleBadLayers::filename( int row )
void QgsHandleBadLayers::setFilename( int row, const QString& filename ) void QgsHandleBadLayers::setFilename( int row, const QString& filename )
{ {
if ( !QFileInfo( filename ).exists() ) if ( !QFileInfo::exists( filename ) )
return; return;
QString type = mLayerList->item( row, 1 )->text(); QString type = mLayerList->item( row, 1 )->text();

View File

@ -48,7 +48,7 @@ QList< QPair<QString, QString> > QgsGPSDetector::availablePorts()
{ {
for ( int i = 0; i < 10; ++i ) for ( int i = 0; i < 10; ++i )
{ {
if ( QFileInfo( linuxDev.arg( i ) ).exists() ) if ( QFileInfo::exists( linuxDev.arg( i ) ) )
{ {
devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) ); devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) );
} }

View File

@ -74,7 +74,7 @@ void QgsCodeEditorPython::setSciLexerPython()
} }
else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == "pap" ) 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 ) ) ); QgsDebugMsg( QString( "The apis file %1 not found" ).arg( mAPISFilesList.at( 0 ) ) );
return; return;
@ -86,7 +86,7 @@ void QgsCodeEditorPython::setSciLexerPython()
{ {
for ( int i = 0; i < mAPISFilesList.size(); i++ ) 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 ) ) ); QgsDebugMsg( QString( "The apis file %1 was not found" ).arg( mAPISFilesList.at( i ) ) );
return; return;

View File

@ -308,7 +308,7 @@ QString QgsProjectionSelector::selectedProj4String()
if ( srsId.toLong() >= USER_CRS_START_ID ) if ( srsId.toLong() >= USER_CRS_START_ID )
{ {
databaseFileName = QgsApplication::qgisUserDbFilePath(); 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(); return QString();
} }
else //must be a system projection then 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 ) if ( lvi->text( QGIS_CRS_ID_COLUMN ).toLong() >= USER_CRS_START_ID )
{ {
databaseFileName = QgsApplication::qgisUserDbFilePath(); databaseFileName = QgsApplication::qgisUserDbFilePath();
if ( !QFileInfo( databaseFileName ).exists() ) if ( !QFileInfo::exists( databaseFileName ) )
{ {
return QString(); return QString();
} }
@ -483,7 +483,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet<QString> *crsFilter )
// if it doesnt exist we copy it in from the global resources dir // 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 //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" ); QgsDebugMsg( "Users qgis.db not found...skipping" );
mUserProjListDone = true; mUserProjListDone = true;
@ -566,7 +566,7 @@ void QgsProjectionSelector::loadCrsList( QSet<QString> *crsFilter )
//read only filesystem because otherwise sqlite will try //read only filesystem because otherwise sqlite will try
//to create the db file on the fly //to create the db file on the fly
if ( !QFileInfo( mSrsDatabaseFileName ).exists() ) if ( !QFileInfo::exists( mSrsDatabaseFileName ) )
{ {
mProjListDone = true; mProjListDone = true;
return; return;
@ -888,7 +888,7 @@ long QgsProjectionSelector::getLargestCrsIdMatch( const QString& theSql )
//check the db is available //check the db is available
QString databaseFileName = QgsApplication::qgisUserDbFilePath(); 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 ); result = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, nullptr );
if ( result ) if ( result )

View File

@ -2036,7 +2036,7 @@ void QgsSvgMarkerSymbolLayerWidget::on_mFileToolButton_clicked()
void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_textEdited( const QString& text ) void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_textEdited( const QString& text )
{ {
if ( !QFileInfo( text ).exists() ) if ( !QFileInfo::exists( text ) )
{ {
return; return;
} }
@ -2047,7 +2047,7 @@ void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_textEdited( const QString&
void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_editingFinished() void QgsSvgMarkerSymbolLayerWidget::on_mFileLineEdit_editingFinished()
{ {
if ( !QFileInfo( mFileLineEdit->text() ).exists() ) if ( !QFileInfo::exists( mFileLineEdit->text() ) )
{ {
QUrl url( mFileLineEdit->text() ); QUrl url( mFileLineEdit->text() );
if ( !url.isValid() ) if ( !url.isValid() )

View File

@ -670,7 +670,7 @@ bool QgsDelimitedTextSourceSelect::validate()
{ {
message = tr( "Please select an input file" ); 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() ); message = tr( "File %1 does not exist" ).arg( txtFilePath->text() );
} }

View File

@ -759,7 +759,7 @@ void QgsGrass::setMapsetSearchPathWatcher()
QString searchFilePath = getDefaultMapsetPath() + "/SEARCH_PATH"; QString searchFilePath = getDefaultMapsetPath() + "/SEARCH_PATH";
if ( QFileInfo( searchFilePath ).exists() ) if ( QFileInfo::exists( searchFilePath ) )
{ {
QgsDebugMsg( "add watcher on SEARCH_PATH file " + searchFilePath ); QgsDebugMsg( "add watcher on SEARCH_PATH file " + searchFilePath );
mMapsetSearchPathWatcher->addPath( searchFilePath ); mMapsetSearchPathWatcher->addPath( searchFilePath );
@ -781,7 +781,7 @@ void QgsGrass::onSearchPathFileChanged( const QString & path )
{ {
// changed or removed // changed or removed
loadMapsetSearchPath(); loadMapsetSearchPath();
if ( !QFileInfo( searchFilePath ).exists() ) // removed if ( !QFileInfo::exists( searchFilePath ) ) // removed
{ {
// reset watcher to mapset // reset watcher to mapset
setMapsetSearchPathWatcher(); setMapsetSearchPathWatcher();
@ -790,7 +790,7 @@ void QgsGrass::onSearchPathFileChanged( const QString & path )
else else
{ {
// mapset directory changed // mapset directory changed
if ( QFileInfo( searchFilePath ).exists() ) // search path file added if ( QFileInfo::exists( searchFilePath ) ) // search path file added
{ {
loadMapsetSearchPath(); loadMapsetSearchPath();
setMapsetSearchPathWatcher(); setMapsetSearchPathWatcher();

View File

@ -804,7 +804,7 @@ bool QgsGrassExternal::import()
QString cmd = QgsGrass::gisbase() + "/bin/r.external"; QString cmd = QgsGrass::gisbase() + "/bin/r.external";
QStringList arguments; QStringList arguments;
if ( QFileInfo( mSource ).exists() ) if ( QFileInfo::exists( mSource ) )
{ {
arguments << "input=" + mSource; arguments << "input=" + mSource;
} }

View File

@ -504,7 +504,7 @@ bool QgsGrassVectorMap::mapOutdated()
{ {
// If the cidx file has been deleted, the map is currently being modified // 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. // 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() ); QgsDebugMsg( "The map is being modified and is unavailable : " + mGrassObject.toString() );
return false; return false;

View File

@ -298,7 +298,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
if ( suffix == "dbf" ) if ( suffix == "dbf" )
{ {
QString pathShp = thePath.left( thePath.count() - 4 ) + ".shp"; QString pathShp = thePath.left( thePath.count() - 4 ) + ".shp";
if ( QFileInfo( pathShp ).exists() ) if ( QFileInfo::exists( pathShp ) )
return nullptr; return nullptr;
} }

View File

@ -374,7 +374,7 @@ void TestQgsWcsPublicServers::test()
QString myPath = myVersionDirPath + '/' + myCoverage.identifier; QString myPath = myVersionDirPath + '/' + myCoverage.identifier;
QString myLogPath = myPath + ".log"; QString myLogPath = myPath + ".log";
if ( QFileInfo( myLogPath ).exists() && !mForce ) if ( QFileInfo::exists( myLogPath ) && !mForce )
{ {
//QMap<QString, QString> log = readLog( myLogPath ); //QMap<QString, QString> log = readLog( myLogPath );
//if ( !log.value( "identifier" ).isEmpty() && log.value( "error" ).isEmpty() ) continue; //if ( !log.value( "identifier" ).isEmpty() && log.value( "error" ).isEmpty() ) continue;