Skip to content

Commit fe20dc8

Browse files
author
timlinux
committed
Use enum properly for qgsmaplayer type and refactored 'LAYERS' to LayerType
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9483 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1e68db9 commit fe20dc8

21 files changed

+74
-74
lines changed

ChangeLog

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ All that remains to do now is sort out syncronisation of layer ordering between
798798
conventions (prefixed with m).
799799

800800

801-
** Import Note *** ONLY THE MAPLAYER REGISTRY SHOULD DELETE LAYERS NOW ***
801+
** Import Note *** ONLY THE MAPLAYER REGISTRY SHOULD DELETE QgsMapLayer::LayerType NOW ***
802802

803803
2004-06-03 [ts] 0.3.0devel14
804804
** Added getPaletteAsPixmap function to raster and display on raster props

python/core/qgsmaplayer.sip

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class QgsMapLayer // TODO: problem when derived from QObject
1111

1212
%ConvertToSubClassCode
1313

14-
if (sipCpp->type() == QgsMapLayer::VECTOR)
14+
if (sipCpp->type() == QgsMapLayer::VectorLayer)
1515
{
1616
sipClass = sipClass_QgsVectorLayer;
1717
}
18-
else if (sipCpp->type() == QgsMapLayer::RASTER)
18+
else if (sipCpp->type() == QgsMapLayer::RasterLayer)
1919
{
2020
sipClass = sipClass_QgsRasterLayer;
2121
}
@@ -27,20 +27,26 @@ class QgsMapLayer // TODO: problem when derived from QObject
2727
%End
2828

2929
public:
30+
/** Layers enum defining the types of layers that can be added to a map */
31+
enum LayerType
32+
{
33+
VectorLayer,
34+
RasterLayer
35+
};
3036

3137
/** Constructor
32-
* @param type Type of layer as defined in LAYERS enum
38+
* @param type Type of layer as defined in QgsMapLayer::LayerType enum
3339
* @param lyrname Display Name of the layer
3440
*/
35-
QgsMapLayer(int type = 0, QString lyrname = QString::null, QString source = QString::null);
41+
QgsMapLayer(QgsMapLayer::LayerType type = QgsMapLayer::VectorLayer, QString lyrname = QString::null, QString source = QString::null);
3642

3743
/** Destructor */
3844
virtual ~QgsMapLayer();
3945

4046
/** Get the type of the layer
41-
* @return Integer matching a value in the LAYERS enum
47+
* @return Integer matching a value in the QgsMapLayer::LayerType enum
4248
*/
43-
int type() const;
49+
QgsMapLayer::LayerType type() const;
4450

4551
/** Get this layer's unique ID, this ID is used to access this layer from map layer registry */
4652
QString getLayerID() const;
@@ -97,12 +103,6 @@ public:
97103
/** Set the visibility of the given sublayer name */
98104
virtual void setSubLayerVisibility(QString name, bool vis);
99105

100-
/** Layers enum defining the types of layers that can be added to a map */
101-
enum LAYERS
102-
{
103-
VECTOR,
104-
RASTER
105-
};
106106

107107
/** True if the layer can be edited */
108108
virtual bool isEditable() const = 0;

src/app/legend/qgslegend.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ void QgsLegend::legendLayerShowProperties()
678678
a separate copy of the dialog pointer needs to be stored with each layer.
679679
*/
680680

681-
if ( ml->type() == QgsMapLayer::RASTER )
681+
if ( ml->type() == QgsMapLayer::RasterLayer )
682682
{
683683
QgsRasterLayerProperties *rlp = NULL; // See note above about reusing this
684684
if ( rlp )

src/app/legend/qgslegendlayer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void QgsLegendLayer::refreshSymbology( const QString& key, double widthScale )
268268
return;
269269
}
270270

271-
if ( theMapLayer->type() == QgsMapLayer::VECTOR ) // VECTOR
271+
if ( theMapLayer->type() == QgsMapLayer::VectorLayer ) // VECTOR
272272
{
273273
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( theMapLayer );
274274
vectorLayerSymbology( vlayer, widthScale ); // get and change symbology
@@ -436,7 +436,7 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
436436
QgsMapLayer* firstLayer = firstMapLayer();
437437
if ( firstLayer )
438438
{
439-
if ( firstLayer->type() == QgsMapLayer::VECTOR )
439+
if ( firstLayer->type() == QgsMapLayer::VectorLayer )
440440
{
441441
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( firstLayer );
442442
switch ( vlayer->type() )
@@ -454,7 +454,7 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
454454
return QgisApp::getThemePixmap( "/mIconLayer.png" );
455455
}
456456
}
457-
else if ( firstLayer->type() == QgsMapLayer::RASTER )
457+
else if ( firstLayer->type() == QgsMapLayer::RasterLayer )
458458
{
459459
QgsRasterLayer* rlayer = dynamic_cast<QgsRasterLayer*>( firstLayer );
460460
QPixmap myPixmap( 32, 32 );
@@ -479,7 +479,7 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingActio
479479
// zoom to layer extent
480480
theMenu.addAction( QgisApp::getThemeIcon( "/mActionZoomToLayer.png" ),
481481
tr( "&Zoom to layer extent" ), legend(), SLOT( legendLayerZoom() ) );
482-
if ( firstLayer && firstLayer->type() == QgsMapLayer::RASTER )
482+
if ( firstLayer && firstLayer->type() == QgsMapLayer::RasterLayer )
483483
{
484484
theMenu.addAction( tr( "&Zoom to best scale (100%)" ), legend(), SLOT( legendLayerZoomNative() ) );
485485
}
@@ -495,7 +495,7 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingActio
495495

496496
theMenu.addSeparator();
497497

498-
if ( firstLayer && firstLayer->type() == QgsMapLayer::VECTOR )
498+
if ( firstLayer && firstLayer->type() == QgsMapLayer::VectorLayer )
499499
{
500500
// attribute table
501501
QAction* tableAction = theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );

src/app/legend/qgslegendlayerfile.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void QgsLegendLayerFile::saveAsShapefileGeneral( bool saveOnlySelection )
229229
{
230230
QgsCoordinateReferenceSystem destCRS;
231231

232-
if ( mLyr.layer()->type() != QgsMapLayer::VECTOR )
232+
if ( mLyr.layer()->type() != QgsMapLayer::VectorLayer )
233233
return;
234234

235235
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( mLyr.layer() );
@@ -374,7 +374,7 @@ void QgsLegendLayerFile::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingA
374374

375375
theMenu.addSeparator();
376376

377-
if ( lyr->type() == QgsMapLayer::VECTOR )
377+
if ( lyr->type() == QgsMapLayer::VectorLayer )
378378
{
379379
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( lyr );
380380

@@ -403,7 +403,7 @@ void QgsLegendLayerFile::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingA
403403

404404
theMenu.addSeparator();
405405
}
406-
else if ( lyr->type() == QgsMapLayer::RASTER )
406+
else if ( lyr->type() == QgsMapLayer::RasterLayer )
407407
{
408408
// TODO: what was this for?
409409
//QgsRasterLayer* rlayer = dynamic_cast<QgsRasterLayer*>(lyr);

src/app/qgisapp.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,7 @@ void QgisApp::fileOpen()
29712971
QMessageBox::critical( this,
29722972
tr( "QGIS Project Read Error" ),
29732973
tr( "" ) + "\n" + QString::fromLocal8Bit( e.what() ) );
2974-
QgsDebugMsg( "BAD LAYERS FOUND" );
2974+
QgsDebugMsg( "BAD QgsMapLayer::LayerType FOUND" );
29752975
}
29762976

29772977
mMapCanvas->freeze( false );
@@ -3040,7 +3040,7 @@ bool QgisApp::addProject( QString projectFile )
30403040
}
30413041
catch ( std::exception & e )
30423042
{
3043-
QgsDebugMsg( "BAD LAYERS FOUND" );
3043+
QgsDebugMsg( "BAD QgsMapLayer::LayerType FOUND" );
30443044

30453045
QMessageBox::critical( this,
30463046
tr( "Unable to open project" ), QString::fromLocal8Bit( e.what() ) );
@@ -4943,7 +4943,7 @@ void QgisApp::showMapTip()
49434943
{
49444944
//QgsDebugMsg("Current layer for maptip display is: " + mypLayer->source());
49454945
// only process vector layers
4946-
if ( mypLayer->type() == QgsMapLayer::VECTOR )
4946+
if ( mypLayer->type() == QgsMapLayer::VectorLayer )
49474947
{
49484948
// Show the maptip if the maptips button is depressed
49494949
if ( mMapTipsVisible )
@@ -5054,7 +5054,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
50545054
mActionAddToOverview->setEnabled( true );
50555055

50565056
/***********Vector layers****************/
5057-
if ( layer->type() == QgsMapLayer::VECTOR )
5057+
if ( layer->type() == QgsMapLayer::VectorLayer )
50585058
{
50595059
mActionSelect->setEnabled( true );
50605060
mActionIdentify->setEnabled( true );
@@ -5198,7 +5198,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
51985198
}
51995199
}
52005200
/*************Raster layers*************/
5201-
else if ( layer->type() == QgsMapLayer::RASTER )
5201+
else if ( layer->type() == QgsMapLayer::RasterLayer )
52025202
{
52035203
mActionSelect->setEnabled( false );
52045204
mActionZoomActualSize->setEnabled( true );

src/app/qgsmapserverexport.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void QgsMapserverExport::writeMapFile()
205205
// feature type
206206
QgsDebugMsg( "\tMapsrver Export checking feature type" );
207207
mapFile << " TYPE ";
208-
if ( lyr->type() == QgsMapLayer::VECTOR )
208+
if ( lyr->type() == QgsMapLayer::VectorLayer )
209209
{
210210
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( lyr );
211211
switch ( vlayer->geometryType() )
@@ -227,7 +227,7 @@ void QgsMapserverExport::writeMapFile()
227227

228228
}
229229
}
230-
if ( lyr->type() == QgsMapLayer::RASTER )
230+
if ( lyr->type() == QgsMapLayer::RasterLayer )
231231
{
232232
mapFile << "RASTER";
233233
}
@@ -252,7 +252,7 @@ void QgsMapserverExport::writeMapFile()
252252
QgsDebugMsg( "\tMapsrver Export checking layer type" );
253253
switch ( lyr->type() )
254254
{
255-
case QgsMapLayer::VECTOR:
255+
case QgsMapLayer::VectorLayer:
256256
// get the provider type
257257
{
258258
QgsVectorLayer* vlyr = dynamic_cast<QgsVectorLayer*>( lyr );
@@ -286,7 +286,7 @@ void QgsMapserverExport::writeMapFile()
286286
}
287287
}
288288
break;
289-
case QgsMapLayer::RASTER:
289+
case QgsMapLayer::RasterLayer:
290290
mapFile << " DATA " << lyr->source().toLocal8Bit().data() << std::endl;
291291

292292
break;

src/app/qgsmaptoolidentify.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )
8787
// coordinates are sent back to the server as pixel coordinates
8888
// not the layer's native CRS. So identify on screen coordinates!
8989
if (
90-
( mLayer->type() == QgsMapLayer::RASTER )
90+
( mLayer->type() == QgsMapLayer::RasterLayer )
9191
&&
9292
( dynamic_cast<QgsRasterLayer*>( mLayer )->providerKey() == "wms" )
9393
)
@@ -99,11 +99,11 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )
9999
// convert screen coordinates to map coordinates
100100
QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
101101

102-
if ( mLayer->type() == QgsMapLayer::VECTOR )
102+
if ( mLayer->type() == QgsMapLayer::VectorLayer )
103103
{
104104
identifyVectorLayer( idPoint );
105105
}
106-
else if ( mLayer->type() == QgsMapLayer::RASTER )
106+
else if ( mLayer->type() == QgsMapLayer::RasterLayer )
107107
{
108108
identifyRasterLayer( idPoint );
109109
}

src/core/composer/qgslegendmodel.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ void QgsLegendModel::setLayerSet( const QStringList& layerIds )
6666

6767
switch ( currentLayer->type() )
6868
{
69-
case QgsMapLayer::VECTOR:
69+
case QgsMapLayer::VectorLayer:
7070
addVectorLayerItems( layerItem, currentLayer );
7171
break;
72-
case QgsMapLayer::RASTER:
72+
case QgsMapLayer::RasterLayer:
7373
addRasterLayerItem( layerItem, currentLayer );
7474
break;
7575
default:
@@ -246,10 +246,10 @@ void QgsLegendModel::updateLayer( QStandardItem* layerItem )
246246
//and add the new ones...
247247
switch ( mapLayer->type() )
248248
{
249-
case QgsMapLayer::VECTOR:
249+
case QgsMapLayer::VectorLayer:
250250
addVectorLayerItems( layerItem, mapLayer );
251251
break;
252-
case QgsMapLayer::RASTER:
252+
case QgsMapLayer::RasterLayer:
253253
addRasterLayerItem( layerItem, mapLayer );
254254
break;
255255
default:
@@ -408,10 +408,10 @@ void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer )
408408
//and child items of layer
409409
switch ( theMapLayer->type() )
410410
{
411-
case QgsMapLayer::VECTOR:
411+
case QgsMapLayer::VectorLayer:
412412
addVectorLayerItems( layerItem, theMapLayer );
413413
break;
414-
case QgsMapLayer::RASTER:
414+
case QgsMapLayer::RasterLayer:
415415
addRasterLayerItem( layerItem, theMapLayer );
416416
break;
417417
default:

src/core/qgsmaplayer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "qgsproject.h"
4141
#include "qgslogger.h"
4242

43-
QgsMapLayer::QgsMapLayer( int type,
43+
QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
4444
QString lyrname,
4545
QString source ) :
4646
mTransparencyLevel( 255 ), // 0 is completely transparent
@@ -82,7 +82,7 @@ QgsMapLayer::~QgsMapLayer()
8282
delete mCRS;
8383
}
8484

85-
int QgsMapLayer::type() const
85+
QgsMapLayer::LayerType QgsMapLayer::type() const
8686
{
8787
return mLayerType;
8888
}

src/core/qgsmaplayer.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,26 @@ class CORE_EXPORT QgsMapLayer : public QObject
4343
Q_OBJECT
4444

4545
public:
46+
/** Layers enum defining the types of layers that can be added to a map */
47+
enum LayerType
48+
{
49+
VectorLayer,
50+
RasterLayer
51+
};
4652

4753
/** Constructor
48-
* @param type Type of layer as defined in LAYERS enum
54+
* @param type Type of layer as defined in QgsMapLayer::LayerType enum
4955
* @param lyrname Display Name of the layer
5056
*/
51-
QgsMapLayer( int type = 0, QString lyrname = QString::null, QString source = QString::null );
57+
QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
5258

5359
/** Destructor */
5460
virtual ~QgsMapLayer();
5561

5662
/** Get the type of the layer
57-
* @return Integer matching a value in the LAYERS enum
63+
* @return Integer matching a value in the QgsMapLayer::LayerType enum
5864
*/
59-
int type() const;
65+
QgsMapLayer::LayerType type() const;
6066

6167
/** Get this layer's unique ID, this ID is used to access this layer from map layer registry */
6268
QString getLayerID() const;
@@ -111,12 +117,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
111117
/** Set the visibility of the given sublayer name */
112118
virtual void setSubLayerVisibility( QString name, bool vis );
113119

114-
/** Layers enum defining the types of layers that can be added to a map */
115-
enum LAYERS
116-
{
117-
VECTOR,
118-
RASTER
119-
};
120120

121121
/** True if the layer can be edited */
122122
virtual bool isEditable() const = 0;
@@ -344,7 +344,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
344344
QString mID;
345345

346346
/** Type of the layer (eg. vector, raster) */
347-
int mLayerType;
347+
QgsMapLayer::LayerType mLayerType;
348348

349349
/** Tag for embedding additional information */
350350
QString mTag;

src/core/qgsmaprenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void QgsMapRenderer::render( QPainter* painter )
321321
QgsMapToPixel rasterMapToPixel;
322322
QgsMapToPixel bk_mapToPixel;
323323

324-
if ( ml->type() == QgsMapLayer::RASTER && fabs( rasterScaleFactor - 1.0 ) > 0.000001 )
324+
if ( ml->type() == QgsMapLayer::RasterLayer && fabs( rasterScaleFactor - 1.0 ) > 0.000001 )
325325
{
326326
scaleRaster = true;
327327
}
@@ -386,7 +386,7 @@ void QgsMapRenderer::render( QPainter* painter )
386386
// TODO: emit drawingProgress((myRenderCounter++),zOrder.size());
387387
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
388388

389-
if ( ml && ( ml->type() != QgsMapLayer::RASTER ) )
389+
if ( ml && ( ml->type() != QgsMapLayer::RasterLayer ) )
390390
{
391391
// only make labels if the layer is visible
392392
// after scale dep viewing settings are checked

src/core/qgsvectorlayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
8989
QString baseName,
9090
QString providerKey,
9191
bool loadDefaultStyleFlag )
92-
: QgsMapLayer( VECTOR, baseName, vectorLayerPath ),
92+
: QgsMapLayer( VectorLayer, baseName, vectorLayerPath ),
9393
mUpdateThreshold( 0 ), // XXX better default value?
9494
mDataProvider( NULL ),
9595
mProviderKey( providerKey ),

0 commit comments

Comments
 (0)