|
14 | 14 | ***************************************************************************/ |
15 | 15 | #include "qgseditformconfig_p.h" |
16 | 16 | #include "qgseditformconfig.h" |
17 | | -#include "qgsnetworkcontentfetcher.h" |
| 17 | +#include "qgsnetworkcontentfetcherregistry.h" |
18 | 18 | #include "qgspathresolver.h" |
19 | 19 | #include "qgsproject.h" |
20 | 20 | #include "qgsreadwritecontext.h" |
@@ -147,75 +147,31 @@ void QgsEditFormConfig::setLayout( QgsEditFormConfig::EditorLayout editorLayout |
147 | 147 | d->mConfiguredRootContainer = true; |
148 | 148 | } |
149 | 149 |
|
150 | | -QString QgsEditFormConfig::uiForm( FormPath path ) const |
| 150 | +QString QgsEditFormConfig::uiForm() const |
151 | 151 | { |
152 | | - if ( path == Original && !d->mUiFormUrl.isEmpty() ) |
153 | | - return d->mUiFormUrl; |
154 | | - else |
155 | | - return d->mUiFormPath; |
| 152 | + return d->mUiFormPath; |
156 | 153 | } |
157 | 154 |
|
158 | 155 | bool QgsEditFormConfig::setUiForm( const QString &ui, QString *errMsg ) |
159 | 156 | { |
160 | | - bool success = false; |
161 | | - |
162 | | - if ( !ui.isEmpty() && ui == d->mUiFormUrl && !d->mUiFormPath.isEmpty() ) |
163 | | - { |
164 | | - // do not download again if URL did not change and was correctly loaded before |
165 | | - return success; |
166 | | - } |
167 | | - |
168 | | - // if the ui points to a URL make a local copy |
169 | | - QString formPath = ui; |
170 | | - QString formUrl = QString(); |
| 157 | + Q_UNUSED( errMsg ); |
171 | 158 | if ( !ui.isEmpty() && !QUrl::fromUserInput( ui ).isLocalFile() ) |
172 | 159 | { |
173 | | - formPath = QString(); |
174 | | - formUrl = ui; |
175 | | - |
176 | | - QgsNetworkContentFetcher fetcher; |
177 | | - QEventLoop loop; |
178 | | - QObject::connect( &fetcher, &QgsNetworkContentFetcher::finished, &loop, &QEventLoop::quit ); |
179 | | - fetcher.fetchContent( QUrl( ui ) ); |
180 | | - |
181 | | - //wait until form is fetched |
182 | | - loop.exec( QEventLoop::ExcludeUserInputEvents ); |
183 | | - |
184 | | - QNetworkReply *reply = fetcher.reply(); |
185 | | - if ( reply && reply->error() == QNetworkReply::NoError ) |
186 | | - { |
187 | | - QTemporaryFile *localFile = new QTemporaryFile( QStringLiteral( "XXXXXX.ui" ) ); |
188 | | - if ( localFile->open() ) |
189 | | - { |
190 | | - localFile->write( reply->readAll() ); |
191 | | - localFile->close(); |
192 | | - success = true; |
193 | | - QgsProject::instance()->addUiFormLocalCopy( localFile ); |
194 | | - formPath = localFile->fileName(); |
195 | | - } |
196 | | - } |
197 | | - if ( !success && errMsg ) |
198 | | - { |
199 | | - *errMsg = QStringLiteral( "Could not load UI from %1 (%2)" ).arg( ui ).arg( reply->errorString() ); |
200 | | - } |
201 | | - } |
202 | | - else |
203 | | - { |
204 | | - success = true; |
| 160 | + // any existing download will not be restarted! |
| 161 | + QgsApplication::instance()->networkContentFetcherRegistry()->fetch( ui, QgsNetworkContentFetcherRegistry::DownloadImmediately ); |
205 | 162 | } |
206 | 163 |
|
207 | | - if ( formPath.isEmpty() ) |
| 164 | + if ( ui.isEmpty() ) |
208 | 165 | { |
209 | 166 | setLayout( GeneratedLayout ); |
210 | 167 | } |
211 | 168 | else |
212 | 169 | { |
213 | 170 | setLayout( UiFileLayout ); |
214 | 171 | } |
215 | | - d->mUiFormPath = formPath; |
216 | | - d->mUiFormUrl = formUrl; |
| 172 | + d->mUiFormPath = ui; |
217 | 173 |
|
218 | | - return success; |
| 174 | + return true; |
219 | 175 | } |
220 | 176 |
|
221 | 177 | bool QgsEditFormConfig::readOnly( int idx ) const |
@@ -452,7 +408,7 @@ void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &con |
452 | 408 | QDomDocument doc( node.ownerDocument() ); |
453 | 409 |
|
454 | 410 | QDomElement efField = doc.createElement( QStringLiteral( "editform" ) ); |
455 | | - QDomText efText = doc.createTextNode( context.pathResolver().writePath( uiForm( Original ) ) ); |
| 411 | + QDomText efText = doc.createTextNode( context.pathResolver().writePath( uiForm() ) ); |
456 | 412 | efField.appendChild( efText ); |
457 | 413 | node.appendChild( efField ); |
458 | 414 |
|
|
0 commit comments