diff --git a/ChangeLog b/ChangeLog index 7e7b0cfaaa7..81bca2a3f94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,15 @@ +July 18, 2002 + Point, line and polygon PostGis layers can be drawn. Still issues with + map exent and positioning of layers on the canvas. Drawing is manual and + not tied to the paint event. No zooming or panning yet. July 10, 2002 -Layers can be selected and added to the map canvas collection however -the rendering code is currently disabled and being reorganized. So if -you add a layer, nothing will be drawn... - + Layers can be selected and added to the map canvas collection however + the rendering code is currently disabled and being reorganized. So if + you add a layer, nothing will be drawn... + July 6, 2002 -This code is preliminary and really has no true functionality other than -the ability to define a PostGIS connection and display the spatially enabled -tables that could be loaded. + This code is preliminary and really has no true functionality other than + the ability to define a PostGIS connection and display the spatially enabled + tables that could be loaded. -This is the initial import of the code base into CVS on Sourceforge.net. + This is the initial import of the code base into CVS on Sourceforge.net. diff --git a/src/qgsdatabaselayer.cpp b/src/qgsdatabaselayer.cpp index ec652ceb938..03267026050 100644 --- a/src/qgsdatabaselayer.cpp +++ b/src/qgsdatabaselayer.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "qgsrect.h" #include #include @@ -90,20 +91,24 @@ void QgsDatabaseLayer::draw(QPainter *p, QgsRect *viewExtent, int yTransform){ double *x; double *y; int *nPoints; + int *numRings; + int *numPolygons; int numPoints; int numLineStrings; - int idx,jdx; + int idx,jdx,kdx; char *ptr; char lsb; int ttype; + QPointArray *pa; switch(wkbType){ case WKBPoint: + p->setPen(Qt::red); x = (double *) (feature + 5); y = (double *) (feature + 5 + sizeof (double)); - p->drawRect ((int) *x, yTransform - (int) *y, 15000, - 15000); + p->drawRect ((int) *x, yTransform - (int) *y, 15000, 15000); break; case WKBLineString: + p->setPen(Qt::blue); // get number of points in the line numPoints = (int)(feature + 1 + sizeof(int)); ptr = feature + 1 + 2 * sizeof(int); @@ -120,6 +125,7 @@ void QgsDatabaseLayer::draw(QPainter *p, QgsRect *viewExtent, int yTransform){ } break; case WKBMultiLineString: + p->setPen(Qt::blue); numLineStrings = (int)(feature[5]); ptr = feature+9; for(jdx = 0; jdx < numLineStrings; jdx++){ @@ -128,20 +134,71 @@ void QgsDatabaseLayer::draw(QPainter *p, QgsRect *viewExtent, int yTransform){ ptr += 5; // skip type since we know its 2 nPoints = (int *)ptr; ptr += sizeof(int); - for(idx = 0; idx < *nPoints; idx++){ - x = (double *) ptr; - ptr += sizeof(double); - y = (double *) ptr; - ptr += sizeof(double); - if(idx == 0) - p->moveTo((int) *x, yTransform - (int) *y); - else - p->lineTo((int) *x, yTransform - (int) *y); + for(idx = 0; idx < *nPoints; idx++){ + x = (double *) ptr; + ptr += sizeof(double); + y = (double *) ptr; + ptr += sizeof(double); + if(idx == 0) + p->moveTo((int) *x, yTransform - (int) *y); + else + p->lineTo((int) *x, yTransform - (int) *y); - } + } } break; case WKBPolygon: + p->setPen(Qt::blue); + // get number of rings in the polygon + numRings = (int *)(feature + 1 + sizeof(int)); + ptr = feature + 1 + 2 * sizeof(int); + 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++){ + // add points to a point array for drawing the polygon + x = (double *) ptr; + ptr += sizeof(double); + y = (double *) ptr; + ptr += sizeof(double); + pa->setPoint(jdx,(int)*x, yTransform - (int)*y); + } + // draw the ring + p->drawPolygon(*pa); + + } + break; + case WKBMultiPolygon: + p->setPen(Qt::blue); + // get the number of polygons + ptr = feature + 5; + numPolygons = (int *)ptr; + 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++){ + // get number of points in the ring + nPoints = (int *)ptr; + ptr += 4; + pa = new QPointArray(*nPoints); + for(jdx = 0; jdx < *nPoints; jdx++){ + // add points to a point array for drawing the polygon + x = (double *) ptr; + ptr += sizeof(double); + y = (double *) ptr; + ptr += sizeof(double); + pa->setPoint(jdx,(int)*x, yTransform - (int)*y); + } + // draw the ring + p->drawPolygon(*pa); + delete pa; + } + } break; } diff --git a/src/qgsmapcanvas.cpp b/src/qgsmapcanvas.cpp index e3d3b1c1430..cf70cb06725 100644 --- a/src/qgsmapcanvas.cpp +++ b/src/qgsmapcanvas.cpp @@ -43,6 +43,7 @@ void QgsMapCanvas::render(){ currentExtent = fullExtent; mapWindow->setLeft(currentExtent.xMin()); mapWindow->setBottom(currentExtent.yMin()); + // determine the dominate direction for the mapcanvas if (width () > height ()) { @@ -54,7 +55,9 @@ void QgsMapCanvas::render(){ mapWindow->setWidth(currentExtent.height()); mapWindow->setHeight(currentExtent.height()); } + paint->setWindow(*mapWindow); + QRect v = paint->viewport (); int d = QMIN (v.width (), v.height ()); int dm = QMAX(v.width(), v.height());