mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-09 00:08:52 -04:00
indented code
git-svn-id: http://svn.osgeo.org/qgis/trunk@787 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
adc62f73ea
commit
b96dcd68b5
@ -5,9 +5,9 @@
|
||||
QgsVectorLayer can be used with any data store for which an appropriate
|
||||
plugin is available.
|
||||
-------------------
|
||||
begin : Oct 29, 2003
|
||||
copyright : (C) 2003 by Gary E.Sherman
|
||||
email : sherman at mrcc.com
|
||||
begin : Oct 29, 2003
|
||||
copyright : (C) 2003 by Gary E.Sherman
|
||||
email : sherman at mrcc.com
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
/* $Id$ */
|
||||
/* $Id$ */
|
||||
|
||||
#include <iostream>
|
||||
#include <cfloat>
|
||||
@ -58,63 +58,69 @@
|
||||
// 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;
|
||||
std::cerr << "BASENAME: " << baseName << std::endl;
|
||||
#endif
|
||||
// load the plugin
|
||||
QgsProviderRegistry *pReg = QgsProviderRegistry::instance();
|
||||
QString ogrlib = pReg->library(providerKey);
|
||||
//QString ogrlib = libDir + "/libpostgresprovider.so";
|
||||
const char *cOgrLib = (const char *)ogrlib;
|
||||
// load the plugin
|
||||
QgsProviderRegistry *pReg = QgsProviderRegistry::instance();
|
||||
QString ogrlib = pReg->library(providerKey);
|
||||
//QString ogrlib = libDir + "/libpostgresprovider.so";
|
||||
const char *cOgrLib = (const char *) ogrlib;
|
||||
#ifdef TESTPROVIDERLIB
|
||||
// test code to help debug provider loading problems
|
||||
// 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);
|
||||
}
|
||||
|
||||
#endif
|
||||
// load the data provider
|
||||
QLibrary *myLib = new QLibrary((const char *)ogrlib);
|
||||
#ifdef DEBUG
|
||||
// load the data provider
|
||||
QLibrary *myLib = new QLibrary((const char *) ogrlib);
|
||||
#ifdef DEBUG
|
||||
std::cout << "Library name is " << myLib->library() << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
bool loaded = myLib->load();
|
||||
if (loaded) {
|
||||
#ifdef DEBUG
|
||||
if (loaded)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cout << "Loaded data provider library" << std::endl;
|
||||
std::cout << "Attempting to resolve the classFactory function" << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
create_it *cf = (create_it *) myLib->resolve("classFactory");
|
||||
valid = false; // assume the layer is invalid until we determine otherwise
|
||||
if (cf) {
|
||||
#ifdef DEBUG
|
||||
if (cf)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cout << "Getting pointer to a dataProvider object from the library\n";
|
||||
#endif
|
||||
#endif
|
||||
dataProvider = cf(vectorLayerPath);
|
||||
if (dataProvider) {
|
||||
#ifdef DEBUG
|
||||
if (dataProvider)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cout << "Instantiated the data provider plugin\n";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(dataProvider->isValid()){
|
||||
if (dataProvider->isValid())
|
||||
{
|
||||
valid = true;
|
||||
// get the extent
|
||||
QgsRect *mbr = dataProvider->extent();
|
||||
// show the extent
|
||||
QString s = mbr->stringRep();
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cout << "Extent of layer: " << s << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
// store the extent
|
||||
layerExtent.setXmax(mbr->xMax());
|
||||
layerExtent.setXmin(mbr->xMin());
|
||||
@ -127,27 +133,30 @@ 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.mid(layerTitle.find(".") + 1);
|
||||
layerTitle = layerTitle.left(layerTitle.find("("));
|
||||
}
|
||||
// upper case the first letter of the layer name
|
||||
layerTitle = layerTitle.left(1).upper() + layerTitle.mid(1);
|
||||
setLayerName(layerTitle);
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
} else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cout << "Unable to instantiate the data provider plugin\n";
|
||||
#endif
|
||||
#endif
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
valid = false;
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cout << "Failed to load " << "../providers/libproviders.so" << "\n";
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
//TODO - fix selection code that formerly used
|
||||
// a boolean vector and set every entry to false
|
||||
@ -161,19 +170,20 @@ const char *cOgrLib = (const char *)ogrlib;
|
||||
|
||||
QgsVectorLayer::~QgsVectorLayer()
|
||||
{
|
||||
if (tabledisplay) {
|
||||
if (tabledisplay)
|
||||
{
|
||||
tabledisplay->close();
|
||||
delete tabledisplay;
|
||||
}
|
||||
if(m_renderer)
|
||||
if (m_renderer)
|
||||
{
|
||||
delete m_renderer;
|
||||
}
|
||||
if(m_rendererDialog)
|
||||
if (m_rendererDialog)
|
||||
{
|
||||
delete m_rendererDialog;
|
||||
}
|
||||
if(m_propertiesDialog)
|
||||
if (m_propertiesDialog)
|
||||
{
|
||||
delete m_propertiesDialog;
|
||||
}
|
||||
@ -183,53 +193,64 @@ QString QgsVectorLayer::providerType()
|
||||
{
|
||||
return providerKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the preferred display field based on some fuzzy logic
|
||||
*/
|
||||
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
|
||||
// is used as the node.
|
||||
* sets the preferred display field based on some fuzzy logic
|
||||
*/
|
||||
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
|
||||
// is used as the node.
|
||||
QString idxName;
|
||||
QString idxId;
|
||||
|
||||
std::vector<QgsField> fields = dataProvider->fields();
|
||||
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
|
||||
#ifdef DEBUG
|
||||
std::cout << "Checking field " << fldName << std::endl;
|
||||
#endif
|
||||
if (fldName.find("name", false) > -1) {
|
||||
#endif
|
||||
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
|
||||
*/
|
||||
* Draw the layer
|
||||
*/
|
||||
void QgsVectorLayer::draw_old(QPainter * p, QgsRect * viewExtent, QgsCoordinateTransform * cXf)
|
||||
{
|
||||
// set pen and fill
|
||||
@ -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,21 +314,24 @@ 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) {
|
||||
#ifdef DEBUG
|
||||
if (fet == 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cout << "get next feature returned null\n";
|
||||
#endif
|
||||
} else {
|
||||
#endif
|
||||
} 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)
|
||||
if(selected.find(fet->featureId())!=selected.end())
|
||||
if (selected.find(fet->featureId()) != selected.end())
|
||||
{
|
||||
// must change color of pen since it holds not only color
|
||||
// but line width
|
||||
if(vectorType()==QGis::Line)
|
||||
if (vectorType() == QGis::Line)
|
||||
pen.setColor(selectionColor);
|
||||
else
|
||||
{
|
||||
@ -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);
|
||||
@ -460,14 +494,13 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cout << "UNKNOWN WKBTYPE ENCOUNTERED\n";
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
delete[] feature;
|
||||
}
|
||||
else
|
||||
delete[]feature;
|
||||
} 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()");
|
||||
@ -508,26 +540,30 @@ int QgsVectorLayer::endian()
|
||||
void QgsVectorLayer::identify(QgsRect * r)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::waitCursor);
|
||||
dataProvider->select(r,true);
|
||||
dataProvider->select(r, true);
|
||||
int featureCount = 0;
|
||||
QgsFeature *fet;
|
||||
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++){
|
||||
#ifdef DEBUG
|
||||
std::cout << attr[i].fieldName()<< " == " << fieldIndex << std::endl;
|
||||
#endif
|
||||
if(attr[i].fieldName().lower() == fieldIndex){
|
||||
std::vector < QgsFeatureAttribute > attr = fet->attributeMap();
|
||||
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)
|
||||
{
|
||||
featureNode->setText(1, attr[i].fieldValue());
|
||||
}
|
||||
ir->addAttribute(featureNode, attr[i].fieldName(), attr[i].fieldValue());
|
||||
@ -535,24 +571,29 @@ void QgsVectorLayer::identify(QgsRect * r)
|
||||
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cout << "Feature count on identify: " << featureCount << std::endl;
|
||||
#endif
|
||||
if (ir) {
|
||||
#endif
|
||||
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();
|
||||
@ -561,28 +602,30 @@ void QgsVectorLayer::table()
|
||||
QObject:connect(tabledisplay, SIGNAL(deleted()), this, SLOT(invalidateTableDisplay()));
|
||||
tabledisplay->table()->setNumRows(dataProvider->featureCount());
|
||||
//tabledisplay->table()->setNumCols(numFields); //+1 for the id-column
|
||||
tabledisplay->table()->setNumCols(numFields+1); //+1 for the id-column
|
||||
tabledisplay->table()->setNumCols(numFields + 1); //+1 for the id-column
|
||||
|
||||
int row = 0;
|
||||
// set up the column headers
|
||||
QHeader *colHeader = tabledisplay->table()->horizontalHeader();
|
||||
colHeader->setLabel(0, "id"); //label for the id-column
|
||||
std::vector<QgsField> fields = dataProvider->fields();
|
||||
std::vector < QgsField > fields = dataProvider->fields();
|
||||
//for (int h = 0; h < numFields; h++) {
|
||||
for(int h=1;h<=numFields;h++)
|
||||
for (int h = 1; h <= numFields; h++)
|
||||
{
|
||||
colHeader->setLabel(h, fields[h-1].getName());
|
||||
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++){
|
||||
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++)
|
||||
{
|
||||
// get the field values
|
||||
tabledisplay->table()->setText(row, i+1, attr[i].fieldValue());
|
||||
tabledisplay->table()->setText(row, i + 1, attr[i].fieldValue());
|
||||
}
|
||||
row++;
|
||||
delete fet;
|
||||
@ -599,13 +642,14 @@ 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)
|
||||
for (std::map < int, bool >::iterator it = selected.begin(); it != selected.end(); ++it)
|
||||
{
|
||||
tabledisplay->table()->selectRowWithId(it->first);
|
||||
#ifdef DEBUG
|
||||
qWarning("selecting row with id " +QString::number(it->first));
|
||||
qWarning("selecting row with id " + QString::number(it->first));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -622,7 +666,7 @@ void QgsVectorLayer::table()
|
||||
|
||||
void QgsVectorLayer::select(int number)
|
||||
{
|
||||
selected[number]=true;
|
||||
selected[number] = true;
|
||||
}
|
||||
|
||||
void QgsVectorLayer::select(QgsRect * rect, bool lock)
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -645,7 +690,7 @@ void QgsVectorLayer::select(QgsRect * rect, bool lock)
|
||||
|
||||
dataProvider->select(rect, true);
|
||||
|
||||
QgsFeature* fet;
|
||||
QgsFeature *fet;
|
||||
|
||||
while (fet = dataProvider->getNextFeature(true))
|
||||
{
|
||||
@ -680,66 +725,65 @@ void QgsVectorLayer::invalidateTableDisplay()
|
||||
tabledisplay = 0;
|
||||
}
|
||||
|
||||
QgsDataProvider* QgsVectorLayer::getDataProvider()
|
||||
QgsDataProvider *QgsVectorLayer::getDataProvider()
|
||||
{
|
||||
return dataProvider;
|
||||
}
|
||||
|
||||
void QgsVectorLayer::showLayerProperties()
|
||||
{
|
||||
if(m_propertiesDialog)
|
||||
if (m_propertiesDialog)
|
||||
{
|
||||
m_propertiesDialog->raise();
|
||||
m_propertiesDialog->show();
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
m_propertiesDialog = new QgsDlgVectorLayerProperties(this);
|
||||
m_propertiesDialog->show();
|
||||
}
|
||||
}
|
||||
|
||||
QgsRenderer* QgsVectorLayer::renderer()
|
||||
QgsRenderer *QgsVectorLayer::renderer()
|
||||
{
|
||||
return m_renderer;
|
||||
}
|
||||
|
||||
QDialog* QgsVectorLayer::rendererDialog()
|
||||
QDialog *QgsVectorLayer::rendererDialog()
|
||||
{
|
||||
return m_rendererDialog;
|
||||
}
|
||||
|
||||
void QgsVectorLayer::setRenderer(QgsRenderer* r)
|
||||
void QgsVectorLayer::setRenderer(QgsRenderer * r)
|
||||
{
|
||||
if(r!=m_renderer)
|
||||
if (r != m_renderer)
|
||||
{
|
||||
if(m_renderer)//delete any previous renderer
|
||||
if (m_renderer) //delete any previous renderer
|
||||
{
|
||||
delete m_renderer;
|
||||
}
|
||||
|
||||
m_renderer=r;
|
||||
m_renderer = r;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsVectorLayer::setRendererDialog(QDialog* dialog)
|
||||
void QgsVectorLayer::setRendererDialog(QDialog * dialog)
|
||||
{
|
||||
if(dialog!=m_rendererDialog)
|
||||
if (dialog != m_rendererDialog)
|
||||
{
|
||||
if(m_rendererDialog)
|
||||
if (m_rendererDialog)
|
||||
{
|
||||
delete m_rendererDialog;
|
||||
}
|
||||
m_rendererDialog=dialog;
|
||||
m_rendererDialog = dialog;
|
||||
}
|
||||
}
|
||||
|
||||
QGis::VectorType QgsVectorLayer::vectorType()
|
||||
{
|
||||
if(dataProvider)
|
||||
if (dataProvider)
|
||||
{
|
||||
int type=dataProvider->geometryType();
|
||||
switch(type)
|
||||
int type = dataProvider->geometryType();
|
||||
switch (type)
|
||||
{
|
||||
case QGis::WKBPoint:
|
||||
return QGis::Point;
|
||||
@ -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()");
|
||||
@ -763,11 +806,13 @@ QGis::VectorType QgsVectorLayer::vectorType()
|
||||
}
|
||||
}
|
||||
|
||||
QgsDlgVectorLayerProperties* QgsVectorLayer::propertiesDialog()
|
||||
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,14 +821,16 @@ void QgsVectorLayer::initContextMenu(QgisApp *app){
|
||||
popMenu->insertSeparator();
|
||||
popMenu->insertItem(tr("&Remove"), app, SLOT(removeLayer()));
|
||||
}
|
||||
//
|
||||
QPopupMenu *QgsVectorLayer::contextMenu(){
|
||||
|
||||
//
|
||||
QPopupMenu *QgsVectorLayer::contextMenu()
|
||||
{
|
||||
return popMenu;
|
||||
}
|
||||
|
||||
QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
{
|
||||
QgsRect rect(DBL_MAX,DBL_MAX,-DBL_MAX,-DBL_MAX);
|
||||
QgsRect rect(DBL_MAX, DBL_MAX, -DBL_MAX, -DBL_MAX);
|
||||
dataProvider->reset();
|
||||
|
||||
QgsFeature *fet;
|
||||
@ -805,7 +852,7 @@ QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
|
||||
while ((fet = dataProvider->getNextFeature(false)))
|
||||
{
|
||||
if(selected.find(fet->featureId())!=selected.end())
|
||||
if (selected.find(fet->featureId()) != selected.end())
|
||||
{
|
||||
feature = fet->getGeometry();
|
||||
wkbType = (int) feature[1];
|
||||
@ -816,19 +863,19 @@ QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
case WKBPoint:
|
||||
x = (double *) (feature + 5);
|
||||
y = (double *) (feature + 5 + sizeof(double));
|
||||
if(*x<rect.xMin())
|
||||
if (*x < rect.xMin())
|
||||
{
|
||||
rect.setXmin(*x);
|
||||
}
|
||||
if(*x>rect.xMax())
|
||||
if (*x > rect.xMax())
|
||||
{
|
||||
rect.setXmax(*x);
|
||||
}
|
||||
if(*y<rect.yMin())
|
||||
if (*y < rect.yMin())
|
||||
{
|
||||
rect.setYmin(*y);
|
||||
}
|
||||
if(*y>rect.yMax())
|
||||
if (*y > rect.yMax())
|
||||
{
|
||||
rect.setYmax(*y);
|
||||
}
|
||||
@ -845,19 +892,19 @@ QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
ptr += sizeof(double);
|
||||
y = (double *) ptr;
|
||||
ptr += sizeof(double);
|
||||
if(*x<rect.xMin())
|
||||
if (*x < rect.xMin())
|
||||
{
|
||||
rect.setXmin(*x);
|
||||
}
|
||||
if(*x>rect.xMax())
|
||||
if (*x > rect.xMax())
|
||||
{
|
||||
rect.setXmax(*x);
|
||||
}
|
||||
if(*y<rect.yMin())
|
||||
if (*y < rect.yMin())
|
||||
{
|
||||
rect.setYmin(*y);
|
||||
}
|
||||
if(*y>rect.yMax())
|
||||
if (*y > rect.yMax())
|
||||
{
|
||||
rect.setYmax(*y);
|
||||
}
|
||||
@ -880,19 +927,19 @@ QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
ptr += sizeof(double);
|
||||
y = (double *) ptr;
|
||||
ptr += sizeof(double);
|
||||
if(*x<rect.xMin())
|
||||
if (*x < rect.xMin())
|
||||
{
|
||||
rect.setXmin(*x);
|
||||
}
|
||||
if(*x>rect.xMax())
|
||||
if (*x > rect.xMax())
|
||||
{
|
||||
rect.setXmax(*x);
|
||||
}
|
||||
if(*y<rect.yMin())
|
||||
if (*y < rect.yMin())
|
||||
{
|
||||
rect.setYmin(*y);
|
||||
}
|
||||
if(*y>rect.yMax())
|
||||
if (*y > rect.yMax())
|
||||
{
|
||||
rect.setYmax(*y);
|
||||
}
|
||||
@ -916,19 +963,19 @@ QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
ptr += sizeof(double);
|
||||
y = (double *) ptr;
|
||||
ptr += sizeof(double);
|
||||
if(*x<rect.xMin())
|
||||
if (*x < rect.xMin())
|
||||
{
|
||||
rect.setXmin(*x);
|
||||
}
|
||||
if(*x>rect.xMax())
|
||||
if (*x > rect.xMax())
|
||||
{
|
||||
rect.setXmax(*x);
|
||||
}
|
||||
if(*y<rect.yMin())
|
||||
if (*y < rect.yMin())
|
||||
{
|
||||
rect.setYmin(*y);
|
||||
}
|
||||
if(*y>rect.yMax())
|
||||
if (*y > rect.yMax())
|
||||
{
|
||||
rect.setYmax(*y);
|
||||
}
|
||||
@ -959,19 +1006,19 @@ QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
ptr += sizeof(double);
|
||||
y = (double *) ptr;
|
||||
ptr += sizeof(double);
|
||||
if(*x<rect.xMin())
|
||||
if (*x < rect.xMin())
|
||||
{
|
||||
rect.setXmin(*x);
|
||||
}
|
||||
if(*x>rect.xMax())
|
||||
if (*x > rect.xMax())
|
||||
{
|
||||
rect.setXmax(*x);
|
||||
}
|
||||
if(*y<rect.yMin())
|
||||
if (*y < rect.yMin())
|
||||
{
|
||||
rect.setYmin(*y);
|
||||
}
|
||||
if(*y>rect.yMax())
|
||||
if (*y > rect.yMax())
|
||||
{
|
||||
rect.setYmax(*y);
|
||||
}
|
||||
@ -981,23 +1028,23 @@ QgsRect QgsVectorLayer::bBoxOfSelected()
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cout << "UNKNOWN WKBTYPE ENCOUNTERED\n";
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
|
||||
}
|
||||
delete[] feature;
|
||||
delete[]feature;
|
||||
}
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
void QgsVectorLayer::setLayerProperties(QgsDlgVectorLayerProperties* properties)
|
||||
void QgsVectorLayer::setLayerProperties(QgsDlgVectorLayerProperties * properties)
|
||||
{
|
||||
if(m_propertiesDialog)
|
||||
if (m_propertiesDialog)
|
||||
{
|
||||
delete m_propertiesDialog;
|
||||
}
|
||||
m_propertiesDialog=properties;
|
||||
m_propertiesDialog = properties;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user