Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move the skybox enabling checkbox to the groupbox widget
Whether skybox is enabled is now saved as part of the 3D Map settings
  • Loading branch information
DelazJ authored and nyalldawson committed Aug 21, 2020
1 parent 7b91f79 commit 09844a7
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 18 deletions.
18 changes: 18 additions & 0 deletions python/3d/auto_generated/qgs3dmapsettings.sip.in
Expand Up @@ -477,6 +477,24 @@ Default value is 96



bool isSkyboxEnabled() const;
%Docstring
Returns whether the skybox is enabled.

.. seealso:: :py:func:`setIsSkyboxEnabled`

.. versionadded:: 3.16
%End

void setIsSkyboxEnabled( bool enabled );
%Docstring
Sets whether the skybox is enabled.

.. seealso:: :py:func:`isSkyboxEnabled`

.. versionadded:: 3.16
%End

signals:
void backgroundColorChanged();
%Docstring
Expand Down
4 changes: 2 additions & 2 deletions src/3d/qgs3dmapscene.cpp
Expand Up @@ -863,9 +863,9 @@ void Qgs3DMapScene::onSkyboxSettingsChanged()
mSkybox = nullptr;
}

mEngine->setFrustumCullingEnabled( !skyboxSettings.isSkyboxEnabled() );
mEngine->setFrustumCullingEnabled( !mMap.isSkyboxEnabled() );

if ( skyboxSettings.isSkyboxEnabled() )
if ( mMap.isSkyboxEnabled() )
{
QMap<QString, QString> faces;
switch ( skyboxSettings.skyboxType() )
Expand Down
4 changes: 3 additions & 1 deletion src/3d/qgs3dmapsettings.cpp
Expand Up @@ -58,6 +58,7 @@ Qgs3DMapSettings::Qgs3DMapSettings( const Qgs3DMapSettings &other )
, mTransformContext( other.mTransformContext )
, mPathResolver( other.mPathResolver )
, mMapThemes( other.mMapThemes )
, mIsSkyboxEnabled( other.mIsSkyboxEnabled )
, mSkyboxSettings()
{
Q_FOREACH ( QgsAbstract3DRenderer *renderer, other.mRenderers )
Expand Down Expand Up @@ -224,9 +225,9 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
}

QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
mIsSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
mSkyboxSettings.readXml( elemSkybox, context );


QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
Expand Down Expand Up @@ -325,6 +326,7 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
elem.appendChild( elemRenderers );

QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
elemSkybox.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
mSkyboxSettings.writeXml( elemSkybox, context );
elem.appendChild( elemSkybox );

Expand Down
17 changes: 16 additions & 1 deletion src/3d/qgs3dmapsettings.h
Expand Up @@ -424,6 +424,20 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
*/
void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;

/**
* Returns whether the skybox is enabled.
* \see setIsSkyboxEnabled()
* \since QGIS 3.16
*/
bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }

/**
* Sets whether the skybox is enabled.
* \see isSkyboxEnabled()
* \since QGIS 3.16
*/
void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }

signals:
//! Emitted when the background color has changed
void backgroundColorChanged();
Expand Down Expand Up @@ -559,7 +573,8 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
QgsMapThemeCollection *mMapThemes = nullptr; //!< Pointer to map themes (e.g. from the current project) to resolve map theme content from the name
double mDpi = 96; //!< Dot per inch value for the screen / painter

QgsSkyboxSettings mSkyboxSettings; //!< Skybox realted configuration
bool mIsSkyboxEnabled = false; //!< Whether the skybox is enabled
QgsSkyboxSettings mSkyboxSettings; //!< Skybox related configuration
};


Expand Down
2 changes: 0 additions & 2 deletions src/3d/qgsskyboxsettings.cpp
Expand Up @@ -23,7 +23,6 @@
void QgsSkyboxSettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
{
const QgsPathResolver &pathResolver = context.pathResolver();
mIsSkyboxEnabled = element.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
QString skyboxTypeStr = element.attribute( QStringLiteral( "skybox-type" ) );
if ( skyboxTypeStr == QStringLiteral( "Distinct Faces" ) )
mSkyboxType = QgsSkyboxEntity::DistinctTexturesSkybox;
Expand All @@ -41,7 +40,6 @@ void QgsSkyboxSettings::readXml( const QDomElement &element, const QgsReadWriteC

void QgsSkyboxSettings::writeXml( QDomElement &element, const QgsReadWriteContext &context ) const
{
element.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
switch ( mSkyboxType )
{
case QgsSkyboxEntity::DistinctTexturesSkybox:
Expand Down
6 changes: 0 additions & 6 deletions src/3d/qgsskyboxsettings.h
Expand Up @@ -41,11 +41,6 @@ class _3D_EXPORT QgsSkyboxSettings
//! Writes settings to a DOM \a element
void writeXml( QDomElement &element, const QgsReadWriteContext &context ) const;

//! Returns whether the skybox is enabled
bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }
//! Sets whether the skybox is enabled
void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }

//! Returns the type of the skybox
QgsSkyboxEntity::SkyboxType skyboxType() const { return mSkyboxType; }
//! Sets the type of the skybox
Expand All @@ -69,7 +64,6 @@ class _3D_EXPORT QgsSkyboxSettings
void setCubeMapFace( const QString &face, const QString &path ) { mCubeMapFacesPaths[face] = path; }

private:
bool mIsSkyboxEnabled = false;
QgsSkyboxEntity::SkyboxType mSkyboxType;
//
QString mPanoramicTexturePath;
Expand Down
3 changes: 3 additions & 0 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Expand Up @@ -127,6 +127,8 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
mSkyboxSettingsWidget = new QgsSkyboxRenderingSettingsWidget( this );
mSkyboxSettingsWidget->setSkyboxSettings( map->skyboxSettings() );
groupSkyboxSettings->layout()->addWidget( mSkyboxSettingsWidget );
groupSkyboxSettings->setChecked( mMap->isSkyboxEnabled() );

}

void Qgs3DMapConfigWidget::apply()
Expand Down Expand Up @@ -239,6 +241,7 @@ void Qgs3DMapConfigWidget::apply()

mMap->setPointLights( widgetLights->pointLights() );
mMap->setDirectionalLights( widgetLights->directionalLights() );
mMap->setIsSkyboxEnabled( groupSkyboxSettings->isChecked() );
mMap->setSkyboxSettings( mSkyboxSettingsWidget->toSkyboxSettings() );
}

Expand Down
8 changes: 7 additions & 1 deletion src/ui/3d/map3dconfigwidget.ui
Expand Up @@ -40,7 +40,7 @@
<x>0</x>
<y>0</y>
<width>541</width>
<height>753</height>
<height>730</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -368,6 +368,12 @@
<property name="title">
<string>Skybox rendering</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3"/>
</widget>
</item>
Expand Down
5 changes: 0 additions & 5 deletions src/ui/3d/skyboxrenderingsettingswidget.ui
Expand Up @@ -107,12 +107,7 @@
</layout>
</widget>
</item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="skyboxEnabledCheckBox">
<property name="text">
<string>Enable skybox</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 09844a7

Please sign in to comment.