*** empty log message ***

git-svn-id: http://svn.osgeo.org/qgis/trunk@28 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2002-07-12 17:51:17 +00:00
parent b1f4a00b0f
commit daab26143f
8 changed files with 206 additions and 164 deletions

View File

@ -37,187 +37,213 @@
#include "qgisapp.h"
#include "xpm/qgis.xpm"
QgisApp::QgisApp(QWidget *parent, const char * name, WFlags fl ) : QgisAppBase(parent, name, fl ){
QgisApp::QgisApp (QWidget * parent, const char *name, WFlags fl):
QgisAppBase (parent, name, fl)
{
QPixmap icon;
icon = QPixmap(qgis_xpm);
setIcon(icon);
QGridLayout *FrameLayout = new QGridLayout( frameMain, 1, 2, 4, 6, "mainFrameLayout");
QSplitter *split = new QSplitter(frameMain);
mapToc = new QWidget(split);//frameMain);
icon = QPixmap (qgis_xpm);
setIcon (icon);
QGridLayout *FrameLayout =
new QGridLayout (frameMain, 1, 2, 4, 6, "mainFrameLayout");
QSplitter *split = new QSplitter (frameMain);
mapToc = new QWidget (split); //frameMain);
//add a canvas
mapCanvas = new QgsMapCanvas(split);
mapCanvas = new QgsMapCanvas (split);
// resize it to fit in the frame
// QRect r = frmCanvas->rect();
// canvas->resize(r.width(), r.height());
mapCanvas->setBackgroundColor(QColor(220,235,255));
mapCanvas->setMinimumWidth(400);
// QRect r = frmCanvas->rect();
// canvas->resize(r.width(), r.height());
mapCanvas->setBackgroundColor (QColor (220, 235, 255));
mapCanvas->setMinimumWidth (400);
FrameLayout->addWidget( split, 0, 0 );
mapToc->setBackgroundColor(QColor(192,192,192));
FrameLayout->addWidget (split, 0, 0);
mapToc->setBackgroundColor (QColor (192, 192, 192));
}
QgisApp::~QgisApp(){
QgisApp::~QgisApp ()
{
}
void QgisApp::addLayer(){
void
QgisApp::addLayer ()
{
// only supports postgis layers at present
// show the postgis dialog
QgsDbSourceSelect *dbs = new QgsDbSourceSelect();
if(dbs->exec()){
// add files to the map canvas
QStringList tables = dbs->selectedTables();
QString connInfo = dbs->connInfo();
// for each selected table, connect to the datbase, parse the WKT geometry,
// and build a cavnasitem for it
// readWKB(connInfo,tables);
QStringList::Iterator it = tables.begin();
while( it != tables.end() ) {
// create the layer
QgsDatabaseLayer *lyr = new QgsDatabaseLayer(connInfo, *it);
// add it to the mapcanvas collection
mapCanvas->addLayer(lyr);
// no drawing done -- need to pass the layer collection
// to the rendering engine (yet to be written)
++it;
QgsDbSourceSelect *dbs = new QgsDbSourceSelect ();
if (dbs->exec ())
{
// add files to the map canvas
QStringList tables = dbs->selectedTables ();
QString connInfo = dbs->connInfo ();
// for each selected table, connect to the datbase, parse the WKT geometry,
// and build a cavnasitem for it
// readWKB(connInfo,tables);
QStringList::Iterator it = tables.begin ();
while (it != tables.end ())
{
// create the layer
QgsDatabaseLayer *lyr = new QgsDatabaseLayer (connInfo, *it);
// add it to the mapcanvas collection
mapCanvas->addLayer (lyr);
// no drawing done -- need to pass the layer collection
// to the rendering engine (yet to be written)
++it;
}
}
}
}
void QgisApp::fileExit(){
QApplication::exit();
void
QgisApp::fileExit ()
{
QApplication::exit ();
}
void QgisApp::zoomIn(){
void
QgisApp::zoomIn ()
{
/* QWMatrix m = mapCanvas->worldMatrix();
m.scale( 2.0, 2.0 );
mapCanvas->setWorldMatrix( m );
*/
m.scale( 2.0, 2.0 );
mapCanvas->setWorldMatrix( m );
*/
}
void QgisApp::zoomOut()
void
QgisApp::zoomOut ()
{
/* QWMatrix m = mapCanvas->worldMatrix();
m.scale( 0.5, 0.5 );
mapCanvas->setWorldMatrix( m );
*/
m.scale( 0.5, 0.5 );
mapCanvas->setWorldMatrix( m );
*/
}
void QgisApp::readWKB(const char *connInfo, QStringList tables){
PgCursor pgc(connInfo, "testcursor");
void
QgisApp::readWKB (const char *connInfo, QStringList tables)
{
PgCursor pgc (connInfo, "testcursor");
// get "endianness"
char *chkEndian = new char[4];
memset(chkEndian,'\0',4);
memset (chkEndian, '\0', 4);
chkEndian[0] = 0xE8;
int *ce = (int *)chkEndian;
int *ce = (int *) chkEndian;
bool isNDR = (232 == *ce);
/* if(*ce != 232)
cout << "Big endian" << endl;
else
cout << "Little endian" << endl;
*/
QStringList::Iterator it = tables.begin();
while( it != tables.end() ) {
// get the extent of the layer
QString esql = "select extent(the_geom) from " + *it;
PgDatabase *pd = new PgDatabase(connInfo);
int result = pd->ExecTuplesOk((const char *)esql);
QString extent = pd->GetValue(0,0);
// parse out the x and y values
extent = extent.right(extent.length() - extent.find("BOX3D(")- 6);
QStringList coordPairs = QStringList::split(",", extent);
QStringList x1y1 = QStringList::split(" ", coordPairs[0]);
QStringList x2y2 = QStringList::split(" ", coordPairs[1]);
double x1 = x1y1[0].toDouble();
double y1 = x1y1[1].toDouble();
double x2 = x2y2[0].toDouble();
double y2 = x2y2[1].toDouble();
double xMu = x2 - x1;
double yMu = y2 - y1;
int subordinantAxisLength;
cout << "Big endian" << endl;
else
cout << "Little endian" << endl;
*/
QStringList::Iterator it = tables.begin ();
while (it != tables.end ())
{
// determine the dominate direction for the mapcanvas
if(mapCanvas->width() > mapCanvas->height()){
subordinantAxisLength = mapCanvas->height();
scaleFactor = yMu/subordinantAxisLength;
mapWindow = new QRect(x1,y1, xMu, xMu);
} else{
subordinantAxisLength = mapCanvas->width();
scaleFactor = xMu/subordinantAxisLength;
mapWindow = new QRect(x1,y1, yMu, yMu);
}
const char * xtent = (const char *)extent;
string sql = "select asbinary(the_geom,";
if(isNDR)
sql += "'NDR'";
else
sql += "'XDR'";
sql += ") as features from ";
sql += *it++;
cout << sql.c_str() << endl;
pgc.Declare(sql.c_str(), true);
int res = pgc.Fetch();
cout << "Number of binary records: " << pgc.Tuples() << endl;
bool setExtent = true;
// process each record
QPainter paint;
paint.begin(mapCanvas);
paint.setWindow(*mapWindow);
QRect v = paint.viewport();
int d = QMIN( v.width(), v.height() );
paint.setViewport( v.left() + (v.width()-d)/2,
v.top() + (v.height()-d)/2, d, d );
// get the extent of the layer
QString esql = "select extent(the_geom) from " + *it;
PgDatabase *pd = new PgDatabase (connInfo);
int result = pd->ExecTuplesOk ((const char *) esql);
QString extent = pd->GetValue (0, 0);
// parse out the x and y values
extent = extent.right (extent.length () - extent.find ("BOX3D(") - 6);
QStringList coordPairs = QStringList::split (",", extent);
QStringList x1y1 = QStringList::split (" ", coordPairs[0]);
QStringList x2y2 = QStringList::split (" ", coordPairs[1]);
double x1 = x1y1[0].toDouble ();
double y1 = x1y1[1].toDouble ();
double x2 = x2y2[0].toDouble ();
double y2 = x2y2[1].toDouble ();
double xMu = x2 - x1;
double yMu = y2 - y1;
int subordinantAxisLength;
paint.setPen(Qt::red);
for(int idx = 0; idx < pgc.Tuples(); idx++){
cout << "Size of this record: " << pgc.GetLength(idx,0) << endl;
// allocate memory for the item
char *feature = new char[pgc.GetLength(idx,0) +1];
memset(feature,'\0',pgc.GetLength(idx,0) +1);
memcpy(feature,pgc.GetValue(idx,0),pgc.GetLength(idx,0) );
// determine the dominate direction for the mapcanvas
if (mapCanvas->width () > mapCanvas->height ())
{
subordinantAxisLength = mapCanvas->height ();
scaleFactor = yMu / subordinantAxisLength;
mapWindow = new QRect (x1, y1, xMu, xMu);
}
else
{
subordinantAxisLength = mapCanvas->width ();
scaleFactor = xMu / subordinantAxisLength;
mapWindow = new QRect (x1, y1, yMu, yMu);
}
cout << "Endian is: " << (int)feature[0] << endl;
cout << "Geometry type is: " << (int)feature[1] << endl;
// print the x,y coordinates
double *x = (double *)(feature+5);
double *y = (double*)(feature+5 + sizeof(double));
cout << "x,y: " << setprecision(16) << *x << ", " << *y << endl;
QPoint pt = paint.xForm(QPoint((int)*x, (int) *y));
cout << "Plotting " << *x << ", " << *y << " at " << pt.x() << ", " << pt.y() << endl;
paint.drawRect((int)*x, mapWindow->bottom()-(int)*y,15000,15000);
// free it
delete[] feature;
}
paint.end();
}
const char *xtent = (const char *) extent;
string sql = "select asbinary(the_geom,";
if (isNDR)
sql += "'NDR'";
else
sql += "'XDR'";
sql += ") as features from ";
sql += *it++;
cout << sql.c_str () << endl;
pgc.Declare (sql.c_str (), true);
int res = pgc.Fetch ();
cout << "Number of binary records: " << pgc.Tuples () << endl;
bool setExtent = true;
// process each record
QPainter paint;
paint.begin (mapCanvas);
paint.setWindow (*mapWindow);
QRect v = paint.viewport ();
int d = QMIN (v.width (), v.height ());
paint.setViewport (v.left () + (v.width () - d) / 2,
v.top () + (v.height () - d) / 2, d, d);
paint.setPen (Qt::red);
for (int idx = 0; idx < pgc.Tuples (); idx++)
{
cout << "Size of this record: " << pgc.GetLength (idx, 0) << endl;
// allocate memory for the item
char *feature = new char[pgc.GetLength (idx, 0) + 1];
memset (feature, '\0', pgc.GetLength (idx, 0) + 1);
memcpy (feature, pgc.GetValue (idx, 0), pgc.GetLength (idx, 0));
cout << "Endian is: " << (int) feature[0] << endl;
cout << "Geometry type is: " << (int) feature[1] << endl;
// print the x,y coordinates
double *x = (double *) (feature + 5);
double *y = (double *) (feature + 5 + sizeof (double));
cout << "x,y: " << setprecision (16) << *x << ", " << *y << endl;
QPoint pt = paint.xForm (QPoint ((int) *x, (int) *y));
cout << "Plotting " << *x << ", " << *y << " at " << pt.
x () << ", " << pt.y () << endl;
paint.drawRect ((int) *x, mapWindow->bottom () - (int) *y, 15000,
15000);
// free it
delete[]feature;
}
paint.end ();
}
}
void QgisApp::drawPoint(double x,double y){
void
QgisApp::drawPoint (double x, double y)
{
QPainter paint;
QWMatrix mat(scaleFactor,0,0,scaleFactor,0,0);
paint.begin(mapCanvas);
QWMatrix mat (scaleFactor, 0, 0, scaleFactor, 0, 0);
paint.begin (mapCanvas);
// paint.setWorldMatrix(mat);
paint.setWindow(*mapWindow);
paint.setPen(Qt::blue);
paint.drawPoint(x,y);
paint.end();
paint.setWindow (*mapWindow);
paint.setPen (Qt::blue);
paint.drawPoint (x, y);
paint.end ();
}

View File

@ -1,9 +1,14 @@
#include <qstring.h>
#include <qrect.h>
#include "qgsdatabaselayer.h"
QgsDatabaseLayer::QgsDatabaseLayer(const char *conninfo, QString table) :
QgsMapLayer(QgsMapLayer::DATABASE, table), tableName(table){
dataSource = conninfo;
// set the extent of the layer
layerExtent.setTop(0);
}
QgsDatabaseLayer::~QgsDatabaseLayer(){
}
void QgsDatabaseLayer::calculateExtent(){
}

View File

@ -29,12 +29,13 @@ public:
QgsDatabaseLayer(const char *conninfo=0, QString table=QString::null);
~QgsDatabaseLayer();
private:
void calculateExtent();
QString type; // maps to one of the OGIS Simple geometry types
QString database;
QString tableName;
QString geometryColumn;
};
#endif

View File

@ -24,4 +24,10 @@ QgsMapCanvas::~QgsMapCanvas(){
}
void QgsMapCanvas::addLayer(QgsMapLayer *lyr){
layers[lyr->name()] = *lyr;
// set zpos to something...
//lyr->zpos = 0;
}
void QgsMapCanvas::render(){
// render all layers in the stack, starting at the base
}

View File

@ -32,6 +32,7 @@ public:
QgsMapCanvas(QWidget *parent=0, const char *name=0);
~QgsMapCanvas();
void addLayer(QgsMapLayer *lyr);
void render();
private:
//! map containing the layers by name
map<QString,QgsMapLayer> layers;

View File

@ -34,4 +34,5 @@ void QgsMapLayer::setlayerName( const QString& _newVal){
const QString QgsMapLayer::name(){
return layerName;
}
void QgsMapLayer::calculateExtent(){
}

View File

@ -23,7 +23,7 @@
/**
*@author Gary E.Sherman
*/
class QRect;
class QgsMapLayer : public QgsDataSource {
public:
@ -35,6 +35,8 @@ class QgsMapLayer : public QgsDataSource {
void setlayerName( const QString& _newVal);
/** Read property of QString layerName. */
const QString name();
virtual void calculateExtent();
const QRect extent();
public: // Public attributes
@ -43,14 +45,16 @@ enum LAYERS {
RASTER,
DATABASE
} ;
protected:
QRect layerExtent;
//! Position in the map stack
int zpos;
private: // Private attributes
/** Name of the layer - used for display */
QString layerName;
/** Type of the layer (eg. vector, raster, database */
int layerType;
//! Position in the map stack
int zpos;
//! Tag for embedding additional information
QString tag;

View File

@ -1,24 +1,22 @@
/* XPM */
static const char *point_layer_xpm[]={
"16 16 6 1",
"16 16 4 1",
". c None",
"c c #008000",
"b c #54d10c",
"d c #5fee0e",
"# c #60ee0e",
"a c #60ef0e",
"b c #008080",
"a c #00c0c0",
"# c #00ffff",
"................",
"................",
"................",
"................",
"................",
"......#ab.......",
".....aaabc......",
"....aaaabcc.....",
"....aaaabbc.....",
"....dd#abcc.....",
".....bcbcc......",
"......ccc.......",
"......#aa.......",
".....###ab......",
"....####abb.....",
"....####aab.....",
"....####abb.....",
".....ababb......",
"......bbb.......",
"................",
"................",
"................",