Skip to content

Commit

Permalink
move vertex for postgis point/multipoint layers
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5644 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jul 27, 2006
1 parent a7c8404 commit fdbaf80
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsgeometry.cpp
Expand Up @@ -238,7 +238,7 @@ QgsPoint QgsGeometry::closestVertex(const QgsPoint& point, QgsGeometryVertexInde
case QGis::WKBPoint:
x = *((double *) (mGeometry + 5));
y = *((double *) (mGeometry + 5 + sizeof(double)));
sqrDist = point.sqrDist(x, y);
actdist = point.sqrDist(x, y);
vertexnr = 0;
break;

Expand Down
5 changes: 4 additions & 1 deletion src/gui/qgisapp.cpp
Expand Up @@ -4667,7 +4667,10 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
mActionCapturePolygon->setEnabled(false);
mActionAddVertex->setEnabled(false);
mActionDeleteVertex->setEnabled(false);
mActionMoveVertex->setEnabled(false);
if(dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries)
{
mActionMoveVertex->setEnabled(true);
}
return;
}
else if(vlayer->vectorType() == QGis::Line)
Expand Down
148 changes: 81 additions & 67 deletions src/gui/qgsmaptoolvertexedit.cpp
Expand Up @@ -110,32 +110,32 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
#ifdef QGISDEBUG
std::cout << "QgsMapCanvas::mousePressEvent: QGis::AddVertex." << std::endl;
#endif

//Find nearest segment of the selected line, move that node to the mouse location
if (!snapSegmentWithContext(point))
{
QMessageBox::warning(0, "Error",
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
QMessageBox::Ok, Qt::NoButton);
return;
}

index = mSnappedBeforeVertex;
// Get the endpoint of the snapped-to segment
mSnappedAtGeometry.vertexAt(x2, y2, index);
// Get the startpoint of the snapped-to segment
index.decrement_back();
mStartPointValid = mSnappedAtGeometry.vertexAt(x1, y1, index);
createRubberBand();
if (mStartPointValid)
{
mRubberBand->addPoint(QgsPoint(x1,y1));
}
mRubberBand->addPoint(toMapCoords(e->pos()));
mRubberBand->addPoint(QgsPoint(x2,y2));
//Find nearest segment of the selected line, move that node to the mouse location
if (!snapSegmentWithContext(point))
{
QMessageBox::warning(0, "Error",
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
QMessageBox::Ok, Qt::NoButton);
return;
}
index = mSnappedBeforeVertex;
// Get the endpoint of the snapped-to segment
mSnappedAtGeometry.vertexAt(x2, y2, index);
// Get the startpoint of the snapped-to segment
index.decrement_back();
mStartPointValid = mSnappedAtGeometry.vertexAt(x1, y1, index);
createRubberBand();
if (mStartPointValid)
{
mRubberBand->addPoint(QgsPoint(x1,y1));
}
mRubberBand->addPoint(toMapCoords(e->pos()));
mRubberBand->addPoint(QgsPoint(x2,y2));
}
else if (mTool == MoveVertex)
{
Expand All @@ -150,53 +150,67 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
QgsPoint snapPoint;

snapPoint = point;
if (!snapSegmentWithContext(snapPoint))
{
QMessageBox::warning(0, "Error",
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
QMessageBox::Ok, Qt::NoButton);
return;
}

snapPoint = point;
if (!snapVertexOfSnappedSegment(snapPoint))
{
QMessageBox::warning(0, "Error",
QObject::tr("Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?"),
QMessageBox::Ok, Qt::NoButton);
return;
}

#ifdef QGISDEBUG
qWarning("Creating rubber band for moveVertex");
#endif

index = mSnappedAtVertex;
createRubberBand();
if(mRubberBandIndex1 != -1)
{
rb1Index.push_back(mRubberBandIndex1);
mSnappedAtGeometry.vertexAt(x1, y1, rb1Index);
mRubberBand->addPoint(QgsPoint(x1,y1));
mStartPointValid = true;
}
else
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>(mCanvas->currentLayer());
if(vlayer->vectorType() == QGis::Point)//snap to point for point/multipoint layers
{
mStartPointValid = false;
}
if(mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1)
{
mRubberBand->addPoint(toMapCoords(e->pos()));
if(!snapVertexWithContext(snapPoint))
{
QMessageBox::warning(0, "Error",
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
QMessageBox::Ok, Qt::NoButton);
return;
}
}
if(mRubberBandIndex2 != -1)
else //snap to segment and take the closest vertex in case of line/multiline/polygon/multipolygon layers
{
rb2Index.push_back(mRubberBandIndex2);
mSnappedAtGeometry.vertexAt(x2, y2, rb2Index);
mRubberBand->addPoint(QgsPoint(x2,y2));
}
if (!snapSegmentWithContext(snapPoint))
{
QMessageBox::warning(0, "Error",
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
QMessageBox::Ok, Qt::NoButton);
return;
}

snapPoint = point;
if (!snapVertexOfSnappedSegment(snapPoint))
{
QMessageBox::warning(0, "Error",
QObject::tr("Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?"),
QMessageBox::Ok, Qt::NoButton);
return;
}

#ifdef QGISDEBUG
qWarning("Creating rubber band for moveVertex");
#endif

index = mSnappedAtVertex;
createRubberBand();
if(mRubberBandIndex1 != -1)
{
rb1Index.push_back(mRubberBandIndex1);
mSnappedAtGeometry.vertexAt(x1, y1, rb1Index);
mRubberBand->addPoint(QgsPoint(x1,y1));
mStartPointValid = true;
}
else
{
mStartPointValid = false;
}
if(mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1)
{
mRubberBand->addPoint(toMapCoords(e->pos()));
}
if(mRubberBandIndex2 != -1)
{
rb2Index.push_back(mRubberBandIndex2);
mSnappedAtGeometry.vertexAt(x2, y2, rb2Index);
mRubberBand->addPoint(QgsPoint(x2,y2));
}
#ifdef QGISDEBUG
qWarning("Creating rubber band for moveVertex");
#endif
}
}
else if (mTool == DeleteVertex)
{
Expand Down
1 change: 1 addition & 0 deletions src/legend/qgslegend.cpp
Expand Up @@ -954,6 +954,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
theLayer = new QgsLegendLayer(this, name);
lastGroup = 0;
}

childelem.attribute("open") == "true" ? expandItem(theLayer) : collapseItem(theLayer);

//set the checkbox of the legend layer to the right state
Expand Down

0 comments on commit fdbaf80

Please sign in to comment.