Skip to content

Commit

Permalink
Emit newProject after save project as ... (#30025)
Browse files Browse the repository at this point in the history
* Emit newProject after save project as ...

Fixes #29919

* Use QgisApp::projectSavedAs signal when project is saved with a new path

* Update browser project home path when saved as

* Set home path when reading a project

* Emit homePathChanged in any case
  • Loading branch information
elpaso committed Jun 6, 2019
1 parent 3bd5a49 commit 58fcd60
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgsbrowsermodel.sip.in
Expand Up @@ -154,6 +154,7 @@ and on Linux the "/" root directory.
%End

signals:

void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );
%Docstring
Emitted when item children fetch was finished
Expand Down Expand Up @@ -222,6 +223,7 @@ Delayed initialization, needed because the provider registry must be already pop
.. seealso:: :py:func:`initialized`
%End


protected:
void addRootItems();
%Docstring
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -1063,7 +1063,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );
mBrowserWidget->hide();
connect( this, &QgisApp::newProject, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome );
// Only connect the first widget: the model is shared, there is no need to refresh multiple times.
connect( this, &QgisApp::connectionsChanged, mBrowserWidget, &QgsBrowserDockWidget::refresh );
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgisApp::connectionsChanged );
Expand All @@ -1074,7 +1073,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mBrowserWidget2->setObjectName( QStringLiteral( "Browser2" ) );
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget2 );
mBrowserWidget2->hide();
connect( this, &QgisApp::newProject, mBrowserWidget2, &QgsBrowserDockWidget::updateProjectHome );
connect( mBrowserWidget2, &QgsBrowserDockWidget::connectionsChanged, this, &QgisApp::connectionsChanged );
connect( mBrowserWidget2, &QgsBrowserDockWidget::openFile, this, &QgisApp::openFile );
connect( mBrowserWidget2, &QgsBrowserDockWidget::handleDropUriList, this, &QgisApp::handleDropUriList );
Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsbrowsermodel.cpp
Expand Up @@ -183,12 +183,11 @@ QMap<QString, QgsDirectoryItem *> QgsBrowserModel::driveItems() const
return mDriveItems;
}


void QgsBrowserModel::initialize()
{
if ( ! mInitialized )
{
connect( QgsProject::instance(), &QgsProject::readProject, this, &QgsBrowserModel::updateProjectHome );
connect( QgsProject::instance(), &QgsProject::projectSaved, this, &QgsBrowserModel::updateProjectHome );
connect( QgsProject::instance(), &QgsProject::homePathChanged, this, &QgsBrowserModel::updateProjectHome );
addRootItems();
mInitialized = true;
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsbrowsermodel.h
Expand Up @@ -171,6 +171,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
QMap<QString, QgsDirectoryItem *> driveItems() const;

signals:

//! Emitted when item children fetch was finished
void stateChanged( const QModelIndex &index, QgsDataItem::State oldState );

Expand Down Expand Up @@ -236,6 +237,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
*/
void initialize();


protected:
//! Populates the model
void addRootItems();
Expand Down
48 changes: 25 additions & 23 deletions src/core/qgsproject.cpp
Expand Up @@ -695,7 +695,7 @@ void QgsProject::clear()

mFile.setFileName( QString() );
mProperties.clearKeys();
mHomePath.clear();
mHomePath = QString();
mAutoTransaction = false;
mEvaluateDefaultValues = false;
mDirty = false;
Expand Down Expand Up @@ -751,6 +751,7 @@ void QgsProject::clear()
mRootGroup->clear();

setDirty( false );
emit homePathChanged();
emit cleared();
}

Expand Down Expand Up @@ -1035,7 +1036,7 @@ bool QgsProject::read( const QString &filename )
bool QgsProject::read()
{
QString filename = mFile.fileName();
bool rc;
bool returnValue;

if ( QgsProjectStorage *storage = projectStorage() )
{
Expand All @@ -1057,32 +1058,33 @@ bool QgsProject::read()
setError( err );
return false;
}

return unzip( inDevice.fileName() ); // calls setError() if returning false
}

if ( QgsZipUtils::isZipFile( mFile.fileName() ) )
{
rc = unzip( mFile.fileName() );
returnValue = unzip( inDevice.fileName() ); // calls setError() if returning false
}
else
{
mAuxiliaryStorage.reset( new QgsAuxiliaryStorage( *this ) );
rc = readProjectFile( mFile.fileName() );
}
if ( QgsZipUtils::isZipFile( mFile.fileName() ) )
{
returnValue = unzip( mFile.fileName() );
}
else
{
mAuxiliaryStorage.reset( new QgsAuxiliaryStorage( *this ) );
returnValue = readProjectFile( mFile.fileName() );
}

//on translation we should not change the filename back
if ( !mTranslator )
{
mFile.setFileName( filename );
}
else
{
//but delete the translator
mTranslator.reset( nullptr );
//on translation we should not change the filename back
if ( !mTranslator )
{
mFile.setFileName( filename );
}
else
{
//but delete the translator
mTranslator.reset( nullptr );
}
}

return rc;
emit homePathChanged();
return returnValue;
}

bool QgsProject::readProjectFile( const QString &filename )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsbrowserdockwidget.cpp
Expand Up @@ -156,7 +156,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent *e )
mPropertiesWidgetHeight = settings.value( settingsSection() + "/propertiesWidgetHeight" ).toFloat();
QList<int> sizes = mSplitter->sizes();
int total = sizes.value( 0 ) + sizes.value( 1 );
int height = static_cast<int>( total ) * mPropertiesWidgetHeight;
int height = static_cast<int>( total * mPropertiesWidgetHeight );
sizes.clear();
sizes << total - height << height;
mSplitter->setSizes( sizes );
Expand Down

0 comments on commit 58fcd60

Please sign in to comment.