19
19
#include " qgsmessagelog.h"
20
20
#include " qgsquerybuilder.h"
21
21
#include " qgsvectorlayer.h"
22
- #include < QStandardItem>
23
-
24
22
25
23
26
24
QgsQueryResultWidget::QgsQueryResultWidget ( QWidget *parent, QgsAbstractDatabaseProviderConnection *connection )
@@ -31,6 +29,9 @@ QgsQueryResultWidget::QgsQueryResultWidget( QWidget *parent, QgsAbstractDatabase
31
29
// Unsure :/
32
30
// mSqlEditor->setLineNumbersVisible( true );
33
31
32
+ mQueryResultsTableView ->hide ();
33
+ mProgressBar ->hide ();
34
+
34
35
connect ( mExecuteButton , &QPushButton::pressed, this , &QgsQueryResultWidget::executeQuery );
35
36
connect ( mClearButton , &QPushButton::pressed, this , [ = ]
36
37
{
@@ -98,13 +99,7 @@ QgsQueryResultWidget::QgsQueryResultWidget( QWidget *parent, QgsAbstractDatabase
98
99
99
100
QgsQueryResultWidget::~QgsQueryResultWidget ()
100
101
{
101
- if ( mApiFetcher )
102
- {
103
- mApiFetcher ->stopFetching ();
104
- mWorkerThread .quit ();
105
- mWorkerThread .wait ();
106
- mWorkerThread .deleteLater ();
107
- }
102
+ cancelApiFetcher ();
108
103
cancelRunningQuery ();
109
104
}
110
105
@@ -125,12 +120,15 @@ void QgsQueryResultWidget::executeQuery()
125
120
mStopButton ->setEnabled ( true );
126
121
mStatusLabel ->show ();
127
122
mStatusLabel ->setText ( tr ( " Running⋯" ) );
123
+ mProgressBar ->show ();
124
+ mProgressBar ->setRange ( 0 , 0 );
128
125
mSqlErrorMessage .clear ();
129
126
130
127
connect ( mStopButton , &QPushButton::pressed, mFeedback .get (), [ = ]
131
128
{
132
129
mStatusLabel ->setText ( tr ( " Stopped" ) );
133
130
mFeedback ->cancel ();
131
+ mProgressBar ->hide ();
134
132
mWasCanceled = true ;
135
133
} );
136
134
@@ -214,6 +212,17 @@ void QgsQueryResultWidget::cancelRunningQuery()
214
212
}
215
213
}
216
214
215
+ void QgsQueryResultWidget::cancelApiFetcher ()
216
+ {
217
+ if ( mApiFetcher )
218
+ {
219
+ mApiFetcher ->stopFetching ();
220
+ mApiFetcherWorkerThread .quit ();
221
+ mApiFetcherWorkerThread .wait ();
222
+ mApiFetcherWorkerThread .deleteLater ();
223
+ }
224
+ }
225
+
217
226
void QgsQueryResultWidget::startFetching ()
218
227
{
219
228
if ( ! mWasCanceled )
@@ -242,7 +251,7 @@ void QgsQueryResultWidget::startFetching()
242
251
updateButtons ();
243
252
updateSqlLayerColumns ( );
244
253
}
245
- mStatusLabel ->setText ( tr ( " Fetched rows: %1 %2. " )
254
+ mStatusLabel ->setText ( tr ( " Fetched rows: %1 %2" )
246
255
.arg ( mModel ->rowCount ( mModel ->index ( -1 , -1 ) ) )
247
256
.arg ( mWasCanceled ? tr ( " (stopped)" ) : QString () ) );
248
257
} );
@@ -256,20 +265,23 @@ void QgsQueryResultWidget::startFetching()
256
265
if ( ! mWasCanceled )
257
266
{
258
267
mStatusLabel ->setText ( " Query executed successfully." );
268
+ mProgressBar ->hide ();
259
269
}
260
270
} );
261
271
}
262
272
}
263
273
else
264
274
{
265
275
mStatusLabel ->setText ( tr ( " SQL command aborted." ) );
276
+ mProgressBar ->hide ();
266
277
}
267
278
}
268
279
269
280
void QgsQueryResultWidget::showError ( const QString &title, const QString &message, bool isSqlError )
270
281
{
271
282
mStatusLabel ->show ();
272
283
mStatusLabel ->setText ( tr ( " There was an error executing the query." ) );
284
+ mProgressBar ->hide ();
273
285
mQueryResultsTableView ->hide ();
274
286
if ( isSqlError )
275
287
{
@@ -317,14 +329,7 @@ void QgsQueryResultWidget::setConnection( QgsAbstractDatabaseProviderConnection
317
329
{
318
330
mConnection .reset ( connection );
319
331
320
- if ( mApiFetcher )
321
- {
322
- mApiFetcher ->stopFetching ();
323
- mWorkerThread .quit ();
324
- mWorkerThread .wait ();
325
- mApiFetcher ->deleteLater ();
326
- mApiFetcher = nullptr ;
327
- }
332
+ cancelApiFetcher ();
328
333
329
334
if ( connection )
330
335
{
@@ -343,15 +348,15 @@ void QgsQueryResultWidget::setConnection( QgsAbstractDatabaseProviderConnection
343
348
344
349
// Add dynamic keywords in a separate thread
345
350
mApiFetcher = new QgsConnectionsApiFetcher ( connection );
346
- mApiFetcher ->moveToThread ( &mWorkerThread );
347
- connect ( &mWorkerThread , &QThread::started, mApiFetcher , &QgsConnectionsApiFetcher::fetchTokens );
348
- connect ( &mWorkerThread , &QThread::finished, mApiFetcher , [ = ]
351
+ mApiFetcher ->moveToThread ( &mApiFetcherWorkerThread );
352
+ connect ( &mApiFetcherWorkerThread , &QThread::started, mApiFetcher , &QgsConnectionsApiFetcher::fetchTokens );
353
+ connect ( &mApiFetcherWorkerThread , &QThread::finished, mApiFetcher , [ = ]
349
354
{
350
355
mApiFetcher ->deleteLater ();
351
356
mApiFetcher = nullptr ;
352
357
} );
353
358
connect ( mApiFetcher , &QgsConnectionsApiFetcher::tokensReady, this , &QgsQueryResultWidget::tokensReady );
354
- mWorkerThread .start ();
359
+ mApiFetcherWorkerThread .start ();
355
360
}
356
361
357
362
updateButtons ();
@@ -380,7 +385,7 @@ void QgsConnectionsApiFetcher::fetchTokens()
380
385
}
381
386
catch ( QgsProviderConnectionException &ex )
382
387
{
383
- QgsMessageLog::logMessage ( tr ( " Error retrieving schemas: %1" ).arg ( ex.what () ) );
388
+ QgsMessageLog::logMessage ( tr ( " Error retrieving schemas: %1" ).arg ( ex.what () ), QStringLiteral ( " QGIS " ), Qgis::MessageLevel::Warning );
384
389
}
385
390
}
386
391
else
@@ -404,7 +409,7 @@ void QgsConnectionsApiFetcher::fetchTokens()
404
409
}
405
410
catch ( QgsProviderConnectionException &ex )
406
411
{
407
- QgsMessageLog::logMessage ( tr ( " Error retrieving tables: %1" ).arg ( ex.what () ) );
412
+ QgsMessageLog::logMessage ( tr ( " Error retrieving tables: %1" ).arg ( ex.what () ), QStringLiteral ( " QGIS " ), Qgis::MessageLevel::Warning );
408
413
}
409
414
410
415
// Get fields
@@ -425,7 +430,7 @@ void QgsConnectionsApiFetcher::fetchTokens()
425
430
}
426
431
catch ( QgsProviderConnectionException &ex )
427
432
{
428
- QgsMessageLog::logMessage ( tr ( " Error retrieving fields for table %1: %2" ).arg ( table, ex.what () ) );
433
+ QgsMessageLog::logMessage ( tr ( " Error retrieving fields for table %1: %2" ).arg ( table, ex.what () ), QStringLiteral ( " QGIS " ), Qgis::MessageLevel::Warning );
429
434
}
430
435
}
431
436
}
0 commit comments