mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Add QgsProject flag to avoid loading print layouts when reading a project file
Speeds up project read time when these aren't needed, and also potentially avoids issues caused by non-thread-safety in layouts (since some items rely on classes which can only be used in the main thread e.g. QWebPage)
This commit is contained in:
parent
532524961c
commit
d0ed374662
@ -237,6 +237,7 @@ Clears the project, removing all settings and resetting it back to an empty, def
|
||||
enum ReadFlag
|
||||
{
|
||||
FlagDontResolveLayers,
|
||||
FlagDontLoadLayouts,
|
||||
};
|
||||
typedef QFlags<QgsProject::ReadFlag> ReadFlags;
|
||||
|
||||
|
@ -1417,7 +1417,8 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags
|
||||
emit labelingEngineSettingsChanged();
|
||||
|
||||
mAnnotationManager->readXml( doc->documentElement(), context );
|
||||
mLayoutManager->readXml( doc->documentElement(), *doc );
|
||||
if ( !( flags & QgsProject::FlagDontLoadLayouts ) )
|
||||
mLayoutManager->readXml( doc->documentElement(), *doc );
|
||||
mBookmarkManager->readXml( doc->documentElement(), *doc );
|
||||
|
||||
// reassign change dependencies now that all layers are loaded
|
||||
|
@ -272,6 +272,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
|
||||
enum ReadFlag
|
||||
{
|
||||
FlagDontResolveLayers = 1 << 0, //!< Don't resolve layer paths (i.e. don't load any layer content). Dramatically improves project read time if the actual data from the layers is not required.
|
||||
FlagDontLoadLayouts = 1 << 1, //!< Don't load print layouts. Improves project read time if layouts are not required, and allows projects to be safely read in background threads (since print layouts are not thread safe).
|
||||
};
|
||||
Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "qgsunittypes.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgssymbollayerutils.h"
|
||||
#include "qgslayoutmanager.h"
|
||||
|
||||
class TestQgsProject : public QObject
|
||||
{
|
||||
@ -457,6 +458,12 @@ void TestQgsProject::testReadFlags()
|
||||
QVERIFY( !layers.value( QStringLiteral( "polys20170310142652234" ) )->isValid() );
|
||||
QCOMPARE( qobject_cast< QgsVectorLayer * >( layers.value( QStringLiteral( "lines20170310142652255" ) ) )->renderer()->type(), QStringLiteral( "categorizedSymbol" ) );
|
||||
QCOMPARE( qobject_cast< QgsVectorLayer * >( layers.value( QStringLiteral( "polys20170310142652234" ) ) )->renderer()->type(), QStringLiteral( "categorizedSymbol" ) );
|
||||
|
||||
|
||||
QString project3Path = QString( TEST_DATA_DIR ) + QStringLiteral( "/layouts/layout_casting.qgs" );
|
||||
QgsProject p3;
|
||||
QVERIFY( p3.read( project3Path, QgsProject::FlagDontLoadLayouts ) );
|
||||
QCOMPARE( p3.layoutManager()->layouts().count(), 0 );
|
||||
}
|
||||
|
||||
void TestQgsProject::testSetGetCrs()
|
||||
|
Loading…
x
Reference in New Issue
Block a user