Commit b6f9b1d8 authored by Dennis Nienhüser's avatar Dennis Nienhüser

Fix some serious memory leaks

Note that QPolygonF and GeoDataLineString etc are all implicitly shared,
so the copy returned by the methods has no negative performance impact.
parent c2f3c3e9
......@@ -32,49 +32,49 @@ BaseClipper::BaseClipper() :
QPolygonF *BaseClipper::lineString2Qpolygon(const GeoDataLineString& lineString)
QPolygonF BaseClipper::lineString2Qpolygon(const GeoDataLineString& lineString)
{
QPolygonF* polygon = new QPolygonF();
QPolygonF polygon;
foreach (const GeoDataCoordinates& coord, lineString) {
// Need to flip the Y axis(latitude)
QPointF point(coord.longitude(), -coord.latitude());
polygon->append(point);
polygon.append(point);
}
return polygon;
}
QPolygonF *BaseClipper::linearRing2Qpolygon(const GeoDataLinearRing& linearRing)
QPolygonF BaseClipper::linearRing2Qpolygon(const GeoDataLinearRing& linearRing)
{
QPolygonF* polygon = new QPolygonF();
QPolygonF polygon;
foreach (const GeoDataCoordinates& coord, linearRing) {
// Need to flip the Y axis(latitude)
QPointF point(coord.longitude(), -coord.latitude());
polygon->append(point);
polygon.append(point);
}
return polygon;
}
GeoDataLineString *BaseClipper::qPolygon2lineString(const QPolygonF& polygon)
GeoDataLineString BaseClipper::qPolygon2lineString(const QPolygonF& polygon)
{
GeoDataLineString* lineString = new GeoDataLineString();
GeoDataLineString lineString;
foreach (const QPointF& point, polygon) {
// Flipping back the Y axis
GeoDataCoordinates coord(point.x(), -point.y());
lineString->append(coord);
lineString.append(coord);
}
return lineString;
}
GeoDataLinearRing *BaseClipper::qPolygon2linearRing(const QPolygonF& polygon)
GeoDataLinearRing BaseClipper::qPolygon2linearRing(const QPolygonF& polygon)
{
GeoDataLinearRing* linearRing = new GeoDataLinearRing();
GeoDataLinearRing linearRing;
foreach (const QPointF& point, polygon) {
// Flipping back the Y axis
GeoDataCoordinates coord(point.x(), -point.y());
linearRing->append(coord);
linearRing.append(coord);
}
return linearRing;
......
......@@ -28,11 +28,11 @@ public:
static qreal tileX2lon( unsigned int x, unsigned int maxTileX );
static qreal tileY2lat( unsigned int y, unsigned int maxTileY );
static QPolygonF* lineString2Qpolygon(const GeoDataLineString &lineString);
static QPolygonF* linearRing2Qpolygon(const GeoDataLinearRing &linearRing);
static QPolygonF lineString2Qpolygon(const GeoDataLineString &lineString);
static QPolygonF linearRing2Qpolygon(const GeoDataLinearRing &linearRing);
static GeoDataLineString* qPolygon2lineString(const QPolygonF& polygon);
static GeoDataLinearRing* qPolygon2linearRing(const QPolygonF& polygon);
static GeoDataLineString qPolygon2lineString(const QPolygonF& polygon);
static GeoDataLinearRing qPolygon2linearRing(const QPolygonF& polygon);
void initClipRect(const GeoDataLatLonBox& clippingBox);
......
......@@ -69,7 +69,7 @@ GeoDataDocument *ShpCoastlineProcessor::cutToTiles(unsigned int zoomLevel, unsig
QVector<QPolygonF> clippedPolygons;
QPolygonF outerBoundary = *BaseClipper::linearRing2Qpolygon(marblePolygon->outerBoundary());
QPolygonF outerBoundary = BaseClipper::linearRing2Qpolygon(marblePolygon->outerBoundary());
qDebug() << "Size before:" << outerBoundary.size();
qDebug() << "Clipping...";
......@@ -82,7 +82,7 @@ GeoDataDocument *ShpCoastlineProcessor::cutToTiles(unsigned int zoomLevel, unsig
qDebug() << polygon.size();
// Dirty fix to close the polygons.
GeoDataLinearRing outerBoundary = *BaseClipper::qPolygon2linearRing(polygon);
GeoDataLinearRing outerBoundary = BaseClipper::qPolygon2linearRing(polygon);
if(outerBoundary.first() != outerBoundary.last()) {
outerBoundary.append(outerBoundary.first());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment