Navigation Menu

Skip to content

Commit

Permalink
QgsReadWriteContext can store message
Browse files Browse the repository at this point in the history
app will show them in message bar when loading layers
  • Loading branch information
3nids committed Feb 28, 2018
1 parent 47ab9b8 commit d421b85
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 2 deletions.
4 changes: 3 additions & 1 deletion python/core/qgsproject.sip.in
Expand Up @@ -910,7 +910,9 @@ Emitted when a layer from a projects was read.
:param n: number of layers
%End

void loadingLayer( const QString & );
void loadingLayer( const QString &layerName );

void loadingLayerMessages( const QString &layerName, const QList<QPair<Qgis::MessageLevel, QString>> &messages );

void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
%Docstring
Expand Down
10 changes: 10 additions & 0 deletions python/core/qgsreadwritecontext.sip.in
Expand Up @@ -35,6 +35,16 @@ Returns path resolver for conversion between relative and absolute paths
void setPathResolver( const QgsPathResolver &resolver );
%Docstring
Sets up path resolver for conversion between relative and absolute paths
%End

void pushMessage( Qgis::MessageLevel level, const QString &message );
%Docstring
append a message to the context
%End

QList<QPair<Qgis::MessageLevel, QString>> takeMessages();
%Docstring
return the stored messages and remove them
%End

};
Expand Down
10 changes: 10 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -3230,6 +3230,8 @@ void QgisApp::setupConnections()
this, &QgisApp::showProgress );
connect( QgsProject::instance(), &QgsProject::loadingLayer,
this, &QgisApp::showStatusMessage );
connect( QgsProject::instance(), &QgsProject::loadingLayerMessages,
this, &QgisApp::loadingLayerMessages );
connect( QgsProject::instance(), &QgsProject::readProject,
this, &QgisApp::readProject );
connect( QgsProject::instance(), &QgsProject::writeProject,
Expand Down Expand Up @@ -11238,6 +11240,14 @@ void QgisApp::showStatusMessage( const QString &message )
mStatusBar->showMessage( message );
}

void QgisApp::loadingLayerMessages( const QString &layerName, const QList<QPair<Qgis::MessageLevel, QString> > &messages )
{
for ( const auto message : messages )
{
messageBar()->pushMessage( layerName, message.second, message.first );
}
}

void QgisApp::displayMapToolMessage( const QString &message, Qgis::MessageLevel level )
{
// remove previous message
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -926,6 +926,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void showProgress( int progress, int totalSteps );
void showStatusMessage( const QString &message );

void loadingLayerMessages( const QString &layerName, const QList<QPair<Qgis::MessageLevel, QString>> &messages );

//! set the active layer
bool setActiveLayer( QgsMapLayer * );

Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -716,6 +716,11 @@ bool QgsProject::_getMapLayers( const QDomDocument &doc, QList<QDomNode> &broken
{
returnStatus = false;
}
const auto messages = context.takeMessages();
if ( messages.count() )
{
emit loadingLayerMessages( tr( "Loading layer %1" ).arg( name ), messages );
}
}
emit layerLoaded( i + 1, nl.count() );
i++;
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsproject.h
Expand Up @@ -887,7 +887,9 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void layerLoaded( int i, int n );

void loadingLayer( const QString & );
void loadingLayer( const QString &layerName );

void loadingLayerMessages( const QString &layerName, const QList<QPair<Qgis::MessageLevel, QString>> &messages );

//! Emitted when the list of layer which are excluded from map identification changes
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsreadwritecontext.h
Expand Up @@ -19,6 +19,7 @@
#define QGSREADWRITECONTEXT_H

#include "qgspathresolver.h"
#include "qgis.h"

/**
* \class QgsReadWriteContext
Expand All @@ -41,8 +42,15 @@ class CORE_EXPORT QgsReadWriteContext
//! Sets up path resolver for conversion between relative and absolute paths
void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }

//! append a message to the context
void pushMessage( Qgis::MessageLevel level, const QString &message ) {mMessages.append( qMakePair( level, message ) );}

//! return the stored messages and remove them
QList<QPair<Qgis::MessageLevel, QString>> takeMessages() {return mMessages; mMessages.clear();}

private:
QgsPathResolver mPathResolver;
QList<QPair<Qgis::MessageLevel, QString>> mMessages;
};

#endif // QGSREADWRITECONTEXT_H

0 comments on commit d421b85

Please sign in to comment.