Skip to content

Commit 2bbdc34

Browse files
committed
Deprecate QgsProject::fileInfo()
1 parent 3c3de3f commit 2bbdc34

11 files changed

+22
-20
lines changed

python/core/qgsproject.sip.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ representation.
9797
.. seealso:: :py:func:`fileInfo`
9898
%End
9999

100-
QFileInfo fileInfo() const;
100+
QFileInfo fileInfo() const /Deprecated/;
101101
%Docstring
102102
Returns QFileInfo object for the project's associated file.
103103

src/app/qgisapp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5536,7 +5536,7 @@ void QgisApp::fileRevert()
55365536
return;
55375537

55385538
// re-open the current project
5539-
addProject( QgsProject::instance()->fileInfo().filePath() );
5539+
addProject( QgsProject::instance()->fileName() );
55405540
}
55415541

55425542
void QgisApp::enableProjectMacros()

src/core/layout/qgslayoutitemhtml.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContex
173173
//set html, using the specified url as base if in Url mode or the project file if in manual mode
174174
const QUrl baseUrl = mContentMode == QgsLayoutItemHtml::Url ?
175175
QUrl( mActualFetchedUrl ) :
176-
QUrl::fromLocalFile( mLayout->project()->fileInfo().absoluteFilePath() );
176+
QUrl::fromLocalFile( mLayout->project()->absoluteFilePath() );
177177

178178
mWebPage->mainFrame()->setHtml( loadedHtml, baseUrl );
179179

src/core/layout/qgslayoutitemlabel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void QgsLayoutItemLabel::contentChanged()
151151
//set this to true after html is loaded.
152152
mHtmlLoaded = false;
153153

154-
const QUrl baseUrl = QUrl::fromLocalFile( mLayout->project()->fileInfo().absoluteFilePath() );
154+
const QUrl baseUrl = QUrl::fromLocalFile( mLayout->project()->absoluteFilePath() );
155155
mWebPage->mainFrame()->setHtml( textToDraw, baseUrl );
156156

157157
//For very basic html labels with no external assets, the html load will already be

src/core/qgsauxiliarystorage.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,9 @@ QgsAuxiliaryStorage::QgsAuxiliaryStorage( const QgsProject &project, bool copy )
503503
{
504504
initTmpFileName();
505505

506-
if ( !project.fileInfo().fileName().isEmpty() )
506+
if ( !project.absoluteFilePath().isEmpty() )
507507
{
508-
const QFileInfo info = project.fileInfo();
509-
const QString path = info.path() + QDir::separator() + info.baseName();
510-
const QString asFileName = path + "." + QgsAuxiliaryStorage::extension();
511-
mFileName = asFileName;
508+
mFileName = filenameForProject( project );
512509
}
513510

514511
open( mFileName );
@@ -776,7 +773,7 @@ spatialite_database_unique_ptr QgsAuxiliaryStorage::open( const QgsProject &proj
776773

777774
QString QgsAuxiliaryStorage::filenameForProject( const QgsProject &project )
778775
{
779-
const QFileInfo info = project.fileInfo();
776+
const QFileInfo info( project.absoluteFilePath() );
780777
const QString path = info.path() + QDir::separator() + info.baseName();
781778
return path + '.' + QgsAuxiliaryStorage::extension();
782779
}

src/core/qgsexpressioncontext.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,15 @@ QgsExpressionContextScope *QgsExpressionContextUtils::projectScope( const QgsPro
778778
scope->setVariable( it.key(), it.value(), true );
779779
}
780780

781+
QString projectPath = project->absoluteFilePath();
782+
QString projectFolder = QFileInfo( projectPath ).path();
783+
QString projectFilename = QFileInfo( projectPath ).fileName();
784+
781785
//add other known project variables
782786
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_title" ), project->title(), true, true ) );
783-
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), QDir::toNativeSeparators( project->fileInfo().filePath() ), true, true ) );
784-
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), QDir::toNativeSeparators( project->fileInfo().dir().path() ), true, true ) );
785-
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), project->fileInfo().fileName(), true, true ) );
787+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), QDir::toNativeSeparators( projectPath ), true, true ) );
788+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), QDir::toNativeSeparators( projectFolder ), true, true ) );
789+
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), projectFilename, true, true ) );
786790
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_home" ), QDir::toNativeSeparators( project->homePath() ), true, true ) );
787791
QgsCoordinateReferenceSystem projectCrs = project->crs();
788792
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true, true ) );

src/core/qgsproject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
159159
* \see fileName()
160160
* \since QGIS 2.9
161161
*/
162-
QFileInfo fileInfo() const;
162+
Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
163163

164164
/**
165165
* Returns last modified time of the project file as returned by the file system (or other project storage).

src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ QgsExternalResourceConfigDlg::QgsExternalResourceConfigDlg( QgsVectorLayer *vl,
3636
mUseLink->setChecked( false );
3737
mFullUrl->setChecked( false );
3838

39-
QString defpath = QgsProject::instance()->fileName().isEmpty() ? QDir::homePath() : QgsProject::instance()->fileInfo().absolutePath();
39+
QString defpath = QgsProject::instance()->fileName().isEmpty() ? QDir::homePath() : QFileInfo( QgsProject::instance()->absoluteFilePath() ).path();
4040

4141
mRootPath->setPlaceholderText( QgsSettings().value( QStringLiteral( "/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( defpath ) ) ).toString() );
4242

@@ -97,7 +97,8 @@ void QgsExternalResourceConfigDlg::chooseDefaultPath()
9797
}
9898
else
9999
{
100-
dir = QgsSettings().value( QStringLiteral( "/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString();
100+
QString path = QFileInfo( QgsProject::instance()->absoluteFilePath() ).path();
101+
dir = QgsSettings().value( QStringLiteral( "/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( path ) ) ).toString();
101102
}
102103

103104
QString rootName = QFileDialog::getExistingDirectory( this, tr( "Select a directory" ), dir, QFileDialog::ShowDirsOnly );

src/gui/qgsexternalresourcewidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ QString QgsExternalResourceWidget::resolvePath( const QString &path )
174174
return path;
175175
break;
176176
case QgsFileWidget::RelativeProject:
177-
return QgsProject::instance()->fileInfo().dir().filePath( path );
177+
return QFileInfo( QgsProject::instance()->absoluteFilePath() ).dir().filePath( path );
178178
break;
179179
case QgsFileWidget::RelativeDefaultPath:
180180
return QDir( mDefaultRoot ).filePath( path );

src/gui/qgsfilewidget.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void QgsFileWidget::openFileDialog()
236236
QUrl url = QUrl::fromUserInput( oldPath );
237237
if ( !url.isValid() )
238238
{
239-
QString defPath = QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() );
239+
QString defPath = QDir::cleanPath( QFileInfo( QgsProject::instance()->absoluteFilePath() ).path() );
240240
if ( defPath.isEmpty() )
241241
{
242242
defPath = QDir::homePath();
@@ -341,7 +341,7 @@ QString QgsFileWidget::relativePath( const QString &filePath, bool removeRelativ
341341
QString RelativePath;
342342
if ( mRelativeStorage == RelativeProject )
343343
{
344-
RelativePath = QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) );
344+
RelativePath = QDir::toNativeSeparators( QDir::cleanPath( QFileInfo( QgsProject::instance()->absoluteFilePath() ).path() ) );
345345
}
346346
else if ( mRelativeStorage == RelativeDefaultPath && !mDefaultRoot.isEmpty() )
347347
{

src/server/services/wms/qgswmsgetcontext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace QgsWms
9999
QgsServerInterface *serverIface, const QgsProject *project,
100100
const QgsServerRequest &request )
101101
{
102-
parentElement.setAttribute( QStringLiteral( "id" ), "ows-context-" + project->fileInfo().baseName() );
102+
parentElement.setAttribute( QStringLiteral( "id" ), "ows-context-" + project->baseName() );
103103

104104
// OWSContext General element
105105
QDomElement generalElem = doc.createElement( QStringLiteral( "General" ) );

0 commit comments

Comments
 (0)