@@ -56,7 +56,7 @@ QgsAbstractFileContentSourceLineEdit::QgsAbstractFileContentSourceLineEdit( QWid
56
56
57
57
connect ( sourceMenu, &QMenu::aboutToShow, this , [this , extractFileAction]
58
58
{
59
- extractFileAction->setEnabled ( mFileLineEdit -> text (). startsWith ( QLatin1String ( " base64: " ), Qt::CaseInsensitive ) );
59
+ extractFileAction->setEnabled ( mMode == ModeBase64 );
60
60
} );
61
61
62
62
QAction *enterUrlAction = new QAction ( tr ( " From URL…" ), sourceMenu );
@@ -70,6 +70,7 @@ QgsAbstractFileContentSourceLineEdit::QgsAbstractFileContentSourceLineEdit( QWid
70
70
connect ( mFileLineEdit , &QLineEdit::textEdited, this , &QgsAbstractFileContentSourceLineEdit::mFileLineEdit_textEdited );
71
71
connect ( mFileLineEdit , &QgsFilterLineEdit::cleared, this , [ = ]
72
72
{
73
+ mMode = ModeFile;
73
74
mFileLineEdit ->setPlaceholderText ( QString () );
74
75
mBase64 .clear ();
75
76
emit sourceChanged ( QString () );
@@ -79,7 +80,16 @@ QgsAbstractFileContentSourceLineEdit::QgsAbstractFileContentSourceLineEdit( QWid
79
80
80
81
QString QgsAbstractFileContentSourceLineEdit::source () const
81
82
{
82
- return mBase64 .isEmpty () ? mFileLineEdit ->text () : mBase64 ;
83
+ switch ( mMode )
84
+ {
85
+ case ModeFile:
86
+ return mFileLineEdit ->text ();
87
+
88
+ case ModeBase64:
89
+ return mBase64 ;
90
+ }
91
+
92
+ return QString ();
83
93
}
84
94
85
95
void QgsAbstractFileContentSourceLineEdit::setLastPathSettingsKey ( const QString &key )
@@ -96,12 +106,14 @@ void QgsAbstractFileContentSourceLineEdit::setSource( const QString &source )
96
106
97
107
if ( isBase64 )
98
108
{
109
+ mMode = ModeBase64;
99
110
mBase64 = source;
100
111
mFileLineEdit ->clear ();
101
112
mFileLineEdit ->setPlaceholderText ( tr ( " Embedded file" ) );
102
113
}
103
114
else
104
115
{
116
+ mMode = ModeFile;
105
117
mBase64 .clear ();
106
118
mFileLineEdit ->setText ( source );
107
119
mFileLineEdit ->setPlaceholderText ( QString () );
@@ -122,6 +134,7 @@ void QgsAbstractFileContentSourceLineEdit::selectFile()
122
134
{
123
135
return ;
124
136
}
137
+ mMode = ModeFile;
125
138
mBase64 .clear ();
126
139
mFileLineEdit ->setText ( file );
127
140
mFileLineEdit ->setPlaceholderText ( QString () );
@@ -135,6 +148,7 @@ void QgsAbstractFileContentSourceLineEdit::selectUrl()
135
148
const QString path = QInputDialog::getText ( this , fileFromUrlTitle (), fileFromUrlText (), QLineEdit::Normal, mFileLineEdit ->text (), &ok );
136
149
if ( ok && path != source () )
137
150
{
151
+ mMode = ModeFile;
138
152
mBase64 .clear ();
139
153
mFileLineEdit ->setText ( path );
140
154
mFileLineEdit ->setPlaceholderText ( QString () );
@@ -173,6 +187,7 @@ void QgsAbstractFileContentSourceLineEdit::embedFile()
173
187
return ;
174
188
175
189
mBase64 = path;
190
+ mMode = ModeBase64;
176
191
177
192
mFileLineEdit ->clear ();
178
193
mFileLineEdit ->setPlaceholderText ( tr ( " Embedded file" ) );
@@ -196,30 +211,27 @@ void QgsAbstractFileContentSourceLineEdit::extractFile()
196
211
s.setValue ( settingsKey (), fi.absolutePath () );
197
212
198
213
// decode current base64 embedded file
199
- QString path = mFileLineEdit ->text ().trimmed ();
200
- if ( path.startsWith ( QLatin1String ( " base64:" ), Qt::CaseInsensitive ) )
201
- {
202
- QByteArray base64 = mBase64 .mid ( 7 ).toLocal8Bit (); // strip 'base64:' prefix
203
- QByteArray decoded = QByteArray::fromBase64 ( base64, QByteArray::OmitTrailingEquals );
214
+ QByteArray base64 = mBase64 .mid ( 7 ).toLocal8Bit (); // strip 'base64:' prefix
215
+ QByteArray decoded = QByteArray::fromBase64 ( base64, QByteArray::OmitTrailingEquals );
204
216
205
- QFile fileOut ( file );
206
- fileOut.open ( QIODevice::WriteOnly );
207
- fileOut.write ( decoded );
208
- fileOut.close ();
217
+ QFile fileOut ( file );
218
+ fileOut.open ( QIODevice::WriteOnly );
219
+ fileOut.write ( decoded );
220
+ fileOut.close ();
209
221
210
- if ( mMessageBar )
211
- {
212
- mMessageBar ->pushMessage ( extractFileTitle (),
213
- tr ( " Successfully extracted file to <a href=\" %1\" >%2</a>" ).arg ( QUrl::fromLocalFile ( file ).toString (), QDir::toNativeSeparators ( file ) ),
214
- Qgis::Success, 0 );
215
- }
222
+ if ( mMessageBar )
223
+ {
224
+ mMessageBar ->pushMessage ( extractFileTitle (),
225
+ tr ( " Successfully extracted file to <a href=\" %1\" >%2</a>" ).arg ( QUrl::fromLocalFile ( file ).toString (), QDir::toNativeSeparators ( file ) ),
226
+ Qgis::Success, 0 );
216
227
}
217
228
}
218
229
219
230
void QgsAbstractFileContentSourceLineEdit::mFileLineEdit_textEdited ( const QString &text )
220
231
{
221
232
mFileLineEdit ->setPlaceholderText ( QString () );
222
233
mBase64 .clear ();
234
+ mMode = ModeFile;
223
235
if ( !text.isEmpty () && !QFileInfo::exists ( text ) )
224
236
{
225
237
QUrl url ( text );
0 commit comments