Skip to content

Commit fdbaf80

Browse files
author
mhugent
committed
move vertex for postgis point/multipoint layers
git-svn-id: http://svn.osgeo.org/qgis/trunk@5644 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a7c8404 commit fdbaf80

File tree

4 files changed

+87
-69
lines changed

4 files changed

+87
-69
lines changed

src/core/qgsgeometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ QgsPoint QgsGeometry::closestVertex(const QgsPoint& point, QgsGeometryVertexInde
238238
case QGis::WKBPoint:
239239
x = *((double *) (mGeometry + 5));
240240
y = *((double *) (mGeometry + 5 + sizeof(double)));
241-
sqrDist = point.sqrDist(x, y);
241+
actdist = point.sqrDist(x, y);
242242
vertexnr = 0;
243243
break;
244244

src/gui/qgisapp.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -4667,7 +4667,10 @@ void QgisApp::activateDeactivateLayerRelatedActions(const QgsMapLayer* layer)
46674667
mActionCapturePolygon->setEnabled(false);
46684668
mActionAddVertex->setEnabled(false);
46694669
mActionDeleteVertex->setEnabled(false);
4670-
mActionMoveVertex->setEnabled(false);
4670+
if(dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries)
4671+
{
4672+
mActionMoveVertex->setEnabled(true);
4673+
}
46714674
return;
46724675
}
46734676
else if(vlayer->vectorType() == QGis::Line)

src/gui/qgsmaptoolvertexedit.cpp

+81-67
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,32 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
110110
#ifdef QGISDEBUG
111111
std::cout << "QgsMapCanvas::mousePressEvent: QGis::AddVertex." << std::endl;
112112
#endif
113-
114-
//Find nearest segment of the selected line, move that node to the mouse location
115-
if (!snapSegmentWithContext(point))
116-
{
117-
QMessageBox::warning(0, "Error",
118-
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
119-
QMessageBox::Ok, Qt::NoButton);
120-
return;
121-
}
122-
123-
index = mSnappedBeforeVertex;
124-
// Get the endpoint of the snapped-to segment
125-
mSnappedAtGeometry.vertexAt(x2, y2, index);
126-
127-
// Get the startpoint of the snapped-to segment
128-
index.decrement_back();
129-
mStartPointValid = mSnappedAtGeometry.vertexAt(x1, y1, index);
130-
131-
createRubberBand();
132-
133-
if (mStartPointValid)
134-
{
135-
mRubberBand->addPoint(QgsPoint(x1,y1));
136-
}
137-
mRubberBand->addPoint(toMapCoords(e->pos()));
138-
mRubberBand->addPoint(QgsPoint(x2,y2));
113+
114+
//Find nearest segment of the selected line, move that node to the mouse location
115+
if (!snapSegmentWithContext(point))
116+
{
117+
QMessageBox::warning(0, "Error",
118+
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
119+
QMessageBox::Ok, Qt::NoButton);
120+
return;
121+
}
122+
123+
index = mSnappedBeforeVertex;
124+
// Get the endpoint of the snapped-to segment
125+
mSnappedAtGeometry.vertexAt(x2, y2, index);
126+
127+
// Get the startpoint of the snapped-to segment
128+
index.decrement_back();
129+
mStartPointValid = mSnappedAtGeometry.vertexAt(x1, y1, index);
130+
131+
createRubberBand();
132+
133+
if (mStartPointValid)
134+
{
135+
mRubberBand->addPoint(QgsPoint(x1,y1));
136+
}
137+
mRubberBand->addPoint(toMapCoords(e->pos()));
138+
mRubberBand->addPoint(QgsPoint(x2,y2));
139139
}
140140
else if (mTool == MoveVertex)
141141
{
@@ -150,53 +150,67 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
150150
QgsPoint snapPoint;
151151

152152
snapPoint = point;
153-
if (!snapSegmentWithContext(snapPoint))
154-
{
155-
QMessageBox::warning(0, "Error",
156-
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
157-
QMessageBox::Ok, Qt::NoButton);
158-
return;
159-
}
160-
161-
snapPoint = point;
162-
if (!snapVertexOfSnappedSegment(snapPoint))
163-
{
164-
QMessageBox::warning(0, "Error",
165-
QObject::tr("Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?"),
166-
QMessageBox::Ok, Qt::NoButton);
167-
return;
168-
}
169-
170-
#ifdef QGISDEBUG
171-
qWarning("Creating rubber band for moveVertex");
172-
#endif
173-
174-
index = mSnappedAtVertex;
175-
createRubberBand();
176-
if(mRubberBandIndex1 != -1)
177-
{
178-
rb1Index.push_back(mRubberBandIndex1);
179-
mSnappedAtGeometry.vertexAt(x1, y1, rb1Index);
180-
mRubberBand->addPoint(QgsPoint(x1,y1));
181-
mStartPointValid = true;
182-
}
183-
else
153+
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>(mCanvas->currentLayer());
154+
if(vlayer->vectorType() == QGis::Point)//snap to point for point/multipoint layers
184155
{
185-
mStartPointValid = false;
186-
}
187-
if(mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1)
188-
{
189-
mRubberBand->addPoint(toMapCoords(e->pos()));
156+
if(!snapVertexWithContext(snapPoint))
157+
{
158+
QMessageBox::warning(0, "Error",
159+
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
160+
QMessageBox::Ok, Qt::NoButton);
161+
return;
162+
}
190163
}
191-
if(mRubberBandIndex2 != -1)
164+
else //snap to segment and take the closest vertex in case of line/multiline/polygon/multipolygon layers
192165
{
193-
rb2Index.push_back(mRubberBandIndex2);
194-
mSnappedAtGeometry.vertexAt(x2, y2, rb2Index);
195-
mRubberBand->addPoint(QgsPoint(x2,y2));
196-
}
166+
if (!snapSegmentWithContext(snapPoint))
167+
{
168+
QMessageBox::warning(0, "Error",
169+
QObject::tr("Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?"),
170+
QMessageBox::Ok, Qt::NoButton);
171+
return;
172+
}
173+
174+
snapPoint = point;
175+
if (!snapVertexOfSnappedSegment(snapPoint))
176+
{
177+
QMessageBox::warning(0, "Error",
178+
QObject::tr("Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?"),
179+
QMessageBox::Ok, Qt::NoButton);
180+
return;
181+
}
182+
183+
#ifdef QGISDEBUG
184+
qWarning("Creating rubber band for moveVertex");
185+
#endif
186+
187+
index = mSnappedAtVertex;
188+
createRubberBand();
189+
if(mRubberBandIndex1 != -1)
190+
{
191+
rb1Index.push_back(mRubberBandIndex1);
192+
mSnappedAtGeometry.vertexAt(x1, y1, rb1Index);
193+
mRubberBand->addPoint(QgsPoint(x1,y1));
194+
mStartPointValid = true;
195+
}
196+
else
197+
{
198+
mStartPointValid = false;
199+
}
200+
if(mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1)
201+
{
202+
mRubberBand->addPoint(toMapCoords(e->pos()));
203+
}
204+
if(mRubberBandIndex2 != -1)
205+
{
206+
rb2Index.push_back(mRubberBandIndex2);
207+
mSnappedAtGeometry.vertexAt(x2, y2, rb2Index);
208+
mRubberBand->addPoint(QgsPoint(x2,y2));
209+
}
197210
#ifdef QGISDEBUG
198211
qWarning("Creating rubber band for moveVertex");
199212
#endif
213+
}
200214
}
201215
else if (mTool == DeleteVertex)
202216
{

src/legend/qgslegend.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
954954
theLayer = new QgsLegendLayer(this, name);
955955
lastGroup = 0;
956956
}
957+
957958
childelem.attribute("open") == "true" ? expandItem(theLayer) : collapseItem(theLayer);
958959

959960
//set the checkbox of the legend layer to the right state

0 commit comments

Comments
 (0)