added validity checking for a layer

git-svn-id: http://svn.osgeo.org/qgis/trunk@586 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2004-01-25 07:32:40 +00:00
parent c2a0152747
commit d51d5df1dd
2 changed files with 13 additions and 2 deletions

View File

@ -62,6 +62,8 @@ QgsVectorLayer::QgsVectorLayer(QString vectorLayerPath, QString baseName, QStrin
:QgsMapLayer(VECTOR, baseName, vectorLayerPath), providerKey(providerKey),
tabledisplay(0), m_renderer(0), m_propertiesDialog(0), m_rendererDialog(0)
{
std::cerr << "VECTORLAYERPATH: " << vectorLayerPath << std::endl;
std::cerr << "BASENAME: " << baseName << std::endl;
// load the plugin
QgsProviderRegistry *pReg = QgsProviderRegistry::instance();
QString ogrlib = pReg->library(providerKey);
@ -87,12 +89,15 @@ const char *cOgrLib = (const char *)ogrlib;
std::cout << "Loaded data provider library" << std::endl;
std::cout << "Attempting to resolve the classFactory function" << std::endl;
create_it *cf = (create_it *) myLib->resolve("classFactory");
valid = false; // assume the layer is invalid until we determine otherwise
if (cf) {
std::cout << "Getting pointer to a dataProvider object from the library\n";
dataProvider = cf(vectorLayerPath);
if (dataProvider) {
std::cout << "Instantiated the data provider plugin\n";
if(dataProvider->isValid()){
valid = true;
// get the extent
QgsRect *mbr = dataProvider->extent();
// show the extent
@ -108,11 +113,14 @@ const char *cOgrLib = (const char *)ogrlib;
// look at the fields in the layer and set the primary
// display field using some real fuzzy logic
setDisplayField();
}
} else {
std::cout << "Unable to instantiate the data provider plugin\n";
valid = false;
}
}
} else {
valid = false;
std::cout << "Failed to load " << "../providers/libproviders.so" << "\n";
}
//TODO - fix selection code that formerly used

View File

@ -91,6 +91,8 @@ class QgsVectorLayer:public QgsMapLayer
virtual QgsRect bBoxOfSelected();
//! Return the provider type for this layer
QString providerType();
//! Return the validity of the layer
inline bool isValid(){ return valid;}
protected:
/**Pointer to the table display object if there is one, else a pointer to 0*/
QgsAttributeTableDisplay* tabledisplay;
@ -118,7 +120,8 @@ class QgsVectorLayer:public QgsMapLayer
QString fieldIndex;
//! Data provider key
QString providerKey;
//! Flag to indicate if this is a valid layer
bool valid;
bool registered;
enum ENDIAN