Skip to content

Commit 00d31f6

Browse files
committedMay 16, 2019
Revert "Merge pull request #10002 from m-kuhn/qgz-attachments"
This reverts commit 0804e34, reversing changes made to e07741f.
1 parent b992999 commit 00d31f6

File tree

8 files changed

+10
-169
lines changed

8 files changed

+10
-169
lines changed
 

‎python/core/auto_generated/qgsproject.sip.in

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -974,34 +974,6 @@ provider.
974974
Returns the current auxiliary storage.
975975

976976
.. versionadded:: 3.0
977-
%End
978-
979-
QString attachedFile( const QString &fileName ) const;
980-
%Docstring
981-
Returns the path to an attached file known by ``fileName``.
982-
983-
.. note::
984-
985-
Attached files are only supported by QGZ file based projects
986-
987-
.. seealso:: :py:func:`collectAttachedFiles`
988-
989-
.. versionadded:: 3.8
990-
%End
991-
992-
QgsStringMap attachedFiles() const;
993-
%Docstring
994-
Returns a map of all attached files with relative paths and real paths.
995-
996-
.. note::
997-
998-
Attached files are only supported by QGZ file based projects
999-
1000-
.. seealso:: :py:func:`collectAttachedFiles`
1001-
1002-
.. seealso:: :py:func:`attachedFile`
1003-
1004-
.. versionadded:: 3.8
1005977
%End
1006978

1007979
const QgsProjectMetadata &metadata() const;
@@ -1418,31 +1390,6 @@ Emitted when the project dirty status changes.
14181390
:param dirty: ``True`` if the project is in a dirty state and has pending unsaved changes.
14191391

14201392
.. versionadded:: 3.2
1421-
%End
1422-
1423-
void collectAttachedFiles( QgsStringMap &files /In,Out/ );
1424-
%Docstring
1425-
Emitted whenever the project is saved to a qgz file.
1426-
This can be used to package additional files into the qgz file by modifying the ``files`` map.
1427-
1428-
Map keys represent relative paths inside the qgz file, map values represent the path to
1429-
the source file.
1430-
1431-
In python, append additional files to the map and return the modified map.
1432-
1433-
.. code-block:: python
1434-
1435-
QgsProject.instance().collectAttachedFiles.connect(lambda files: files + ['/absolute/path/to/my/attachment.txt'])
1436-
1437-
.. note::
1438-
1439-
Only will be emitted with QGZ project files
1440-
1441-
.. seealso:: :py:func:`attachedFiles`
1442-
1443-
.. seealso:: :py:func:`attachedFile`
1444-
1445-
.. versionadded:: 3.8
14461393
%End
14471394

14481395
public slots:

‎python/core/auto_generated/qgsziputils.sip.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ Unzip a zip file in an output directory.
3939
.. versionadded:: 3.0
4040
%End
4141

42-
bool zip( const QString &zip, const QStringList &files, const QString &root = QString() );
42+
bool zip( const QString &zip, const QStringList &files );
4343
%Docstring
4444
Zip the list of files in the zip file. If the zip file already exists or is
4545
empty, an error is returned. If an input file does not exist, an error is
4646
also returned.
4747

4848
:param zip: The zip filename
4949
:param files: The absolute path to files to embed within the zip
50-
:param root: The root path in which the files are located. This is used to determine the relative path inside the zip file.
5150

5251
.. versionadded:: 3.0
5352
%End

‎src/core/qgsarchive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool QgsArchive::zip( const QString &filename )
6161
QFile tmpFile( tempPath + QDir::separator() + uuid );
6262

6363
// zip content
64-
if ( ! QgsZipUtils::zip( tmpFile.fileName(), mFiles, dir() ) )
64+
if ( ! QgsZipUtils::zip( tmpFile.fileName(), mFiles ) )
6565
{
6666
QString err = QObject::tr( "Unable to zip content" );
6767
QgsMessageLog::logMessage( err, QStringLiteral( "QgsArchive" ) );

‎src/core/qgsproject.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,26 +2763,10 @@ bool QgsProject::zip( const QString &filename )
27632763
return false;
27642764
}
27652765

2766-
QgsStringMap attachedFiles;
2767-
emit collectAttachedFiles( attachedFiles );
2768-
27692766
// create the archive
27702767
archive->addFile( qgsFile.fileName() );
27712768
archive->addFile( asFileName );
27722769

2773-
// add additional collected attachment files
2774-
auto attachedFilesIterator = attachedFiles.constBegin();
2775-
while ( attachedFilesIterator != attachedFiles.constEnd() )
2776-
{
2777-
QString filepath = info.path() + QDir::separator() + attachedFilesIterator.key();
2778-
QDir().mkpath( QFileInfo( filepath ).dir().path() );
2779-
if ( QFile::copy( attachedFilesIterator.value(), filepath ) )
2780-
archive->addFile( filepath );
2781-
else
2782-
QgsMessageLog::logMessage( QStringLiteral( "Could not copy file '%1' to '%2'" ).arg( attachedFilesIterator.value(), filepath ) );
2783-
++attachedFilesIterator;
2784-
}
2785-
27862770
// zip
27872771
if ( !archive->zip( filename ) )
27882772
{
@@ -2972,21 +2956,6 @@ QgsAuxiliaryStorage *QgsProject::auxiliaryStorage()
29722956
return mAuxiliaryStorage.get();
29732957
}
29742958

2975-
QString QgsProject::attachedFile( const QString &fileName ) const
2976-
{
2977-
return mArchive->dir() + QDir::separator() + fileName;
2978-
}
2979-
2980-
QgsStringMap QgsProject::attachedFiles() const
2981-
{
2982-
QgsStringMap files;
2983-
QString dir = mArchive->dir();
2984-
const QStringList tempFiles = mArchive->files();
2985-
for ( const QString &tempFile : tempFiles )
2986-
files.insert( tempFile, dir + QDir::separator() + tempFile );
2987-
return files;
2988-
}
2989-
29902959
const QgsProjectMetadata &QgsProject::metadata() const
29912960
{
29922961
return mMetadata;

‎src/core/qgsproject.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -966,25 +966,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
966966
*/
967967
QgsAuxiliaryStorage *auxiliaryStorage();
968968

969-
/**
970-
* Returns the path to an attached file known by \a fileName.
971-
*
972-
* \note Attached files are only supported by QGZ file based projects
973-
* \see collectAttachedFiles()
974-
* \since QGIS 3.8
975-
*/
976-
QString attachedFile( const QString &fileName ) const;
977-
978-
/**
979-
* Returns a map of all attached files with relative paths and real paths.
980-
*
981-
* \note Attached files are only supported by QGZ file based projects
982-
* \see collectAttachedFiles()
983-
* \see attachedFile()
984-
* \since QGIS 3.8
985-
*/
986-
QgsStringMap attachedFiles() const;
987-
988969
/**
989970
* Returns a reference to the project's metadata store.
990971
* \see setMetadata()
@@ -1348,26 +1329,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
13481329
*/
13491330
void isDirtyChanged( bool dirty );
13501331

1351-
/**
1352-
* Emitted whenever the project is saved to a qgz file.
1353-
* This can be used to package additional files into the qgz file by modifying the \a files map.
1354-
*
1355-
* Map keys represent relative paths inside the qgz file, map values represent the path to
1356-
* the source file.
1357-
*
1358-
* In python, append additional files to the map and return the modified map.
1359-
*
1360-
* \code{.py}
1361-
* QgsProject.instance().collectAttachedFiles.connect(lambda files: files + ['/absolute/path/to/my/attachment.txt'])
1362-
* \endcode
1363-
*
1364-
* \note Only will be emitted with QGZ project files
1365-
* \see attachedFiles()
1366-
* \see attachedFile()
1367-
* \since QGIS 3.8
1368-
*/
1369-
void collectAttachedFiles( QgsStringMap &files SIP_INOUT );
1370-
13711332
public slots:
13721333

13731334
/**

‎src/core/qgsziputils.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QString
8282
if ( zip_fread( file, buf.get(), len ) != -1 )
8383
{
8484
QString fileName( stat.name );
85-
// remove leading `/` e.g. `/project.qgs` -> `project.qgs`
86-
while ( fileName.startsWith( QDir::separator() ) )
87-
fileName.remove( 0, 1 );
8885
QFileInfo newFile( QDir( dir ), fileName );
8986

9087
// Create path for a new file if it does not exist.
@@ -132,7 +129,7 @@ bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QString
132129
return true;
133130
}
134131

135-
bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files, const QString &root )
132+
bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files )
136133
{
137134
if ( zipFilename.isEmpty() )
138135
{
@@ -156,22 +153,15 @@ bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files, con
156153
return false;
157154
}
158155

159-
const QByteArray filePathUtf8 = file.toUtf8();
160-
zip_source *src = zip_source_file( z, filePathUtf8.constData(), 0, 0 );
156+
const QByteArray fileNamePtr = file.toUtf8();
157+
zip_source *src = zip_source_file( z, fileNamePtr.constData(), 0, 0 );
161158
if ( src )
162159
{
163-
QString fileName;
164-
if ( root.isEmpty() || !file.startsWith( root ) )
165-
fileName = fileInfo.fileName();
166-
else
167-
fileName = file.right( file.length() - root.length() );
168-
169-
170-
const QByteArray fileNameUtf8 = fileName.toUtf8();
160+
const QByteArray fileInfoPtr = fileInfo.fileName().toUtf8();
171161
#if LIBZIP_VERSION_MAJOR < 1
172-
int rc = ( int ) zip_add( z, fileNameUtf8.constData(), src );
162+
int rc = ( int ) zip_add( z, fileInfoPtr.constData(), src );
173163
#else
174-
int rc = ( int ) zip_file_add( z, fileNameUtf8.constData(), src, 0 );
164+
int rc = ( int ) zip_file_add( z, fileInfoPtr.constData(), src, 0 );
175165
#endif
176166
if ( rc == -1 )
177167
{

‎src/core/qgsziputils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ namespace QgsZipUtils
5454
* also returned.
5555
* \param zip The zip filename
5656
* \param files The absolute path to files to embed within the zip
57-
* \param root The root path in which the files are located. This is used to determine the relative path inside the zip file.
5857
* \since QGIS 3.0
5958
*/
60-
CORE_EXPORT bool zip( const QString &zip, const QStringList &files, const QString &root = QString() );
59+
CORE_EXPORT bool zip( const QString &zip, const QStringList &files );
6160
};
6261

6362
#endif //QGSZIPUTILS_H

‎tests/src/core/testqgsproject.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class TestQgsProject : public QObject
4343
void testLayerFlags();
4444
void testLocalFiles();
4545
void testLocalUrlFiles();
46-
void testAttachedFiles();
4746
};
4847

4948
void TestQgsProject::init()
@@ -405,6 +404,7 @@ void TestQgsProject::testLocalFiles()
405404
f2.close();
406405
QgsPathResolver resolver( f.fileName( ) );
407406
QCOMPARE( resolver.writePath( layerPath ), QString( "./" + info.baseName() + ".shp" ) ) ;
407+
408408
}
409409

410410
void TestQgsProject::testLocalUrlFiles()
@@ -427,30 +427,6 @@ void TestQgsProject::testLocalUrlFiles()
427427

428428
}
429429

430-
void TestQgsProject::testAttachedFiles()
431-
{
432-
QTemporaryDir dir;
433-
QString qgzFileName = dir.filePath( QStringLiteral( "project.qgz" ) );
434-
435-
QTemporaryFile attachedFile;
436-
437-
if ( attachedFile.open() )
438-
{
439-
QTextStream stream( &attachedFile );
440-
stream << QStringLiteral( "success" ) << endl;
441-
}
442-
443-
QgsProject prj;
444-
connect( &prj, &QgsProject::collectAttachedFiles, this, [ &attachedFile ]( QgsStringMap & files ) { files.insert( QStringLiteral( "test/file.txt" ), attachedFile.fileName() ); } );
445-
prj.write( qgzFileName );
446-
prj.clear();
447-
prj.read( qgzFileName );
448-
QFile extractedFile( prj.attachedFile( QStringLiteral( "test/file.txt" ) ) );
449-
extractedFile.open( QFile::ReadOnly | QFile::Text );
450-
QTextStream in( &extractedFile );
451-
QCOMPARE( QString::fromUtf8( extractedFile.readAll().constData() ), QStringLiteral( "success\n" ) );
452-
}
453-
454430

455431
QGSTEST_MAIN( TestQgsProject )
456432
#include "testqgsproject.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.