mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Fix for bugs 1188781 and 1188780 (identify and select don't work on
projected layers) git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@3223 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
458f33b56f
commit
5550b100c0
@ -1,3 +1,4 @@
|
||||
|
||||
/***************************************************************************
|
||||
qgsvectorlayer.cpp
|
||||
This class implements a generic means to display vector layers. The features
|
||||
@ -190,7 +191,7 @@ QgsVectorLayer::~QgsVectorLayer()
|
||||
}
|
||||
}
|
||||
|
||||
bool QgsVectorLayer::projectionsEnabled()
|
||||
bool QgsVectorLayer::projectionsEnabled() const
|
||||
{
|
||||
if (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0)
|
||||
{
|
||||
@ -350,7 +351,8 @@ void QgsVectorLayer::drawLabels(QPainter * p, QgsRect * viewExtent, QgsMapToPixe
|
||||
// select the records in the extent. The provider sets a spatial filter
|
||||
// and sets up the selection set for retrieval
|
||||
dataProvider->reset();
|
||||
dataProvider->select(viewExtent);
|
||||
QgsRect r = inverseProjectRect(*viewExtent);
|
||||
dataProvider->select(&r);
|
||||
|
||||
//main render loop
|
||||
QgsFeature *fet;
|
||||
@ -387,6 +389,36 @@ void QgsVectorLayer::drawLabels(QPainter * p, QgsRect * viewExtent, QgsMapToPixe
|
||||
}
|
||||
}
|
||||
|
||||
QgsRect QgsVectorLayer::inverseProjectRect(const QgsRect& r) const
|
||||
{
|
||||
// Undo a coordinate transformation if one was in effect
|
||||
if (projectionsEnabled())
|
||||
{
|
||||
try
|
||||
{
|
||||
QgsPoint p1 = mCoordinateTransform->transform(r.xMin(), r.yMin(),
|
||||
QgsCoordinateTransform::INVERSE);
|
||||
QgsPoint p2 = mCoordinateTransform->transform(r.xMax(), r.yMax(),
|
||||
QgsCoordinateTransform::INVERSE);
|
||||
#ifdef QGISDEBUG
|
||||
std::cerr << "Projections are enabled\n";
|
||||
std::cerr << "Rectangle was: " << r.stringRep(true) << '\n';
|
||||
QgsRect tt(p1, p2);
|
||||
std::cerr << "Inverse transformed to: " << tt.stringRep(true) << '\n';
|
||||
#endif
|
||||
return QgsRect(p1, p2);
|
||||
|
||||
}
|
||||
catch (QgsCsException &e)
|
||||
{
|
||||
qDebug("Inverse transform error in %s line %d:\n%s",
|
||||
__FILE__, __LINE__, e.what());
|
||||
}
|
||||
}
|
||||
else
|
||||
return QgsRect(r);
|
||||
}
|
||||
|
||||
unsigned char* QgsVectorLayer::drawLineString(unsigned char* feature,
|
||||
QPainter* p,
|
||||
QgsMapToPixel* mtp,
|
||||
@ -816,7 +848,9 @@ QgsVectorLayer::endian_t QgsVectorLayer::endian()
|
||||
void QgsVectorLayer::identify(QgsRect * r)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
dataProvider->select(r, true);
|
||||
|
||||
QgsRect pr = inverseProjectRect(*r);
|
||||
dataProvider->select(&pr, true);
|
||||
int featureCount = 0;
|
||||
QgsFeature *fet;
|
||||
unsigned char *feature;
|
||||
@ -1095,7 +1129,8 @@ void QgsVectorLayer::select(QgsRect * rect, bool lock)
|
||||
}
|
||||
}
|
||||
|
||||
dataProvider->select(rect, true);
|
||||
QgsRect r = inverseProjectRect(*rect);
|
||||
dataProvider->select(&r, true);
|
||||
|
||||
QgsFeature *fet;
|
||||
|
||||
@ -2397,6 +2432,7 @@ bool QgsVectorLayer::snapPoint(QgsPoint& point, double tolerance)
|
||||
double minvertexdist;//the distance between 'point' and 'vertexFeature'
|
||||
|
||||
QgsRect selectrect(point.x()-tolerance,point.y()-tolerance,point.x()+tolerance,point.y()+tolerance);
|
||||
selectrect = inverseProjectRect(selectrect);
|
||||
dataProvider->reset();
|
||||
dataProvider->select(&selectrect);
|
||||
while ((fet = dataProvider->getNextFeature(false)))
|
||||
|
@ -340,7 +340,7 @@ protected slots:
|
||||
|
||||
private: // Private attributes
|
||||
/** A simple helper method to find out if on the fly projections are enabled or not */
|
||||
bool projectionsEnabled();
|
||||
bool projectionsEnabled() const;
|
||||
//! Draws the layer labels using coordinate transformation
|
||||
void drawLabels(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * cXf, QPaintDevice * dst);
|
||||
|
||||
@ -352,6 +352,10 @@ private: // Private attributes
|
||||
std::vector<double>& z,
|
||||
QgsMapToPixel* mtp, bool projectionsEnabledFlag);
|
||||
|
||||
// Inverse projects the given rectangle if coordinate transforms are
|
||||
// in effect. Alters the given rectangle
|
||||
QgsRect inverseProjectRect(const QgsRect& r) const;
|
||||
|
||||
// Draw the linestring as given in the WKB format. Returns a pointer
|
||||
// to the byte after the end of the line string binary data stream
|
||||
// (WKB).
|
||||
|
Loading…
x
Reference in New Issue
Block a user