Skip to content
Permalink
Browse files

QgsReadWriteContext can store message

app will show them in message bar when loading layers
  • Loading branch information
3nids committed Feb 28, 2018
1 parent 47ab9b8 commit d421b857e535aa5de7d00de084978f2e6947fbb3
@@ -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
@@ -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

};
@@ -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,
@@ -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
@@ -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 * );

@@ -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++;
@@ -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 );
@@ -19,6 +19,7 @@
#define QGSREADWRITECONTEXT_H

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

/**
* \class QgsReadWriteContext
@@ -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.
You can’t perform that action at this time.