*** empty log message ***

git-svn-id: http://svn.osgeo.org/qgis/trunk@30 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2002-07-13 17:34:35 +00:00
parent 971793965f
commit 8183abe60d
10 changed files with 212 additions and 36 deletions

View File

@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: qgis
# Generated by qmake (1.02a) on: Thu Jul 11 19:53:34 2002
# Generated by qmake (1.02a) on: Sat Jul 13 08:56:49 2002
# Project: src.pro
# Template: app
# Command: $(QMAKE) src.pro
@ -51,7 +51,8 @@ HEADERS = qgsdbsourceselectbase.ui.h \
qgsshapefilelayer.h \
qgstable.h \
qgsdbsourceselect.h \
qgsnewconnection.h
qgsnewconnection.h \
qgsrect.h
SOURCES = main.cpp \
qgisapp.cpp \
qgsdatabaselayer.cpp \
@ -60,7 +61,8 @@ SOURCES = main.cpp \
qgsmaplayer.cpp \
qgsrasterlayer.cpp \
qgsdbsourceselect.cpp \
qgsnewconnection.cpp
qgsnewconnection.cpp \
qgsrect.cpp
OBJECTS = main.o \
qgisapp.o \
qgsdatabaselayer.o \
@ -70,6 +72,7 @@ OBJECTS = main.o \
qgsrasterlayer.o \
qgsdbsourceselect.o \
qgsnewconnection.o \
qgsrect.o \
qgsdbsourceselectbase.o \
qgisappbase.o \
qgsnewconnectionbase.o
@ -164,6 +167,7 @@ qgisapp.o: qgisapp.cpp qgsmapcanvas.h \
qgsdbsourceselect.h \
qgsdatabaselayer.h \
qgisapp.h \
xpm/qgis.xpm \
qgsdbsourceselectbase.h \
qgsmaplayer.h \
qgsdatasource.h \
@ -179,14 +183,18 @@ qgsmapcanvas.o: qgsmapcanvas.cpp qgsmaplayer.h \
qgsmapcanvas.h \
qgsdatasource.h
qgsmaplayer.o: qgsmaplayer.cpp qgsmaplayer.h \
qgsmaplayer.o: qgsmaplayer.cpp qgsrect.h \
qgsmaplayer.h \
qgsdatasource.h
qgsrasterlayer.o: qgsrasterlayer.cpp qgsrasterlayer.h \
qgsmaplayer.h \
qgsdatasource.h
qgsdbsourceselect.o: qgsdbsourceselect.cpp qgsdbsourceselect.h \
qgsdbsourceselect.o: qgsdbsourceselect.cpp xpm/point_layer.xpm \
xpm/line_layer.xpm \
xpm/polygon_layer.xpm \
qgsdbsourceselect.h \
qgsnewconnection.h \
qgsdbsourceselectbase.h \
qgsnewconnectionbase.h
@ -194,6 +202,8 @@ qgsdbsourceselect.o: qgsdbsourceselect.cpp qgsdbsourceselect.h \
qgsnewconnection.o: qgsnewconnection.cpp qgsnewconnection.h \
qgsnewconnectionbase.h
qgsrect.o: qgsrect.cpp qgsrect.h
qgsdbsourceselectbase.h: qgsdbsourceselectbase.ui qgsdbsourceselectbase.ui.h
$(UIC) qgsdbsourceselectbase.ui -o qgsdbsourceselectbase.h

View File

@ -1,14 +1,69 @@
#include <qstring.h>
#include <qrect.h>
#include <libpq++.h>
#include <qmessagebox.h>
#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;
// set the extent of the layer
layerExtent.setTop(0);
}
QgsDatabaseLayer::~QgsDatabaseLayer(){
}
void QgsDatabaseLayer::calculateExtent(){
PgDatabase *pd = new PgDatabase(conninfo);
if(pd->Status()==CONNECTION_OK){
// get the geometry column
QString sql = "select f_geometry_column from geometry_columns where f_table_name='"
+ tableName + "'";
qWarning("Getting geometry column: " + sql);
int result = pd->ExecTuplesOk((const char *) sql);
if(result){
geometryColumn = pd->GetValue(0,"f_geometry_column");
// set the extent of the layer
QString sql = "select xmax(extent(" + geometryColumn + ")) as xmax,"
"xmin(extent(" + geometryColumn + ")) as xmin,"
"ymax(extent(" + geometryColumn + ")) as ymax,"
"ymin(extent(" + geometryColumn + ")) as ymin"
" from " + tableName;
qWarning("Getting extents: " + sql);
result = pd->ExecTuplesOk((const char *)sql);
if(result){
QString vRight = pd->GetValue(0,"right");
layerExtent.setXmax(QString(pd->GetValue(0,"xmax")).toDouble());
layerExtent.setXmin(QString(pd->GetValue(0,"xmin")).toDouble());
layerExtent.setYmax(QString(pd->GetValue(0,"ymax")).toDouble());
layerExtent.setYmin(QString(pd->GetValue(0,"ymin")).toDouble());
QString xMsg;
QTextOStream(&xMsg).precision(18);
QTextOStream(&xMsg).width(18);
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);
valid = false;
}
}else{
QString msg = "Unable to get geometry information for " + tableName;
//QMessageBox::warning(this,"Connection Problem",msg);
valid = false;
}
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
*/
}

View File

@ -4,7 +4,7 @@
begin : Fri Jun 28 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman@mrcc.com
***************************************************************************/
***************************************************************************/
/***************************************************************************
* *
@ -18,6 +18,7 @@
#ifndef QGSDATABASELAYER_H
#define QGSDATABASELAYER_H
class QString;
#include "qgsmaplayer.h"
/*! \class QgsDatabaseLayer
@ -26,28 +27,39 @@ class QString;
* At present Qgis supports PostGIS "layers" in PostgresQL.
*/
class QgsDatabaseLayer : public QgsMapLayer {
public:
public:
/*! Constructor
* @param conninfo Pointer to the connection information required to
* connect to PostgresQl
*@param table Name of the table in the database that this layer
* represents
*/
QgsDatabaseLayer(const char *conninfo=0, QString table=QString::null);
//! Destructor
~QgsDatabaseLayer();
QgsDatabaseLayer(const char *conninfo=0, QString table=QString::null);
//! Destructor
~QgsDatabaseLayer();
void draw(QPainter *p, QRect *viewExtent=0);
private:
//! Calculates extent of the layer using SQL and PostGIS functions
void calculateExtent();
//! Type geometry contained in the layer. This corresponds to one of the OGIS Simple geometry types
QString type;
//! Name of the database containing the layer (table)
QString database;
//! Name of the table containing the features
QString tableName;
//! Name of the columen in the table that contains the geometry for the features
QString geometryColumn;
//! Calculates extent of the layer using SQL and PostGIS functions
void calculateExtent();
//! Type geometry contained in the layer. This corresponds to one of the OGIS Simple geometry types
QString type;
//! WKB type
int wkbType;
//! Name of the database containing the layer (table)
QString database;
//! Name of the table containing the features
QString tableName;
//! Name of the columen in the table that contains the geometry for the features
QString geometryColumn;
//OGIS WKB types
enum WKBTYPE{
WKBPoint=1,
WKBLineString,
WKBPolygon,
WKBMultiPoint,
WKBMultiLineString,
WKBMultiPolygon
};
};

View File

@ -14,12 +14,15 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsrect.h"
#include "qgsmaplayer.h"
QgsMapLayer::QgsMapLayer(int type, QString lyrname )
: QgsDataSource(), layerType(type), layerName(lyrname)
: QgsDataSource(), layerName(lyrname), layerType(type)
{
// assume the layer is valid (data source exists and can be used)
// until we learn otherwise
valid = true;
}
QgsMapLayer::~QgsMapLayer(){
}
@ -36,3 +39,5 @@ const QString QgsMapLayer::name(){
}
void QgsMapLayer::calculateExtent(){
}
void QgsMapLayer::draw(QPainter *, QRect *){
}

View File

@ -20,8 +20,8 @@
#include <qwidget.h>
#include "qgsdatasource.h"
#include "qgsrect.h"
class QRect;
/** \class QgsMapLayer
* \brief Base class for all map layer types.
@ -55,10 +55,15 @@ class QgsMapLayer : public QgsDataSource {
* based on the layer type
*/
virtual void calculateExtent();
virtual void draw(QPainter *, QRect * = 0);
/*! Return the extent of the layer as a QRect
*/
const QRect extent();
const QgsRect extent();
/*! Returns the status of the layer. An invalid layer is one which has a bad datasource
* or other problem. Child classes set this flag when intialized
*@return True if the layer is valid and can be accessed
*/
bool isValid();
public: // Public attributes
//! Layers enum defining the types of layers that can be added to a map
@ -69,9 +74,11 @@ class QgsMapLayer : public QgsDataSource {
} ;
protected:
//! Extent of the layer
QRect layerExtent;
QgsRect layerExtent;
//! Position in the map stack
int zpos;
//! Indicates if the layer is valid and can be drawn
bool valid;
private: // Private attributes
/** Name of the layer - used for display */
QString layerName;

View File

@ -3,3 +3,5 @@ QgsRasterLayer::QgsRasterLayer(){
}
QgsRasterLayer::~QgsRasterLayer(){
}
void QgsRasterLayer::draw(QPainter *p, QRect *viewExtent){
}

View File

@ -29,6 +29,7 @@ class QgsRasterLayer : public QgsMapLayer {
QgsRasterLayer();
//! Destructor
~QgsRasterLayer();
void draw(QPainter *p, QRect *viewExtent);
};
#endif

43
src/qgsrect.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "qgsrect.h"
QgsRect::QgsRect(double minX, double minY, double maxX, double maxY) :
xmin(minX), ymin(minY), xmax(maxX), ymax(maxY){
}
QgsRect::~QgsRect(){
}
void QgsRect::setXmin(double x){
xmin = x;
}
void QgsRect::setXmax(double x){
xmax = x;
}
void QgsRect::setYmin(double y){
ymin = y;
}
void QgsRect::setYmax(double y){
ymax = y;
}
double QgsRect::xMax(){
return xmax;
}
double QgsRect::xMin(){
return xmin;
}
double QgsRect::yMax(){
return ymax;
}
double QgsRect::yMin(){
return ymin;
}
void QgsRect::normalize(){
double temp;
if( xmin > xmax){
temp = xmin;
xmin = xmax;
xmax = temp;
}
if(ymin > ymax){
temp = ymin;
ymin = ymax;
ymax = temp;
}
}

39
src/qgsrect.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef QGSRECT_H
#define QGSRECT_H
/*! \class QgsRect
* \brief A rectangle specified with double values.
*
* QgsRect is used to store a rectangle when double values are required.
* Examples are storing a layer extent or the current view extent of a map
*/
class QgsRect{
public:
//! Constructor
QgsRect(double xmin=0, double ymin=0, double xmax=0, double ymax=0);
//! Destructor
~QgsRect();
//! Set the minimum x value
void setXmin(double x);
//! Set the maximum x value
void setXmax(double x);
//! Set the maximum y value
void setYmin(double y);
//! 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
void normalize();
private:
double xmax;
double xmin;
double ymax;
double ymin;
};
#endif // QGSRECT_H

View File

@ -19,7 +19,8 @@ HEADERS += qgsdbsourceselectbase.ui.h \
qgsshapefilelayer.h \
qgstable.h \
qgsdbsourceselect.h \
qgsnewconnection.h
qgsnewconnection.h \
qgsrect.h
INTERFACES += qgsdbsourceselectbase.ui qgisappbase.ui qgsnewconnectionbase.ui
SOURCES += main.cpp \
@ -30,4 +31,5 @@ SOURCES += main.cpp \
qgsmaplayer.cpp \
qgsrasterlayer.cpp \
qgsdbsourceselect.cpp \
qgsnewconnection.cpp
qgsnewconnection.cpp \
qgsrect.cpp