Skip to content
Permalink
Browse files
Show any warning messages generated while loading a QLR in the
messagebar

E.g. missing font warnings
  • Loading branch information
nyalldawson committed May 24, 2021
1 parent 203d8e7 commit e3baef2dd489ce6f3982cd706d9dc36fe6ef3296
Showing with 43 additions and 3 deletions.
  1. +43 −3 src/app/qgisapp.cpp
@@ -7406,10 +7406,50 @@ void QgisApp::dwgImport()
void QgisApp::openLayerDefinition( const QString &path )
{
QString errorMessage;
bool loaded = QgsLayerDefinition::loadLayerDefinition( path, QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMessage );
if ( !loaded || !errorMessage.isEmpty() )
QgsReadWriteContext context;
bool loaded = false;

QFile file( path );
if ( !file.open( QIODevice::ReadOnly ) )
{
errorMessage = QStringLiteral( "Can not open file" );
}
else
{
QDomDocument doc;
QString message;
if ( !doc.setContent( &file, &message ) )
{
errorMessage = message;
}
else
{
QFileInfo fileinfo( file );
QDir::setCurrent( fileinfo.absoluteDir().path() );

context.setPathResolver( QgsPathResolver( path ) );
context.setProjectTranslator( QgsProject::instance() );

loaded = QgsLayerDefinition::loadLayerDefinition( doc, QgsProject::instance(), QgsProject::instance()->layerTreeRoot(), errorMessage, context );
}
}

if ( loaded )
{
const QList< QgsReadWriteContext::ReadWriteMessage > messages = context.takeMessages();
QVector< QgsReadWriteContext::ReadWriteMessage > shownMessages;
for ( const QgsReadWriteContext::ReadWriteMessage &message : messages )
{
if ( shownMessages.contains( message ) )
continue;

visibleMessageBar()->pushMessage( QString(), message.message(), message.categories().join( '\n' ), message.level() );

shownMessages.append( message );
}
}
else if ( !loaded || !errorMessage.isEmpty() )
{
QgsDebugMsg( errorMessage );
visibleMessageBar()->pushMessage( tr( "Error loading layer definition" ), errorMessage, Qgis::Warning );
}
}

0 comments on commit e3baef2

Please sign in to comment.