Skip to content

Commit

Permalink
Show provider errors more prominently
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Feb 20, 2016
1 parent fef9c93 commit 4c63c85
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsvectordataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ class QgsVectorDataProvider : QgsDataProvider
*/
virtual QSet<QString> layerDependencies() const;

signals:
/** Signals an error in this provider */
void raiseError( const QString& msg );

protected:
void clearMinMaxCache();
void fillMinMaxCache();
Expand Down
4 changes: 4 additions & 0 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,10 @@ class QgsVectorLayer : QgsMapLayer
*/
void writeCustomSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage ) const;

/**
* Signals an error related to this vector layer.
*/
void raiseError( const QString& msg );

protected:
/** Set the extent */
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9574,6 +9574,8 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
}
}

connect( vlayer, SIGNAL( raiseError( QString ) ), this, SLOT( onLayerError( QString ) ) );

provider = vProvider;
}

Expand Down Expand Up @@ -11225,6 +11227,15 @@ void QgisApp::showStatisticsDockWidget()
mStatisticalSummaryDockWidget->raise();
}

void QgisApp::onLayerError( const QString& msg )
{
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( sender() );

Q_ASSERT( layer );

mInfoBar->pushCritical( tr( "Layer %1" ).arg( layer->name() ), msg );
}


#ifdef HAVE_TOUCH
bool QgisApp::gestureEvent( QGestureEvent *event )
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
void showStatisticsDockWidget();

/** Pushes a layer error to the message bar */
void onLayerError( const QString& msg );

signals:
/** Emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectordataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ void QgsVectorDataProvider::pushError( const QString& msg )
{
QgsDebugMsg( msg );
mErrors << msg;
emit raiseError( msg );
}

QSet<QString> QgsVectorDataProvider::layerDependencies() const
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectordataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
*/
virtual QSet<QString> layerDependencies() const;

signals:
/** Signals an error in this provider */
void raiseError( const QString& msg );

protected:
void clearMinMaxCache();
void fillMinMaxCache();
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
// version big-time with an abnormal termination error
delete mDataProvider;
mDataProvider = ( QgsVectorDataProvider* )( QgsProviderRegistry::instance()->provider( provider, mDataSource ) );
connect( mDataProvider, SIGNAL( raiseError( QString ) ), this, SIGNAL( raiseError( QString ) ) );

if ( !mDataProvider )
{
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* This can be due to manually adding attributes or due to a join.
*/
void updatedFields();

/**
* TODO QGIS3: remove in favor of QObject::destroyed
*/
void layerDeleted();

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

/**
* Signals an error related to this vector layer.
*/
void raiseError( const QString& msg );

private slots:
void onJoinedFieldsChanged();
void onFeatureDeleted( QgsFeatureId fid );
Expand Down

0 comments on commit 4c63c85

Please sign in to comment.