Commit 2f111432 authored by Mariano Lizarraga's avatar Mariano Lizarraga

Finished scaffolding the graphical addition of WP via the MapWidget. Added the...

Finished scaffolding the graphical addition of WP via the MapWidget. Added the possibility to display the latitude and longitude of the cursor as a property of QMapControl. Major reorganization of the MapWidget constructor
parent 0a242d66
......@@ -27,7 +27,7 @@
namespace qmapcontrol
{
MapControl::MapControl(QSize size, MouseMode mousemode)
: size(size), mymousemode(mousemode), scaleVisible(false)
: size(size), mymousemode(mousemode), scaleVisible(false), cursorPosVisible(false)
{
layermanager = new LayerManager(this, size);
screen_middle = QPoint(size.width()/2, size.height()/2);
......@@ -41,6 +41,9 @@ namespace qmapcontrol
this, SLOT(loadingFinished()));
this->setMaximumSize(size.width()+1, size.height()+1);
distanceList<<5000000<<2000000<<1000000<<1000000<<1000000<<100000<<100000<<50000<<50000<<10000<<10000<<10000<<1000<<1000<<500<<200<<100<<50<<25;
}
MapControl::~MapControl()
......@@ -127,6 +130,8 @@ namespace qmapcontrol
{
QWidget::paintEvent(evnt);
QPainter painter(this);
double line;
// painter.translate(150,190);
// painter.scale(0.5,0.5);
......@@ -150,11 +155,8 @@ namespace qmapcontrol
// draw scale
if (scaleVisible)
{
QList<double> distanceList;
distanceList<<5000000<<2000000<<1000000<<1000000<<1000000<<100000<<100000<<50000<<50000<<10000<<10000<<10000<<1000<<1000<<500<<200<<100<<50<<25;
if (currentZoom() >= 0 && distanceList.size() > currentZoom())
{
double line;
line = distanceList.at( currentZoom() ) / pow(2, 18-currentZoom() ) / 0.597164;
// draw the scale
......@@ -199,12 +201,25 @@ namespace qmapcontrol
//qt = painter.transform();
qm = painter.combinedMatrix();
*/
if (mousepressed && mymousemode == Dragging)
{
QRect rect = QRect(pre_click_px, current_mouse_pos);
painter.drawRect(rect);
}
// Draw the Lat and Lon if needed
if (cursorPosVisible) {
line = distanceList.at( currentZoom() ) / pow(2, 18-currentZoom() ) / 0.597164;
QString str;
str = QString(tr(" Lat: %1")).arg(currentWorldCoordinate.y());
painter.drawText(QPoint((int)line+70,size.height()-15), str);
str = QString(tr(" Lon: %1")).arg(currentWorldCoordinate.x());
painter.drawText(QPoint((int)line+160,size.height()-15), str);
}
emit viewChanged(currentCoordinate(), currentZoom());
}
......@@ -256,7 +271,8 @@ namespace qmapcontrol
void MapControl::mouseMoveEvent(QMouseEvent* evnt)
{
// emit(mouseEvent(evnt));
emit(mouseEvent(evnt));
/*
// rotating
......@@ -275,8 +291,13 @@ namespace qmapcontrol
}
// emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos())));
currentWorldCoordinate = clickToWorldCoordinate(evnt->pos());
emit(mouseMoveCoordinateEvent(currentWorldCoordinate));
update();
// emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos())));
//emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos())));
}
QPointF MapControl::clickToWorldCoordinate(QPoint click)
......@@ -403,6 +424,11 @@ namespace qmapcontrol
scaleVisible = show;
}
void MapControl::showCoord(bool show)
{
cursorPosVisible = show;
}
void MapControl::resize(const QSize newSize)
{
this->size = newSize;
......
......@@ -214,6 +214,14 @@ namespace qmapcontrol
*/
void showScale ( bool show );
//! Displays the Lat and Lon within the widget
/*!
*
* @param show true if Lat and Lon should be displayed
*/
void showCoord ( bool show );
private:
LayerManager* layermanager;
QPoint screen_middle; // middle of the widget (half size)
......@@ -223,9 +231,14 @@ namespace qmapcontrol
QSize size; // size of the widget
QPointF currentWorldCoordinate; // updated by mouseMove
QList<double> distanceList;
bool mousepressed;
MouseMode mymousemode;
bool scaleVisible;
bool cursorPosVisible;
bool m_loadingFlag;
......@@ -244,7 +257,7 @@ namespace qmapcontrol
void mouseMoveEvent ( QMouseEvent* evnt );
signals:
// void mouseEvent(const QMouseEvent* evnt);
void mouseEvent(const QMouseEvent* evnt);
//! Emitted AFTER a MouseEvent occured
/*!
......@@ -256,6 +269,15 @@ namespace qmapcontrol
*/
void mouseEventCoordinate ( const QMouseEvent* evnt, const QPointF coordinate );
//! Emitted on mouse move generating
/*!
* This signals allows to receive the mouse position in the world coordinate.
* It is emitted on mouseMoveEvents.
* setMouseTracking must be set programatically to have this method work.
* @param coordinate the corresponding world coordinate
*/
void mouseMoveCoordinateEvent(const QPointF coordinate);
//! Emitted, after a Rectangular is dragged.
/*!
* It is possible to select a rectangular area in the map, if the MouseMode is set to Dragging.
......
......@@ -44,30 +44,26 @@ MapWidget::MapWidget(QWidget *parent) :
m_ui(new Ui::MapWidget)
{
m_ui->setupUi(this);
// Accept focus by clicking or keyboard
this->setFocusPolicy(Qt::StrongFocus);
// create MapControl
mc = new MapControl(QSize(320, 240));
mc->showScale(true);
mc->showCoord(true);
mc->enablePersistentCache();
//uasIcons = QMap<int, CirclePoint*>();
//QSize(480,640)
// ImageManager::instance()->setProxy("www-cache", 8080);
mc->setMouseTracking(true); // required to update the mouse position for diplay and capture
// create MapAdapter to get maps from
TileMapAdapter* osmAdapter = new TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17);
//GoogleSatMapAdapter* gSatAdapter = new GoogleSatMapAdapter();
// create a layer with the mapadapter and type MapLayer
osmLayer = new Layer("Custom Layer", osmAdapter, Layer::MapLayer);
//Layer* gSatLayer = new Layer("Custom Layer", gSatAdapter, Layer::MapLayer);
// add Layer to the MapControl
mc->addLayer(osmLayer);
//mc->addLayer(gSatLayer);
mc->setZoom(3);
// display the MapControl in the application
QHBoxLayout* layout = new QHBoxLayout;
......@@ -75,40 +71,81 @@ MapWidget::MapWidget(QWidget *parent) :
layout->addWidget(mc);
setLayout(layout);
// create buttons as controls for zoom
// create buttons to control the map (zoom, GPS tracking and WP capture)
QPushButton* zoomin = new QPushButton(QIcon(":/images/actions/list-add.svg"), "", this);
QPushButton* zoomout = new QPushButton(QIcon(":/images/actions/list-remove.svg"), "", this);
createPath = new QPushButton(QIcon(":/images/actions/go-bottom.svg"), "", this);
followgps = new QPushButton(QIcon(":/images/actions/system-lock-screen.svg"), "", this);
followgps->setCheckable(true);
// gpsposition = new QLabel();
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
createPath->setMaximumWidth(50);
followgps->setMaximumWidth(50);
//gpsposition->setFont(QFont("Arial", 10));
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
// add zoom buttons to the layout of the MapControl
// Set checkable buttons
// TODO: Currently checked buttons are are very difficult to distinguish when checked.
// create a style and the slots to change the background so it is easier to distinguish
followgps->setCheckable(true);
createPath->setCheckable(true);
// add buttons to control the map (zoom, GPS tracking and WP capture)
QVBoxLayout* innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
innerlayout->addWidget(followgps);
//innerlayout->addWidget(gpsposition);
innerlayout->addWidget(createPath);
mc->setLayout(innerlayout);
// Connect the required signals-slots
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)),
this, SLOT(addUAS(UASInterface*)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(captureMapClick(const QMouseEvent*, const QPointF)));
connect(createPath, SIGNAL(clicked(bool)),
this, SLOT(createPathButtonClicked()));
this->setVisible(false);
// Attic (Code that was commented)
// ==============================
//uasIcons = QMap<int, CirclePoint*>();
//QSize(480,640)
// ImageManager::instance()->setProxy("www-cache", 8080);
//GoogleSatMapAdapter* gSatAdapter = new GoogleSatMapAdapter();
//Layer* gSatLayer = new Layer("Custom Layer", gSatAdapter, Layer::MapLayer);
//mc->addLayer(gSatLayer);
// gpsposition = new QLabel();
//gpsposition->setFont(QFont("Arial", 10));
//GPS_Neo* gm = new GPS_Neo();
//connect(gm, SIGNAL(new_position(float, QPointF)),
// this, SLOT(updatePosition(float, QPointF)));
//gm->start();
mc->setZoom(3);
}
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*)));
void MapWidget::createPathButtonClicked(){
this->setCursor(createPath->isChecked()? Qt::PointingHandCursor : Qt::ArrowCursor);
}
this->setVisible(false);
void MapWidget::captureMapClick(const QMouseEvent* event, const QPointF coordinate){
if (QEvent::MouseButtonRelease == event->type() && createPath->isChecked()){
qDebug()<< "Click Event";
qDebug()<< "Lat: " << coordinate.y();
qDebug()<< "Lon: " << coordinate.x();
}
}
MapWidget::~MapWidget()
......@@ -180,7 +217,7 @@ void MapWidget::updateGlobalPosition(UASInterface* uas, double lat, double lon,
// points.append(new Point(8.260378, 50.030345, "Wiesbaden-Mainz-Amoneburg, Dyckerhoffstraße"));
// Connect click events of the layer to this object
//connect(osmLayer, SIGNAL(geometryClicked(Geometry*, QPoint)),
// connect(osmLayer, SIGNAL(geometryClicked(Geometry*, QPoint)),
// this, SLOT(geometryClicked(Geometry*, QPoint)));
// Sets the view to the interesting area
......
......@@ -60,8 +60,11 @@ protected:
void keyPressEvent(QKeyEvent *event);
void resizeEvent(QResizeEvent* event);
QPushButton* followgps;
QPushButton* createPath;
QLabel* gpsposition;
MapControl* mc;
int zoomLevel;
int detailZoom; ///< Steps zoomed in further than qMapControl allows
......@@ -70,13 +73,17 @@ protected:
TileMapAdapter* osmAdapter;
GoogleSatMapAdapter* gSatAdapter;
Layer* osmLayer;
Layer* gSatLayer;
//Layer* gSatLayer;
QMap<int, CirclePoint*> uasIcons;
QMap<int, LineString*> uasTrails;
UASInterface* mav;
quint64 lastUpdate;
protected slots:
void captureMapClick (const QMouseEvent* event, const QPointF coordinate);
void createPathButtonClicked();
private:
Ui::MapWidget *m_ui;
};
......
......@@ -10,6 +10,12 @@
<height>300</height>
</rect>
</property>
<property name="cursor">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment