Skip to content
Permalink
Browse files

Defer load of 3d symbols in default style until after 3d symbol regis…

…try is populated

Otherwise it's impossible to load these symbols
  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent d8e4453 commit 396540a5e7025a388887785ecb549f1e2fb9fb82
Showing with 50 additions and 7 deletions.
  1. +1 −0 src/3d/CMakeLists.txt
  2. +6 −0 src/3d/qgs3d.cpp
  3. +38 −7 src/core/symbology/qgsstyle.cpp
  4. +5 −0 src/core/symbology/qgsstyle.h
@@ -160,6 +160,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/3d
${CMAKE_SOURCE_DIR}/src/core/textrenderer
${CMAKE_SOURCE_DIR}/external
${CMAKE_SOURCE_DIR}/external/nlohmann

@@ -35,6 +35,8 @@
#include "qgspoint3dsymbol_p.h"
#include "qgsline3dsymbol_p.h"

#include "qgsstyle.h"

Qgs3D *Qgs3D::instance()
{
static Qgs3D *sInstance( new Qgs3D() );
@@ -65,6 +67,10 @@ void Qgs3D::initialize()

instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phong" ), QObject::tr( "Realistic (Phong)" ),
QgsPhongMaterialSettings::create, nullptr ) );

// because we are usually populating the 3d registry AFTER QgsApplication initialisation, we need to defer creation
// of 3d symbols in the default style until now
QgsStyle::defaultStyle()->handleDeferred3DSymbolCreation();
}

QgsMaterialRegistry *Qgs3D::materialRegistry()
@@ -456,6 +456,27 @@ QStringList QgsStyle::colorRampNames() const
return mColorRamps.keys();
}

void QgsStyle::handleDeferred3DSymbolCreation()
{
for ( auto it = mDeferred3DsymbolElements.constBegin(); it != mDeferred3DsymbolElements.constEnd(); ++it )
{
const QString symbolType = it.value().attribute( QStringLiteral( "type" ) );
std::unique_ptr< QgsAbstract3DSymbol > symbol( QgsApplication::symbol3DRegistry()->createSymbol( symbolType ) );
if ( symbol )
{
symbol->readXml( it.value(), QgsReadWriteContext() );
addSymbol3D( it.key(), symbol.release(), false );
emit entityAdded( Symbol3DEntity, it.key() );
}
else
{
QgsDebugMsg( "Cannot open 3d symbol " + it.key() );
continue;
}
}
mDeferred3DsymbolElements.clear();
}

bool QgsStyle::openDatabase( const QString &filename )
{
int rc = mCurrentDB.open( filename );
@@ -760,6 +781,9 @@ bool QgsStyle::load( const QString &filename )
QgsScopedRuntimeProfile profile( tr( "Load 3d symbols shapes" ) );
query = QgsSqlite3Mprintf( "SELECT * FROM symbol3d" );
statement = mCurrentDB.prepare( query, rc );

const bool registry3dPopulated = !QgsApplication::symbol3DRegistry()->symbolTypes().empty();

while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
QDomDocument doc;
@@ -773,17 +797,24 @@ bool QgsStyle::load( const QString &filename )
}
QDomElement settingsElement = doc.documentElement();

const QString symbolType = settingsElement.attribute( QStringLiteral( "type" ) );
std::unique_ptr< QgsAbstract3DSymbol > symbol( QgsApplication::symbol3DRegistry()->createSymbol( symbolType ) );
if ( symbol )
if ( !registry3dPopulated )
{
symbol->readXml( settingsElement, QgsReadWriteContext() );
m3dSymbols.insert( settingsName, symbol.release() );
mDeferred3DsymbolElements.insert( settingsName, settingsElement );
}
else
{
QgsDebugMsg( "Cannot open 3d symbol " + settingsName );
continue;
const QString symbolType = settingsElement.attribute( QStringLiteral( "type" ) );
std::unique_ptr< QgsAbstract3DSymbol > symbol( QgsApplication::symbol3DRegistry()->createSymbol( symbolType ) );
if ( symbol )
{
symbol->readXml( settingsElement, QgsReadWriteContext() );
m3dSymbols.insert( settingsName, symbol.release() );
}
else
{
QgsDebugMsg( "Cannot open 3d symbol " + settingsName );
continue;
}
}
}
}
@@ -1084,6 +1084,9 @@ class CORE_EXPORT QgsStyle : public QObject
mutable QHash< QgsSymbol::SymbolType, QHash< QSizeF, QgsLegendPatchShape > > mDefaultPatchCache;
mutable QHash< QgsSymbol::SymbolType, QHash< QSizeF, QList< QList< QPolygonF > > > > mDefaultPatchQPolygonFCache;

QMap< QString, QDomElement > mDeferred3DsymbolElements;
void handleDeferred3DSymbolCreation();

static QgsStyle *sDefaultStyle;

//! Convenience function to open the DB and return a sqlite3 object
@@ -1136,6 +1139,8 @@ class CORE_EXPORT QgsStyle : public QObject
*/
static QString tagmapEntityIdFieldName( StyleEntity type );

friend class Qgs3D;

Q_DISABLE_COPY( QgsStyle )
};

0 comments on commit 396540a

Please sign in to comment.
You can’t perform that action at this time.