Skip to content

Commit 9b8de1b

Browse files
author
wonder
committedJan 27, 2008
- QgisInterface's functions addRasterLayer/addVectorLayer return pointer to layer instead of just bool
- renamed QgisApp::addLayer to more appropriate QgisApp::addVectorLayer - cleanups in loading of raster/vector layers in QgisApp git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8055 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

9 files changed

+93
-255
lines changed

9 files changed

+93
-255
lines changed
 

‎python/gui/qgisinterface.sip

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ class QgisInterface : QObject
3636
virtual void zoomActiveLayer()=0;
3737

3838
//! Add a vector layer
39-
virtual bool addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
39+
virtual QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
4040
//! Add a raster layer given a raster layer file name
41-
virtual bool addRasterLayer(QString rasterLayerPath)=0;
42-
//! Add a raster layer given a QgsRasterLayer object
43-
virtual bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRenderFlag=false)=0;
41+
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
4442

4543
//! Add a project
4644
virtual bool addProject(QString theProject)=0;

‎src/app/qgisapp.cpp

Lines changed: 55 additions & 181 deletions
Large diffs are not rendered by default.

‎src/app/qgisapp.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class QgsProviderRegistry;
5050
class QgsPythonDialog;
5151
class QgsRasterLayer;
5252
class QgsRect;
53+
class QgsVectorLayer;
5354

5455
#include <map>
5556

@@ -72,36 +73,23 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
7273
//! Destructor
7374
~QgisApp();
7475
/**
75-
* Add a vector layer to the canvas
76+
* Add a vector layer to the canvas, returns pointer to it
7677
*/
77-
void addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
78+
QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
79+
7880
/** \brief overloaded vesion of the privat addLayer method that takes a list of
7981
* filenames instead of prompting user with a dialog.
8082
@param enc encoding type for the layer
8183
@returns true if successfully added layer
82-
@note
83-
This should be deprecated because it's possible to have a
84-
heterogeneous set of files; i.e., a mix of raster and vector.
85-
It's much better to try to just open one file at a time.
8684
*/
87-
bool addLayer(QStringList const & theLayerQStringList, const QString& enc);
85+
bool addVectorLayers(QStringList const & theLayerQStringList, const QString& enc);
8886

89-
/** open a vector layer for the given file
90-
@returns false if unable to open a raster layer for rasterFile
91-
@note
92-
This is essentially a simplified version of the above
93-
*/
94-
bool addLayer(QFileInfo const & vectorFile);
9587
/** overloaded vesion of the private addRasterLayer()
9688
Method that takes a list of filenames instead of prompting
9789
user with a dialog.
9890
@returns true if successfully added layer(s)
99-
@note
100-
This should be deprecated because it's possible to have a
101-
heterogeneous set of files; i.e., a mix of raster and vector.
102-
It's much better to try to just open one file at a time.
10391
*/
104-
bool addRasterLayer(QStringList const & theLayerQStringList, bool guiWarning=true);
92+
bool addRasterLayers(QStringList const & theLayerQStringList, bool guiWarning=true);
10593

10694
/** Open a raster layer using the Raster Data Provider.
10795
* Note this is included to support WMS layers only at this stage,
@@ -124,9 +112,11 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
124112
@note
125113
This is essentially a simplified version of the above
126114
*/
127-
bool addRasterLayer(QFileInfo const & rasterFile, bool guiWarning=true);
115+
QgsRasterLayer* addRasterLayer(QString const & rasterFile, QString const & baseName, bool guiWarning=true);
116+
128117
/** Add a 'pre-made' map layer to the project */
129118
void addMapLayer(QgsMapLayer *theMapLayer);
119+
130120
/** Set the extents of the map canvas */
131121
void setExtent(QgsRect theRect);
132122
//! Remove all layers from the map and legend - reimplements same method from qgisappbase
@@ -330,7 +320,7 @@ public slots:
330320
void destinationSrsChanged();
331321
// void debugHook();
332322
//! Add a vector layer to the map
333-
void addLayer();
323+
void addVectorLayer();
334324
//! Exit Qgis
335325
void fileExit();
336326
//! Add a WMS layer to the map
@@ -414,10 +404,9 @@ public slots:
414404

415405
private:
416406
/** Add a raster layer to the map (passed in as a ptr).
417-
* It won't force a refresh unless you explicitly
418-
* use the force redraw flag.
407+
* It won't force a refresh.
419408
*/
420-
bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRedrawFlag=false);
409+
bool addRasterLayer(QgsRasterLayer * theRasterLayer);
421410
//@todo We should move these next two into vector layer class
422411
/** This helper checks to see whether the filename appears to be a valid vector file name */
423412
bool isValidVectorFileName (QString theFileNameQString);

‎src/app/qgisappinterface.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/* $Id$ */
1919

2020
#include <iostream>
21+
#include <QFileInfo>
2122
#include <QString>
2223
#include <QMenu>
2324

@@ -56,22 +57,26 @@ void QgisAppInterface::zoomActiveLayer()
5657
qgis->zoomToLayerExtent();
5758
}
5859

59-
bool QgisAppInterface::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
60+
QgsVectorLayer* QgisAppInterface::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
6061
{
61-
qgis->addVectorLayer(vectorLayerPath, baseName, providerKey);
62-
//TODO fix this so it returns something meaningfull
63-
return true;
62+
if (baseName.isEmpty())
63+
{
64+
QFileInfo fi(vectorLayerPath);
65+
baseName = fi.completeBaseName();
66+
}
67+
return qgis->addVectorLayer(vectorLayerPath, baseName, providerKey);
6468
}
6569

66-
bool QgisAppInterface::addRasterLayer(QString rasterLayerPath)
70+
QgsRasterLayer* QgisAppInterface::addRasterLayer(QString rasterLayerPath, QString baseName)
6771
{
68-
return qgis->addRasterLayer( QStringList(rasterLayerPath) );
72+
if (baseName.isEmpty())
73+
{
74+
QFileInfo fi(rasterLayerPath);
75+
baseName = fi.completeBaseName();
76+
}
77+
return qgis->addRasterLayer(rasterLayerPath, baseName);
6978
}
7079

71-
bool QgisAppInterface::addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRenderFlag)
72-
{
73-
return qgis->addRasterLayer(theRasterLayer, theForceRenderFlag);
74-
}
7580

7681
bool QgisAppInterface::addProject(QString theProjectName)
7782
{
@@ -116,16 +121,6 @@ void QgisAppInterface::openURL(QString url, bool useQgisDocDirectory)
116121
qgis->openURL(url, useQgisDocDirectory);
117122
}
118123

119-
std::map<QString, int> QgisAppInterface::menuMapByName()
120-
{
121-
return qgis->menuMapByName();
122-
}
123-
124-
std::map<int, QString> QgisAppInterface::menuMapById()
125-
{
126-
return qgis->menuMapById();
127-
}
128-
129124
QgsMapCanvas * QgisAppInterface::getMapCanvas()
130125
{
131126
return qgis->getMapCanvas();

‎src/app/qgisappinterface.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ class QgisAppInterface : public QgisInterface
5151
void zoomActiveLayer();
5252

5353
//! Add a vector layer
54-
bool addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
54+
QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
5555
//! Add a raster layer given its file name
56-
bool addRasterLayer(QString rasterLayerPath);
57-
//! Add a raster layer given a raster layer obj
58-
bool addRasterLayer(QgsRasterLayer * theRasterLayer,bool theForceRenderFlag=false);
56+
QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName);
5957

6058
//! Add a project
6159
bool addProject(QString theProjectName);
@@ -81,11 +79,6 @@ class QgisAppInterface : public QgisInterface
8179
*/
8280
void openURL(QString url, bool useQgisDocDirectory=true);
8381

84-
/** Get the menu info mapped by menu name (key is name, value is menu id) */
85-
std::map<QString,int> menuMapByName();
86-
/** Get the menu info mapped by menu id (key is menu id, value is name) */
87-
std::map<int,QString> menuMapById();
88-
8982
/** Return a pointer to the map canvas used by qgisapp */
9083
QgsMapCanvas * getMapCanvas();
9184

‎src/gui/qgisinterface.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class QgisApp;
3232
class QgsMapLayer;
3333
class QgsMapCanvas;
3434
class QgsRasterLayer;
35+
class QgsVectorLayer;
3536

3637
/**
3738
* \class QgisInterface
@@ -68,11 +69,9 @@ class GUI_EXPORT QgisInterface : public QObject
6869
virtual void zoomActiveLayer()=0;
6970

7071
//! Add a vector layer
71-
virtual bool addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
72+
virtual QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
7273
//! Add a raster layer given a raster layer file name
73-
virtual bool addRasterLayer(QString rasterLayerPath)=0;
74-
//! Add a raster layer given a QgsRasterLayer object
75-
virtual bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRenderFlag=false)=0;
74+
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
7675

7776
//! Add a project
7877
virtual bool addProject(QString theProject)=0;

‎src/plugins/grass/qgsgrassbrowser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ void QgsGrassBrowser::addMap()
173173
if ( type == QgsGrassModel::Raster )
174174
{
175175
std::cerr << "add raster: " << uri.ascii() << std::endl;
176-
QgsRasterLayer *layer = new QgsRasterLayer( uri, map );
177-
mIface->addRasterLayer(layer);
176+
mIface->addRasterLayer(uri, map);
178177
mapSelected = true;
179178
}
180179
else if ( type == QgsGrassModel::Vector )

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,8 +1494,7 @@ void QgsGrassModule::viewOutput()
14941494
+ QgsGrass::getDefaultMapset()
14951495
+ "/cellhd/" + map;
14961496

1497-
QgsRasterLayer *layer = new QgsRasterLayer( uri, map );
1498-
mIface->addRasterLayer(layer);
1497+
mIface->addRasterLayer(uri, map);
14991498
}
15001499
}
15011500

‎src/plugins/grass/qgsgrassplugin.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,8 @@ void QgsGrassPlugin::addRaster()
411411
pos = uri.findRev('/', pos-1);
412412
QString name = uri.right( uri.length() - pos - 1 );
413413
name.replace('/', ' ');
414-
415-
//qGisInterface->addRasterLayer( uri );
416-
QgsRasterLayer *layer = new QgsRasterLayer( uri, sel->map );
417-
if( !layer->isValid() ) {
418-
// let the user know something went wrong - addRasterLayer cleans up
419-
QMessageBox::warning( 0, tr("Warning"), tr("Could not add raster layer: " ) + uri);
420-
}
421-
qGisInterface->addRasterLayer(layer);
422-
423-
mCanvas->refresh();
414+
415+
qGisInterface->addRasterLayer(uri, sel->map);
424416
}
425417
}
426418

0 commit comments

Comments
 (0)
Please sign in to comment.