Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update documentation and sip binding
  • Loading branch information
pblottiere committed Jul 31, 2017
1 parent d23137e commit 75811ef
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 5 deletions.
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -127,6 +127,7 @@
%Include qgsvirtuallayerdefinitionutils.sip
%Include qgsmapthemecollection.sip
%Include qgsxmlutils.sip
%Include qgsarchive.sip
%Include qgsziputils.sip
%Include qgsvector.sip
%Include auth/qgsauthcertutils.sip
Expand Down
126 changes: 126 additions & 0 deletions python/core/qgsarchive.sip
@@ -0,0 +1,126 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsarchive.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsArchive
{
%Docstring
Class allowing to manage the zip/unzip actions on project
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsarchive.h"
%End
public:

QgsArchive();
%Docstring
Constructor
%End

QgsArchive( const QgsArchive &other );
%Docstring
Copy constructor
%End


~QgsArchive();
%Docstring
Destructor
%End

bool zip( const QString &zipFilename );
%Docstring
Zip the content of this archive
\param zipFilename The name of the zip to generate
:return: false if something goes wrong, true otherwise
:rtype: bool
%End

bool zip();
%Docstring
Zip the content of this archive. THe current filename is used.
:return: false if something goes wrong, true otherwise
:rtype: bool
%End

bool unzip( const QString &zipFilename );
%Docstring
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.
\param zipFilename The zip file to unzip
:return: true if a project file has been found, false otherwise
:rtype: bool
%End

bool unzip();
%Docstring
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.
:return: true if a project file has been found, false otherwise
:rtype: bool
%End

void clear();
%Docstring
Clear the current content of this archive and create a new temporary
directory.
%End

void addFile( const QString &filename );
%Docstring
Add a new file to this archive. During a zip action, this file will be
part of the resulting zipped file.
\param filename A file to add when zipping this archive
%End

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

QString filename() const;
%Docstring
Returns the current zip filename.
:rtype: str
%End

QString projectFile() const;
%Docstring
Returns the current .qgs project file or an empty string if there's none
:rtype: str
%End

QStringList files() const;
%Docstring
Returns the list of files within this archive
:rtype: list of str
%End

QString dir() const;
%Docstring
Returns the current temporary directory.
:rtype: str
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsarchive.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
21 changes: 20 additions & 1 deletion python/core/qgsproject.sip
Expand Up @@ -615,7 +615,15 @@ Returns the number of registered layers.
bool unzip( const QString &filename );
%Docstring
Unzip a project
\param filename The project filename to unzip
\param filename The zip file to unzip
:return: true if unzip is well performed, false otherwise
.. versionadded:: 3.0
:rtype: bool
%End

bool unzip();
%Docstring
Unzip a project with the current zip filename
:return: true if unzip is well performed, false otherwise
.. versionadded:: 3.0
:rtype: bool
Expand All @@ -632,18 +640,29 @@ Returns the number of registered layers.

bool zip();
%Docstring
Zip the project with the current zip filename
:return: true if zip is well performed, false otherwise
.. versionadded:: 3.0
:rtype: bool
%End

QString zipFileName() const;
%Docstring
Returns the current zip filename or an empty string if none.
.. versionadded:: 3.0
:rtype: str
%End

void setZipFileName( const QString &filename );
%Docstring
Sets the current zip filename.
\param filename The zip filename
.. versionadded:: 3.0
%End

bool unzipped() const;
%Docstring
Returns true if the project comes from a zip archive, false otherwise.
:rtype: bool
%End

Expand Down
32 changes: 31 additions & 1 deletion src/core/qgsarchive.cpp
Expand Up @@ -25,10 +25,24 @@ QgsArchive::QgsArchive()
{
}

QgsArchive::~QgsArchive()
QgsArchive::QgsArchive( const QgsArchive &other )
: mDir( new QTemporaryDir() )
, mFiles( other.mFiles )
, mFilename( other.mFilename )
{
}

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

return *this;
}

QString QgsArchive::dir() const
{
return mDir->path();
Expand All @@ -41,6 +55,14 @@ void QgsArchive::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
Expand Down Expand Up @@ -75,6 +97,14 @@ bool QgsArchive::zip( const QString &filename )
return true;
}

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

bool QgsArchive::unzip( const QString &filename )
{
clear();
Expand Down
69 changes: 67 additions & 2 deletions src/core/qgsarchive.h
Expand Up @@ -36,30 +36,94 @@ class CORE_EXPORT QgsArchive
public:

/**
* Constructor for QgsArchive
* Constructor
*/
QgsArchive();
~QgsArchive();

/**
* Copy constructor
*/
QgsArchive( const QgsArchive &other );

QgsArchive &operator=( const QgsArchive &other );

/**
* Destructor
*/
~QgsArchive() = default;

/**
* Zip the content of this archive
* \param zipFilename The name of the zip to generate
* \returns false if something goes wrong, true otherwise
*/
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. 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.
* \param zipFilename The zip file to unzip
* \returns true if a project file has been found, false otherwise
*/
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.
*/
void clear();

/**
* Add a new file to this archive. During a zip action, this file will be
* part of the resulting zipped file.
* \param filename A file to add when zipping this archive
*/
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 current .qgs project file or an empty string if there's none
*/
QString projectFile() const;

/**
* Returns the list of files within this archive
*/
QStringList files() const;

/**
* Returns the current temporary directory.
*/
QString dir() const;

private:
#ifndef SIP_RUN
// used when unzip is performed
std::unique_ptr<QTemporaryDir> mDir;

Expand All @@ -68,6 +132,7 @@ class CORE_EXPORT QgsArchive

// zip filename
QString mFilename;
#endif
};

#endif
5 changes: 5 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -2071,6 +2071,11 @@ QList<QgsMapLayer *> QgsProject::mapLayersByName( const QString &layerName ) con
return mLayerStore->mapLayersByName( layerName );
}

bool QgsProject::unzip()
{
return unzip( mArchive->filename() );
}

bool QgsProject::unzip( const QString &filename )
{
clearError();
Expand Down

0 comments on commit 75811ef

Please sign in to comment.