mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -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
|
// create the layer
|
||||||
//qWarning("creating lyr");
|
//qWarning("creating lyr");
|
||||||
QgsVectorLayer *lyr = new QgsVectorLayer(connInfo + " table=" + *it, *it, "postgres");
|
QgsVectorLayer *lyr = new QgsVectorLayer(connInfo + " table=" + *it, *it, "postgres");
|
||||||
|
if(lyr->isValid()){
|
||||||
|
// init the context menu so it can connect to slots in main app
|
||||||
|
lyr->initContextMenu(this);
|
||||||
|
|
||||||
// init the context menu so it can connect to slots in main app
|
// give it a random color
|
||||||
lyr->initContextMenu(this);
|
QgsSingleSymRenderer* renderer=new QgsSingleSymRenderer();//add single symbol renderer as default
|
||||||
|
lyr->setRenderer(renderer);
|
||||||
// give it a random color
|
renderer->initializeSymbology(lyr);
|
||||||
QgsSingleSymRenderer* renderer=new QgsSingleSymRenderer();//add single symbol renderer as default
|
// add it to the mapcanvas collection
|
||||||
lyr->setRenderer(renderer);
|
mapCanvas->addLayer(lyr);
|
||||||
renderer->initializeSymbology(lyr);
|
}else{
|
||||||
// add it to the mapcanvas collection
|
std::cerr << *it << " is an invalid layer - not loaded" << std::endl;
|
||||||
mapCanvas->addLayer(lyr);
|
QMessageBox::critical(this, tr("Invalid Layer"),
|
||||||
|
tr("%1 is an invalid layer and cannot be loaded.").arg(*it));
|
||||||
|
delete lyr;
|
||||||
|
}
|
||||||
//qWarning("incrementing iterator");
|
//qWarning("incrementing iterator");
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,12 @@ public:
|
|||||||
/**Returns the maximum value of an attributs
|
/**Returns the maximum value of an attributs
|
||||||
@param position the number of the attribute*/
|
@param position the number of the attribute*/
|
||||||
virtual QString maxValue(int position)=0;
|
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
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user