Skip to content

Commit

Permalink
Deprecate QgsProject::fileInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent 3c3de3f commit 2bbdc34
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsproject.sip.in
Expand Up @@ -97,7 +97,7 @@ representation.
.. seealso:: :py:func:`fileInfo`
%End

QFileInfo fileInfo() const;
QFileInfo fileInfo() const /Deprecated/;
%Docstring
Returns QFileInfo object for the project's associated file.

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -5536,7 +5536,7 @@ void QgisApp::fileRevert()
return;

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

void QgisApp::enableProjectMacros()
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemhtml.cpp
Expand Up @@ -173,7 +173,7 @@ void QgsLayoutItemHtml::loadHtml( const bool useCache, const QgsExpressionContex
//set html, using the specified url as base if in Url mode or the project file if in manual mode
const QUrl baseUrl = mContentMode == QgsLayoutItemHtml::Url ?
QUrl( mActualFetchedUrl ) :
QUrl::fromLocalFile( mLayout->project()->fileInfo().absoluteFilePath() );
QUrl::fromLocalFile( mLayout->project()->absoluteFilePath() );

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

Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemlabel.cpp
Expand Up @@ -151,7 +151,7 @@ void QgsLayoutItemLabel::contentChanged()
//set this to true after html is loaded.
mHtmlLoaded = false;

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

//For very basic html labels with no external assets, the html load will already be
Expand Down
9 changes: 3 additions & 6 deletions src/core/qgsauxiliarystorage.cpp
Expand Up @@ -503,12 +503,9 @@ QgsAuxiliaryStorage::QgsAuxiliaryStorage( const QgsProject &project, bool copy )
{
initTmpFileName();

if ( !project.fileInfo().fileName().isEmpty() )
if ( !project.absoluteFilePath().isEmpty() )
{
const QFileInfo info = project.fileInfo();
const QString path = info.path() + QDir::separator() + info.baseName();
const QString asFileName = path + "." + QgsAuxiliaryStorage::extension();
mFileName = asFileName;
mFileName = filenameForProject( project );
}

open( mFileName );
Expand Down Expand Up @@ -776,7 +773,7 @@ spatialite_database_unique_ptr QgsAuxiliaryStorage::open( const QgsProject &proj

QString QgsAuxiliaryStorage::filenameForProject( const QgsProject &project )
{
const QFileInfo info = project.fileInfo();
const QFileInfo info( project.absoluteFilePath() );
const QString path = info.path() + QDir::separator() + info.baseName();
return path + '.' + QgsAuxiliaryStorage::extension();
}
Expand Down
10 changes: 7 additions & 3 deletions src/core/qgsexpressioncontext.cpp
Expand Up @@ -778,11 +778,15 @@ QgsExpressionContextScope *QgsExpressionContextUtils::projectScope( const QgsPro
scope->setVariable( it.key(), it.value(), true );
}

QString projectPath = project->absoluteFilePath();
QString projectFolder = QFileInfo( projectPath ).path();
QString projectFilename = QFileInfo( projectPath ).fileName();

//add other known project variables
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_title" ), project->title(), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), QDir::toNativeSeparators( project->fileInfo().filePath() ), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), QDir::toNativeSeparators( project->fileInfo().dir().path() ), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), project->fileInfo().fileName(), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), QDir::toNativeSeparators( projectPath ), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), QDir::toNativeSeparators( projectFolder ), true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), projectFilename, true, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_home" ), QDir::toNativeSeparators( project->homePath() ), true, true ) );
QgsCoordinateReferenceSystem projectCrs = project->crs();
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true, true ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsproject.h
Expand Up @@ -159,7 +159,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
* \see fileName()
* \since QGIS 2.9
*/
QFileInfo fileInfo() const;
Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;

/**
* Returns last modified time of the project file as returned by the file system (or other project storage).
Expand Down
5 changes: 3 additions & 2 deletions src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp
Expand Up @@ -36,7 +36,7 @@ QgsExternalResourceConfigDlg::QgsExternalResourceConfigDlg( QgsVectorLayer *vl,
mUseLink->setChecked( false );
mFullUrl->setChecked( false );

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

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

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

QString rootName = QFileDialog::getExistingDirectory( this, tr( "Select a directory" ), dir, QFileDialog::ShowDirsOnly );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsexternalresourcewidget.cpp
Expand Up @@ -174,7 +174,7 @@ QString QgsExternalResourceWidget::resolvePath( const QString &path )
return path;
break;
case QgsFileWidget::RelativeProject:
return QgsProject::instance()->fileInfo().dir().filePath( path );
return QFileInfo( QgsProject::instance()->absoluteFilePath() ).dir().filePath( path );
break;
case QgsFileWidget::RelativeDefaultPath:
return QDir( mDefaultRoot ).filePath( path );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsfilewidget.cpp
Expand Up @@ -236,7 +236,7 @@ void QgsFileWidget::openFileDialog()
QUrl url = QUrl::fromUserInput( oldPath );
if ( !url.isValid() )
{
QString defPath = QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() );
QString defPath = QDir::cleanPath( QFileInfo( QgsProject::instance()->absoluteFilePath() ).path() );
if ( defPath.isEmpty() )
{
defPath = QDir::homePath();
Expand Down Expand Up @@ -341,7 +341,7 @@ QString QgsFileWidget::relativePath( const QString &filePath, bool removeRelativ
QString RelativePath;
if ( mRelativeStorage == RelativeProject )
{
RelativePath = QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) );
RelativePath = QDir::toNativeSeparators( QDir::cleanPath( QFileInfo( QgsProject::instance()->absoluteFilePath() ).path() ) );
}
else if ( mRelativeStorage == RelativeDefaultPath && !mDefaultRoot.isEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsgetcontext.cpp
Expand Up @@ -99,7 +99,7 @@ namespace QgsWms
QgsServerInterface *serverIface, const QgsProject *project,
const QgsServerRequest &request )
{
parentElement.setAttribute( QStringLiteral( "id" ), "ows-context-" + project->fileInfo().baseName() );
parentElement.setAttribute( QStringLiteral( "id" ), "ows-context-" + project->baseName() );

// OWSContext General element
QDomElement generalElem = doc.createElement( QStringLiteral( "General" ) );
Expand Down

0 comments on commit 2bbdc34

Please sign in to comment.