zoom updates

git-svn-id: http://svn.osgeo.org/qgis/trunk@115 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2002-09-17 05:51:04 +00:00
parent 8f4d5a6a9a
commit 8d5899c780
13 changed files with 187 additions and 126 deletions

View File

@ -156,10 +156,10 @@
<enum>WidgetOrigin</enum>
</property>
<property name="frameShape">
<enum>Panel</enum>
<enum>PopupPanel</enum>
</property>
<property name="frameShadow">
<enum>Raised</enum>
<enum>Sunken</enum>
</property>
<property name="readOnly">
<bool>true</bool>
@ -209,6 +209,11 @@
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Quantum GIS is licensed under the GNU General Public License</string>
</property>
@ -219,12 +224,17 @@
</property>
<property name="geometry">
<rect>
<x>70</x>
<x>80</x>
<y>50</y>
<width>194</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>http://www.gnu.org/licenses</string>
</property>

View File

@ -37,7 +37,7 @@ QgsMapLayer(QgsMapLayer::DATABASE, table, conninfo), tableName(table)
if (pd->Status() == CONNECTION_OK) {
// get the geometry column
QString sql = "select f_geometry_column,type from geometry_columns where f_table_name='" + tableName + "'";
// qWarning("Getting geometry column: " + sql);
// qWarning("Getting geometry column: " + sql);
int result = pd->ExecTuplesOk((const char *) sql);
if (result) {
// set the simple type for use with symbology operations
@ -53,7 +53,7 @@ QgsMapLayer(QgsMapLayer::DATABASE, table, conninfo), tableName(table)
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);
// qWarning("Getting extents: " + sql);
result = pd->ExecTuplesOk((const char *) sql);
if (result) {
@ -67,7 +67,7 @@ QgsMapLayer(QgsMapLayer::DATABASE, table, conninfo), tableName(table)
QTextOStream(&xMsg).width(18);
QTextOStream(&xMsg) << "Set extents to: " << layerExtent.
xMin() << ", " << layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax();
// qWarning(xMsg);
// qWarning(xMsg);
} else {
QString msg = "Unable to access " + tableName;
@ -114,7 +114,7 @@ void QgsDatabaseLayer::draw(QPainter * p, QgsRect * viewExtent, int yTransform)
sql += " where " + geometryColumn;
sql += " && GeometryFromText('BOX3D(" + viewExtent->stringRep();
sql += ")'::box3d,-1)";
// qWarning(sql);
// qWarning(sql);
pgs.Declare((const char *) sql, true);
//! \todo Check return from Fecth();
int res = pgs.Fetch();
@ -267,13 +267,13 @@ void QgsDatabaseLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTra
sql += " where " + geometryColumn;
sql += " && GeometryFromText('BOX3D(" + viewExtent->stringRep();
sql += ")'::box3d,-1)";
// qWarning(sql);
// qWarning(sql);
pgs.Declare((const char *) sql, true);
int res = pgs.Fetch();
QString msg;
QTextOStream(&msg) << "Number of matching records: " << pgs.Tuples() << endl;
// qWarning(msg);
// std::cout << "Using following transform parameters:\n" << cXf->showParameters() << std::endl;
// qWarning(msg);
// std::cout << "Using following transform parameters:\n" << cXf->showParameters() << std::endl;
for (int idx = 0; idx < pgs.Tuples(); idx++) {
// allocate memory for the item
char *feature = new char[pgs.GetLength(idx, 0) + 1];
@ -416,7 +416,8 @@ void QgsDatabaseLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTra
}
void QgsDatabaseLayer::identify(QgsRect *r){
void QgsDatabaseLayer::identify(QgsRect * r)
{
}
int QgsDatabaseLayer::endian()
{

View File

@ -83,7 +83,7 @@ void QgsDbSourceSelect::dbConnect()
m_connInfo = host + " " + database + " " + username + " " + password;
qDebug(m_connInfo);
PgDatabase *pd = new PgDatabase((const char *) m_connInfo);
// std::cout << pd->ErrorMessage();
// std::cout << pd->ErrorMessage();
if (pd->Status() == CONNECTION_OK) {
// clear the existing entries
lstTables->clear();

View File

@ -38,7 +38,7 @@ QgsLayerProperties::QgsLayerProperties(QgsMapLayer * lyr):layer(lyr)
sym = layer->symbol();
btnSetColor->setPaletteBackgroundColor(sym->color());
btnSetFillColor->setPaletteBackgroundColor(sym->fillColor());
spinLineWidth->setValue(sym->lineWidth());
setCaption("Layer Properties - " + lyr->name());
@ -49,10 +49,10 @@ QgsLayerProperties::~QgsLayerProperties()
}
void QgsLayerProperties::selectFillColor()
{
QColor fc = QColorDialog::getColor(sym->fillColor(), this);
if (fc.isValid()) {
btnSetFillColor->setPaletteBackgroundColor(fc);
sym->setFillColor(fc);
}
@ -61,18 +61,18 @@ void QgsLayerProperties::selectOutlineColor()
{
QColor oc = QColorDialog::getColor(sym->color(), this);
if (oc.isValid()) {
btnSetColor->setPaletteBackgroundColor(oc);
sym->setColor(oc);
}
}
QString QgsLayerProperties::displayName(){
QString QgsLayerProperties::displayName()
{
return txtDisplayName->text();
}
void QgsLayerProperties::setLineWidth(int w){
void QgsLayerProperties::setLineWidth(int w)
{
sym->setLineWidth(w);
}

View File

@ -46,15 +46,15 @@ void QgsLegend::update()
listView->clear();
std::list< QString>::iterator zi = map->zOrder.begin();
while (zi != map->zOrder.end()) {
QgsMapLayer *lyr = map->layerByName(*zi);
QgsLegendItem *lvi = new QgsLegendItem(lyr, listView); // lyr->name(), QCheckListItem::CheckBox );
std::list < QString >::iterator zi = map->zOrder.begin();
while (zi != map->zOrder.end()) {
QgsMapLayer *lyr = map->layerByName(*zi);
QgsLegendItem *lvi = new QgsLegendItem(lyr, listView); // lyr->name(), QCheckListItem::CheckBox );
zi++;
}
zi++;
}
// Get the list of layers in order from the
// map canvas and add legenditems to the legend

View File

@ -95,7 +95,7 @@ void QgsMapCanvas::addLayer(QgsMapLayer * lyr)
incrementZpos();
lyr->setZ(layers.size() - 1);
updateZpos();
zOrder.push_back(lyr->name());
zOrder.push_back(lyr->name());
connect(lyr, SIGNAL(visibilityChanged()), this, SLOT(layerStateChange()));
//lyr->zpos = 0;
}
@ -106,78 +106,80 @@ void QgsMapCanvas::incrementZpos()
void QgsMapCanvas::updateZpos()
{
}
QgsMapLayer *QgsMapCanvas::getZpos(int )
QgsMapLayer *QgsMapCanvas::getZpos(int)
{
// QString name = zOrder[index];
// return layers[name];
// QString name = zOrder[index];
// return layers[name];
return 0;
}
QgsMapLayer *QgsMapCanvas::layerByName(QString name)
{
return layers[name];
}
void QgsMapCanvas::render2()
{
QString msg = frozen?"frozen":"thawed";
QString msg = frozen ? "frozen" : "thawed";
//std::cout << "Map canvas is " << msg << std::endl;
if(!frozen){
if (!drawing) {
// std::cout << "IN RENDER 2" << std::endl;
drawing = true;
QPainter *paint = new QPainter();
paint->begin(this);
if (!frozen) {
if (!drawing) {
// std::cout << "IN RENDER 2" << std::endl;
drawing = true;
QPainter *paint = new QPainter();
paint->begin(this);
// calculate the translation and scaling parameters
double muppX, muppY;
muppY = currentExtent.height() / height();
muppX = currentExtent.width() / width();
// std::cout << "MuppX is: " << muppX << "\nMuppY is: " << muppY << std::endl;
m_mupp = muppY > muppX ? muppY : muppX;
// calculate the actual extent of the mapCanvas
double dxmin, dxmax, dymin, dymax, whitespace;
if (muppY > muppX) {
dymin = currentExtent.yMin();
dymax = currentExtent.yMax();
whitespace = ((width() * m_mupp) - currentExtent.width()) / 2;
dxmin = currentExtent.xMin() - whitespace;
dxmax = currentExtent.xMax() + whitespace;
} else {
dxmin = currentExtent.xMin();
dxmax = currentExtent.xMax();
whitespace = ((height() * m_mupp) - currentExtent.height()) / 2;
dymin = currentExtent.yMin() - whitespace;
dymax = currentExtent.yMax() + whitespace;
// calculate the translation and scaling parameters
double muppX, muppY;
muppY = currentExtent.height() / height();
muppX = currentExtent.width() / width();
// std::cout << "MuppX is: " << muppX << "\nMuppY is: " << muppY << std::endl;
m_mupp = muppY > muppX ? muppY : muppX;
// calculate the actual extent of the mapCanvas
double dxmin, dxmax, dymin, dymax, whitespace;
if (muppY > muppX) {
dymin = currentExtent.yMin();
dymax = currentExtent.yMax();
whitespace = ((width() * m_mupp) - currentExtent.width()) / 2;
dxmin = currentExtent.xMin() - whitespace;
dxmax = currentExtent.xMax() + whitespace;
} else {
dxmin = currentExtent.xMin();
dxmax = currentExtent.xMax();
whitespace = ((height() * m_mupp) - currentExtent.height()) / 2;
dymin = currentExtent.yMin() - whitespace;
dymax = currentExtent.yMax() + whitespace;
}
// std::cout << "dxmin: " << dxmin << std::endl << "dymin: " << dymin << std::
// endl << "dymax: " << dymax << std::endl << "whitespace: " << whitespace << std::endl;
coordXForm->setParameters(m_mupp, dxmin, dymin, height()); //currentExtent.xMin(), currentExtent.yMin(), currentExtent.yMax());
// update the currentExtent to match the device coordinates
currentExtent.setXmin(dxmin);
currentExtent.setXmax(dxmax);
currentExtent.setYmin(dymin);
currentExtent.setYmax(dymax);
// render all layers in the stack, starting at the base
std::map < QString, QgsMapLayer * >::iterator mi = layers.begin();
// std::cout << "MAP LAYER COUNT: " << layers.size() << std::endl;
while (mi != layers.end()) {
QgsMapLayer *ml = (*mi).second;
if(ml){
// QgsDatabaseLayer *dbl = (QgsDatabaseLayer *)&ml;
// std::cout << "Rendering " << ml->name() << std::endl;
if (ml->visible())
ml->draw(paint, &currentExtent, coordXForm);
mi++;
// mi.draw(p, &fullExtent);
}
}
// std::cout << "dxmin: " << dxmin << std::endl << "dymin: " << dymin << std::
// endl << "dymax: " << dymax << std::endl << "whitespace: " << whitespace << std::endl;
coordXForm->setParameters(m_mupp, dxmin, dymin, height()); //currentExtent.xMin(), currentExtent.yMin(), currentExtent.yMax());
// update the currentExtent to match the device coordinates
currentExtent.setXmin(dxmin);
currentExtent.setXmax(dxmax);
currentExtent.setYmin(dymin);
currentExtent.setYmax(dymax);
// render all layers in the stack, starting at the base
std::map < QString, QgsMapLayer * >::iterator mi = layers.begin();
// std::cout << "MAP LAYER COUNT: " << layers.size() << std::endl;
while (mi != layers.end()) {
QgsMapLayer *ml = (*mi).second;
if (ml) {
// QgsDatabaseLayer *dbl = (QgsDatabaseLayer *)&ml;
// std::cout << "Rendering " << ml->name() << std::endl;
if (ml->visible())
ml->draw(paint, &currentExtent, coordXForm);
mi++;
// mi.draw(p, &fullExtent);
}
}
paint->end();
drawing = false;
paint->end();
drawing = false;
}
}
}
}
void QgsMapCanvas::render()
{
@ -220,12 +222,12 @@ void QgsMapCanvas::render()
paint->end();
*/
}
void QgsMapCanvas::paintEvent(QPaintEvent * )
void QgsMapCanvas::paintEvent(QPaintEvent *)
{
if (!drawing)
if (!drawing)
render2();
// else
// std::cout << "Can't paint in paint event -- drawing = true" << std::endl;
// else
// std::cout << "Can't paint in paint event -- drawing = true" << std::endl;
}
QgsRect QgsMapCanvas::extent()
@ -260,16 +262,18 @@ void QgsMapCanvas::mousePressEvent(QMouseEvent * e)
boxStartPoint = e->pos();
switch (mapTool) {
case QGis::ZoomIn:
case QGis::ZoomOut:
zoomBox.setRect(0, 0, 0, 0);
break;
case QGis::Pan:
// create a pixmap to use in panning the map canvas
tempPanImage = new QPixmap();
//*tempPanImage = QPixmap::grabWidget(this);
*tempPanImage = QPixmap::grabWindow(winId());
*tempPanImage = QPixmap::grabWindow(winId());
backgroundFill = new QPixmap(tempPanImage->width(), tempPanImage->height());
backgroundFill->fill(bgColor);
break;
@ -283,6 +287,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
QPainter paint;
QPen pen(Qt::gray);
QgsPoint ll, ur;
QgsRect *zoomRect ;
if (dragging) {
dragging = false;
switch (mapTool) {
@ -309,6 +314,32 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
clear();
render2();
break;
case QGis::ZoomOut:
// erase the rubber band box
paint.begin(this);
paint.setPen(pen);
paint.setRasterOp(Qt::XorROP);
paint.drawRect(zoomBox);
paint.end();
// store the rectangle
zoomBox.setRight(e->pos().x());
zoomBox.setBottom(e->pos().y());
// scale the extent so the current view fits inside the zoomBox
ll = coordXForm->toMapCoordinates(zoomBox.left(), zoomBox.bottom());
ur = coordXForm->toMapCoordinates(zoomBox.right(), zoomBox.top());
zoomRect = new QgsRect( ll, ur);
double sf;
if (zoomBox.width() > zoomBox.height()) {
sf = currentExtent.width()/zoomRect->width();
} else {
sf = currentExtent.height()/zoomRect->height();
}
delete zoomRect;
currentExtent.scale(sf);
clear();
render2();
break;
case QGis::Pan:
// new extent based on offset
delete tempPanImage;
@ -351,9 +382,10 @@ void QgsMapCanvas::mouseMoveEvent(QMouseEvent * e)
QPainter paint;
QPen pen(Qt::gray);
// this is a drag-type operation (zoom, pan or other maptool)
switch (mapTool) {
case QGis::ZoomIn:
case QGis::ZoomOut:
// draw the rubber band box as the user drags the mouse
dragging = true;
@ -425,35 +457,37 @@ int QgsMapCanvas::layerCount()
void QgsMapCanvas::layerStateChange()
{
if(!frozen){
clear();
render2();
if (!frozen) {
clear();
render2();
}
}
void QgsMapCanvas::freeze(bool frz){
void QgsMapCanvas::freeze(bool frz)
{
frozen = frz;
}
void QgsMapCanvas::remove(QString key){
std::map<QString,QgsMapLayer *>newLayers;
void QgsMapCanvas::remove(QString key)
{
std::map < QString, QgsMapLayer * >newLayers;
std::map < QString, QgsMapLayer * >::iterator mi = layers.begin();
while (mi != layers.end()) {
QgsMapLayer *ml = (*mi).second;
if(ml->name() != key)
newLayers[ml->name()] = ml;
mi++;
std::map < QString, QgsMapLayer * >::iterator mi = layers.begin();
while (mi != layers.end()) {
QgsMapLayer *ml = (*mi).second;
if (ml->name() != key)
newLayers[ml->name()] = ml;
mi++;
}
}
QgsMapLayer *l = layers[key];
layers = newLayers;
delete l;
zOrder.remove(key);
zOrder.remove(key);
}

View File

@ -48,9 +48,11 @@ const QString QgsMapLayer::name()
{
return layerName;
}
QString QgsMapLayer::source(){
QString QgsMapLayer::source()
{
return dataSource;
}
}
const QgsRect QgsMapLayer::extent()
{
return layerExtent;
@ -62,12 +64,12 @@ QgsRect QgsMapLayer::calculateExtent()
}
void QgsMapLayer::draw(QPainter *, QgsRect * viewExtent, int yTransform)
{
// std::cout << "In QgsMapLayer::draw" << std::endl;
// std::cout << "In QgsMapLayer::draw" << std::endl;
}
void QgsMapLayer::draw(QPainter *, QgsRect *, QgsCoordinateTransform *)
{
// std::cout << "In QgsMapLayer::draw" << std::endl;
// std::cout << "In QgsMapLayer::draw" << std::endl;
}
@ -133,5 +135,6 @@ void QgsMapLayer::setFeatureType(const int &_newVal)
feature = _newVal;
}
void QgsMapLayer::identify(QgsRect *r){
}
void QgsMapLayer::identify(QgsRect * r)
{
}

View File

@ -50,7 +50,7 @@ void QgsNewConnection::testConnection()
"host=" + txtHost->text() + " dbname=" + txtDatabase->text() +
" user=" + txtUsername->text() + " password=" + txtPassword->text();
PgDatabase *pd = new PgDatabase((const char *) connInfo);
// std::cout << pd->ErrorMessage();
// std::cout << pd->ErrorMessage();
if (pd->Status() == CONNECTION_OK) {
// Database successfully opened; we can now issue SQL commands.
QMessageBox::information(this, "Test connection", "Connection to " + txtDatabase->text() + " was successfull");

View File

@ -27,5 +27,6 @@ void QgsRasterLayer::draw(QPainter * p, QRect * viewExtent)
{
}
void QgsRasterLayer::identify(QgsRect *r){
}
void QgsRasterLayer::identify(QgsRect * r)
{
}

View File

@ -15,11 +15,18 @@
* *
***************************************************************************/
#include <qstring.h>
#include "qgspoint.h"
#include "qgsrect.h"
QgsRect::QgsRect(double minX, double minY, double maxX, double maxY):xmin(minX), ymin(minY), xmax(maxX), ymax(maxY)
{
}
QgsRect::QgsRect(QgsPoint p1, QgsPoint p2){
xmin = p1.x();
xmax = p2.x();
ymin = p1.y();
ymax = p2.y();
normalize();
}
QgsRect::~QgsRect()
{
}

View File

@ -19,6 +19,7 @@
#define QGSRECT_H
class QString;
class QgsPoint;
/*! \class QgsRect
* \brief A rectangle specified with double values.
@ -30,6 +31,8 @@ class QgsRect{
public:
//! Constructor
QgsRect(double xmin=0, double ymin=0, double xmax=0, double ymax=0);
//! Construct a rectangle from two points
QgsRect(QgsPoint p1, QgsPoint p2);
//! Destructor
~QgsRect();
//! Set the minimum x value

View File

@ -82,7 +82,7 @@ void QgsShapeFileLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTr
// reset the pointer to read from start of features
// set the spatial filter
// std::cout << "Drawing " << dataSource << std::endl;
// std::cout << "Drawing " << dataSource << std::endl;
OGRGeometry *filter = 0;
filter = new OGRPolygon();
std::ostrstream wktExtent;
@ -238,7 +238,7 @@ void QgsShapeFileLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTr
delete[]feature;
delete fet;
}
// std::cout << featureCount << " features in ogr layer within the extent" << std::endl;
// std::cout << featureCount << " features in ogr layer within the extent" << std::endl;
OGRGeometry *filt = ogrLayer->GetSpatialFilter();
filt->dumpReadable(stdout);
ogrLayer->ResetReading();
@ -259,5 +259,6 @@ int QgsShapeFileLayer::endian()
return XDR;
}
void QgsShapeFileLayer::identify(QgsRect *r){
void QgsShapeFileLayer::identify(QgsRect * r)
{
}

View File

@ -46,11 +46,12 @@ void QgsSymbol::setFillColor(QColor c)
m_fillColor = c;
}
int QgsSymbol::lineWidth(){
int QgsSymbol::lineWidth()
{
return m_lineWidth;
}
void QgsSymbol::setLineWidth(int w){
void QgsSymbol::setLineWidth(int w)
{
m_lineWidth = w;
}