mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Make setEditable() return true/false to indicate success/error
This commit is contained in:
parent
f6f6ebdb44
commit
15cd8331ac
@ -242,13 +242,14 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
|
||||
|
||||
/** Turns on/off editing mode of the provider. When in editing mode, it is possible
|
||||
* to overwrite data of the provider using writeBlock() calls.
|
||||
* @note Only some providers support editing mode and even those may fail to turn turn
|
||||
* the underlying data source into editing mode, so it is necessery to check afterwards
|
||||
* with isEditable() whether the operation was successful.
|
||||
* @note Only some providers support editing mode and even those may fail to turn
|
||||
* the underlying data source into editing mode, so it is necessery to check the return
|
||||
* value whether the operation was successful.
|
||||
* @returns true if the switch to/from editing mode was successful
|
||||
* @see isEditable(), writeBlock()
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
virtual void setEditable( bool enabled );
|
||||
virtual bool setEditable( bool enabled );
|
||||
|
||||
/** Writes into the provider datasource*/
|
||||
// TODO: add data type (may be defferent from band type)
|
||||
|
@ -360,13 +360,14 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
|
||||
|
||||
/** Turns on/off editing mode of the provider. When in editing mode, it is possible
|
||||
* to overwrite data of the provider using writeBlock() calls.
|
||||
* @note Only some providers support editing mode and even those may fail to turn turn
|
||||
* the underlying data source into editing mode, so it is necessery to check afterwards
|
||||
* with isEditable() whether the operation was successful.
|
||||
* @note Only some providers support editing mode and even those may fail to turn
|
||||
* the underlying data source into editing mode, so it is necessery to check the return
|
||||
* value whether the operation was successful.
|
||||
* @returns true if the switch to/from editing mode was successful
|
||||
* @see isEditable(), writeBlock()
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
virtual void setEditable( bool enabled ) { Q_UNUSED( enabled ); }
|
||||
virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ); return false; }
|
||||
|
||||
//! Writes into the provider datasource
|
||||
// TODO: add data type (may be defferent from band type)
|
||||
|
@ -2933,16 +2933,16 @@ bool QgsGdalProvider::isEditable() const
|
||||
return mUpdate;
|
||||
}
|
||||
|
||||
void QgsGdalProvider::setEditable( bool enabled )
|
||||
bool QgsGdalProvider::setEditable( bool enabled )
|
||||
{
|
||||
if ( enabled == mUpdate )
|
||||
return;
|
||||
return false;
|
||||
|
||||
if ( !mValid )
|
||||
return;
|
||||
return false;
|
||||
|
||||
if ( mGdalDataset != mGdalBaseDataset )
|
||||
return; // ignore the case of warped VRT for now (more complicated setup)
|
||||
return false; // ignore the case of warped VRT for now (more complicated setup)
|
||||
|
||||
closeDataset();
|
||||
|
||||
@ -2954,12 +2954,13 @@ void QgsGdalProvider::setEditable( bool enabled )
|
||||
{
|
||||
QString msg = QStringLiteral( "Cannot reopen GDAL dataset %1:\n%2" ).arg( dataSourceUri(), QString::fromUtf8( CPLGetLastErrorMsg() ) );
|
||||
appendError( ERRMSG( msg ) );
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
|
||||
mGdalDataset = mGdalBaseDataset;
|
||||
mValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// pyramids resampling
|
||||
|
@ -149,7 +149,7 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
|
||||
static QMap<QString, QString> supportedMimes();
|
||||
|
||||
bool isEditable() const override;
|
||||
void setEditable( bool enabled ) override;
|
||||
bool setEditable( bool enabled ) override;
|
||||
bool write( void* data, int band, int width, int height, int xOffset, int yOffset ) override;
|
||||
|
||||
bool setNoDataValue( int bandNo, double noDataValue ) override;
|
||||
|
@ -184,15 +184,22 @@ void TestQgsRasterBlock::testWrite()
|
||||
res = rlayer->dataProvider()->writeBlock( block4, 1 );
|
||||
QVERIFY( !res );
|
||||
|
||||
// make the provider editable
|
||||
// some sanity checks
|
||||
QVERIFY( !rlayer->dataProvider()->isEditable() );
|
||||
rlayer->dataProvider()->setEditable( true );
|
||||
res = rlayer->dataProvider()->setEditable( false );
|
||||
QVERIFY( !res );
|
||||
|
||||
// make the provider editable
|
||||
res = rlayer->dataProvider()->setEditable( true );
|
||||
QVERIFY( res );
|
||||
QVERIFY( rlayer->dataProvider()->isEditable() );
|
||||
|
||||
res = rlayer->dataProvider()->writeBlock( block4, 1 );
|
||||
QVERIFY( res );
|
||||
|
||||
rlayer->dataProvider()->setEditable( false );
|
||||
// finish the editing session
|
||||
res = rlayer->dataProvider()->setEditable( false );
|
||||
QVERIFY( res );
|
||||
QVERIFY( !rlayer->dataProvider()->isEditable() );
|
||||
|
||||
// verify the change is there
|
||||
|
Loading…
x
Reference in New Issue
Block a user