Skip to content
Permalink
Browse files

Remove zip/unzip methods from QgsProject

  • Loading branch information
pblottiere committed Jul 31, 2017
1 parent 2d660a1 commit 3480390dd62aee74bf39650574438c3a3219714c
Showing with 86 additions and 216 deletions.
  1. +6 −35 src/app/qgisapp.cpp
  2. +0 −33 src/core/qgsarchive.cpp
  3. +0 −29 src/core/qgsarchive.h
  4. +55 −72 src/core/qgsproject.cpp
  5. +13 −47 src/core/qgsproject.h
  6. +5 −0 src/core/qgsziputils.cpp
  7. +7 −0 src/core/qgsziputils.h
@@ -5285,15 +5285,7 @@ bool QgisApp::addProject( const QString &projectFile )
bool autoSetupOnFirstLayer = mLayerTreeCanvasBridge->autoSetupOnFirstLayer();
mLayerTreeCanvasBridge->setAutoSetupOnFirstLayer( false );

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

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

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

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

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

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

bool writeOk = false;
QString writtenFileName;

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

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

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

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

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

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

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

if ( writeOk )
{
setTitleBarText_( *this ); // update title bar
@@ -29,17 +29,13 @@ QgsArchive::QgsArchive()
QgsArchive::QgsArchive( const QgsArchive &other )
: mFiles( other.mFiles )
, mDir( new QTemporaryDir() )
, mFilename( other.mFilename )
{
}

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

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

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

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

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

return true;
}

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

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

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

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

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

QStringList QgsArchive::files() const
{
return mFiles;
@@ -59,12 +59,6 @@ class CORE_EXPORT QgsArchive
*/
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
* in the temporary directory.
@@ -73,15 +67,6 @@ class CORE_EXPORT QgsArchive
*/
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
* directory.
@@ -95,17 +80,6 @@ class CORE_EXPORT QgsArchive
*/
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
*/
@@ -124,9 +98,6 @@ class CORE_EXPORT QgsArchive
#ifndef SIP_RUN
// used when unzip is performed
std::unique_ptr<QTemporaryDir> mDir;

// zip filename
QString mFilename;
#endif
};

0 comments on commit 3480390

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