Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
ff026e1f
Unverified
Commit
ff026e1f
authored
Jun 10, 2020
by
Don Gagne
Committed by
GitHub
Jun 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8813 from airmap/vertex_select
QGCMapPolygon select vertexes functionality
parents
55dd50c1
c43a4967
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
133 additions
and
4 deletions
+133
-4
QGCMapPolygon.cc
src/MissionManager/QGCMapPolygon.cc
+24
-0
QGCMapPolygon.h
src/MissionManager/QGCMapPolygon.h
+5
-0
QGCMapPolygonTest.cc
src/MissionManager/QGCMapPolygonTest.cc
+35
-0
QGCMapPolygonTest.h
src/MissionManager/QGCMapPolygonTest.h
+3
-2
QGCMapPolyline.cc
src/MissionManager/QGCMapPolyline.cc
+23
-0
QGCMapPolyline.h
src/MissionManager/QGCMapPolyline.h
+5
-0
QGCMapPolylineTest.cc
src/MissionManager/QGCMapPolylineTest.cc
+35
-0
QGCMapPolylineTest.h
src/MissionManager/QGCMapPolylineTest.h
+3
-2
No files found.
src/MissionManager/QGCMapPolygon.cc
View file @
ff026e1f
...
...
@@ -13,6 +13,7 @@
#include "QGCQGeoCoordinate.h"
#include "QGCApplication.h"
#include "ShapeFileHelper.h"
#include "QGCLoggingCategory.h"
#include <QGeoRectangle>
#include <QDebug>
...
...
@@ -311,6 +312,11 @@ void QGCMapPolygon::removeVertex(int vertexIndex)
QObject
*
coordObj
=
_polygonModel
.
removeAt
(
vertexIndex
);
coordObj
->
deleteLater
();
if
(
vertexIndex
==
_selectedVertexIndex
)
{
selectVertex
(
-
1
);
}
else
if
(
vertexIndex
<
_selectedVertexIndex
)
{
selectVertex
(
_selectedVertexIndex
-
1
);
}
// else do nothing - keep current selected vertex
_polygonPath
.
removeAt
(
vertexIndex
);
emit
pathChanged
();
...
...
@@ -627,3 +633,21 @@ void QGCMapPolygon::setShowAltColor(bool showAltColor){
emit
showAltColorChanged
(
showAltColor
);
}
}
void
QGCMapPolygon
::
selectVertex
(
int
index
)
{
if
(
index
==
_selectedVertexIndex
)
return
;
// do nothing
if
(
-
1
<=
index
&&
index
<
count
())
{
_selectedVertexIndex
=
index
;
}
else
{
if
(
!
qgcApp
()
->
runningUnitTests
())
{
qCWarning
(
ParameterManagerLog
)
<<
QString
(
"QGCMapPolygon: Selected vertex index (%1) is out of bounds! "
"Polygon vertices indexes range is [%2..%3]."
).
arg
(
index
).
arg
(
0
).
arg
(
count
()
-
1
);
}
_selectedVertexIndex
=
-
1
;
// deselect vertex
}
emit
selectedVertexChanged
(
_selectedVertexIndex
);
}
src/MissionManager/QGCMapPolygon.h
View file @
ff026e1f
...
...
@@ -42,6 +42,7 @@ public:
Q_PROPERTY
(
bool
empty
READ
empty
NOTIFY
isEmptyChanged
)
Q_PROPERTY
(
bool
traceMode
READ
traceMode
WRITE
setTraceMode
NOTIFY
traceModeChanged
)
Q_PROPERTY
(
bool
showAltColor
READ
showAltColor
WRITE
setShowAltColor
NOTIFY
showAltColorChanged
)
Q_PROPERTY
(
int
selectedVertex
READ
selectedVertex
WRITE
selectVertex
NOTIFY
selectedVertexChanged
)
Q_INVOKABLE
void
clear
(
void
);
Q_INVOKABLE
void
appendVertex
(
const
QGeoCoordinate
&
coordinate
);
...
...
@@ -111,6 +112,7 @@ public:
bool
empty
(
void
)
const
{
return
_polygonModel
.
count
()
==
0
;
}
bool
traceMode
(
void
)
const
{
return
_traceMode
;
}
bool
showAltColor
(
void
)
const
{
return
_showAltColor
;
}
int
selectedVertex
()
const
{
return
_selectedVertexIndex
;
}
QVariantList
path
(
void
)
const
{
return
_polygonPath
;
}
QmlObjectListModel
*
qmlPathModel
(
void
)
{
return
&
_polygonModel
;
}
...
...
@@ -123,6 +125,7 @@ public:
void
setInteractive
(
bool
interactive
);
void
setTraceMode
(
bool
traceMode
);
void
setShowAltColor
(
bool
showAltColor
);
void
selectVertex
(
int
index
);
static
const
char
*
jsonPolygonKey
;
...
...
@@ -138,6 +141,7 @@ signals:
bool
isEmptyChanged
(
void
);
void
traceModeChanged
(
bool
traceMode
);
void
showAltColorChanged
(
bool
showAltColor
);
void
selectedVertexChanged
(
int
index
);
private
slots
:
void
_polygonModelCountChanged
(
int
count
);
...
...
@@ -162,6 +166,7 @@ private:
bool
_resetActive
=
false
;
bool
_traceMode
=
false
;
bool
_showAltColor
=
false
;
int
_selectedVertexIndex
=
-
1
;
};
#endif
src/MissionManager/QGCMapPolygonTest.cc
View file @
ff026e1f
...
...
@@ -219,3 +219,38 @@ void QGCMapPolygonTest::_testKMLLoad(void)
QVERIFY
(
!
_mapPolygon
->
loadKMLOrSHPFile
(
QStringLiteral
(
":/unittest/PolygonBadCoordinatesNode.kml"
)));
checkExpectedMessageBox
();
}
void
QGCMapPolygonTest
::
_testSelectVertex
(
void
)
{
// Create polygon
foreach
(
auto
vertex
,
_polyPoints
)
{
_mapPolygon
->
appendVertex
(
vertex
);
}
QVERIFY
(
_mapPolygon
->
selectedVertex
()
==
-
1
);
QVERIFY
(
_mapPolygon
->
count
()
==
_polyPoints
.
count
());
// Test deselect
_mapPolygon
->
selectVertex
(
-
1
);
QVERIFY
(
_mapPolygon
->
selectedVertex
()
==
-
1
);
// Test out of bounds
_mapPolygon
->
selectVertex
(
_polyPoints
.
count
());
QVERIFY
(
_mapPolygon
->
selectedVertex
()
==
-
1
);
// Simple select test
_mapPolygon
->
selectVertex
(
_polyPoints
.
count
()
-
1
);
QVERIFY
(
_mapPolygon
->
selectedVertex
()
==
_polyPoints
.
count
()
-
1
);
// Keep selected test
_mapPolygon
->
selectVertex
(
0
);
_mapPolygon
->
removeVertex
(
_polyPoints
.
count
()
-
1
);
QVERIFY
(
_mapPolygon
->
selectedVertex
()
==
0
);
// Deselect if selected vertex removed
_mapPolygon
->
appendVertex
(
_polyPoints
[
_polyPoints
.
count
()
-
1
]);
_mapPolygon
->
selectVertex
(
_polyPoints
.
count
()
-
1
);
_mapPolygon
->
removeVertex
(
_polyPoints
.
count
()
-
1
);
QVERIFY
(
_mapPolygon
->
selectedVertex
()
==
-
1
);
// Shift selected index down if removed index < selected index
_mapPolygon
->
appendVertex
(
_polyPoints
[
_polyPoints
.
count
()
-
1
]);
_mapPolygon
->
selectVertex
(
_polyPoints
.
count
()
-
1
);
_mapPolygon
->
removeVertex
(
0
);
QVERIFY
(
_mapPolygon
->
selectedVertex
()
==
_mapPolygon
->
count
()
-
1
);
}
src/MissionManager/QGCMapPolygonTest.h
View file @
ff026e1f
...
...
@@ -17,18 +17,19 @@
class
QGCMapPolygonTest
:
public
UnitTest
{
Q_OBJECT
public:
QGCMapPolygonTest
(
void
);
protected:
void
init
(
void
)
final
;
void
cleanup
(
void
)
final
;
private
slots
:
void
_testDirty
(
void
);
void
_testVertexManipulation
(
void
);
void
_testKMLLoad
(
void
);
void
_testSelectVertex
(
void
);
private:
enum
{
...
...
src/MissionManager/QGCMapPolyline.cc
View file @
ff026e1f
...
...
@@ -243,6 +243,11 @@ void QGCMapPolyline::removeVertex(int vertexIndex)
QObject
*
coordObj
=
_polylineModel
.
removeAt
(
vertexIndex
);
coordObj
->
deleteLater
();
if
(
vertexIndex
==
_selectedVertexIndex
)
{
selectVertex
(
-
1
);
}
else
if
(
vertexIndex
<
_selectedVertexIndex
)
{
selectVertex
(
_selectedVertexIndex
-
1
);
}
// else do nothing - keep current selected vertex
_polylinePath
.
removeAt
(
vertexIndex
);
emit
pathChanged
();
...
...
@@ -444,3 +449,21 @@ void QGCMapPolyline::setTraceMode(bool traceMode)
emit
traceModeChanged
(
traceMode
);
}
}
void
QGCMapPolyline
::
selectVertex
(
int
index
)
{
if
(
index
==
_selectedVertexIndex
)
return
;
// do nothing
if
(
-
1
<=
index
&&
index
<
count
())
{
_selectedVertexIndex
=
index
;
}
else
{
if
(
!
qgcApp
()
->
runningUnitTests
())
{
qCWarning
(
ParameterManagerLog
)
<<
QString
(
"QGCMapPolyline: Selected vertex index (%1) is out of bounds! "
"Polyline vertices indexes range is [%2..%3]."
).
arg
(
index
).
arg
(
0
).
arg
(
count
()
-
1
);
}
_selectedVertexIndex
=
-
1
;
// deselect vertex
}
emit
selectedVertexChanged
(
_selectedVertexIndex
);
}
src/MissionManager/QGCMapPolyline.h
View file @
ff026e1f
...
...
@@ -33,6 +33,7 @@ public:
Q_PROPERTY
(
bool
isValid
READ
isValid
NOTIFY
isValidChanged
)
Q_PROPERTY
(
bool
empty
READ
empty
NOTIFY
isEmptyChanged
)
Q_PROPERTY
(
bool
traceMode
READ
traceMode
WRITE
setTraceMode
NOTIFY
traceModeChanged
)
Q_PROPERTY
(
int
selectedVertex
READ
selectedVertex
WRITE
selectVertex
NOTIFY
selectedVertexChanged
)
Q_INVOKABLE
void
clear
(
void
);
Q_INVOKABLE
void
appendVertex
(
const
QGeoCoordinate
&
coordinate
);
...
...
@@ -90,6 +91,7 @@ public:
bool
isValid
(
void
)
const
{
return
_polylineModel
.
count
()
>=
2
;
}
bool
empty
(
void
)
const
{
return
_polylineModel
.
count
()
==
0
;
}
bool
traceMode
(
void
)
const
{
return
_traceMode
;
}
int
selectedVertex
()
const
{
return
_selectedVertexIndex
;
}
QmlObjectListModel
*
qmlPathModel
(
void
)
{
return
&
_polylineModel
;
}
QmlObjectListModel
&
pathModel
(
void
)
{
return
_polylineModel
;
}
...
...
@@ -98,6 +100,7 @@ public:
void
setPath
(
const
QVariantList
&
path
);
void
setInteractive
(
bool
interactive
);
void
setTraceMode
(
bool
traceMode
);
void
selectVertex
(
int
index
);
static
const
char
*
jsonPolylineKey
;
...
...
@@ -110,6 +113,7 @@ signals:
void
isValidChanged
(
void
);
void
isEmptyChanged
(
void
);
void
traceModeChanged
(
bool
traceMode
);
void
selectedVertexChanged
(
int
index
);
private
slots
:
void
_polylineModelCountChanged
(
int
count
);
...
...
@@ -128,4 +132,5 @@ private:
bool
_interactive
;
bool
_resetActive
;
bool
_traceMode
=
false
;
int
_selectedVertexIndex
=
-
1
;
};
src/MissionManager/QGCMapPolylineTest.cc
View file @
ff026e1f
...
...
@@ -200,3 +200,38 @@ void QGCMapPolylineTest::_testKMLLoad(void)
checkExpectedMessageBox();
}
#endif
void
QGCMapPolylineTest
::
_testSelectVertex
(
void
)
{
// Create polyline
foreach
(
auto
vertex
,
_linePoints
)
{
_mapPolyline
->
appendVertex
(
vertex
);
}
QVERIFY
(
_mapPolyline
->
selectedVertex
()
==
-
1
);
QVERIFY
(
_mapPolyline
->
count
()
==
_linePoints
.
count
());
// Test deselect
_mapPolyline
->
selectVertex
(
-
1
);
QVERIFY
(
_mapPolyline
->
selectedVertex
()
==
-
1
);
// Test out of bounds
_mapPolyline
->
selectVertex
(
_linePoints
.
count
());
QVERIFY
(
_mapPolyline
->
selectedVertex
()
==
-
1
);
// Simple select test
_mapPolyline
->
selectVertex
(
_linePoints
.
count
()
-
1
);
QVERIFY
(
_mapPolyline
->
selectedVertex
()
==
_linePoints
.
count
()
-
1
);
// Keep selected test
_mapPolyline
->
selectVertex
(
0
);
_mapPolyline
->
removeVertex
(
_linePoints
.
count
()
-
1
);
QVERIFY
(
_mapPolyline
->
selectedVertex
()
==
0
);
// Deselect if selected vertex removed
_mapPolyline
->
appendVertex
(
_linePoints
[
_linePoints
.
count
()
-
1
]);
_mapPolyline
->
selectVertex
(
_linePoints
.
count
()
-
1
);
_mapPolyline
->
removeVertex
(
_linePoints
.
count
()
-
1
);
QVERIFY
(
_mapPolyline
->
selectedVertex
()
==
-
1
);
// Shift selected index down if removed index < selected index
_mapPolyline
->
appendVertex
(
_linePoints
[
_linePoints
.
count
()
-
1
]);
_mapPolyline
->
selectVertex
(
_linePoints
.
count
()
-
1
);
_mapPolyline
->
removeVertex
(
0
);
QVERIFY
(
_mapPolyline
->
selectedVertex
()
==
_mapPolyline
->
count
()
-
1
);
}
src/MissionManager/QGCMapPolylineTest.h
View file @
ff026e1f
...
...
@@ -17,18 +17,19 @@
class
QGCMapPolylineTest
:
public
UnitTest
{
Q_OBJECT
public:
QGCMapPolylineTest
(
void
);
protected:
void
init
(
void
)
final
;
void
cleanup
(
void
)
final
;
private
slots
:
void
_testDirty
(
void
);
void
_testVertexManipulation
(
void
);
// void _testKMLLoad(void);
void
_testSelectVertex
(
void
);
private:
enum
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment