Skip to content
Permalink
Browse files

Deprecate QgsProject::fileInfo()

  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent 3c3de3f commit 2bbdc343344a47157152ddaa8bbfe2fcee9da1f7
@@ -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.

@@ -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()
@@ -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 );

@@ -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
@@ -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 );
@@ -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();
}
@@ -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 ) );
@@ -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).
@@ -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() );

@@ -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 );
@@ -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 );
@@ -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();
@@ -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() )
{
@@ -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" ) );

0 comments on commit 2bbdc34

Please sign in to comment.
You can’t perform that action at this time.