@@ -66,7 +66,7 @@ QgsSvgSourceLineEdit::QgsSvgSourceLineEdit( QWidget *parent )
66
66
67
67
QString QgsSvgSourceLineEdit::source () const
68
68
{
69
- return mFileLineEdit ->text ();
69
+ return mBase64 . isEmpty () ? mFileLineEdit ->text () : mBase64 ;
70
70
}
71
71
72
72
void QgsSvgSourceLineEdit::setLastPathSettingsKey ( const QString &key )
@@ -76,9 +76,16 @@ void QgsSvgSourceLineEdit::setLastPathSettingsKey( const QString &key )
76
76
77
77
void QgsSvgSourceLineEdit::setSource ( const QString &source )
78
78
{
79
- if ( source == mFileLineEdit ->text () )
79
+ const bool isBase64 = source.startsWith ( QLatin1String ( " base64:" ), Qt::CaseInsensitive );
80
+
81
+ if ( ( !isBase64 && source == mFileLineEdit ->text () ) || ( isBase64 && source == mBase64 ) )
80
82
return ;
81
83
84
+ if ( isBase64 )
85
+ mBase64 = source;
86
+ else
87
+ mBase64 .clear ();
88
+
82
89
mFileLineEdit ->setText ( source );
83
90
emit sourceChanged ( source );
84
91
}
@@ -95,6 +102,7 @@ void QgsSvgSourceLineEdit::selectFile()
95
102
{
96
103
return ;
97
104
}
105
+ mBase64 .clear ();
98
106
mFileLineEdit ->setText ( file );
99
107
s.setValue ( settingsKey (), fi.absolutePath () );
100
108
emit sourceChanged ( mFileLineEdit ->text () );
@@ -106,6 +114,7 @@ void QgsSvgSourceLineEdit::selectUrl()
106
114
const QString path = QInputDialog::getText ( this , tr ( " SVG From URL" ), tr ( " Enter SVG URL" ), QLineEdit::Normal, mFileLineEdit ->text (), &ok );
107
115
if ( ok && path != source () )
108
116
{
117
+ mBase64 .clear ();
109
118
mFileLineEdit ->setText ( path );
110
119
emit sourceChanged ( mFileLineEdit ->text () );
111
120
}
@@ -141,8 +150,9 @@ void QgsSvgSourceLineEdit::embedFile()
141
150
if ( path == source () )
142
151
return ;
143
152
153
+ mBase64 = path;
144
154
mFileLineEdit ->setText ( path );
145
- emit sourceChanged ( mFileLineEdit -> text () );
155
+ emit sourceChanged ( path );
146
156
}
147
157
148
158
void QgsSvgSourceLineEdit::extractFile ()
@@ -164,7 +174,7 @@ void QgsSvgSourceLineEdit::extractFile()
164
174
QString path = mFileLineEdit ->text ().trimmed ();
165
175
if ( path.startsWith ( QLatin1String ( " base64:" ), Qt::CaseInsensitive ) )
166
176
{
167
- QByteArray base64 = path .mid ( 7 ).toLocal8Bit (); // strip 'base64:' prefix
177
+ QByteArray base64 = mBase64 .mid ( 7 ).toLocal8Bit (); // strip 'base64:' prefix
168
178
QByteArray decoded = QByteArray::fromBase64 ( base64, QByteArray::OmitTrailingEquals );
169
179
170
180
QFile fileOut ( file );
0 commit comments