summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/imports/location/location.cpp2
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp14
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h3
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp87
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h10
5 files changed, 109 insertions, 7 deletions
diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp
index f1494a04..44f4bd5a 100644
--- a/src/imports/location/location.cpp
+++ b/src/imports/location/location.cpp
@@ -51,6 +51,7 @@
#include <QtLocation/private/qdeclarativepolylinemapitem_p.h>
#include <QtLocation/private/qdeclarativepolygonmapitem_p.h>
#include <QtLocation/private/qdeclarativegeomapparameter_p.h>
+#include <QtLocation/private/qdeclarativegeomapcopyrightsnotice_p.h>
//Place includes
#include <QtLocation/private/qdeclarativecategory_p.h>
@@ -171,6 +172,7 @@ public:
// Register the 5.9 types
minor = 9;
qmlRegisterType<QDeclarativeGeoMapParameter>(uri, major, minor, "MapParameter");
+ qmlRegisterType<QDeclarativeGeoMapCopyrightNotice>(uri, major, minor, "MapCopyrightNotice");
//registrations below are version independent
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 456291a7..7e35321c 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -244,10 +244,17 @@ void QDeclarativeGeoMap::onMapChildrenChanged()
// create a new one and set its parent, re-assign it to the weak pointer, then connect the copyrights-change signal
m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
copyrights = m_copyrights.data();
+
connect(m_map, SIGNAL(copyrightsChanged(QImage)),
copyrights, SLOT(copyrightsChanged(QImage)));
+ connect(m_map, SIGNAL(copyrightsChanged(QImage)),
+ this, SIGNAL(copyrightsChanged(QImage)));
+
connect(m_map, SIGNAL(copyrightsChanged(QString)),
copyrights, SLOT(copyrightsChanged(QString)));
+ connect(m_map, SIGNAL(copyrightsChanged(QString)),
+ this, SIGNAL(copyrightsChanged(QString)));
+
connect(copyrights, SIGNAL(linkActivated(QString)),
this, SIGNAL(copyrightLinkActivated(QString)));
@@ -643,10 +650,17 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
}
m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
+
connect(m_map, SIGNAL(copyrightsChanged(QImage)),
m_copyrights.data(), SLOT(copyrightsChanged(QImage)));
+ connect(m_map, SIGNAL(copyrightsChanged(QImage)),
+ this, SIGNAL(copyrightsChanged(QImage)));
+
connect(m_map, SIGNAL(copyrightsChanged(QString)),
m_copyrights.data(), SLOT(copyrightsChanged(QString)));
+ connect(m_map, SIGNAL(copyrightsChanged(QString)),
+ this, SIGNAL(copyrightsChanged(QString)));
+
connect(m_copyrights.data(), SIGNAL(linkActivated(QString)),
this, SIGNAL(copyrightLinkActivated(QString)));
connect(m_map, &QGeoMap::sgNodeChanged, this, &QQuickItem::update);
diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h
index efaf3817..b010bda2 100644
--- a/src/location/declarativemaps/qdeclarativegeomap_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomap_p.h
@@ -196,6 +196,8 @@ Q_SIGNALS:
void maximumTiltChanged(qreal maximumTilt);
void minimumFieldOfViewChanged(qreal minimumFieldOfView);
void maximumFieldOfViewChanged(qreal maximumFieldOfView);
+ void copyrightsChanged(const QImage &copyrightsImage);
+ void copyrightsChanged(const QString &copyrightsHtml);
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE ;
@@ -255,6 +257,7 @@ private:
friend class QDeclarativeGeoMapItem;
friend class QDeclarativeGeoMapItemView;
friend class QQuickGeoMapGestureArea;
+ friend class QDeclarativeGeoMapCopyrightNotice;
Q_DISABLE_COPY(QDeclarativeGeoMap)
};
diff --git a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp
index 7b5a5765..2cabebde 100644
--- a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice.cpp
@@ -42,21 +42,95 @@
#include <QtGui/QPainter>
#include <QtQuick/private/qquickanchors_p.h>
#include <QtQuick/private/qquickanchors_p_p.h>
+#include <QtLocation/private/qdeclarativegeomap_p.h>
QT_BEGIN_NAMESPACE
+/*!
+ \qmltype MapCopyrightNotice
+ \instantiates QDeclarativeGeoMapCopyrightNotice
+ \inqmlmodule QtLocation
+ \ingroup qml-QtLocation5-maps
+ \since Qt Location 5.9
+
+ \brief The MapCopyrightNotice item displays the current valid
+ copyright notice for a Map element.
+
+ This object can be used to place an additional copyright notices
+ programmatically.
+
+ Note that declaring a MapCopyrightNotice inside a QtLocation::Map element
+ is not possible, like for any other QQuickItem.
+
+ The release of this API with Qt 5.9 is a Technology Preview.
+*/
+
+/*!
+ \qmlproperty bool QtLocation::MapCopyrightNotice::mapSource
+
+ This property holds the current map source providing the copyright data shown
+ in this notice.
+ In order to let the MapCopyrightNotice display a copyright, this property must
+ be set, as it is the only data source for this element.
+*/
+
QDeclarativeGeoMapCopyrightNotice::QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent)
-: QQuickPaintedItem(parent), m_copyrightsHtml(0), m_copyrightsVisible(true)
+: QQuickPaintedItem(parent), m_copyrightsHtml(0), m_copyrightsVisible(true), m_mapSource(0)
+{
+ // If this item is constructed inside the map, automatically anchor it where it always used to be.
+ if (qobject_cast<QDeclarativeGeoMap *>(parent))
+ anchorToBottomLeft();
+}
+
+QDeclarativeGeoMapCopyrightNotice::~QDeclarativeGeoMapCopyrightNotice()
{
+}
+
+void QDeclarativeGeoMapCopyrightNotice::anchorToBottomLeft()
+{
+ if (!parent())
+ return;
QQuickAnchors *anchors = property("anchors").value<QQuickAnchors *>();
if (anchors) {
- anchors->setLeft(QQuickAnchorLine(parent, QQuickAnchors::LeftAnchor));
- anchors->setBottom(QQuickAnchorLine(parent, QQuickAnchors::BottomAnchor));
+ anchors->setLeft(QQuickAnchorLine(qobject_cast<QQuickItem *>(parent()), QQuickAnchors::LeftAnchor));
+ anchors->setBottom(QQuickAnchorLine(qobject_cast<QQuickItem *>(parent()), QQuickAnchors::BottomAnchor));
}
}
-QDeclarativeGeoMapCopyrightNotice::~QDeclarativeGeoMapCopyrightNotice()
+void QDeclarativeGeoMapCopyrightNotice::setMapSource(QDeclarativeGeoMap *mapSource)
+{
+ if (m_mapSource == mapSource)
+ return;
+
+ if (m_mapSource) {
+ // disconnect this object from current map source
+ m_mapSource->disconnect(this);
+ m_copyrightsHtml->clear();
+ m_copyrightsImage = QImage();
+ m_mapSource = Q_NULLPTR;
+ }
+
+ if (mapSource) {
+ m_mapSource = mapSource;
+ // First update the copyright. Only Image will do here, no need to store HTML right away.
+ if (!mapSource->m_copyrights->m_copyrightsImage.isNull())
+ m_copyrightsImage = mapSource->m_copyrights->m_copyrightsImage;
+
+ connect(m_mapSource, SIGNAL(copyrightsChanged(QImage)),
+ this, SLOT(copyrightsChanged(QImage)));
+ connect(m_mapSource, SIGNAL(copyrightsChanged(QString)),
+ this, SLOT(copyrightsChanged(QString)));
+ connect(this, SIGNAL(linkActivated(QString)),
+ m_mapSource, SIGNAL(copyrightLinkActivated(QString)));
+ }
+
+ update();
+ emit mapSourceChanged();
+}
+
+QDeclarativeGeoMap *QDeclarativeGeoMapCopyrightNotice::mapSource()
{
+ return m_mapSource;
}
/*!
@@ -130,10 +204,11 @@ void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QImage &copyrigh
void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QString &copyrightsHtml)
{
- if (copyrightsHtml.isEmpty() || !m_copyrightsVisible) {
- m_copyrightsImage = QImage();
+ if (copyrightsHtml.isEmpty()) {
setVisible(false);
return;
+ } else if (!m_copyrightsVisible) {
+ setVisible(false);
} else {
setVisible(true);
}
diff --git a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h
index 1aeef7c1..551bf411 100644
--- a/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomapcopyrightsnotice_p.h
@@ -57,18 +57,24 @@
QT_BEGIN_NAMESPACE
class QTextDocument;
+class QDeclarativeGeoMap;
class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapCopyrightNotice : public QQuickPaintedItem
{
Q_OBJECT
+ Q_PROPERTY(QDeclarativeGeoMap *mapSource READ mapSource WRITE setMapSource NOTIFY mapSourceChanged)
public:
- explicit QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent);
+ QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent = Q_NULLPTR);
~QDeclarativeGeoMapCopyrightNotice();
void setCopyrightsZ(int copyrightsZ);
void setCopyrightsVisible(bool visible);
+ void anchorToBottomLeft();
+
+ void setMapSource(QDeclarativeGeoMap *mapSource);
+ QDeclarativeGeoMap *mapSource();
public Q_SLOTS:
void copyrightsChanged(const QImage &copyrightsImage);
@@ -76,6 +82,7 @@ public Q_SLOTS:
signals:
void linkActivated(const QString &link);
+ void mapSourceChanged();
protected:
void paint(QPainter *painter) Q_DECL_OVERRIDE;
@@ -87,6 +94,7 @@ private:
QImage m_copyrightsImage;
QString m_activeAnchor;
bool m_copyrightsVisible;
+ QDeclarativeGeoMap *m_mapSource;
};
QT_END_NAMESPACE