From 022574f6a44acd9ee24784120c556d8f4ef26f56 Mon Sep 17 00:00:00 2001 From: gsherman Date: Tue, 16 Jul 2002 04:55:37 +0000 Subject: [PATCH] minor updates git-svn-id: http://svn.osgeo.org/qgis/trunk@31 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgsdatabaselayer.cpp | 66 +++++++++++++++++++++++++++++++--------- src/qgsdatabaselayer.h | 13 ++++++-- src/qgsmaplayer.cpp | 4 +-- src/qgsmaplayer.h | 4 +-- src/qgsrect.cpp | 25 ++++++++++++--- src/qgsrect.h | 28 +++++++++++------ 6 files changed, 104 insertions(+), 36 deletions(-) diff --git a/src/qgsdatabaselayer.cpp b/src/qgsdatabaselayer.cpp index 6784d618a4a..cf682744728 100644 --- a/src/qgsdatabaselayer.cpp +++ b/src/qgsdatabaselayer.cpp @@ -1,11 +1,11 @@ #include -#include +#include "qgsrect.h" #include #include #include "qgsdatabaselayer.h" QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) : - QgsMapLayer(QgsMapLayer::DATABASE, table), tableName(table){ + QgsMapLayer(QgsMapLayer::DATABASE, table),tableName(table){ // create the database layer and get the needed information // about it from the database dataSource = conninfo; @@ -39,6 +39,7 @@ QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) : QTextOStream(&xMsg) << "Set extents to: " << layerExtent.xMin() << ", " << layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax(); qWarning(xMsg); + }else{ QString msg = "Unable to access " + tableName; //QMessageBox::warning(this,"Connection Problem",msg); @@ -53,17 +54,52 @@ QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) : delete pd; } } - QgsDatabaseLayer::~QgsDatabaseLayer(){ - } - void QgsDatabaseLayer::calculateExtent(){ - } - void QgsDatabaseLayer::draw(QPainter *p, QRect *viewExtent){ - // painter is active (begin has been called - /* Steps to draw the layer - 1. get the features in the view extent by SQL query - 2. read WKB for a feature - 3. transform - 4. draw - */ +QgsDatabaseLayer::~QgsDatabaseLayer(){ +} +QgsRect QgsDatabaseLayer::calculateExtent(){ + return layerExtent; +} +void QgsDatabaseLayer::draw(QPainter *p, QgsRect *viewExtent){ + // painter is active (begin has been called + /* Steps to draw the layer + 1. get the features in the view extent by SQL query + 2. read WKB for a feature + 3. transform + 4. draw + */ + PgCursor pgs(dataSource, "drawCursor"); + QString sql = "select asbinary(" + geometryColumn + ",'" + endianString() + + "') as features from " + tableName + " where " + geometryColumn + + " && GeometryFromText('BOX3D(" + viewExtent->xMin() + " " + viewExtent->yMin() + + "," + viewExtent->xMax() + " " + viewExtent->yMax() + ")'::box3d,-1)"; + pgs.Declare((const char *)sql, true); + int res = pgs.Fetch(); + cout << "Number of matching records: " << pgs.Tuples() << endl; + for (int idx = 0; idx < pgs.Tuples (); idx++) + { + // read each feature based on its type + } - } + + +} +int QgsDatabaseLayer::endian(){ + char *chkEndian = new char[4]; + memset (chkEndian, '\0', 4); + chkEndian[0] = 0xE8; + int *ce = (int *) chkEndian; + if(232 == *ce) + return NDR; + else + return XDR; +} +QString QgsDatabaseLayer::endianString(){ + char *chkEndian = new char[4]; + memset (chkEndian, '\0', 4); + chkEndian[0] = 0xE8; + int *ce = (int *) chkEndian; + if(232 == *ce) + return QString("NDR"); + else + return QString("XDR"); +} diff --git a/src/qgsdatabaselayer.h b/src/qgsdatabaselayer.h index e76484daca6..6b6bbb7ee8f 100644 --- a/src/qgsdatabaselayer.h +++ b/src/qgsdatabaselayer.h @@ -18,6 +18,7 @@ #ifndef QGSDATABASELAYER_H #define QGSDATABASELAYER_H class QString; +class QgsRect; #include "qgsmaplayer.h" @@ -37,10 +38,10 @@ class QgsDatabaseLayer : public QgsMapLayer { QgsDatabaseLayer(const char *conninfo=0, QString table=QString::null); //! Destructor ~QgsDatabaseLayer(); - void draw(QPainter *p, QRect *viewExtent=0); + void draw(QPainter *p, QgsRect *viewExtent=0); private: //! Calculates extent of the layer using SQL and PostGIS functions - void calculateExtent(); + QgsRect calculateExtent(); //! Type geometry contained in the layer. This corresponds to one of the OGIS Simple geometry types QString type; //! WKB type @@ -60,7 +61,13 @@ class QgsDatabaseLayer : public QgsMapLayer { WKBMultiLineString, WKBMultiPolygon }; - + enum ENDIAN{ + NDR, + XDR + }; + // Returns the endian type for the client + int endian(); + QString endianString(); }; #endif diff --git a/src/qgsmaplayer.cpp b/src/qgsmaplayer.cpp index b330dde6a51..5b93d0fc729 100644 --- a/src/qgsmaplayer.cpp +++ b/src/qgsmaplayer.cpp @@ -37,7 +37,7 @@ void QgsMapLayer::setlayerName( const QString& _newVal){ const QString QgsMapLayer::name(){ return layerName; } -void QgsMapLayer::calculateExtent(){ +QgsRect QgsMapLayer::calculateExtent(){ } -void QgsMapLayer::draw(QPainter *, QRect *){ +void QgsMapLayer::draw(QPainter *, QgsRect *){ } diff --git a/src/qgsmaplayer.h b/src/qgsmaplayer.h index 4e2077d68e8..1f439b89d01 100644 --- a/src/qgsmaplayer.h +++ b/src/qgsmaplayer.h @@ -54,8 +54,8 @@ class QgsMapLayer : public QgsDataSource { * This function must be overridden in all child classes and implemented * based on the layer type */ - virtual void calculateExtent(); - virtual void draw(QPainter *, QRect * = 0); + virtual QgsRect calculateExtent(); + virtual void draw(QPainter *, QgsRect * = 0); /*! Return the extent of the layer as a QRect */ const QgsRect extent(); diff --git a/src/qgsrect.cpp b/src/qgsrect.cpp index 9bcd11101f4..d592741a0ff 100644 --- a/src/qgsrect.cpp +++ b/src/qgsrect.cpp @@ -16,16 +16,16 @@ void QgsRect::setYmin(double y){ void QgsRect::setYmax(double y){ ymax = y; } -double QgsRect::xMax(){ +double QgsRect::xMax() const { return xmax; } -double QgsRect::xMin(){ +double QgsRect::xMin() const { return xmin; } -double QgsRect::yMax(){ +double QgsRect::yMax() const { return ymax; } -double QgsRect::yMin(){ +double QgsRect::yMin() const { return ymin; } void QgsRect::normalize(){ @@ -41,3 +41,20 @@ void QgsRect::normalize(){ ymax = temp; } } + +bool QgsRect::operator==(const QgsRect &r1){ + return (r1.xMax() == this->xMax() && r1.xMin() == this->xMin() && + r1.yMax() == this->yMax() && r1.yMin() == this->yMin()); +} + +QgsRect & QgsRect::operator=(const QgsRect &r){ + if(&r != this){ + xmax = r.xMax(); + xmin = r.xMin(); + ymax = r.yMax(); + ymin = r.yMin(); + } + return *this; + + +} diff --git a/src/qgsrect.h b/src/qgsrect.h index ffe2fa9d256..f69f4aae946 100644 --- a/src/qgsrect.h +++ b/src/qgsrect.h @@ -16,20 +16,28 @@ class QgsRect{ void setXmin(double x); //! Set the maximum x value void setXmax(double x); - //! Set the maximum y value + //! Set the maximum y value void setYmin(double y); - //! Set the maximum y value + //! Set the maximum y value void setYmax(double y); //! Get the x maximum value (right side of rectangle) - double xMax(); - //! Get the x maximum value (right side of rectangle) - double xMin(); - //! Get the x minimum value (left side of rectangle) - double yMax(); - //! Get the y maximum value (top side of rectangle) - double yMin(); - //! Normalize the rectangle so it has non-negative width/height + double xMax() const; + //! Get the x maximum value (right side of rectangle) + double xMin() const; + //! Get the x minimum value (left side of rectangle) + double yMax() const; + //! Get the y maximum value (top side of rectangle) + double yMin() const; + //! Normalize the rectangle so it has non-negative width/height void normalize(); + /*! Comparison operator + @return True if rectangles are equal + */ + bool operator==(const QgsRect &r1); + /*! Assignment operator + * @param r1 QgsRect to assign from + */ + QgsRect & operator=(const QgsRect &r1); private: double xmax; double xmin;