summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Wilson <alex.wilson@nokia.com>2011-12-16 13:50:35 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-16 06:47:44 +0100
commit968a6a1dc0b7551ee73322e87566f3aad1a9710d (patch)
treefefe98873293ae178e523f783142d1a1509377de
parent4f770dc2728f04faeb1e8204057f79ad4fd24e73 (diff)
downloadqtlocation-968a6a1dc0b7551ee73322e87566f3aad1a9710d.tar.gz
Line borders for MapPolygons and MapCircles
Change-Id: Ica4fe8a5ecca4293a841d4c25161a8921f5757ec Reviewed-by: David Laing <david.laing@nokia.com>
-rw-r--r--examples/declarative/mapviewer/content/map/CircleItem.qml4
-rw-r--r--examples/declarative/mapviewer/content/map/PolygonItem.qml4
-rw-r--r--examples/declarative/mapviewer/content/map/PolylineItem.qml5
-rw-r--r--src/imports/location/qdeclarativecirclemapitem.cpp54
-rw-r--r--src/imports/location/qdeclarativecirclemapitem_p.h12
-rw-r--r--src/imports/location/qdeclarativepolygonmapitem.cpp48
-rw-r--r--src/imports/location/qdeclarativepolygonmapitem_p.h11
7 files changed, 126 insertions, 12 deletions
diff --git a/examples/declarative/mapviewer/content/map/CircleItem.qml b/examples/declarative/mapviewer/content/map/CircleItem.qml
index c69bc2ef..f1a46ae4 100644
--- a/examples/declarative/mapviewer/content/map/CircleItem.qml
+++ b/examples/declarative/mapviewer/content/map/CircleItem.qml
@@ -45,6 +45,10 @@ import QtLocation 5.0
MapCircle {
color: "yellow"
+ border.color: "red"
+ border.width: 5
+ smooth: true
+ opacity: 0.8
function setGeometry(markers){
var count = markers.length
diff --git a/examples/declarative/mapviewer/content/map/PolygonItem.qml b/examples/declarative/mapviewer/content/map/PolygonItem.qml
index 927bf337..ee50421d 100644
--- a/examples/declarative/mapviewer/content/map/PolygonItem.qml
+++ b/examples/declarative/mapviewer/content/map/PolygonItem.qml
@@ -45,6 +45,10 @@ import QtLocation 5.0
MapPolygon {
color: "green"
+ border.color: "darkgreen"
+ border.width: 4
+ smooth: true
+ opacity: 0.8
function setGeometry(markers){
var count = markers.length
diff --git a/examples/declarative/mapviewer/content/map/PolylineItem.qml b/examples/declarative/mapviewer/content/map/PolylineItem.qml
index b0181887..a3ea72f4 100644
--- a/examples/declarative/mapviewer/content/map/PolylineItem.qml
+++ b/examples/declarative/mapviewer/content/map/PolylineItem.qml
@@ -43,7 +43,10 @@ import QtLocation 5.0
//TODO: remove/refactor me when items are integrated
MapPolyline {
- color: "blue"
+ line.color: "blue"
+ line.width: 4
+ opacity: 0.7
+ smooth: true
function setGeometry(markers){
var count = markers.length
diff --git a/src/imports/location/qdeclarativecirclemapitem.cpp b/src/imports/location/qdeclarativecirclemapitem.cpp
index a2e2a026..b921e459 100644
--- a/src/imports/location/qdeclarativecirclemapitem.cpp
+++ b/src/imports/location/qdeclarativecirclemapitem.cpp
@@ -167,16 +167,32 @@ QDeclarativeCircleMapItem::QDeclarativeCircleMapItem(QQuickItem *parent):
{
setFlag(ItemHasContents, true);
+ QObject::connect(&border_, SIGNAL(colorChanged(QColor)),
+ this, SLOT(handleBorderUpdated()));
+ QObject::connect(&border_, SIGNAL(widthChanged(qreal)),
+ this, SLOT(handleBorderUpdated()));
}
QDeclarativeCircleMapItem::~QDeclarativeCircleMapItem()
{
}
+QDeclarativeMapLineProperties *QDeclarativeCircleMapItem::border()
+{
+ return &border_;
+}
+
+void QDeclarativeCircleMapItem::handleBorderUpdated()
+{
+ updateMapItem(true);
+}
+
void QDeclarativeCircleMapItem::setMap(QDeclarativeGeoMap* quickMap, Map *map)
{
- QDeclarativeGeoMapItemBase::setMap(quickMap,map);
- if (map) QObject::connect(map, SIGNAL(cameraDataChanged(CameraData)), this, SLOT(handleCameraDataChanged(CameraData)));
+ QDeclarativeGeoMapItemBase::setMap(quickMap, map);
+ if (map)
+ QObject::connect(map, SIGNAL(cameraDataChanged(CameraData)),
+ this, SLOT(handleCameraDataChanged(CameraData)));
}
void QDeclarativeCircleMapItem::setCenter(QDeclarativeCoordinate *center)
@@ -257,8 +273,11 @@ void QDeclarativeCircleMapItem::updateMapItem(bool dirtyGeometry)
return;
mapCircleNode_->setBrushColor(color_);
+ mapCircleNode_->setPenColor(border_.color());
+ mapCircleNode_->setLineWidth(border_.width());
- if (dirtyGeometry) mapCircleNode_->setGeometry(*map(), radius(),center()->coordinate());
+ if (dirtyGeometry)
+ mapCircleNode_->setGeometry(*map(), radius(),center()->coordinate());
const QSizeF& size = mapCircleNode_->size();
@@ -267,7 +286,6 @@ void QDeclarativeCircleMapItem::updateMapItem(bool dirtyGeometry)
setPositionOnMap(center()->coordinate(), QPointF(size.width(),size.height()) / 2);
update();
-
}
void QDeclarativeCircleMapItem::handleCameraDataChanged(const CameraData& cameraData)
@@ -310,11 +328,15 @@ bool QDeclarativeCircleMapItem::contains(QPointF point)
MapCircleNode::MapCircleNode():
fillColor_(Qt::black),
borderColor_(Qt::black),
+ borderWidth_(3),
+ border_(new MapPolylineNode()),
geometry_(QSGGeometry::defaultAttributes_Point2D(),0)
{
geometry_.setDrawingMode(GL_TRIANGLE_FAN);
QSGGeometryNode::setMaterial(&fill_material_);
QSGGeometryNode::setGeometry(&geometry_);
+
+ appendChildNode(border_);
}
MapCircleNode::~MapCircleNode() {}
@@ -353,7 +375,12 @@ void MapCircleNode::update()
setMaterial(&fill_material_);
}
- //TODO: implement me : borders , gradient
+ border_->setPenColor(borderColor_);
+ border_->setLineWidth(borderWidth_);
+
+ border_->update();
+
+ //TODO: implement me : gradient
}
void MapCircleNode::setBrushColor(const QColor &color)
@@ -376,13 +403,22 @@ QColor MapCircleNode::penColor() const
return borderColor_;
}
+qreal MapCircleNode::lineWidth() const
+{
+ return borderWidth_;
+}
+
+void MapCircleNode::setLineWidth(qreal width)
+{
+ borderWidth_ = width;
+}
+
bool MapCircleNode::contains(QPointF point)
{
return polygon_.containsPoint(point, Qt::OddEvenFill);
}
-
-void MapCircleNode::setGeometry(const Map& map, qreal radius,const QGeoCoordinate &center)
+void MapCircleNode::setGeometry(const Map& map, qreal radius, const QGeoCoordinate &center)
{
path_.clear();
calcualtePeripheralPoints(path_, center, radius, 125);
@@ -393,6 +429,10 @@ void MapCircleNode::setGeometry(const Map& map, qreal radius,const QGeoCoordinat
polygon_.clear();
updatePolygon(polygon_, map, path_, w, h);
size_ = QSizeF(w, h);
+
+ QList<QGeoCoordinate> pathClosed = path_;
+ pathClosed.append(pathClosed.at(0));
+ border_->setGeometry(map, pathClosed);
}
QT_END_NAMESPACE
diff --git a/src/imports/location/qdeclarativecirclemapitem_p.h b/src/imports/location/qdeclarativecirclemapitem_p.h
index 886c9fa0..38efe7dd 100644
--- a/src/imports/location/qdeclarativecirclemapitem_p.h
+++ b/src/imports/location/qdeclarativecirclemapitem_p.h
@@ -43,6 +43,7 @@
#define QDECLARATIVECIRCLEMAPITEM_H
#include "qdeclarativegeomapitembase_p.h"
+#include "qdeclarativepolylinemapitem_p.h"
#include <QSGGeometryNode>
#include <QSGFlatColorMaterial>
@@ -57,6 +58,7 @@ class QDeclarativeCircleMapItem : public QDeclarativeGeoMapItemBase
Q_PROPERTY(QDeclarativeCoordinate* center READ center WRITE setCenter NOTIFY centerChanged)
Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ Q_PROPERTY(QDeclarativeMapLineProperties *border READ border)
public:
QDeclarativeCircleMapItem(QQuickItem *parent = 0);
@@ -75,6 +77,7 @@ public:
QColor color() const;
void setColor(const QColor &color);
+ QDeclarativeMapLineProperties *border();
void dragStarted();
void dragEnded();
@@ -87,6 +90,7 @@ Q_SIGNALS:
protected Q_SLOTS:
virtual void updateMapItem(bool dirtyGeomoetry=true);
+ void handleBorderUpdated();
private Q_SLOTS:
void handleCameraDataChanged(const CameraData& cameraData);
@@ -95,6 +99,7 @@ private:
//TODO: pimpl
QDeclarativeCoordinate internalCoordinate_;
QDeclarativeCoordinate *center_;
+ QDeclarativeMapLineProperties border_;
MapCircleNode *mapCircleNode_;
QColor color_;
qreal radius_;
@@ -116,6 +121,9 @@ public:
return size_;
}
+ void setLineWidth(qreal width);
+ qreal lineWidth() const;
+
QColor penColor() const;
void setPenColor(const QColor &pen);
@@ -124,13 +132,15 @@ public:
void update();
bool contains(QPointF point);
- void setGeometry(const Map &map, qreal radius,const QGeoCoordinate &center);
+ void setGeometry(const Map &map, qreal radius, const QGeoCoordinate &center);
private:
QSGFlatColorMaterial fill_material_;
//QSGFlatColorMaterial border_material_;
QColor fillColor_;
QColor borderColor_;
+ qreal borderWidth_;
+ MapPolylineNode *border_;
//keeps pixel geometry
QSGGeometry geometry_;
//keeps geographic geometry
diff --git a/src/imports/location/qdeclarativepolygonmapitem.cpp b/src/imports/location/qdeclarativepolygonmapitem.cpp
index 2591eb22..2ac68962 100644
--- a/src/imports/location/qdeclarativepolygonmapitem.cpp
+++ b/src/imports/location/qdeclarativepolygonmapitem.cpp
@@ -89,16 +89,32 @@ QDeclarativePolygonMapItem::QDeclarativePolygonMapItem(QQuickItem *parent) :
zoomLevel_(0.0)
{
setFlag(ItemHasContents, true);
+ QObject::connect(&border_, SIGNAL(colorChanged(QColor)),
+ this, SLOT(handleBorderUpdated()));
+ QObject::connect(&border_, SIGNAL(widthChanged(qreal)),
+ this, SLOT(handleBorderUpdated()));
+}
+
+void QDeclarativePolygonMapItem::handleBorderUpdated()
+{
+ updateMapItem(true);
}
QDeclarativePolygonMapItem::~QDeclarativePolygonMapItem()
{
}
+QDeclarativeMapLineProperties *QDeclarativePolygonMapItem::border()
+{
+ return &border_;
+}
+
void QDeclarativePolygonMapItem::setMap(QDeclarativeGeoMap* quickMap, Map *map)
{
- QDeclarativeGeoMapItemBase::setMap(quickMap,map);
- if (map) QObject::connect(map, SIGNAL(cameraDataChanged(CameraData)), this, SLOT(handleCameraDataChanged(CameraData)));
+ QDeclarativeGeoMapItemBase::setMap(quickMap, map);
+ if (map)
+ QObject::connect(map, SIGNAL(cameraDataChanged(CameraData)),
+ this, SLOT(handleCameraDataChanged(CameraData)));
}
QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativePolygonMapItem::declarativePath()
@@ -182,6 +198,7 @@ void QDeclarativePolygonMapItem::setColor(const QColor &color)
updateMapItem(false);
emit colorChanged(color_);
}
+
QSGNode* QDeclarativePolygonMapItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* data)
{
Q_UNUSED(data);
@@ -204,6 +221,8 @@ QDeclarativePolygonMapItem::updateMapItem(bool dirtyGeometry)
return;
mapPolygonNode_->setBrushColor(color_);
+ mapPolygonNode_->setPenColor(border_.color());
+ mapPolygonNode_->setLineWidth(border_.width());
if (dirtyGeometry)
mapPolygonNode_->setGeometry(*map(), path_);
@@ -242,11 +261,15 @@ bool QDeclarativePolygonMapItem::contains(QPointF point)
MapPolygonNode::MapPolygonNode() :
fillColor_(Qt::black),
borderColor_(Qt::black),
+ borderWidth_(3.0),
+ border_(new MapPolylineNode()),
geometry_(QSGGeometry::defaultAttributes_Point2D(), 0)
{
geometry_.setDrawingMode(GL_POLYGON);
QSGGeometryNode::setMaterial(&fill_material_);
QSGGeometryNode::setGeometry(&geometry_);
+
+ appendChildNode(border_);
}
MapPolygonNode::~MapPolygonNode()
@@ -281,7 +304,22 @@ void MapPolygonNode::update()
setMaterial(&fill_material_);
}
- //TODO: implement me : borders , gradient
+ border_->setPenColor(borderColor_);
+ border_->setLineWidth(borderWidth_);
+
+ border_->update();
+
+ //TODO: implement me : gradient
+}
+
+qreal MapPolygonNode::lineWidth() const
+{
+ return borderWidth_;
+}
+
+void MapPolygonNode::setLineWidth(qreal width)
+{
+ borderWidth_ = width;
}
void MapPolygonNode::setBrushColor(const QColor &color)
@@ -316,4 +354,8 @@ void MapPolygonNode::setGeometry(const Map& map, const QList<QGeoCoordinate> &pa
polygon_.clear();
updatePolygon(polygon_, map, path, w, h);
size_ = QSizeF(w, h);
+
+ QList<QGeoCoordinate> pathClosed = path;
+ pathClosed.append(pathClosed.at(0));
+ border_->setGeometry(map, pathClosed);
}
diff --git a/src/imports/location/qdeclarativepolygonmapitem_p.h b/src/imports/location/qdeclarativepolygonmapitem_p.h
index 060ca0f7..0f8ca5eb 100644
--- a/src/imports/location/qdeclarativepolygonmapitem_p.h
+++ b/src/imports/location/qdeclarativepolygonmapitem_p.h
@@ -43,6 +43,7 @@
#define QDECLARATIVEPOLYGONMAPITEM
#include "qdeclarativegeomapitembase_p.h"
+#include "qdeclarativepolylinemapitem_p.h"
#include <QSGGeometryNode>
#include <QSGFlatColorMaterial>
@@ -56,6 +57,7 @@ class QDeclarativePolygonMapItem : public QDeclarativeGeoMapItemBase
Q_PROPERTY(QDeclarativeListProperty<QDeclarativeCoordinate> path READ declarativePath NOTIFY pathChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ Q_PROPERTY(QDeclarativeMapLineProperties *border READ border)
public:
QDeclarativePolygonMapItem(QQuickItem *parent = 0);
@@ -73,6 +75,8 @@ public:
QColor color() const;
void setColor(const QColor &color);
+ QDeclarativeMapLineProperties *border();
+
void dragStarted();
bool contains(QPointF point);
@@ -82,6 +86,7 @@ Q_SIGNALS:
protected Q_SLOTS:
virtual void updateMapItem(bool dirtyGeomoetry = true);
+ void handleBorderUpdated();
private Q_SLOTS:
// map size changed
@@ -96,6 +101,7 @@ private:
private:
MapPolygonNode *mapPolygonNode_;
+ QDeclarativeMapLineProperties border_;
QList<QDeclarativeCoordinate*> coordPath_;
QList<QGeoCoordinate> path_;
QColor color_;
@@ -119,6 +125,9 @@ public:
QColor penColor() const;
void setPenColor(const QColor &pen);
+ qreal lineWidth() const;
+ void setLineWidth(qreal width);
+
QColor brushColor() const;
void setBrushColor(const QColor &color);
@@ -131,6 +140,8 @@ private:
QSGFlatColorMaterial fill_material_;
QColor fillColor_;
QColor borderColor_;
+ qreal borderWidth_;
+ MapPolylineNode *border_;
QSGGeometry geometry_;
QPolygonF polygon_;
QSizeF size_;