indented code

git-svn-id: http://svn.osgeo.org/qgis/trunk@787 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2004-02-11 05:43:51 +00:00
parent adc62f73ea
commit b96dcd68b5

View File

@ -58,9 +58,9 @@
// typedef for the QgsDataProvider class factory
typedef QgsDataProvider *create_it(const char *uri);
QgsVectorLayer::QgsVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
:QgsMapLayer(VECTOR, baseName, vectorLayerPath), providerKey(providerKey),
tabledisplay(0), m_renderer(0), m_propertiesDialog(0), m_rendererDialog(0)
QgsVectorLayer::QgsVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey):QgsMapLayer(VECTOR, baseName, vectorLayerPath), providerKey(providerKey),
tabledisplay(0), m_renderer(0), m_propertiesDialog(0),
m_rendererDialog(0)
{
#ifdef DEBUG
std::cerr << "VECTORLAYERPATH: " << vectorLayerPath << std::endl;
@ -74,10 +74,12 @@ const char *cOgrLib = (const char *)ogrlib;
#ifdef TESTPROVIDERLIB
// test code to help debug provider loading problems
void *handle = dlopen(cOgrLib, RTLD_LAZY);
if (!handle) {
if (!handle)
{
std::cout << "Error in dlopen: " << dlerror() << std::endl;
} else {
} else
{
std::cout << "dlopen suceeded" << std::endl;
dlclose(handle);
}
@ -89,24 +91,28 @@ const char *cOgrLib = (const char *)ogrlib;
std::cout << "Library name is " << myLib->library() << std::endl;
#endif
bool loaded = myLib->load();
if (loaded) {
if (loaded)
{
#ifdef DEBUG
std::cout << "Loaded data provider library" << std::endl;
std::cout << "Attempting to resolve the classFactory function" << std::endl;
#endif
create_it *cf = (create_it *) myLib->resolve("classFactory");
valid = false; // assume the layer is invalid until we determine otherwise
if (cf) {
if (cf)
{
#ifdef DEBUG
std::cout << "Getting pointer to a dataProvider object from the library\n";
#endif
dataProvider = cf(vectorLayerPath);
if (dataProvider) {
if (dataProvider)
{
#ifdef DEBUG
std::cout << "Instantiated the data provider plugin\n";
#endif
if(dataProvider->isValid()){
if (dataProvider->isValid())
{
valid = true;
// get the extent
QgsRect *mbr = dataProvider->extent();
@ -127,7 +133,8 @@ const char *cOgrLib = (const char *)ogrlib;
setDisplayField();
QString layerTitle = baseName;
if(providerKey == "postgres"){
if (providerKey == "postgres")
{
// adjust the display name for postgres layers
layerTitle = layerTitle.mid(layerTitle.find(".") + 1);
layerTitle = layerTitle.left(layerTitle.find("("));
@ -136,14 +143,16 @@ const char *cOgrLib = (const char *)ogrlib;
layerTitle = layerTitle.left(1).upper() + layerTitle.mid(1);
setLayerName(layerTitle);
}
} else {
} else
{
#ifdef DEBUG
std::cout << "Unable to instantiate the data provider plugin\n";
#endif
valid = false;
}
}
} else {
} else
{
valid = false;
#ifdef DEBUG
std::cout << "Failed to load " << "../providers/libproviders.so" << "\n";
@ -161,7 +170,8 @@ const char *cOgrLib = (const char *)ogrlib;
QgsVectorLayer::~QgsVectorLayer()
{
if (tabledisplay) {
if (tabledisplay)
{
tabledisplay->close();
delete tabledisplay;
}
@ -183,10 +193,12 @@ QString QgsVectorLayer::providerType()
{
return providerKey;
}
/**
* sets the preferred display field based on some fuzzy logic
*/
void QgsVectorLayer::setDisplayField(){
void QgsVectorLayer::setDisplayField()
{
// Determine the field index for the feature column of the identify
// dialog. We look for fields containing "name" first and second for
// fields containing "id". If neither are found, the first field
@ -196,37 +208,46 @@ void QgsVectorLayer::setDisplayField(){
std::vector < QgsField > fields = dataProvider->fields();
int j = 0;
for(int j=0; j< fields.size(); j++){
for (int j = 0; j < fields.size(); j++)
{
QString fldName = fields[j].getName();
#ifdef DEBUG
std::cout << "Checking field " << fldName << std::endl;
#endif
if (fldName.find("name", false) > -1) {
if (fldName.find("name", false) > -1)
{
idxName = fldName;
break;
}
if(fldName.find("descrip", false) > -1){
if (fldName.find("descrip", false) > -1)
{
idxName = fldName;
break;
}
if (fldName.find("id", false)> -1) {
if (fldName.find("id", false) > -1)
{
idxId = fldName;
break;
}
}
if (idxName.length() > 0) {
if (idxName.length() > 0)
{
fieldIndex = idxName;
} else {
if (idxId.length() > 0) {
} else
{
if (idxId.length() > 0)
{
fieldIndex = idxId;
}else{
} else
{
fieldIndex = fields[0].getName();
}
}
}
/*
* Draw the layer
*/
@ -245,7 +266,8 @@ void QgsVectorLayer::draw_old(QPainter * p, QgsRect * viewExtent, QgsCoordinateT
void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTransform * cXf)
{
if (/*1 == 1*/m_renderer) {
if ( /*1 == 1 */ m_renderer)
{
// painter is active (begin has been called
/* Steps to draw the layer
1. get the features in the view extent by SQL query
@ -292,13 +314,16 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
QgsPoint pt;
QPointArray *pa;
int wkbType;
while ((fet = dataProvider->getNextFeature(attributesneeded))) {//true is necessary for graduated symbol
while ((fet = dataProvider->getNextFeature(attributesneeded)))
{ //true is necessary for graduated symbol
if (fet == 0) {
if (fet == 0)
{
#ifdef DEBUG
std::cout << "get next feature returned null\n";
#endif
} else {
} else
{
//if feature is selected, change the color of the painter
//TODO fix this selection code to work with the provider
//if ((*selected)[(fet->featureId())] == true)
@ -328,7 +353,8 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
// std::cout << "Feature type: " << wkbType << std::endl;
// read each feature based on its type
switch (wkbType) {
switch (wkbType)
{
case WKBPoint:
p->setBrush(*brush);
@ -352,7 +378,8 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
ptr = feature + 5;
nPoints = (int *) ptr;
ptr = feature + 1 + 2 * sizeof(int);
for (idx = 0; idx < *nPoints; idx++) {
for (idx = 0; idx < *nPoints; idx++)
{
x = (double *) ptr;
ptr += sizeof(double);
y = (double *) ptr;
@ -370,13 +397,15 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
numLineStrings = (int) (feature[5]);
ptr = feature + 9;
for (jdx = 0; jdx < numLineStrings; jdx++) {
for (jdx = 0; jdx < numLineStrings; jdx++)
{
// each of these is a wbklinestring so must handle as such
lsb = *ptr;
ptr += 5; // skip type since we know its 2
nPoints = (int *) ptr;
ptr += sizeof(int);
for (idx = 0; idx < *nPoints; idx++) {
for (idx = 0; idx < *nPoints; idx++)
{
x = (double *) ptr;
ptr += sizeof(double);
y = (double *) ptr;
@ -398,13 +427,15 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
numRings = (int *) (feature + 1 + sizeof(int));
//std::cout << "Number of rings: " << *numRings << std::endl;
ptr = feature + 1 + 2 * sizeof(int);
for (idx = 0; idx < *numRings; idx++) {
for (idx = 0; idx < *numRings; idx++)
{
// get number of points in the ring
nPoints = (int *) ptr;
//std::cout << "Number of points: " << *nPoints << std::endl;
ptr += 4;
pa = new QPointArray(*nPoints);
for (jdx = 0; jdx < *nPoints; jdx++) {
for (jdx = 0; jdx < *nPoints; jdx++)
{
// add points to a point array for drawing the polygon
// std::cout << "Adding points to array\n";
x = (double *) ptr;
@ -428,18 +459,21 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
// get the number of polygons
ptr = feature + 5;
numPolygons = (int *) ptr;
for (kdx = 0; kdx < *numPolygons; kdx++) {
for (kdx = 0; kdx < *numPolygons; kdx++)
{
//skip the endian and feature type info and
// get number of rings in the polygon
ptr = feature + 14;
numRings = (int *) ptr;
ptr += 4;
for (idx = 0; idx < *numRings; idx++) {
for (idx = 0; idx < *numRings; idx++)
{
// get number of points in the ring
nPoints = (int *) ptr;
ptr += 4;
pa = new QPointArray(*nPoints);
for (jdx = 0; jdx < *nPoints; jdx++) {
for (jdx = 0; jdx < *nPoints; jdx++)
{
// add points to a point array for drawing the polygon
x = (double *) ptr;
ptr += sizeof(double);
@ -466,8 +500,7 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
break;
}
delete[]feature;
}
else
} else
{
//pass the feature to the renderer
m_renderer->renderFeature(p, fet, cXf);
@ -480,8 +513,7 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
}
}
qApp->processEvents();
}
else
} else
{
#ifdef DEBUG
qWarning("Warning, QgsRenderer is null in QgsVectorLayer::draw()");
@ -514,20 +546,24 @@ void QgsVectorLayer::identify(QgsRect * r)
unsigned char *feature;
// display features falling within the search radius
QgsIdentifyResults *ir = 0;
while ((fet = dataProvider->getNextFeature(true))) {
while ((fet = dataProvider->getNextFeature(true)))
{
featureCount++;
if(featureCount == 1){
if (featureCount == 1)
{
ir = new QgsIdentifyResults();
}
QListViewItem *featureNode = ir->addNode("foo");
featureNode->setText(0, fieldIndex);
std::vector < QgsFeatureAttribute > attr = fet->attributeMap();
for(int i=0; i < attr.size(); i++){
for (int i = 0; i < attr.size(); i++)
{
#ifdef DEBUG
std::cout << attr[i].fieldName() << " == " << fieldIndex << std::endl;
#endif
if(attr[i].fieldName().lower() == fieldIndex){
if (attr[i].fieldName().lower() == fieldIndex)
{
featureNode->setText(1, attr[i].fieldValue());
}
ir->addAttribute(featureNode, attr[i].fieldName(), attr[i].fieldValue());
@ -538,21 +574,26 @@ void QgsVectorLayer::identify(QgsRect * r)
#ifdef DEBUG
std::cout << "Feature count on identify: " << featureCount << std::endl;
#endif
if (ir) {
if (ir)
{
ir->setTitle(name());
ir->show();
}
QApplication::restoreOverrideCursor();
if (featureCount == 0) {
QMessageBox::information(0, tr("No features found"), tr("No features were found in the active layer at the point you clicked"));
if (featureCount == 0)
{
QMessageBox::information(0, tr("No features found"),
tr("No features were found in the active layer at the point you clicked"));
}
}
void QgsVectorLayer::table()
{
if (tabledisplay) {
if (tabledisplay)
{
tabledisplay->raise();
} else {
} else
{
// display the attribute table
QApplication::setOverrideCursor(Qt::waitCursor);
dataProvider->reset();
@ -574,13 +615,15 @@ void QgsVectorLayer::table()
colHeader->setLabel(h, fields[h - 1].getName());
}
QgsFeature *fet;
while ((fet = dataProvider->getNextFeature(true))) {
while ((fet = dataProvider->getNextFeature(true)))
{
//id-field
tabledisplay->table()->setText(row, 0, QString::number(fet->featureId()));
tabledisplay->table()->insertFeatureId(fet->featureId(), row); //insert the id into the search tree of qgsattributetable
std::vector < QgsFeatureAttribute > attr = fet->attributeMap();
for(int i=0; i < attr.size(); i++){
for (int i = 0; i < attr.size(); i++)
{
// get the field values
tabledisplay->table()->setText(row, i + 1, attr[i].fieldValue());
}
@ -599,7 +642,8 @@ void QgsVectorLayer::table()
tabledisplay->table()->clearSelection(); //deselect the first row
QObject::disconnect(tabledisplay->table(), SIGNAL(selectionChanged()), tabledisplay->table(), SLOT(handleChangedSelections()));
QObject::disconnect(tabledisplay->table(), SIGNAL(selectionChanged()), tabledisplay->table(),
SLOT(handleChangedSelections()));
for (std::map < int, bool >::iterator it = selected.begin(); it != selected.end(); ++it)
{
@ -630,7 +674,8 @@ void QgsVectorLayer::select(QgsRect * rect, bool lock)
QApplication::setOverrideCursor(Qt::waitCursor);
if (tabledisplay)
{
QObject::disconnect(tabledisplay->table(), SIGNAL(selectionChanged()), tabledisplay->table(), SLOT(handleChangedSelections()));
QObject::disconnect(tabledisplay->table(), SIGNAL(selectionChanged()), tabledisplay->table(),
SLOT(handleChangedSelections()));
QObject::disconnect(tabledisplay->table(), SIGNAL(selected(int)), this, SLOT(select(int))); //disconnecting because of performance reason
}
@ -691,8 +736,7 @@ void QgsVectorLayer::showLayerProperties()
{
m_propertiesDialog->raise();
m_propertiesDialog->show();
}
else
} else
{
m_propertiesDialog = new QgsDlgVectorLayerProperties(this);
m_propertiesDialog->show();
@ -754,8 +798,7 @@ QGis::VectorType QgsVectorLayer::vectorType()
case QGis::WKBMultiPolygon:
return QGis::Polygon;
}
}
else
} else
{
#ifdef DEBUG
qWarning("warning, pointer to dataProvider is null in QgsVectorLayer::vectorType()");
@ -767,7 +810,9 @@ QgsDlgVectorLayerProperties* QgsVectorLayer::propertiesDialog()
{
return m_propertiesDialog;
}
void QgsVectorLayer::initContextMenu(QgisApp *app){
void QgsVectorLayer::initContextMenu(QgisApp * app)
{
popMenu = new QPopupMenu();
popMenu->insertItem(tr("&Zoom to extent of selected layer"), app, SLOT(zoomToLayerExtent()));
popMenu->insertItem(tr("&Open attribute table"), app, SLOT(attributeTable()));
@ -776,8 +821,10 @@ void QgsVectorLayer::initContextMenu(QgisApp *app){
popMenu->insertSeparator();
popMenu->insertItem(tr("&Remove"), app, SLOT(removeLayer()));
}
//
QPopupMenu *QgsVectorLayer::contextMenu(){
QPopupMenu *QgsVectorLayer::contextMenu()
{
return popMenu;
}