Skip to content

Commit 15cd833

Browse files
committedJan 19, 2017
Make setEditable() return true/false to indicate success/error
1 parent f6f6ebd commit 15cd833

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed
 

‎python/core/raster/qgsrasterdataprovider.sip

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,14 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
242242

243243
/** Turns on/off editing mode of the provider. When in editing mode, it is possible
244244
* to overwrite data of the provider using writeBlock() calls.
245-
* @note Only some providers support editing mode and even those may fail to turn turn
246-
* the underlying data source into editing mode, so it is necessery to check afterwards
247-
* with isEditable() whether the operation was successful.
245+
* @note Only some providers support editing mode and even those may fail to turn
246+
* the underlying data source into editing mode, so it is necessery to check the return
247+
* value whether the operation was successful.
248+
* @returns true if the switch to/from editing mode was successful
248249
* @see isEditable(), writeBlock()
249250
* @note added in QGIS 3.0
250251
*/
251-
virtual void setEditable( bool enabled );
252+
virtual bool setEditable( bool enabled );
252253

253254
/** Writes into the provider datasource*/
254255
// TODO: add data type (may be defferent from band type)

‎src/core/raster/qgsrasterdataprovider.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,14 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
360360

361361
/** Turns on/off editing mode of the provider. When in editing mode, it is possible
362362
* to overwrite data of the provider using writeBlock() calls.
363-
* @note Only some providers support editing mode and even those may fail to turn turn
364-
* the underlying data source into editing mode, so it is necessery to check afterwards
365-
* with isEditable() whether the operation was successful.
363+
* @note Only some providers support editing mode and even those may fail to turn
364+
* the underlying data source into editing mode, so it is necessery to check the return
365+
* value whether the operation was successful.
366+
* @returns true if the switch to/from editing mode was successful
366367
* @see isEditable(), writeBlock()
367368
* @note added in QGIS 3.0
368369
*/
369-
virtual void setEditable( bool enabled ) { Q_UNUSED( enabled ); }
370+
virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ); return false; }
370371

371372
//! Writes into the provider datasource
372373
// TODO: add data type (may be defferent from band type)

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,16 +2933,16 @@ bool QgsGdalProvider::isEditable() const
29332933
return mUpdate;
29342934
}
29352935

2936-
void QgsGdalProvider::setEditable( bool enabled )
2936+
bool QgsGdalProvider::setEditable( bool enabled )
29372937
{
29382938
if ( enabled == mUpdate )
2939-
return;
2939+
return false;
29402940

29412941
if ( !mValid )
2942-
return;
2942+
return false;
29432943

29442944
if ( mGdalDataset != mGdalBaseDataset )
2945-
return; // ignore the case of warped VRT for now (more complicated setup)
2945+
return false; // ignore the case of warped VRT for now (more complicated setup)
29462946

29472947
closeDataset();
29482948

@@ -2954,12 +2954,13 @@ void QgsGdalProvider::setEditable( bool enabled )
29542954
{
29552955
QString msg = QStringLiteral( "Cannot reopen GDAL dataset %1:\n%2" ).arg( dataSourceUri(), QString::fromUtf8( CPLGetLastErrorMsg() ) );
29562956
appendError( ERRMSG( msg ) );
2957-
return;
2957+
return false;
29582958
}
29592959

29602960
//Since we are not a virtual warped dataset, mGdalDataSet and mGdalBaseDataset are supposed to be the same
29612961
mGdalDataset = mGdalBaseDataset;
29622962
mValid = true;
2963+
return true;
29632964
}
29642965

29652966
// pyramids resampling

‎src/providers/gdal/qgsgdalprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
149149
static QMap<QString, QString> supportedMimes();
150150

151151
bool isEditable() const override;
152-
void setEditable( bool enabled ) override;
152+
bool setEditable( bool enabled ) override;
153153
bool write( void* data, int band, int width, int height, int xOffset, int yOffset ) override;
154154

155155
bool setNoDataValue( int bandNo, double noDataValue ) override;

‎tests/src/core/testqgsrasterblock.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,22 @@ void TestQgsRasterBlock::testWrite()
184184
res = rlayer->dataProvider()->writeBlock( block4, 1 );
185185
QVERIFY( !res );
186186

187-
// make the provider editable
187+
// some sanity checks
188188
QVERIFY( !rlayer->dataProvider()->isEditable() );
189-
rlayer->dataProvider()->setEditable( true );
189+
res = rlayer->dataProvider()->setEditable( false );
190+
QVERIFY( !res );
191+
192+
// make the provider editable
193+
res = rlayer->dataProvider()->setEditable( true );
194+
QVERIFY( res );
190195
QVERIFY( rlayer->dataProvider()->isEditable() );
191196

192197
res = rlayer->dataProvider()->writeBlock( block4, 1 );
193198
QVERIFY( res );
194199

195-
rlayer->dataProvider()->setEditable( false );
200+
// finish the editing session
201+
res = rlayer->dataProvider()->setEditable( false );
202+
QVERIFY( res );
196203
QVERIFY( !rlayer->dataProvider()->isEditable() );
197204

198205
// verify the change is there

0 commit comments

Comments
 (0)
Please sign in to comment.