Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move reponsibility for saving/restoring temporal properties
to QgsMapLayer::read/writeCommonStyle

Correctly stores these settings in QML files and when duplicating
layers

Fixes #36531, fixes #36530
  • Loading branch information
nyalldawson committed May 19, 2020
1 parent 8499e09 commit 79f8fd9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmaplayer.sip.in
Expand Up @@ -96,6 +96,7 @@ This is the base class for all map layer types (vector, raster).
CustomProperties,
GeometryOptions,
Relations,
Temporal,
AllStyleCategories
};
typedef QFlags<QgsMapLayer::StyleCategory> StyleCategories;
Expand Down
4 changes: 0 additions & 4 deletions src/core/mesh/qgsmeshlayer.cpp
Expand Up @@ -1033,8 +1033,6 @@ bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &con
QString errorMsg;
readSymbology( layer_node, errorMsg, context );

// read temporal
temporalProperties()->readXml( layer_node.toElement(), context );
if ( !mTemporalProperties->timeExtent().begin().isValid() )
temporalProperties()->setDefaultsFromDataProviderTemporalCapabilities( dataProvider()->temporalCapabilities() );

Expand Down Expand Up @@ -1089,8 +1087,6 @@ bool QgsMeshLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const
}
layer_node.appendChild( elemExtraDatasets );
}
// write temporal
mTemporalProperties->writeXml( mapLayerNode, document, context );

QDomElement elemStaticDataset = document.createElement( QStringLiteral( "static-active-dataset" ) );
if ( mStaticScalarDatasetIndex.isValid() )
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -53,6 +53,7 @@
#include "qgsvectordataprovider.h"
#include "qgsxmlutils.h"
#include "qgsstringutils.h"
#include "qgsmaplayertemporalproperties.h"

QString QgsMapLayer::extensionPropertyType( QgsMapLayer::PropertyType type )
{
Expand Down Expand Up @@ -579,6 +580,11 @@ void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &doc
layerElement.appendChild( layerFlagsElem );
}

if ( categories.testFlag( Temporal ) && const_cast< QgsMapLayer * >( this )->temporalProperties() )
{
const_cast< QgsMapLayer * >( this )->temporalProperties()->writeXml( layerElement, document, context );
}

// custom properties
if ( categories.testFlag( CustomProperties ) )
{
Expand Down Expand Up @@ -1672,6 +1678,11 @@ void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsRea
}
setFlags( flags );
}

if ( categories.testFlag( Temporal ) && temporalProperties() )
{
temporalProperties()->readXml( layerElement.toElement(), context );
}
}

QUndoStack *QgsMapLayer::undoStack()
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaplayer.h
Expand Up @@ -167,8 +167,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
CustomProperties = 1 << 11, //!< Custom properties (by plugins for instance)
GeometryOptions = 1 << 12, //!< Geometry validation configuration
Relations = 1 << 13, //!< Relations
Temporal = 1 << 14, //!< Temporal properties
AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations,
MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal,
};
Q_ENUM( StyleCategory )
Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
Expand Down
5 changes: 0 additions & 5 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1561,8 +1561,6 @@ bool QgsVectorLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c
return false;
}

mTemporalProperties->readXml( layer_node.toElement(), context );

readStyleManager( layer_node );

QDomNode depsNode = layer_node.namedItem( QStringLiteral( "dataDependencies" ) );
Expand Down Expand Up @@ -1877,9 +1875,6 @@ bool QgsVectorLayer::writeXml( QDomNode &layer_node,
// save expression fields
mExpressionFieldBuffer->writeXml( layer_node, document );

// write temporal properties
mTemporalProperties->writeXml( mapLayerNode, document, context );

writeStyleManager( layer_node, document );

// auxiliary layer
Expand Down
5 changes: 0 additions & 5 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1965,8 +1965,6 @@ bool QgsRasterLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c
}
}

mTemporalProperties->readXml( layer_node.toElement(), context );

readStyleManager( layer_node );

return res;
Expand Down Expand Up @@ -2069,9 +2067,6 @@ bool QgsRasterLayer::writeXml( QDomNode &layer_node,
layer_node.appendChild( noData );
}

// write temporal properties
mTemporalProperties->writeXml( mapLayerNode, document, context );

writeStyleManager( layer_node, document );

//write out the symbology
Expand Down
13 changes: 13 additions & 0 deletions src/gui/qgsmaplayerstylecategoriesmodel.cpp
Expand Up @@ -231,6 +231,19 @@ QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int ro
return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/relations.svg" ) );
}
break;

case QgsMapLayer::StyleCategory::Temporal:
switch ( role )
{
case Qt::DisplayRole:
return tr( "Temporal Properties" );
case Qt::ToolTipRole:
return tr( "Temporal properties" );
case Qt::DecorationRole:
return QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/temporal.svg" ) );
}
break;

case QgsMapLayer::StyleCategory::AllStyleCategories:
switch ( role )
{
Expand Down

0 comments on commit 79f8fd9

Please sign in to comment.