mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-27 00:03:38 -04:00
- 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@8055 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
6b0f7eadf1
commit
a85df15615
@ -36,11 +36,9 @@ class QgisInterface : QObject
|
|||||||
virtual void zoomActiveLayer()=0;
|
virtual void zoomActiveLayer()=0;
|
||||||
|
|
||||||
//! Add a vector layer
|
//! Add a vector layer
|
||||||
virtual bool addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
|
virtual QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
|
||||||
//! Add a raster layer given a raster layer file name
|
//! Add a raster layer given a raster layer file name
|
||||||
virtual bool addRasterLayer(QString rasterLayerPath)=0;
|
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
|
||||||
//! Add a raster layer given a QgsRasterLayer object
|
|
||||||
virtual bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRenderFlag=false)=0;
|
|
||||||
|
|
||||||
//! Add a project
|
//! Add a project
|
||||||
virtual bool addProject(QString theProject)=0;
|
virtual bool addProject(QString theProject)=0;
|
||||||
|
@ -514,7 +514,7 @@ void QgisApp::createActions()
|
|||||||
mActionAddNonDbLayer= new QAction(QIcon(myIconPath+"/mActionAddNonDbLayer.png"), tr("Add a Vector Layer..."), this);
|
mActionAddNonDbLayer= new QAction(QIcon(myIconPath+"/mActionAddNonDbLayer.png"), tr("Add a Vector Layer..."), this);
|
||||||
mActionAddNonDbLayer->setShortcut(tr("V","Add a Vector Layer"));
|
mActionAddNonDbLayer->setShortcut(tr("V","Add a Vector Layer"));
|
||||||
mActionAddNonDbLayer->setStatusTip(tr("Add a Vector Layer"));
|
mActionAddNonDbLayer->setStatusTip(tr("Add a Vector Layer"));
|
||||||
connect(mActionAddNonDbLayer, SIGNAL(triggered()), this, SLOT(addLayer()));
|
connect(mActionAddNonDbLayer, SIGNAL(triggered()), this, SLOT(addVectorLayer()));
|
||||||
//
|
//
|
||||||
mActionAddRasterLayer= new QAction(QIcon(myIconPath+"/mActionAddRasterLayer.png"), tr("Add a Raster Layer..."), this);
|
mActionAddRasterLayer= new QAction(QIcon(myIconPath+"/mActionAddRasterLayer.png"), tr("Add a Raster Layer..."), this);
|
||||||
mActionAddRasterLayer->setShortcut(tr("R","Add a Raster Layer"));
|
mActionAddRasterLayer->setShortcut(tr("R","Add a Raster Layer"));
|
||||||
@ -1676,7 +1676,7 @@ static QString createFileFilter_(QString const &longName, QString const &glob)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Builds the list of file filter strings to later be used by
|
Builds the list of file filter strings to later be used by
|
||||||
QgisApp::addLayer()
|
QgisApp::addVectorLayer()
|
||||||
|
|
||||||
We query OGR for a list of supported vector formats; we then build a list
|
We query OGR for a list of supported vector formats; we then build a list
|
||||||
of file filter strings from that list. We return a string that contains
|
of file filter strings from that list. We return a string that contains
|
||||||
@ -1905,11 +1905,8 @@ static void openFilesRememberingFilter_(QString const &filterName,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
This method prompts the user for a list of vector filenames with a dialog.
|
This method prompts the user for a list of vector filenames with a dialog.
|
||||||
|
|
||||||
@todo XXX I'd really like to return false, but can't because this
|
|
||||||
XXX is for a slot that was defined void; need to fix.
|
|
||||||
*/
|
*/
|
||||||
void QgisApp::addLayer()
|
void QgisApp::addVectorLayer()
|
||||||
{
|
{
|
||||||
if(mMapCanvas && mMapCanvas->isDrawing())
|
if(mMapCanvas && mMapCanvas->isDrawing())
|
||||||
{
|
{
|
||||||
@ -1932,96 +1929,16 @@ void QgisApp::addLayer()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addLayer(selectedFiles, enc);
|
addVectorLayers(selectedFiles, enc);
|
||||||
} // QgisApp::addLayer()
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool QgisApp::addVectorLayers(QStringList const & theLayerQStringList, const QString& enc)
|
||||||
|
|
||||||
bool QgisApp::addLayer(QFileInfo const & vectorFile)
|
|
||||||
{
|
{
|
||||||
// let the user know we're going to possibly be taking a while
|
|
||||||
// Let render() do its own cursor management
|
|
||||||
// QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
||||||
|
|
||||||
mMapCanvas->freeze(); // XXX why do we do this?
|
|
||||||
|
|
||||||
// create the layer
|
|
||||||
QgsDebugMsg("completeBaseName is: " + vectorFile.completeBaseName());
|
|
||||||
|
|
||||||
QgsVectorLayer *layer = new QgsVectorLayer(vectorFile.filePath(),
|
|
||||||
vectorFile.completeBaseName(),
|
|
||||||
"ogr");
|
|
||||||
Q_CHECK_PTR( layer );
|
|
||||||
|
|
||||||
if ( ! layer )
|
|
||||||
{
|
|
||||||
mMapCanvas->freeze(false);
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
|
|
||||||
// XXX insert meaningful whine to the user here
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layer->isValid())
|
|
||||||
{
|
|
||||||
// Register this layer with the layers registry
|
|
||||||
QgsMapLayerRegistry::instance()->addMapLayer(layer);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QString msg = vectorFile.completeBaseName() + " ";
|
|
||||||
msg += tr("is not a valid or recognized data source");
|
|
||||||
QMessageBox::critical(this, tr("Invalid Data Source"), msg);
|
|
||||||
|
|
||||||
// since the layer is bad, stomp on it
|
|
||||||
delete layer;
|
|
||||||
|
|
||||||
mMapCanvas->freeze(false);
|
|
||||||
|
|
||||||
// Let render() do its own cursor management
|
|
||||||
// QApplication::restoreOverrideCursor();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update UI
|
|
||||||
qApp->processEvents();
|
|
||||||
|
|
||||||
// draw the map
|
|
||||||
mMapCanvas->freeze(false);
|
|
||||||
mMapCanvas->refresh();
|
|
||||||
|
|
||||||
// Let render() do its own cursor management
|
|
||||||
// QApplication::restoreOverrideCursor();
|
|
||||||
|
|
||||||
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} // QgisApp::addLayer()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** \brief overloaded vesion of the above method that takes a list of
|
|
||||||
* filenames instead of prompting user with a dialog.
|
|
||||||
|
|
||||||
XXX yah know, this could be changed to just iteratively call the above
|
|
||||||
|
|
||||||
*/
|
|
||||||
bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& enc)
|
|
||||||
{
|
|
||||||
mMapCanvas->freeze();
|
|
||||||
|
|
||||||
// Let render() do its own cursor management
|
|
||||||
// QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
||||||
|
|
||||||
for ( QStringList::ConstIterator it = theLayerQStringList.begin();
|
for ( QStringList::ConstIterator it = theLayerQStringList.begin();
|
||||||
it != theLayerQStringList.end();
|
it != theLayerQStringList.end();
|
||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
QFileInfo fi(*it);
|
QFileInfo fi(*it);
|
||||||
QString base = fi.completeBaseName();
|
QString base = fi.completeBaseName();
|
||||||
@ -2080,9 +1997,7 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
|
|||||||
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
||||||
|
|
||||||
|
|
||||||
return true;
|
} // QgisApp::addVectorLayer()
|
||||||
|
|
||||||
} // QgisApp::addLayer()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -2188,8 +2103,6 @@ void QgisApp::addWmsLayer()
|
|||||||
|
|
||||||
QgsServerSourceSelect *wmss = new QgsServerSourceSelect(this);
|
QgsServerSourceSelect *wmss = new QgsServerSourceSelect(this);
|
||||||
|
|
||||||
mMapCanvas->freeze();
|
|
||||||
|
|
||||||
if (wmss->exec())
|
if (wmss->exec())
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -2712,10 +2625,9 @@ void QgisApp::newVectorLayer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//then add the layer to the view
|
//then add the layer to the view
|
||||||
QStringList filelist;
|
QStringList filenames;
|
||||||
filelist.append(filename);
|
filenames.append(filename);
|
||||||
addLayer(filelist, enc);
|
addVectorLayers(filenames, enc);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgisApp::fileOpen()
|
void QgisApp::fileOpen()
|
||||||
@ -3107,12 +3019,12 @@ bool QgisApp::openLayer(const QString & fileName)
|
|||||||
{
|
{
|
||||||
QFileInfo fileInfo(fileName);
|
QFileInfo fileInfo(fileName);
|
||||||
// try to load it as raster
|
// try to load it as raster
|
||||||
bool ok = false;
|
QgsMapLayer* ok = NULL;
|
||||||
CPLPushErrorHandler(CPLQuietErrorHandler);
|
CPLPushErrorHandler(CPLQuietErrorHandler);
|
||||||
if (QgsRasterLayer::isValidRasterFileName(fileName))
|
if (QgsRasterLayer::isValidRasterFileName(fileName))
|
||||||
ok = addRasterLayer(fileInfo, false);
|
ok = addRasterLayer(fileName, false);
|
||||||
else // nope - try to load it as a shape/ogr
|
else // nope - try to load it as a shape/ogr
|
||||||
ok = addLayer(fileInfo);
|
ok = addVectorLayer(fileName, fileName, "ogr");
|
||||||
CPLPopErrorHandler();
|
CPLPopErrorHandler();
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
@ -3754,10 +3666,6 @@ void QgisApp::userScale()
|
|||||||
}
|
}
|
||||||
void QgisApp::testButton()
|
void QgisApp::testButton()
|
||||||
{
|
{
|
||||||
/* QgsShapeFileLayer *sfl = new QgsShapeFileLayer("foo");
|
|
||||||
mMapCanvas->addLayer(sfl); */
|
|
||||||
// delete sfl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgisApp::menubar_highlighted( int i )
|
void QgisApp::menubar_highlighted( int i )
|
||||||
@ -4394,11 +4302,11 @@ QgsMapLayer *QgisApp::activeLayer()
|
|||||||
parameter is used in the Map Legend so it should be formed in a meaningful
|
parameter is used in the Map Legend so it should be formed in a meaningful
|
||||||
way.
|
way.
|
||||||
*/
|
*/
|
||||||
void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
|
QgsVectorLayer* QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
|
||||||
{
|
{
|
||||||
if(mMapCanvas && mMapCanvas->isDrawing())
|
if(mMapCanvas && mMapCanvas->isDrawing())
|
||||||
{
|
{
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mMapCanvas->freeze();
|
mMapCanvas->freeze();
|
||||||
@ -4423,8 +4331,6 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString
|
|||||||
// Register this layer with the layers registry
|
// Register this layer with the layers registry
|
||||||
QgsMapLayerRegistry::instance()->addMapLayer(layer);
|
QgsMapLayerRegistry::instance()->addMapLayer(layer);
|
||||||
|
|
||||||
QgsProject::instance()->dirty(false); // XXX this might be redundant
|
|
||||||
|
|
||||||
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -4432,6 +4338,10 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString
|
|||||||
{
|
{
|
||||||
QMessageBox::critical(this,tr("Layer is not valid"),
|
QMessageBox::critical(this,tr("Layer is not valid"),
|
||||||
tr("The layer is not a valid layer and can not be added to the map"));
|
tr("The layer is not a valid layer and can not be added to the map"));
|
||||||
|
|
||||||
|
delete layer;
|
||||||
|
mMapCanvas->freeze(false);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update UI
|
// update UI
|
||||||
@ -4444,6 +4354,8 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString
|
|||||||
// Let render() do its own cursor management
|
// Let render() do its own cursor management
|
||||||
// QApplication::restoreOverrideCursor();
|
// QApplication::restoreOverrideCursor();
|
||||||
|
|
||||||
|
return layer;
|
||||||
|
|
||||||
} // QgisApp::addVectorLayer
|
} // QgisApp::addVectorLayer
|
||||||
|
|
||||||
|
|
||||||
@ -5067,9 +4979,7 @@ void QgisApp::showCapturePointCoordinate(QgsPoint & theQgsPoint)
|
|||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
/** @todo XXX I'd *really* like to return, ya know, _false_.
|
// this is a slot for action from GUI to add raster layer
|
||||||
*/
|
|
||||||
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
|
|
||||||
void QgisApp::addRasterLayer()
|
void QgisApp::addRasterLayer()
|
||||||
{
|
{
|
||||||
if(mMapCanvas && mMapCanvas->isDrawing())
|
if(mMapCanvas && mMapCanvas->isDrawing())
|
||||||
@ -5077,8 +4987,6 @@ void QgisApp::addRasterLayer()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//mMapCanvas->freeze(true);
|
|
||||||
|
|
||||||
QString fileFilters;
|
QString fileFilters;
|
||||||
|
|
||||||
QStringList selectedFiles;
|
QStringList selectedFiles;
|
||||||
@ -5093,9 +5001,8 @@ void QgisApp::addRasterLayer()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addRasterLayer(selectedFiles);
|
addRasterLayers(selectedFiles);
|
||||||
mMapCanvas->freeze(false);
|
|
||||||
mMapCanvas->refresh();
|
|
||||||
}// QgisApp::addRasterLayer()
|
}// QgisApp::addRasterLayer()
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -5104,7 +5011,7 @@ void QgisApp::addRasterLayer()
|
|||||||
// of the calling method to manage things such as the frozen state of the mapcanvas and
|
// of the calling method to manage things such as the frozen state of the mapcanvas and
|
||||||
// using waitcursors etc. - this method wont and SHOULDNT do it
|
// using waitcursors etc. - this method wont and SHOULDNT do it
|
||||||
//
|
//
|
||||||
bool QgisApp::addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRedrawFlag)
|
bool QgisApp::addRasterLayer(QgsRasterLayer * theRasterLayer)
|
||||||
{
|
{
|
||||||
if(mMapCanvas && mMapCanvas->isDrawing())
|
if(mMapCanvas && mMapCanvas->isDrawing())
|
||||||
{
|
{
|
||||||
@ -5120,59 +5027,37 @@ bool QgisApp::addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRedra
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theRasterLayer->isValid())
|
if (!theRasterLayer->isValid())
|
||||||
{
|
|
||||||
// register this layer with the central layers registry
|
|
||||||
QgsMapLayerRegistry::instance()->addMapLayer(theRasterLayer);
|
|
||||||
// XXX doesn't the mMapCanvas->addLayer() do this?
|
|
||||||
// XXX now it does
|
|
||||||
// QObject::connect(theRasterLayer,
|
|
||||||
// SIGNAL(repaintRequested()),
|
|
||||||
// mMapCanvas,
|
|
||||||
// SLOT(refresh()));
|
|
||||||
|
|
||||||
// connect up any request the raster may make to update the app progress
|
|
||||||
QObject::connect(theRasterLayer,
|
|
||||||
SIGNAL(drawingProgress(int,int)),
|
|
||||||
this,
|
|
||||||
SLOT(showProgress(int,int)));
|
|
||||||
// connect up any request the raster may make to update the statusbar message
|
|
||||||
QObject::connect(theRasterLayer,
|
|
||||||
SIGNAL(setStatus(QString)),
|
|
||||||
this,
|
|
||||||
SLOT(showStatusMessage(QString)));
|
|
||||||
|
|
||||||
// add it to the mapcanvas collection
|
|
||||||
// no longer necessary since adding to registry automatically adds to canvas
|
|
||||||
// mMapCanvas->addLayer(theRasterLayer);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
delete theRasterLayer;
|
delete theRasterLayer;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theForceRedrawFlag)
|
// register this layer with the central layers registry
|
||||||
{
|
QgsMapLayerRegistry::instance()->addMapLayer(theRasterLayer);
|
||||||
// update UI
|
|
||||||
qApp->processEvents();
|
|
||||||
// draw the map
|
|
||||||
mMapCanvas->freeze(false);
|
|
||||||
mMapCanvas->refresh();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
// connect up any request the raster may make to update the app progress
|
||||||
|
QObject::connect(theRasterLayer,
|
||||||
|
SIGNAL(drawingProgress(int,int)),
|
||||||
|
this,
|
||||||
|
SLOT(showProgress(int,int)));
|
||||||
|
// connect up any request the raster may make to update the statusbar message
|
||||||
|
QObject::connect(theRasterLayer,
|
||||||
|
SIGNAL(setStatus(QString)),
|
||||||
|
this,
|
||||||
|
SLOT(showStatusMessage(QString)));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
|
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
|
||||||
|
|
||||||
bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
|
QgsRasterLayer* QgisApp::addRasterLayer(QString const & rasterFile, QString const & baseName, bool guiWarning)
|
||||||
{
|
{
|
||||||
if(mMapCanvas && mMapCanvas->isDrawing())
|
if(mMapCanvas && mMapCanvas->isDrawing())
|
||||||
{
|
{
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let the user know we're going to possibly be taking a while
|
// let the user know we're going to possibly be taking a while
|
||||||
@ -5183,7 +5068,7 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
|
|||||||
// XXX ya know QgsRasterLayer can snip out the basename on its own;
|
// XXX ya know QgsRasterLayer can snip out the basename on its own;
|
||||||
// XXX why do we have to pass it in for it?
|
// XXX why do we have to pass it in for it?
|
||||||
QgsRasterLayer *layer =
|
QgsRasterLayer *layer =
|
||||||
new QgsRasterLayer(rasterFile.filePath(), rasterFile.completeBaseName());
|
new QgsRasterLayer(rasterFile, baseName); // fi.completeBaseName());
|
||||||
|
|
||||||
if (!addRasterLayer(layer))
|
if (!addRasterLayer(layer))
|
||||||
{
|
{
|
||||||
@ -5196,12 +5081,12 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
|
|||||||
if(guiWarning)
|
if(guiWarning)
|
||||||
{
|
{
|
||||||
// don't show the gui warning (probably because we are loading from command line)
|
// don't show the gui warning (probably because we are loading from command line)
|
||||||
QString msg(rasterFile.completeBaseName()
|
QString msg(rasterFile
|
||||||
+ tr(" is not a valid or recognized raster data source"));
|
+ tr(" is not a valid or recognized raster data source"));
|
||||||
QMessageBox::critical(this, tr("Invalid Data Source"), msg);
|
QMessageBox::critical(this, tr("Invalid Data Source"), msg);
|
||||||
}
|
}
|
||||||
delete layer;
|
delete layer;
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -5212,7 +5097,9 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
|
|||||||
// Let render() do its own cursor management
|
// Let render() do its own cursor management
|
||||||
// QApplication::restoreOverrideCursor();
|
// QApplication::restoreOverrideCursor();
|
||||||
|
|
||||||
return true;
|
mMapCanvas->refresh();
|
||||||
|
|
||||||
|
return layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // QgisApp::addRasterLayer
|
} // QgisApp::addRasterLayer
|
||||||
@ -5275,21 +5162,7 @@ void QgisApp::addRasterLayer(QString const & rasterLayerPath,
|
|||||||
|
|
||||||
if( layer && layer->isValid() )
|
if( layer && layer->isValid() )
|
||||||
{
|
{
|
||||||
// Register this layer with the layers registry
|
addRasterLayer(layer);
|
||||||
QgsMapLayerRegistry::instance()->addMapLayer(layer);
|
|
||||||
|
|
||||||
// connect up any request the raster may make to update the app progress
|
|
||||||
QObject::connect(layer,
|
|
||||||
SIGNAL(drawingProgress(int,int)),
|
|
||||||
this,
|
|
||||||
SLOT(showProgress(int,int)));
|
|
||||||
// connect up any request the raster may make to update the statusbar message
|
|
||||||
QObject::connect(layer,
|
|
||||||
SIGNAL(setStatus(QString)),
|
|
||||||
this,
|
|
||||||
SLOT(showStatusMessage(QString)));
|
|
||||||
|
|
||||||
QgsProject::instance()->dirty(false); // XXX this might be redundant
|
|
||||||
|
|
||||||
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
||||||
|
|
||||||
@ -5314,7 +5187,7 @@ void QgisApp::addRasterLayer(QString const & rasterLayerPath,
|
|||||||
|
|
||||||
|
|
||||||
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
|
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *)
|
||||||
bool QgisApp::addRasterLayer(QStringList const &theFileNameQStringList, bool guiWarning)
|
bool QgisApp::addRasterLayers(QStringList const &theFileNameQStringList, bool guiWarning)
|
||||||
{
|
{
|
||||||
if(mMapCanvas && mMapCanvas->isDrawing())
|
if(mMapCanvas && mMapCanvas->isDrawing())
|
||||||
{
|
{
|
||||||
@ -5384,6 +5257,7 @@ bool QgisApp::addRasterLayer(QStringList const &theFileNameQStringList, bool gui
|
|||||||
|
|
||||||
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
statusBar()->message(mMapCanvas->extent().stringRep(2));
|
||||||
mMapCanvas->freeze(false);
|
mMapCanvas->freeze(false);
|
||||||
|
mMapCanvas->refresh();
|
||||||
|
|
||||||
// Let render() do its own cursor management
|
// Let render() do its own cursor management
|
||||||
// QApplication::restoreOverrideCursor();
|
// QApplication::restoreOverrideCursor();
|
||||||
|
@ -50,6 +50,7 @@ class QgsProviderRegistry;
|
|||||||
class QgsPythonDialog;
|
class QgsPythonDialog;
|
||||||
class QgsRasterLayer;
|
class QgsRasterLayer;
|
||||||
class QgsRect;
|
class QgsRect;
|
||||||
|
class QgsVectorLayer;
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -72,36 +73,23 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
|
|||||||
//! Destructor
|
//! Destructor
|
||||||
~QgisApp();
|
~QgisApp();
|
||||||
/**
|
/**
|
||||||
* Add a vector layer to the canvas
|
* Add a vector layer to the canvas, returns pointer to it
|
||||||
*/
|
*/
|
||||||
void addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
|
QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
|
||||||
|
|
||||||
/** \brief overloaded vesion of the privat addLayer method that takes a list of
|
/** \brief overloaded vesion of the privat addLayer method that takes a list of
|
||||||
* filenames instead of prompting user with a dialog.
|
* filenames instead of prompting user with a dialog.
|
||||||
@param enc encoding type for the layer
|
@param enc encoding type for the layer
|
||||||
@returns true if successfully added layer
|
@returns true if successfully added layer
|
||||||
@note
|
|
||||||
This should be deprecated because it's possible to have a
|
|
||||||
heterogeneous set of files; i.e., a mix of raster and vector.
|
|
||||||
It's much better to try to just open one file at a time.
|
|
||||||
*/
|
*/
|
||||||
bool addLayer(QStringList const & theLayerQStringList, const QString& enc);
|
bool addVectorLayers(QStringList const & theLayerQStringList, const QString& enc);
|
||||||
|
|
||||||
/** open a vector layer for the given file
|
|
||||||
@returns false if unable to open a raster layer for rasterFile
|
|
||||||
@note
|
|
||||||
This is essentially a simplified version of the above
|
|
||||||
*/
|
|
||||||
bool addLayer(QFileInfo const & vectorFile);
|
|
||||||
/** overloaded vesion of the private addRasterLayer()
|
/** overloaded vesion of the private addRasterLayer()
|
||||||
Method that takes a list of filenames instead of prompting
|
Method that takes a list of filenames instead of prompting
|
||||||
user with a dialog.
|
user with a dialog.
|
||||||
@returns true if successfully added layer(s)
|
@returns true if successfully added layer(s)
|
||||||
@note
|
|
||||||
This should be deprecated because it's possible to have a
|
|
||||||
heterogeneous set of files; i.e., a mix of raster and vector.
|
|
||||||
It's much better to try to just open one file at a time.
|
|
||||||
*/
|
*/
|
||||||
bool addRasterLayer(QStringList const & theLayerQStringList, bool guiWarning=true);
|
bool addRasterLayers(QStringList const & theLayerQStringList, bool guiWarning=true);
|
||||||
|
|
||||||
/** Open a raster layer using the Raster Data Provider.
|
/** Open a raster layer using the Raster Data Provider.
|
||||||
* Note this is included to support WMS layers only at this stage,
|
* Note this is included to support WMS layers only at this stage,
|
||||||
@ -124,9 +112,11 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
|
|||||||
@note
|
@note
|
||||||
This is essentially a simplified version of the above
|
This is essentially a simplified version of the above
|
||||||
*/
|
*/
|
||||||
bool addRasterLayer(QFileInfo const & rasterFile, bool guiWarning=true);
|
QgsRasterLayer* addRasterLayer(QString const & rasterFile, QString const & baseName, bool guiWarning=true);
|
||||||
|
|
||||||
/** Add a 'pre-made' map layer to the project */
|
/** Add a 'pre-made' map layer to the project */
|
||||||
void addMapLayer(QgsMapLayer *theMapLayer);
|
void addMapLayer(QgsMapLayer *theMapLayer);
|
||||||
|
|
||||||
/** Set the extents of the map canvas */
|
/** Set the extents of the map canvas */
|
||||||
void setExtent(QgsRect theRect);
|
void setExtent(QgsRect theRect);
|
||||||
//! Remove all layers from the map and legend - reimplements same method from qgisappbase
|
//! Remove all layers from the map and legend - reimplements same method from qgisappbase
|
||||||
@ -330,7 +320,7 @@ public slots:
|
|||||||
void destinationSrsChanged();
|
void destinationSrsChanged();
|
||||||
// void debugHook();
|
// void debugHook();
|
||||||
//! Add a vector layer to the map
|
//! Add a vector layer to the map
|
||||||
void addLayer();
|
void addVectorLayer();
|
||||||
//! Exit Qgis
|
//! Exit Qgis
|
||||||
void fileExit();
|
void fileExit();
|
||||||
//! Add a WMS layer to the map
|
//! Add a WMS layer to the map
|
||||||
@ -414,10 +404,9 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/** Add a raster layer to the map (passed in as a ptr).
|
/** Add a raster layer to the map (passed in as a ptr).
|
||||||
* It won't force a refresh unless you explicitly
|
* It won't force a refresh.
|
||||||
* use the force redraw flag.
|
|
||||||
*/
|
*/
|
||||||
bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRedrawFlag=false);
|
bool addRasterLayer(QgsRasterLayer * theRasterLayer);
|
||||||
//@todo We should move these next two into vector layer class
|
//@todo We should move these next two into vector layer class
|
||||||
/** This helper checks to see whether the filename appears to be a valid vector file name */
|
/** This helper checks to see whether the filename appears to be a valid vector file name */
|
||||||
bool isValidVectorFileName (QString theFileNameQString);
|
bool isValidVectorFileName (QString theFileNameQString);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
@ -56,22 +57,26 @@ void QgisAppInterface::zoomActiveLayer()
|
|||||||
qgis->zoomToLayerExtent();
|
qgis->zoomToLayerExtent();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgisAppInterface::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
|
QgsVectorLayer* QgisAppInterface::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
|
||||||
{
|
{
|
||||||
qgis->addVectorLayer(vectorLayerPath, baseName, providerKey);
|
if (baseName.isEmpty())
|
||||||
//TODO fix this so it returns something meaningfull
|
{
|
||||||
return true;
|
QFileInfo fi(vectorLayerPath);
|
||||||
|
baseName = fi.completeBaseName();
|
||||||
|
}
|
||||||
|
return qgis->addVectorLayer(vectorLayerPath, baseName, providerKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgisAppInterface::addRasterLayer(QString rasterLayerPath)
|
QgsRasterLayer* QgisAppInterface::addRasterLayer(QString rasterLayerPath, QString baseName)
|
||||||
{
|
{
|
||||||
return qgis->addRasterLayer( QStringList(rasterLayerPath) );
|
if (baseName.isEmpty())
|
||||||
|
{
|
||||||
|
QFileInfo fi(rasterLayerPath);
|
||||||
|
baseName = fi.completeBaseName();
|
||||||
|
}
|
||||||
|
return qgis->addRasterLayer(rasterLayerPath, baseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgisAppInterface::addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRenderFlag)
|
|
||||||
{
|
|
||||||
return qgis->addRasterLayer(theRasterLayer, theForceRenderFlag);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QgisAppInterface::addProject(QString theProjectName)
|
bool QgisAppInterface::addProject(QString theProjectName)
|
||||||
{
|
{
|
||||||
@ -116,16 +121,6 @@ void QgisAppInterface::openURL(QString url, bool useQgisDocDirectory)
|
|||||||
qgis->openURL(url, useQgisDocDirectory);
|
qgis->openURL(url, useQgisDocDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<QString, int> QgisAppInterface::menuMapByName()
|
|
||||||
{
|
|
||||||
return qgis->menuMapByName();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<int, QString> QgisAppInterface::menuMapById()
|
|
||||||
{
|
|
||||||
return qgis->menuMapById();
|
|
||||||
}
|
|
||||||
|
|
||||||
QgsMapCanvas * QgisAppInterface::getMapCanvas()
|
QgsMapCanvas * QgisAppInterface::getMapCanvas()
|
||||||
{
|
{
|
||||||
return qgis->getMapCanvas();
|
return qgis->getMapCanvas();
|
||||||
|
@ -51,11 +51,9 @@ class QgisAppInterface : public QgisInterface
|
|||||||
void zoomActiveLayer();
|
void zoomActiveLayer();
|
||||||
|
|
||||||
//! Add a vector layer
|
//! Add a vector layer
|
||||||
bool addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
|
QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey);
|
||||||
//! Add a raster layer given its file name
|
//! Add a raster layer given its file name
|
||||||
bool addRasterLayer(QString rasterLayerPath);
|
QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName);
|
||||||
//! Add a raster layer given a raster layer obj
|
|
||||||
bool addRasterLayer(QgsRasterLayer * theRasterLayer,bool theForceRenderFlag=false);
|
|
||||||
|
|
||||||
//! Add a project
|
//! Add a project
|
||||||
bool addProject(QString theProjectName);
|
bool addProject(QString theProjectName);
|
||||||
@ -81,11 +79,6 @@ class QgisAppInterface : public QgisInterface
|
|||||||
*/
|
*/
|
||||||
void openURL(QString url, bool useQgisDocDirectory=true);
|
void openURL(QString url, bool useQgisDocDirectory=true);
|
||||||
|
|
||||||
/** Get the menu info mapped by menu name (key is name, value is menu id) */
|
|
||||||
std::map<QString,int> menuMapByName();
|
|
||||||
/** Get the menu info mapped by menu id (key is menu id, value is name) */
|
|
||||||
std::map<int,QString> menuMapById();
|
|
||||||
|
|
||||||
/** Return a pointer to the map canvas used by qgisapp */
|
/** Return a pointer to the map canvas used by qgisapp */
|
||||||
QgsMapCanvas * getMapCanvas();
|
QgsMapCanvas * getMapCanvas();
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ class QgisApp;
|
|||||||
class QgsMapLayer;
|
class QgsMapLayer;
|
||||||
class QgsMapCanvas;
|
class QgsMapCanvas;
|
||||||
class QgsRasterLayer;
|
class QgsRasterLayer;
|
||||||
|
class QgsVectorLayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class QgisInterface
|
* \class QgisInterface
|
||||||
@ -68,11 +69,9 @@ class GUI_EXPORT QgisInterface : public QObject
|
|||||||
virtual void zoomActiveLayer()=0;
|
virtual void zoomActiveLayer()=0;
|
||||||
|
|
||||||
//! Add a vector layer
|
//! Add a vector layer
|
||||||
virtual bool addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
|
virtual QgsVectorLayer* addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)=0;
|
||||||
//! Add a raster layer given a raster layer file name
|
//! Add a raster layer given a raster layer file name
|
||||||
virtual bool addRasterLayer(QString rasterLayerPath)=0;
|
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
|
||||||
//! Add a raster layer given a QgsRasterLayer object
|
|
||||||
virtual bool addRasterLayer(QgsRasterLayer * theRasterLayer, bool theForceRenderFlag=false)=0;
|
|
||||||
|
|
||||||
//! Add a project
|
//! Add a project
|
||||||
virtual bool addProject(QString theProject)=0;
|
virtual bool addProject(QString theProject)=0;
|
||||||
|
@ -173,8 +173,7 @@ void QgsGrassBrowser::addMap()
|
|||||||
if ( type == QgsGrassModel::Raster )
|
if ( type == QgsGrassModel::Raster )
|
||||||
{
|
{
|
||||||
std::cerr << "add raster: " << uri.ascii() << std::endl;
|
std::cerr << "add raster: " << uri.ascii() << std::endl;
|
||||||
QgsRasterLayer *layer = new QgsRasterLayer( uri, map );
|
mIface->addRasterLayer(uri, map);
|
||||||
mIface->addRasterLayer(layer);
|
|
||||||
mapSelected = true;
|
mapSelected = true;
|
||||||
}
|
}
|
||||||
else if ( type == QgsGrassModel::Vector )
|
else if ( type == QgsGrassModel::Vector )
|
||||||
|
@ -1494,8 +1494,7 @@ void QgsGrassModule::viewOutput()
|
|||||||
+ QgsGrass::getDefaultMapset()
|
+ QgsGrass::getDefaultMapset()
|
||||||
+ "/cellhd/" + map;
|
+ "/cellhd/" + map;
|
||||||
|
|
||||||
QgsRasterLayer *layer = new QgsRasterLayer( uri, map );
|
mIface->addRasterLayer(uri, map);
|
||||||
mIface->addRasterLayer(layer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,15 +412,7 @@ void QgsGrassPlugin::addRaster()
|
|||||||
QString name = uri.right( uri.length() - pos - 1 );
|
QString name = uri.right( uri.length() - pos - 1 );
|
||||||
name.replace('/', ' ');
|
name.replace('/', ' ');
|
||||||
|
|
||||||
//qGisInterface->addRasterLayer( uri );
|
qGisInterface->addRasterLayer(uri, sel->map);
|
||||||
QgsRasterLayer *layer = new QgsRasterLayer( uri, sel->map );
|
|
||||||
if( !layer->isValid() ) {
|
|
||||||
// let the user know something went wrong - addRasterLayer cleans up
|
|
||||||
QMessageBox::warning( 0, tr("Warning"), tr("Could not add raster layer: " ) + uri);
|
|
||||||
}
|
|
||||||
qGisInterface->addRasterLayer(layer);
|
|
||||||
|
|
||||||
mCanvas->refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user