Skip to content
Permalink
Browse files
completely reload provider if GRASS source data have changed
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15749 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Apr 17, 2011
1 parent a8507ae commit df6d87cff45d78d97f40e1d3e58eff6d50a222dc
@@ -94,8 +94,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
// enable or disable Build Pyramids button depending on selection in pyramid list
connect( lbxPyramidResolutions, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleBuildPyramidsButton() ) );

connect( mRasterLayer, SIGNAL( dataChanged( int ) ), this, SLOT( dataChanged( int ) ) );

// set up the scale based layer visibility stuff....
chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
leMinimumScale->setText( QString::number( lyr->minimumScale(), 'f' ) );
@@ -3040,11 +3038,6 @@ void QgsRasterLayerProperties::on_btnResetNull_clicked( )
}
}

void QgsRasterLayerProperties::dataChanged( int change )
{
QgsDebugMsg( "entered." );
}

void QgsRasterLayerProperties::toggleBuildPyramidsButton()
{
if ( lbxPyramidResolutions->selectedItems().empty() )
@@ -99,9 +99,6 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
/** \brief this slot sets StdDev switch box to 0.00 when user enters min max values */
void userDefinedMinMax_textEdited( QString );

/** \brief data changed reciever */
void dataChanged( int change );

private slots:
/** This slow handles necessary interface modifications (i.e. loading min max values) */
void on_cboBlue_currentIndexChanged( const QString& );
@@ -287,9 +287,6 @@ class CORE_EXPORT QgsDataProvider : public QObject
/** Current time stamp of data source */
virtual QDateTime dataTimestamp() const { return QDateTime(); }

/** test if at least one of specified data/metadata changed since provider was loaded */
virtual bool changed( int change ) { return false; }

signals:

/**
@@ -313,18 +310,18 @@ class CORE_EXPORT QgsDataProvider : public QObject
*/
void dataChanged( int change );

protected:
/**
* Timestamp of data in the moment when the data were loaded by provider.
*/
QDateTime mTimestamp;
private:

/**
* Universal Resource Identifier for source data.
* This could be a file, database, or server address.
*/
QString mDataSourceURI;

/**
* Timestamp of data in the moment when the data were loaded by provider.
*/
QDateTime mTimestamp;
};


@@ -116,17 +116,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
ProgressPyramids = 1
};

enum Change
{
NoChange = 0,
ValuesChange = 1,
ExtentChange = 1 << 1,
CrsChange = 1 << 2,
DataTypeChange = 1 << 3,
ColorTableChange = 1 << 4,
SizeChange = 1 << 5
};

QgsRasterDataProvider();

QgsRasterDataProvider( QString const & uri );
@@ -480,24 +469,17 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
/** \brief Set null value in char */
QByteArray noValueBytes( int theBandNo );

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

/** Current time stamp of data source */
virtual QDateTime dataTimestamp() const { return QDateTime(); }

/** Give list of changed data/metadata since provider was loaded */
virtual int changed( ) { return NoChange; }

signals:
/** Emit a signal to notify of the progress event.
* Emited theProgress is in percents (0.0-100.0) */
void progress( int theType, double theProgress, QString theMessage );

/**
* This is emitted whenever data or metadata (e.g. color table, extent) has changed
* @param changed binary combination of changes
* @note added in 1.7
*/
void dataChanged( int change );

protected:
/**Dots per intch. Extended WMS (e.g. QGIS mapserver) support DPI dependent output and therefore
are suited for printing. A value of -1 means it has not been set
@@ -127,6 +127,10 @@ QgsRasterLayer::QgsRasterLayer( int dummy,
, mInvertColor( false )
, mModified( false )
, mProviderKey( providerKey )
, mLayers( layers )
, mStyles( styles )
, mFormat( format )
, mCrs( crs )
{
QgsDebugMsg( "(8 arguments) starting. with layer list of " +
layers.join( ", " ) + " and style list of " + styles.join( ", " ) + " and format of " +
@@ -2531,6 +2535,21 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
QgsDebugMsg( "exiting." );
} // QgsRasterLayer::setDataProvider

void QgsRasterLayer::closeDataProvider()
{
mValid = false;
delete mRasterShader;
mRasterShader = 0;
delete mDataProvider;
mDataProvider = 0;

mRasterStatsList.clear();
mContrastEnhancementList.clear();

mHasPyramids = false;
mPyramidList.clear();
}

void QgsRasterLayer::setColorShadingAlgorithm( ColorShadingAlgorithm theShadingAlgorithm )
{
QgsDebugMsg( "called with [" + QString::number( theShadingAlgorithm ) + "]" );
@@ -4436,38 +4455,13 @@ bool QgsRasterLayer::update()
QgsDebugMsg( "entered." );

// Check if data changed
//if ( mLastModified < QgsRasterLayer::lastModified( source() ) )
//{
// TODO: lastModified to provider -> outdated
// TODO: check what has to be cleard, rebuild
int change = mDataProvider->changed();
if ( change != QgsRasterDataProvider::NoChange )
if ( mDataProvider->dataTimestamp() > mDataProvider->timestamp() )
{
QgsDebugMsg( "reload data" );
//mHasPyramids = false;
//mPyramidList.clear();

//mRasterStatsList.clear();
mValid = mDataProvider->reload();

for ( int i = 1; i <= mBandCount; i++ )
{
// TODO : refresh all data, move to separate method from constructor
// Reload color table
if ( i - 1 < mRasterStatsList.size() )
{
QList<QgsColorRampShader::ColorRampItem> ct;
ct = mDataProvider->colorTable( i );

mRasterStatsList[i-1].colorTable = ct;
if ( mRasterType == Palette )
{
QgsColorRampShader* myColorRampShader = ( QgsColorRampShader* ) mRasterShader->rasterShaderFunction();
myColorRampShader->setColorRampItemList( *colorTable( 1 ) );
}
}
}
emit dataChanged( change );
closeDataProvider();
init();
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
emit dataChanged();
}
return mValid;
}
@@ -685,10 +685,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

/**
* This is emitted whenever data or metadata (e.g. color table, extent) has changed
* @param changed binary combination of changes, defined in QgsRasterDataProvider
* @note added in 1.7
*/
void dataChanged( int change );
void dataChanged();

protected:

@@ -767,8 +766,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
const QgsMapToPixel* theQgsMapToPixel,
int theBandNoInt );

/** \brief Close data set and release related data */
void closeDataset();
/** \brief Close data provider and clear related members */
void closeDataProvider();

/** \brief helper function to create zero padded band names */
QString generateBandName( int );
@@ -913,6 +912,13 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

/** \brief Flag indicating if the nodatavalue is valid*/
bool mValidNoDataValue;

/** WMS parameters */
/* TODO: put everything to URI */
QStringList mLayers;
QStringList mStyles;
QString mFormat;
QString mCrs;
};

/*#include <QColor>
@@ -74,6 +74,8 @@ QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
QgsDebugMsg( QString( "mapset: %1" ).arg( mMapset ) );
QgsDebugMsg( QString( "mapName: %1" ).arg( mMapName ) );

mTimestamp = dataTimestamp();

mRasterValue.start( mGisdbase, mLocation, mMapset, mMapName );
mValidNoDataValue = true;

@@ -485,21 +487,24 @@ QString QgsGrassRasterProvider::description() const
return PROVIDER_DESCRIPTION;
}

int QgsGrassRasterProvider::changed()
QDateTime QgsGrassRasterProvider::dataTimestamp() const
{
QgsDebugMsg( "Entered" );
// TODO
return ValuesChange | ExtentChange | CrsChange | DataTypeChange | ColorTableChange | SizeChange;
}

bool QgsGrassRasterProvider::reload()
{
QgsDebugMsg( "Entered" );
return true;
QDateTime time;
QString mapset = mGisdbase + "/" + mLocation + "/" + mMapset;
QStringList dirs;
dirs << "cell" << "colr";
foreach( QString dir, dirs )
{
QString path = mapset + "/" + dir + "/" + mMapName;
QFileInfo fi( path );
if ( fi.exists() && fi.lastModified() > time )
{
time = fi.lastModified();
}
}
QgsDebugMsg( "timestamp = " + time.toString() );
return time;
}
//void QgsGrassRasterProvider::buildSupportedRasterFileFilter( QString & theFileFiltersString )
//{
//}

/**
* Class factory to return a pointer to a newly created
@@ -552,7 +557,14 @@ void QgsGrassRasterValue::start( QString gisdbase, QString location,
}
QgsGrassRasterValue::~QgsGrassRasterValue()
{
if ( mProcess ) delete mProcess;
if ( mProcess )
{
QgsDebugMsg( "closing process" );
mProcess->closeWriteChannel();
mProcess->waitForFinished();
QgsDebugMsg( "process finished" );
delete mProcess;
}
}

QString QgsGrassRasterValue::value( double x, double y )
@@ -244,8 +244,7 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
bool theThoroughBandScanFlag = false
);

int changed( );
bool reload( );
virtual QDateTime dataTimestamp() const;
private:

/**

0 comments on commit df6d87c

Please sign in to comment.