Skip to content

Commit

Permalink
Remove zip/unzip methods from QgsProject
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jul 31, 2017
1 parent 2d660a1 commit 3480390
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 216 deletions.
41 changes: 6 additions & 35 deletions src/app/qgisapp.cpp
Expand Up @@ -5285,15 +5285,7 @@ bool QgisApp::addProject( const QString &projectFile )
bool autoSetupOnFirstLayer = mLayerTreeCanvasBridge->autoSetupOnFirstLayer(); bool autoSetupOnFirstLayer = mLayerTreeCanvasBridge->autoSetupOnFirstLayer();
mLayerTreeCanvasBridge->setAutoSetupOnFirstLayer( false ); mLayerTreeCanvasBridge->setAutoSetupOnFirstLayer( false );


bool readOk = false; bool readOk = QgsProject::instance()->read( projectFile );
if ( zip )
{
readOk = QgsProject::instance()->unzip( projectFile );
}
else
{
readOk = QgsProject::instance()->read( projectFile );
}


if ( !readOk && !zip ) if ( !readOk && !zip )
{ {
Expand Down Expand Up @@ -5429,7 +5421,7 @@ bool QgisApp::fileSave()
// that the project file name is reset to null in fileNew() // that the project file name is reset to null in fileNew()
QFileInfo fullPath; QFileInfo fullPath;


if ( QgsProject::instance()->fileName().isNull() && QgsProject::instance()->zipFileName().isNull() ) if ( QgsProject::instance()->fileName().isNull() )
{ {
// Retrieve last used project dir from persistent settings // Retrieve last used project dir from persistent settings
QgsSettings settings; QgsSettings settings;
Expand All @@ -5453,22 +5445,16 @@ bool QgisApp::fileSave()
{ {
if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 ) if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 )
fullPath.setFile( fullPath.filePath() + ".qgz" ); fullPath.setFile( fullPath.filePath() + ".qgz" );

QgsProject::instance()->setZipFileName( fullPath.filePath() );
} }
else else
{ {
if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 ) if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 )
fullPath.setFile( fullPath.filePath() + ".qgs" ); fullPath.setFile( fullPath.filePath() + ".qgs" );

QgsProject::instance()->setFileName( fullPath.filePath() );
} }
} }
else else
{ {
QFileInfo fi( QgsProject::instance()->fileName() ); QFileInfo fi( QgsProject::instance()->fileName() );
if ( QgsProject::instance()->unzipped() )
fi.setFile( QgsProject::instance()->zipFileName() );


fullPath = fi.absoluteFilePath(); fullPath = fi.absoluteFilePath();
if ( fi.exists() && !mProjectLastModified.isNull() && mProjectLastModified != fi.lastModified() ) if ( fi.exists() && !mProjectLastModified.isNull() && mProjectLastModified != fi.lastModified() )
Expand All @@ -5493,19 +5479,8 @@ bool QgisApp::fileSave()
} }
} }


bool writeOk = false; bool writeOk = QgsProject::instance()->write( fullPath.filePath() );
QString writtenFileName; QString writtenFileName = QgsProject::instance()->fileName();

if ( QgsProject::instance()->unzipped() )
{
writeOk = QgsProject::instance()->zip();
writtenFileName = QgsProject::instance()->zipFileName();
}
else
{
writeOk = QgsProject::instance()->write();
writtenFileName = QgsProject::instance()->fileName();
}


if ( writeOk ) if ( writeOk )
{ {
Expand Down Expand Up @@ -5554,23 +5529,19 @@ void QgisApp::fileSaveAs()


settings.setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() ); settings.setValue( QStringLiteral( "UI/lastProjectDir" ), fullPath.path() );


bool writeOk = false;
if ( filter == zipExt ) if ( filter == zipExt )
{ {
if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 ) if ( fullPath.suffix().compare( QLatin1String( "qgz" ), Qt::CaseInsensitive ) != 0 )
fullPath.setFile( fullPath.filePath() + ".qgz" ); fullPath.setFile( fullPath.filePath() + ".qgz" );

writeOk = QgsProject::instance()->zip( fullPath.filePath() );
} }
else // .qgs else // .qgs
{ {
if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 ) if ( fullPath.suffix().compare( QLatin1String( "qgs" ), Qt::CaseInsensitive ) != 0 )
fullPath.setFile( fullPath.filePath() + ".qgs" ); fullPath.setFile( fullPath.filePath() + ".qgs" );

QgsProject::instance()->setFileName( fullPath.filePath() );
writeOk = QgsProject::instance()->write();
} }


bool writeOk = QgsProject::instance()->write( fullPath.filePath() );

if ( writeOk ) if ( writeOk )
{ {
setTitleBarText_( *this ); // update title bar setTitleBarText_( *this ); // update title bar
Expand Down
33 changes: 0 additions & 33 deletions src/core/qgsarchive.cpp
Expand Up @@ -29,17 +29,13 @@ QgsArchive::QgsArchive()
QgsArchive::QgsArchive( const QgsArchive &other ) QgsArchive::QgsArchive( const QgsArchive &other )
: mFiles( other.mFiles ) : mFiles( other.mFiles )
, mDir( new QTemporaryDir() ) , mDir( new QTemporaryDir() )
, mFilename( other.mFilename )
{ {
} }


QgsArchive &QgsArchive::operator=( const QgsArchive &other ) QgsArchive &QgsArchive::operator=( const QgsArchive &other )
{ {
if ( this != &other ) if ( this != &other )
{
mFilename = other.mFilename;
mFiles = other.mFiles; mFiles = other.mFiles;
}


return *this; return *this;
} }
Expand All @@ -52,18 +48,9 @@ QString QgsArchive::dir() const
void QgsArchive::clear() void QgsArchive::clear()
{ {
mDir.reset( new QTemporaryDir() ); mDir.reset( new QTemporaryDir() );
mFilename.clear();
mFiles.clear(); mFiles.clear();
} }


bool QgsArchive::zip()
{
if ( mFilename.isEmpty() )
return false;
else
return zip( mFilename );
}

bool QgsArchive::zip( const QString &filename ) bool QgsArchive::zip( const QString &filename )
{ {
// create a temporary path // create a temporary path
Expand Down Expand Up @@ -93,23 +80,13 @@ bool QgsArchive::zip( const QString &filename )


// keep the zip filename // keep the zip filename
tmpFile.setAutoRemove( false ); tmpFile.setAutoRemove( false );
mFilename = filename;


return true; return true;
} }


bool QgsArchive::unzip()
{
if ( mFilename.isEmpty() )
return false;
else
return unzip( mFilename );
}

bool QgsArchive::unzip( const QString &filename ) bool QgsArchive::unzip( const QString &filename )
{ {
clear(); clear();
mFilename = filename;
return QgsZipUtils::unzip( filename, mDir->path(), mFiles ); return QgsZipUtils::unzip( filename, mDir->path(), mFiles );
} }


Expand All @@ -118,16 +95,6 @@ void QgsArchive::addFile( const QString &file )
mFiles.append( file ); mFiles.append( file );
} }


QString QgsArchive::filename() const
{
return mFilename;
}

void QgsArchive::setFileName( const QString &filename )
{
mFilename = filename;
}

QStringList QgsArchive::files() const QStringList QgsArchive::files() const
{ {
return mFiles; return mFiles;
Expand Down
29 changes: 0 additions & 29 deletions src/core/qgsarchive.h
Expand Up @@ -59,12 +59,6 @@ class CORE_EXPORT QgsArchive
*/ */
bool zip( const QString &zipFilename ); bool zip( const QString &zipFilename );


/**
* Zip the content of this archive. THe current filename is used.
* \returns false if something goes wrong, true otherwise
*/
bool zip();

/** /**
* Clear the current content of this archive and unzip. Files are unzipped * Clear the current content of this archive and unzip. Files are unzipped
* in the temporary directory. * in the temporary directory.
Expand All @@ -73,15 +67,6 @@ class CORE_EXPORT QgsArchive
*/ */
virtual bool unzip( const QString &zipFilename ); virtual bool unzip( const QString &zipFilename );


/**
* Clear the current content of this archive and unzip. If a project file
* is found in the content, then this archive may be considered as a valid
* one. Files are unzipped in the temporary directory. The current filename
* is used.
* \returns true if a project file has been found, false otherwise
*/
bool unzip();

/** /**
* Clear the current content of this archive and create a new temporary * Clear the current content of this archive and create a new temporary
* directory. * directory.
Expand All @@ -95,17 +80,6 @@ class CORE_EXPORT QgsArchive
*/ */
void addFile( const QString &filename ); void addFile( const QString &filename );


/**
* Set the filename to use when zipping/unzipping this archive.
* \param filename The zip filename
*/
void setFileName( const QString &filename );

/**
* Returns the current zip filename.
*/
QString filename() const;

/** /**
* Returns the list of files within this archive * Returns the list of files within this archive
*/ */
Expand All @@ -124,9 +98,6 @@ class CORE_EXPORT QgsArchive
#ifndef SIP_RUN #ifndef SIP_RUN
// used when unzip is performed // used when unzip is performed
std::unique_ptr<QTemporaryDir> mDir; std::unique_ptr<QTemporaryDir> mDir;

// zip filename
QString mFilename;
#endif #endif
}; };


Expand Down

0 comments on commit 3480390

Please sign in to comment.