Skip to content

Commit

Permalink
More improvements for add/move/delete vertex.
Browse files Browse the repository at this point in the history
* Menu now show which of add/move/delete is toggled on.
* Refresh-map now is hooked up to Ctrl+R so that added/moved/deleted nodes can be seen properly and quickly.
* Multiple edits on the same geometry now work.
Geometry editing now works in a basic end-to-end fashion for PostGIS.  Other providers still need to be tested.


git-svn-id: http://svn.osgeo.org/qgis/trunk@3682 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Jul 1, 2005
1 parent dedf813 commit 348dd98
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 74 deletions.
12 changes: 12 additions & 0 deletions src/qgisappbase.ui
Expand Up @@ -329,6 +329,9 @@
<property name="whatsThis">
<string>Refresh the map by clearing the map canvas and redrawing all visible layers</string>
</property>
<property name="accel">
<string>Ctrl+R</string>
</property>
</action>
<action>
<property name="name">
Expand Down Expand Up @@ -1099,6 +1102,9 @@
<property name="name">
<cstring>actionAddVertex</cstring>
</property>
<property name="toggleAction">
<bool>true</bool>
</property>
<property name="text">
<string>Add Vertex</string>
</property>
Expand All @@ -1110,6 +1116,9 @@
<property name="name">
<cstring>actionMoveVertex</cstring>
</property>
<property name="toggleAction">
<bool>true</bool>
</property>
<property name="text">
<string>Move Vertex</string>
</property>
Expand All @@ -1121,6 +1130,9 @@
<property name="name">
<cstring>actionDeleteVertex</cstring>
</property>
<property name="toggleAction">
<bool>true</bool>
</property>
<property name="text">
<string>Delete Vertex</string>
</property>
Expand Down
5 changes: 3 additions & 2 deletions src/qgsgeometry.cpp
Expand Up @@ -403,7 +403,7 @@ bool QgsGeometry::insertVertexBefore(double x, double y,
// in the geometry - append it.
(*new_sequence)->add( geos::Coordinate(x, y) );
}

// TODO: Check that the sequence is still simple, e.g. with geos::Geometry->isSimple()
}


Expand Down Expand Up @@ -532,7 +532,7 @@ bool QgsGeometry::moveVertexAt(double x, double y,
(*new_sequence)->add( old_sequence->getAt(i) );
}
}

// TODO: Check that the sequence is still simple, e.g. with geos::Geometry->isSimple()
}


Expand Down Expand Up @@ -657,6 +657,7 @@ bool QgsGeometry::deleteVertexAt(int atVertex,
}
}

// TODO: Check that the sequence is still simple, e.g. with geos::Geometry->isSimple()
}


Expand Down
101 changes: 29 additions & 72 deletions src/qgsvectorlayer.cpp
Expand Up @@ -836,7 +836,7 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
else
{
// Cache this for the use of (e.g.) modifying the feature's geometry.
mCachedGeometries[fet->featureId()] = fet->geometryAndOwnership();
// mCachedGeometries[fet->featureId()] = fet->geometryAndOwnership();

if (mDeleted.find(fet->featureId())==mDeleted.end())
{
Expand All @@ -845,17 +845,21 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
// check to see if the feature has an uncommitted modification.
// if so, substitute the modified geometry

//TODO

//#ifdef QGISDEBUG
// std::cerr << "QgsVectorLayer::draw: Looking for modified geometry for " << fet->featureId() << std::endl;
//#endif
if (mChangedGeometries.find(fet->featureId()) != mChangedGeometries.end())
{
#ifdef QGISDEBUG
std::cerr << "Found modified geometry for " << fet->featureId() << std::endl;
std::cerr << "QgsVectorLayer::draw: Found modified geometry for " << fet->featureId() << std::endl;
#endif
// substitute the modified geometry for the committed version
fet->setGeometry( mChangedGeometries[ fet->featureId() ] );
}


// Cache this for the use of (e.g.) modifying the feature's uncommitted geometry.
mCachedGeometries[fet->featureId()] = fet->geometryAndOwnership();

bool sel=mSelected.find(fet->featureId()) != mSelected.end();
m_renderer->renderFeature(p, fet, &marker, &markerScaleFactor,
sel, oversampling, widthScale );
Expand Down Expand Up @@ -2985,6 +2989,15 @@ bool QgsVectorLayer::snapVertexWithContext(QgsPoint& point,
// Go through the committed features
while ((feature = dataProvider->getNextFeature(false)))
{
if (mChangedGeometries.find(feature->featureId()) != mChangedGeometries.end())
{
#ifdef QGISDEBUG
std::cerr << "QgsVectorLayer::snapSegmentWithContext: Found modified geometry for " << feature->featureId() << std::endl;
#endif
// substitute the modified geometry for the committed version
feature->setGeometry( mChangedGeometries[ feature->featureId() ] );
}

minDistSegPoint = feature->geometry()->closestVertexWithContext(origPoint,
atVertexTemp,
testSqrDist);
Expand All @@ -3007,39 +3020,7 @@ bool QgsVectorLayer::snapVertexWithContext(QgsPoint& point,
}
}

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::snapVertexWithContext: Checking changed features."
<< "." << std::endl;
#endif

// Also go through the changed features
for (std::map<int, QgsGeometry>::iterator iter = mChangedGeometries.begin();
iter != mChangedGeometries.end();
++iter)
{
minDistSegPoint = (*iter).second.closestVertexWithContext(origPoint,
atVertexTemp,
testSqrDist);

if (testSqrDist < minSqrDist)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;

atVertex = atVertexTemp;
snappedFeatureId = (*iter).first;
snappedGeometry = (*iter).second;
}
}

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::snapVertexWithContext: Finishing"
<< " with feature ID " << snappedFeatureId
// << " and beforeVertex " << beforeVertex
<< "." << std::endl;
#endif


#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::snapVertexWithContext: Checking new features."
<< "." << std::endl;
Expand Down Expand Up @@ -3097,7 +3078,7 @@ bool QgsVectorLayer::snapSegmentWithContext(QgsPoint& point,
#endif

// Sanity checking
if ( tolerance<=0 ||
if ( tolerance<=0 ||
!dataProvider)
{
// set some default values before we bail
Expand Down Expand Up @@ -3127,8 +3108,16 @@ bool QgsVectorLayer::snapSegmentWithContext(QgsPoint& point,
// Go through the committed features
while ((feature = dataProvider->getNextFeature(false)))
{



if (mChangedGeometries.find(feature->featureId()) != mChangedGeometries.end())
{
#ifdef QGISDEBUG
std::cerr << "QgsVectorLayer::snapSegmentWithContext: Found modified geometry for " << feature->featureId() << std::endl;
#endif
// substitute the modified geometry for the committed version
feature->setGeometry( mChangedGeometries[ feature->featureId() ] );
}

minDistSegPoint = feature->geometry()->closestSegmentWithContext(origPoint,
beforeVertexTemp,
testSqrDist);
Expand All @@ -3151,39 +3140,7 @@ bool QgsVectorLayer::snapSegmentWithContext(QgsPoint& point,
}
}

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::snapSegmentWithContext: Checking changed features."
<< "." << std::endl;
#endif

// Also go through the changed features
for (std::map<int, QgsGeometry>::iterator iter = mChangedGeometries.begin();
iter != mChangedGeometries.end();
++iter)
{
minDistSegPoint = (*iter).second.closestSegmentWithContext(origPoint,
beforeVertexTemp,
testSqrDist);

if (testSqrDist < minSqrDist)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;

beforeVertex = beforeVertexTemp;
snappedFeatureId = (*iter).first;
snappedGeometry = (*iter).second;
}
}

#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::snapSegmentWithContext: Finishing"
<< " with feature ID " << snappedFeatureId
// << " and beforeVertex " << beforeVertex
<< "." << std::endl;
#endif


#ifdef QGISDEBUG
std::cout << "QgsVectorLayer::snapSegmentWithContext: Checking new features."
<< "." << std::endl;
Expand Down

0 comments on commit 348dd98

Please sign in to comment.