Skip to content

Commit 4c63c85

Browse files
committed
Show provider errors more prominently
1 parent fef9c93 commit 4c63c85

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

python/core/qgsvectordataprovider.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ class QgsVectorDataProvider : QgsDataProvider
352352
*/
353353
virtual QSet<QString> layerDependencies() const;
354354

355+
signals:
356+
/** Signals an error in this provider */
357+
void raiseError( const QString& msg );
358+
355359
protected:
356360
void clearMinMaxCache();
357361
void fillMinMaxCache();

python/core/qgsvectorlayer.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,10 @@ class QgsVectorLayer : QgsMapLayer
17861786
*/
17871787
void writeCustomSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage ) const;
17881788

1789+
/**
1790+
* Signals an error related to this vector layer.
1791+
*/
1792+
void raiseError( const QString& msg );
17891793

17901794
protected:
17911795
/** Set the extent */

src/app/qgisapp.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9574,6 +9574,8 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
95749574
}
95759575
}
95769576

9577+
connect( vlayer, SIGNAL( raiseError( QString ) ), this, SLOT( onLayerError( QString ) ) );
9578+
95779579
provider = vProvider;
95789580
}
95799581

@@ -11225,6 +11227,15 @@ void QgisApp::showStatisticsDockWidget()
1122511227
mStatisticalSummaryDockWidget->raise();
1122611228
}
1122711229

11230+
void QgisApp::onLayerError( const QString& msg )
11231+
{
11232+
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( sender() );
11233+
11234+
Q_ASSERT( layer );
11235+
11236+
mInfoBar->pushCritical( tr( "Layer %1" ).arg( layer->name() ), msg );
11237+
}
11238+
1122811239

1122911240
#ifdef HAVE_TOUCH
1123011241
bool QgisApp::gestureEvent( QGestureEvent *event )

src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
12781278
*/
12791279
void showStatisticsDockWidget();
12801280

1281+
/** Pushes a layer error to the message bar */
1282+
void onLayerError( const QString& msg );
1283+
12811284
signals:
12821285
/** Emitted when a key is pressed and we want non widget sublasses to be able
12831286
to pick up on this (e.g. maplayer) */

src/core/qgsvectordataprovider.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ void QgsVectorDataProvider::pushError( const QString& msg )
559559
{
560560
QgsDebugMsg( msg );
561561
mErrors << msg;
562+
emit raiseError( msg );
562563
}
563564

564565
QSet<QString> QgsVectorDataProvider::layerDependencies() const

src/core/qgsvectordataprovider.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
404404
*/
405405
virtual QSet<QString> layerDependencies() const;
406406

407+
signals:
408+
/** Signals an error in this provider */
409+
void raiseError( const QString& msg );
410+
407411
protected:
408412
void clearMinMaxCache();
409413
void fillMinMaxCache();

src/core/qgsvectorlayer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,7 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
15241524
// version big-time with an abnormal termination error
15251525
delete mDataProvider;
15261526
mDataProvider = ( QgsVectorDataProvider* )( QgsProviderRegistry::instance()->provider( provider, mDataSource ) );
1527+
connect( mDataProvider, SIGNAL( raiseError( QString ) ), this, SIGNAL( raiseError( QString ) ) );
15271528

15281529
if ( !mDataProvider )
15291530
{

src/core/qgsvectorlayer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
18311831
* This can be due to manually adding attributes or due to a join.
18321832
*/
18331833
void updatedFields();
1834+
1835+
/**
1836+
* TODO QGIS3: remove in favor of QObject::destroyed
1837+
*/
18341838
void layerDeleted();
18351839

18361840
void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
@@ -1898,6 +1902,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
18981902
*/
18991903
void writeCustomSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage ) const;
19001904

1905+
/**
1906+
* Signals an error related to this vector layer.
1907+
*/
1908+
void raiseError( const QString& msg );
1909+
19011910
private slots:
19021911
void onJoinedFieldsChanged();
19031912
void onFeatureDeleted( QgsFeatureId fid );

0 commit comments

Comments
 (0)