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
b95fd4cb
Commit
b95fd4cb
authored
Aug 26, 2010
by
Mariano Lizarraga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dragging of waypoints now working in the map control
parent
42386f6f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
32 deletions
+109
-32
layer.cpp
lib/QMapControl/src/layer.cpp
+31
-14
layer.h
lib/QMapControl/src/layer.h
+23
-0
mapcontrol.cpp
lib/QMapControl/src/mapcontrol.cpp
+2
-0
MapWidget.cc
src/ui/MapWidget.cc
+47
-17
MapWidget.h
src/ui/MapWidget.h
+6
-1
No files found.
lib/QMapControl/src/layer.cpp
View file @
b95fd4cb
...
...
@@ -110,28 +110,45 @@ namespace qmapcontrol
}
void
Layer
::
mouseEvent
(
const
QMouseEvent
*
evnt
,
const
QPoint
mapmiddle_px
)
{
if
(
takesMouseEvents
())
{
if
(
evnt
->
button
()
==
Qt
::
LeftButton
&&
evnt
->
type
()
==
QEvent
::
MouseButtonPress
)
if
(
takesMouseEvents
()
)
{
// check for collision
QPointF
c
=
mapAdapter
->
displayToCoordinate
(
QPoint
(
evnt
->
x
()
-
screenmiddle
.
x
()
+
mapmiddle_px
.
x
(),
evnt
->
y
()
-
screenmiddle
.
y
()
+
mapmiddle_px
.
y
()));
Point
*
tmppoint
=
new
Point
(
c
.
x
(),
c
.
y
());
for
(
int
i
=
0
;
i
<
geometries
.
count
();
i
++
)
if
(
evnt
->
button
()
==
Qt
::
LeftButton
&&
evnt
->
type
()
==
QEvent
::
MouseButtonPress
)
{
if
(
geometries
.
at
(
i
)
->
isVisible
()
&&
geometries
.
at
(
i
)
->
Touches
(
tmppoint
,
mapAdapter
))
//if (geometries.at(i)->Touches(c, mapAdapter))
// check for collision
QPointF
c
=
mapAdapter
->
displayToCoordinate
(
QPoint
(
evnt
->
x
()
-
screenmiddle
.
x
()
+
mapmiddle_px
.
x
(),
evnt
->
y
()
-
screenmiddle
.
y
()
+
mapmiddle_px
.
y
()));
Point
*
tmppoint
=
new
Point
(
c
.
x
(),
c
.
y
());
for
(
int
i
=
0
;
i
<
geometries
.
count
();
i
++
)
{
emit
(
geometryClicked
(
geometries
.
at
(
i
),
QPoint
(
evnt
->
x
(),
evnt
->
y
())));
if
(
geometries
.
at
(
i
)
->
isVisible
()
&&
geometries
.
at
(
i
)
->
Touches
(
tmppoint
,
mapAdapter
))
//if (geometries.at(i)->Touches(c, mapAdapter))
{
emit
(
geometryClicked
(
geometries
.
at
(
i
),
QPoint
(
evnt
->
x
(),
evnt
->
y
())));
draggingGeometry
=
true
;
geometrySelected
=
geometries
.
at
(
i
);
}
}
delete
tmppoint
;
}
if
(
evnt
->
type
()
==
QEvent
::
MouseButtonRelease
){
QPointF
c
=
mapAdapter
->
displayToCoordinate
(
QPoint
(
evnt
->
x
()
-
screenmiddle
.
x
()
+
mapmiddle_px
.
x
(),
evnt
->
y
()
-
screenmiddle
.
y
()
+
mapmiddle_px
.
y
()));
draggingGeometry
=
false
;
emit
(
geometryEndDrag
(
geometrySelected
,
c
));
geometrySelected
=
0
;
}
if
(
evnt
->
type
()
==
QEvent
::
MouseMove
&&
draggingGeometry
){
QPointF
c
=
mapAdapter
->
displayToCoordinate
(
QPoint
(
evnt
->
x
()
-
screenmiddle
.
x
()
+
mapmiddle_px
.
x
(),
evnt
->
y
()
-
screenmiddle
.
y
()
+
mapmiddle_px
.
y
()));
emit
(
geometryDragged
(
geometrySelected
,
c
));
}
delete
tmppoint
;
}
}
}
bool
Layer
::
takesMouseEvents
()
const
{
...
...
lib/QMapControl/src/layer.h
View file @
b95fd4cb
...
...
@@ -63,6 +63,7 @@ namespace qmapcontrol
public:
friend
class
LayerManager
;
//! sets the type of a layer, see Layer class doc for further information
enum
LayerType
{
...
...
@@ -157,6 +158,9 @@ namespace qmapcontrol
bool
takeevents
;
mutable
QRect
myoffscreenViewport
;
Geometry
*
geometrySelected
;
bool
draggingGeometry
;
signals:
//! This signal is emitted when a Geometry is clicked
/*!
...
...
@@ -167,6 +171,25 @@ namespace qmapcontrol
*/
void
geometryClicked
(
Geometry
*
geometry
,
QPoint
point
);
//! This signal is emitted while a Geometry is being dragged
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The layer emits a signal as it is dragged
* @param geometry The selected Geometry
* @param coordinate The new coordinate (in world coordinates)
*/
void
geometryDragged
(
Geometry
*
geometrySelected
,
QPointF
coordinate
);
//! This signal is emitted when a User releases the button after selecting a Geometry
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The layer emits a signal when it is released
* @param geometry The selected Geometry
* @param coordinate The new coordinate (in world coordinates)
*/
void
geometryEndDrag
(
Geometry
*
geometrySelected
,
QPointF
coordinate
);
void
updateRequest
(
QRectF
rect
);
void
updateRequest
();
...
...
lib/QMapControl/src/mapcontrol.cpp
View file @
b95fd4cb
...
...
@@ -255,6 +255,7 @@ namespace qmapcontrol
void
MapControl
::
mouseReleaseEvent
(
QMouseEvent
*
evnt
)
{
layermanager
->
mouseEvent
(
evnt
);
mousepressed
=
false
;
if
(
mymousemode
==
Dragging
)
{
...
...
@@ -271,6 +272,7 @@ namespace qmapcontrol
void
MapControl
::
mouseMoveEvent
(
QMouseEvent
*
evnt
)
{
layermanager
->
mouseEvent
(
evnt
);
emit
(
mouseEvent
(
evnt
));
...
...
src/ui/MapWidget.cc
View file @
b95fd4cb
...
...
@@ -190,11 +190,16 @@ MapWidget::MapWidget(QWidget *parent) :
this
,
SLOT
(
captureMapClick
(
const
QMouseEvent
*
,
const
QPointF
)));
connect
(
createPath
,
SIGNAL
(
clicked
(
bool
)),
this
,
SLOT
(
createPathButtonClicked
()));
this
,
SLOT
(
createPathButtonClicked
(
bool
)));
connect
(
geomLayer
,
SIGNAL
(
geometryClicked
(
Geometry
*
,
QPoint
)),
this
,
SLOT
(
captureGeometryClick
(
Geometry
*
,
QPoint
)));
connect
(
geomLayer
,
SIGNAL
(
geometryDragged
(
Geometry
*
,
QPointF
)),
this
,
SLOT
(
captureGeometryDrag
(
Geometry
*
,
QPointF
)));
connect
(
geomLayer
,
SIGNAL
(
geometryEndDrag
(
Geometry
*
,
QPointF
)),
this
,
SLOT
(
captureGeometryEndDrag
(
Geometry
*
,
QPointF
)));
// Configure the WP Path's pen
pointPen
=
new
QPen
(
QColor
(
0
,
255
,
0
));
...
...
@@ -290,12 +295,15 @@ void MapWidget::mapproviderSelected(QAction* action)
}
void
MapWidget
::
createPathButtonClicked
()
void
MapWidget
::
createPathButtonClicked
(
bool
checked
)
{
Q_UNUSED
(
checked
);
if
(
createPath
->
isChecked
())
{
// change the cursor shape
this
->
setCursor
(
Qt
::
PointingHandCursor
);
mc
->
setMouseMode
(
qmapcontrol
::
MapControl
::
None
);
// Clear the previous WP track
// TODO: Move this to an actual clear track button and add a warning dialog
...
...
@@ -303,8 +311,12 @@ void MapWidget::createPathButtonClicked()
wps
.
clear
();
path
->
setPoints
(
wps
);
mc
->
layer
(
"Waypoints"
)
->
addGeometry
(
path
);
wpIndex
.
clear
();
}
else
{
this
->
setCursor
(
Qt
::
ArrowCursor
);
mc
->
setMouseMode
(
qmapcontrol
::
MapControl
::
Panning
);
}
}
...
...
@@ -313,37 +325,55 @@ void MapWidget::createPathButtonClicked()
void
MapWidget
::
captureMapClick
(
const
QMouseEvent
*
event
,
const
QPointF
coordinate
){
if
(
QEvent
::
MouseButtonRelease
==
event
->
type
()
&&
createPath
->
isChecked
()){
// Create waypoint name
QString
str
;
str
=
QString
(
"WP%1"
).
arg
(
path
->
numberOfPoints
()
+
1
);
qDebug
()
<<
"Waypoint "
<<
str
;
qDebug
()
<<
"Lat: "
<<
coordinate
.
y
();
qDebug
()
<<
"Lon: "
<<
coordinate
.
x
();
str
=
QString
(
"WP%1"
).
arg
(
path
->
numberOfPoints
());
// create the WP and set everything in the LineString to display the path
mc
->
layer
(
"Waypoints"
)
->
addGeometry
(
new
CirclePoint
(
coordinate
.
x
(),
coordinate
.
y
(),
10
,
str
));
wps
.
append
(
new
Point
(
coordinate
.
x
(),
coordinate
.
y
(),
str
));
path
->
addPoint
(
new
Point
(
coordinate
.
x
(),
coordinate
.
y
(),
str
));
CirclePoint
*
tempCirclePoint
=
new
CirclePoint
(
coordinate
.
x
(),
coordinate
.
y
(),
10
,
str
);
mc
->
layer
(
"Waypoints"
)
->
addGeometry
(
tempCirclePoint
);
Point
*
tempPoint
=
new
Point
(
coordinate
.
x
(),
coordinate
.
y
(),
str
);
wps
.
append
(
tempPoint
);
path
->
addPoint
(
tempPoint
);
wpIndex
.
insert
(
str
,
tempPoint
);
// Refresh the screen
mc
->
updateRequestNew
();
}
}
void
MapWidget
::
captureGeometryClick
(
Geometry
*
geom
,
QPoint
point
){
Q_UNUSED
(
geom
);
Q_UNUSED
(
point
);
mc
->
setMouseMode
(
qmapcontrol
::
MapControl
::
None
);
qDebug
()
<<
geom
->
name
();
qDebug
()
<<
geom
->
GeometryType
;
qDebug
()
<<
point
;
}
void
MapWidget
::
captureGeometryDrag
(
Geometry
*
geom
,
QPointF
coordinate
){
Q_UNUSED
(
coordinate
);
Point
*
point2Find
;
point2Find
=
wpIndex
[
geom
->
name
()];
point2Find
->
setCoordinate
(
coordinate
);
point2Find
=
dynamic_cast
<
Point
*>
(
geom
);
point2Find
->
setCoordinate
(
coordinate
);
// Refresh the screen
mc
->
updateRequestNew
();
}
void
MapWidget
::
captureGeometryEndDrag
(
Geometry
*
geom
,
QPointF
coordinate
){
mc
->
setMouseMode
(
qmapcontrol
::
MapControl
::
Panning
);
qDebug
()
<<
geom
->
name
();
qDebug
()
<<
geom
->
GeometryType
;
qDebug
()
<<
coordinate
;
//
qDebug() << geom->name();
//
qDebug() << geom->GeometryType;
// qDebug() << point
;
}
MapWidget
::~
MapWidget
()
...
...
src/ui/MapWidget.h
View file @
b95fd4cb
...
...
@@ -102,14 +102,19 @@ protected:
protected
slots
:
void
captureMapClick
(
const
QMouseEvent
*
event
,
const
QPointF
coordinate
);
void
createPathButtonClicked
();
void
createPathButtonClicked
(
bool
checked
);
void
captureGeometryClick
(
Geometry
*
,
QPoint
);
void
mapproviderSelected
(
QAction
*
action
);
void
captureGeometryDrag
(
Geometry
*
geom
,
QPointF
coordinate
);
void
captureGeometryEndDrag
(
Geometry
*
geom
,
QPointF
coordinate
);
signals:
void
movePoint
(
QPointF
newCoord
);
private:
Ui
::
MapWidget
*
m_ui
;
QList
<
Point
*>
wps
;
QHash
<
QString
,
Point
*>
wpIndex
;
LineString
*
path
;
QPen
*
pointPen
;
};
...
...
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