mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
added validity checking prior to adding vector layer
git-svn-id: http://svn.osgeo.org/qgis/trunk@587 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
6f5652e4ea
commit
249f85df22
@ -499,16 +499,22 @@ void QgisApp::addDatabaseLayer()
|
||||
// create the layer
|
||||
//qWarning("creating lyr");
|
||||
QgsVectorLayer *lyr = new QgsVectorLayer(connInfo + " table=" + *it, *it, "postgres");
|
||||
|
||||
// init the context menu so it can connect to slots in main app
|
||||
lyr->initContextMenu(this);
|
||||
|
||||
// give it a random color
|
||||
QgsSingleSymRenderer* renderer=new QgsSingleSymRenderer();//add single symbol renderer as default
|
||||
lyr->setRenderer(renderer);
|
||||
renderer->initializeSymbology(lyr);
|
||||
// add it to the mapcanvas collection
|
||||
mapCanvas->addLayer(lyr);
|
||||
if(lyr->isValid()){
|
||||
// init the context menu so it can connect to slots in main app
|
||||
lyr->initContextMenu(this);
|
||||
|
||||
// give it a random color
|
||||
QgsSingleSymRenderer* renderer=new QgsSingleSymRenderer();//add single symbol renderer as default
|
||||
lyr->setRenderer(renderer);
|
||||
renderer->initializeSymbology(lyr);
|
||||
// add it to the mapcanvas collection
|
||||
mapCanvas->addLayer(lyr);
|
||||
}else{
|
||||
std::cerr << *it << " is an invalid layer - not loaded" << std::endl;
|
||||
QMessageBox::critical(this, tr("Invalid Layer"),
|
||||
tr("%1 is an invalid layer and cannot be loaded.").arg(*it));
|
||||
delete lyr;
|
||||
}
|
||||
//qWarning("incrementing iterator");
|
||||
++it;
|
||||
}
|
||||
|
@ -115,7 +115,12 @@ public:
|
||||
/**Returns the maximum value of an attributs
|
||||
@param position the number of the attribute*/
|
||||
virtual QString maxValue(int position)=0;
|
||||
|
||||
/**
|
||||
* Returns true if this is a valid layer. It is up to individual providers
|
||||
* to determine what constitutes a valid layer
|
||||
*/
|
||||
virtual bool isValid()=0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user