Skip to content

Commit

Permalink
only check/uncheck layer files in QgsLegend::selectAll (not all items…
Browse files Browse the repository at this point in the history
…). Added a wkb method for QgsGeometry::moveVertex to handle all shape types

git-svn-id: http://svn.osgeo.org/qgis/trunk@5349 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 23, 2006
1 parent addea8a commit 07baabf
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 8 deletions.
145 changes: 145 additions & 0 deletions src/core/qgsgeometry.cpp
Expand Up @@ -514,6 +514,150 @@ bool QgsGeometry::insertVertexBefore(double x, double y,

}

bool QgsGeometry::moveVertexAt(double x, double y, QgsGeometryVertexIndex atVertex)
{
int vertexnr = atVertex.back();

if(mDirtyWkb)
{
exportGeosToWkb();
}

unsigned int wkbType;
double *xPtr, *yPtr;
unsigned char* ptr = mGeometry+1;
memcpy(&wkbType, ptr, sizeof(wkbType));
ptr += sizeof(wkbType);

switch(wkbType)
{
case QGis::WKBPoint:
{
if(vertexnr == 0)
{
memcpy(ptr, &x, sizeof(double));
ptr += sizeof(double);
memcpy(ptr, &y, sizeof(double));
return true;
}
else
{
return false;
}
}
case QGis::WKBMultiPoint:
case QGis::WKBLineString:
{
int* nrPoints = (int*)ptr;
if(vertexnr > *nrPoints || vertexnr < 0)
{
return false;
}
ptr += sizeof(int);
ptr += 2*sizeof(double)*vertexnr;
memcpy(ptr, &x, sizeof(double));
ptr += sizeof(double);
memcpy(ptr, &y, sizeof(double));
return true;
}
case QGis::WKBMultiLineString:
{
int* nrLines = (int*)ptr;
ptr += sizeof(int);
int* nrPoints = 0; //numer of points in a line
int pointindex = 0;
for(int linenr = 0; linenr < *nrLines; ++linenr)
{
nrPoints = (int*)ptr;
ptr += sizeof(int);
if(vertexnr >= pointindex && vertexnr < pointindex + (*nrPoints))
{
ptr += (vertexnr-pointindex)*2*sizeof(double);
memcpy(ptr, &x, sizeof(double));
memcpy(ptr+sizeof(double), &y, sizeof(double));
return true;
}
pointindex += (*nrPoints);
ptr += 2*sizeof(double)*(*nrPoints);
}
return false;
}
case QGis::WKBPolygon:
{
int* nrRings = (int*)ptr;
ptr += sizeof(int);
int* nrPoints = 0; //numer of points in a ring
int pointindex = 0;

for(int ringnr = 0; ringnr < *nrRings; ++ringnr)
{
nrPoints = (int*)ptr;
ptr += sizeof(int);
if(vertexnr == pointindex || vertexnr == pointindex + (*nrPoints-1))//move two points
{
memcpy(ptr, &x, sizeof(double));
memcpy(ptr+sizeof(double), &y, sizeof(double));
memcpy(ptr+2*sizeof(double)*(*nrPoints-1), &x, sizeof(double));
memcpy(ptr+sizeof(double)+2*sizeof(double)*(*nrPoints-1), &y, sizeof(double));
return true;
}
else if(vertexnr > pointindex && vertexnr < pointindex + (*nrPoints-1))//move only one point
{
ptr += 2*sizeof(double)*(vertexnr - pointindex);
memcpy(ptr, &x, sizeof(double));
ptr += sizeof(double);
memcpy(ptr, &y, sizeof(double));
return true;
}
ptr += 2*sizeof(double)*(*nrPoints);
pointindex += *nrPoints;
}
return false;
}
case QGis::WKBMultiPolygon:
{
int* nrPolygons = (int*)ptr;
ptr += sizeof(int);
int* nrRings = 0; //number of rings in a polygon
int* nrPoints = 0; //number of points in a ring
int pointindex = 0;

for(int polynr = 0; polynr < *nrPolygons; ++polynr)
{
nrRings = (int*)ptr;
ptr += sizeof(int);
for(int ringnr = 0; ringnr< *nrRings; ++ringnr)
{
nrPoints = (int*)ptr;
ptr += sizeof(int);
if(vertexnr == pointindex || vertexnr == pointindex + (*nrPoints-1))//move two points
{
memcpy(ptr, &x, sizeof(double));
memcpy(ptr+sizeof(double), &y, sizeof(double));
memcpy(ptr+2*sizeof(double)*(*nrPoints-1), &x, sizeof(double));
memcpy(ptr+sizeof(double)+2*sizeof(double)*(*nrPoints-1), &y, sizeof(double));
return true;
}
else if(vertexnr > pointindex && vertexnr < pointindex + (*nrPoints-1))//move only one point
{
ptr += 2*sizeof(double)*(vertexnr - pointindex);
memcpy(ptr, &x, sizeof(double));
ptr += sizeof(double);
memcpy(ptr, &y, sizeof(double));
return true;
}
ptr += 2*sizeof(double)*(*nrPoints);
pointindex += *nrPoints;
}
}
return false;
}
}
}



#if 0
bool QgsGeometry::moveVertexAt(double x, double y,
QgsGeometryVertexIndex atVertex)
{
Expand Down Expand Up @@ -551,6 +695,7 @@ bool QgsGeometry::moveVertexAt(double x, double y,

return false;
}
#endif

bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
{
Expand Down
12 changes: 6 additions & 6 deletions src/gui/qgsvectorlayer.cpp
Expand Up @@ -792,8 +792,8 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
QgsDebugMsg("QgsVectorLayer::draw: Destroying all cached geometries.");

// TODO: This area has suspect memory management
if(mEditable)
{
//if(mEditable)
//{
for (std::map<int, QgsGeometry*>::iterator it = mCachedGeometries.begin();
it != mCachedGeometries.end();
++it )
Expand All @@ -802,7 +802,7 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
}
QgsDebugMsg("QgsVectorLayer::draw: Clearing all cached geometries.");
mCachedGeometries.clear();
}
//}

dataProvider->select(viewExtent);
dataProvider->updateFeatureCount();
Expand Down Expand Up @@ -869,10 +869,10 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
}

// Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
if(mEditable)
{
//if(mEditable)
//{
mCachedGeometries[fet->featureId()] = fet->geometryAndOwnership();
}
//}
bool sel=mSelected.find(fet->featureId()) != mSelected.end();
m_renderer->renderFeature(p, fet, &marker, &markerScaleFactor,
sel, widthScale );
Expand Down
8 changes: 6 additions & 2 deletions src/legend/qgslegend.cpp
Expand Up @@ -121,8 +121,12 @@ void QgsLegend::selectAll(bool select)

while (theItem)
{
theItem->setCheckState(0, (select ? Qt::Checked : Qt::Unchecked));
handleItemChange(theItem, 0);
QgsLegendItem* litem = dynamic_cast<QgsLegendItem*>(theItem);
if(litem && litem->type() == QgsLegendItem::LEGEND_LAYER_FILE)
{
theItem->setCheckState(0, (select ? Qt::Checked : Qt::Unchecked));
handleItemChange(theItem, 0);
}
theItem = nextItem(theItem);
}
}
Expand Down

0 comments on commit 07baabf

Please sign in to comment.