File tree Expand file tree Collapse file tree 3 files changed +30
-15
lines changed Expand file tree Collapse file tree 3 files changed +30
-15
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,14 @@ class QgsArchive
67
67
\param filename A file to add when zipping this archive
68
68
%End
69
69
70
+ bool removeFile( const QString &filename );
71
+ %Docstring
72
+ Remove a file from this archive and from the filesystem.
73
+ \param filename The path of the file to remove
74
+ :return: true if the file has been removed from the filesystem, false otherwise
75
+ :rtype: bool
76
+ %End
77
+
70
78
QStringList files() const;
71
79
%Docstring
72
80
Returns the list of files within this archive
@@ -79,8 +87,6 @@ class QgsArchive
79
87
:rtype: str
80
88
%End
81
89
82
- protected:
83
-
84
90
};
85
91
86
92
class QgsProjectArchive : QgsArchive
Original file line number Diff line number Diff line change @@ -95,14 +95,26 @@ void QgsArchive::addFile( const QString &file )
95
95
mFiles .append ( file );
96
96
}
97
97
98
+ bool QgsArchive::removeFile ( const QString &file )
99
+ {
100
+ bool rc = false ;
101
+
102
+ if ( !file.isEmpty () && mFiles .contains ( file ) && QFile::exists ( file ) )
103
+ rc = QFile::remove ( file );
104
+
105
+ mFiles .removeOne ( file );
106
+
107
+ return rc;
108
+ }
109
+
98
110
QStringList QgsArchive::files () const
99
111
{
100
112
return mFiles ;
101
113
}
102
114
103
115
QString QgsProjectArchive::projectFile () const
104
116
{
105
- Q_FOREACH ( const QString &file, mFiles )
117
+ Q_FOREACH ( const QString &file, files () )
106
118
{
107
119
QFileInfo fileInfo ( file );
108
120
if ( fileInfo.suffix ().compare ( QLatin1String ( " qgs" ), Qt::CaseInsensitive ) == 0 )
@@ -122,14 +134,5 @@ bool QgsProjectArchive::unzip( const QString &filename )
122
134
123
135
bool QgsProjectArchive::clearProjectFile ()
124
136
{
125
- bool rc = false ;
126
- QString file = projectFile ();
127
-
128
- if ( !file.isEmpty () && QFile::exists ( file ) )
129
- rc = QFile::remove ( file );
130
-
131
- if ( rc )
132
- mFiles .removeOne ( file );
133
-
134
- return rc;
137
+ return removeFile ( projectFile () );
135
138
}
Original file line number Diff line number Diff line change @@ -80,6 +80,13 @@ class CORE_EXPORT QgsArchive
80
80
*/
81
81
void addFile ( const QString &filename );
82
82
83
+ /* *
84
+ * Remove a file from this archive and from the filesystem.
85
+ * \param filename The path of the file to remove
86
+ * \returns true if the file has been removed from the filesystem, false otherwise
87
+ */
88
+ bool removeFile ( const QString &filename );
89
+
83
90
/* *
84
91
* Returns the list of files within this archive
85
92
*/
@@ -90,11 +97,10 @@ class CORE_EXPORT QgsArchive
90
97
*/
91
98
QString dir () const ;
92
99
93
- protected :
100
+ private :
94
101
// content of the archive
95
102
QStringList mFiles ;
96
103
97
- private:
98
104
// used when unzip is performed
99
105
std::unique_ptr<QTemporaryDir> mDir ;
100
106
};
You can’t perform that action at this time.
0 commit comments