Skip to content

Commit

Permalink
save timestamp in project file
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15752 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Apr 17, 2011
1 parent 8817358 commit 0c463d3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )

maplayer.appendChild( layerName );

// timestamp if supported
if ( timestamp() > QDateTime() )
{
QDomElement stamp = document.createElement( "timestamp" );
QDomText stampText = document.createTextNode( timestamp().toString( Qt::ISODate ) );
stamp.appendChild( stampText );
maplayer.appendChild( stamp );
}

maplayer.appendChild( layerName );

// zorder
// This is no longer stored in the project file. It is superfluous since the layers
// are written and read in the proper order.
Expand Down
7 changes: 5 additions & 2 deletions src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef QGSMAPLAYER_H
#define QGSMAPLAYER_H


#include <QDateTime>
#include <QObject>
#include <QUndoStack>
#include <QVariant>
Expand Down Expand Up @@ -95,7 +95,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** This is the method that does the actual work of
* drawing the layer onto a paint device.
* @param rendererContext describes the extents,
* resolution etc. that should be used when rendering the
* resolumon etc. that should be used when rendering the
* layer.
*/
virtual bool draw( QgsRenderContext& rendererContext );
Expand Down Expand Up @@ -332,6 +332,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
* added in 1.5 */
void clearCacheImage();

/** Time stamp of data source in the moment when data/metadata were loaded by provider */
virtual QDateTime timestamp() const { return QDateTime() ; }

signals:

/** Emit a signal to notify of a progress event */
Expand Down
29 changes: 22 additions & 7 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3257,9 +3257,8 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )
QDomNode rpNode = layer_node.namedItem( "rasterproperties" );

// Collect sublayer names and styles
QStringList layers;
QStringList styles;
QString format;
mLayers.clear();
mStyles.clear();

if ( mProviderKey == "wms" )
{
Expand All @@ -3269,20 +3268,21 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )
// TODO: sublayer visibility - post-0.8 release timeframe

// collect name for the sublayer
layers += layerElement.namedItem( "name" ).toElement().text();
mLayers += layerElement.namedItem( "name" ).toElement().text();

// collect style for the sublayer
styles += layerElement.namedItem( "style" ).toElement().text();
mStyles += layerElement.namedItem( "style" ).toElement().text();

layerElement = layerElement.nextSiblingElement( "wmsSublayer" );
}

// Collect format
format = rpNode.namedItem( "wmsFormat" ).toElement().text();
mFormat = rpNode.namedItem( "wmsFormat" ).toElement().text();
}

mCrs = crs().authid();
// Collect CRS
setDataProvider( mProviderKey, layers, styles, format, crs().authid() );
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );

QString theError;
bool res = readSymbology( layer_node, theError );
Expand All @@ -3299,6 +3299,21 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )
mGrayBandName = bandName( 1 );
}

// Check timestamp
QDomNode stampNode = layer_node.namedItem( "timestamp" );
if ( !stampNode.isNull() )
{
QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
// TODO: very bad, we have to load twice!!! Make QgsDataProvider::timestamp() static?
if ( stamp < mDataProvider->dataTimestamp() )
{
QgsDebugMsg( "data changed, reload provider" );
closeDataProvider();
init();
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
}
}

return res;
} // QgsRasterLayer::readXml( QDomNode & layer_node )

Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
*/
virtual void setSubLayerVisibility( const QString & name, bool vis );

/** Time stamp of data source in the moment when data/metadata were loaded by provider */
virtual QDateTime timestamp() const { return mDataProvider->timestamp() ; }

public slots:
/** \brief Create GDAL pyramid overviews */
QString buildPyramids( const RasterPyramidList &,
Expand Down

0 comments on commit 0c463d3

Please sign in to comment.