diff options
author | Harald Meyer <dev@meh.at> | 2015-07-14 13:45:56 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-09-02 05:20:15 +0000 |
commit | ffbdf2cf0517cc773a012dc07f17532297e03d8d (patch) | |
tree | 253878fc3fa8a65f1630a74271b4b66816ea061d | |
parent | 2aaf3b9f70a02d0b00a7556922e9808523f31066 (diff) | |
download | qtlocation-ffbdf2cf0517cc773a012dc07f17532297e03d8d.tar.gz |
Added parameter to hide map copyrights notice.
In some cases (for instance a helper mini map) the copyright notice is displayed
multiple times. The new parameter allows to hide the copyright notice in such cases.
Change-Id: I659c1ac019b8c21545c410a38cdc840f93d928ce
Task-number: QTBUG-47025
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
5 files changed, 61 insertions, 4 deletions
diff --git a/examples/location/mapviewer/map/MiniMap.qml b/examples/location/mapviewer/map/MiniMap.qml index 29a6a880..35996063 100644 --- a/examples/location/mapviewer/map/MiniMap.qml +++ b/examples/location/mapviewer/map/MiniMap.qml @@ -62,6 +62,7 @@ Rectangle{ center: map.center plugin: map.plugin gesture.enabled: false + copyrightsVisible: false MapRectangle { color: "#44ff0000" diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 87023708..dbef7045 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -181,7 +181,8 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) m_zoomLevel(8.0), m_componentCompleted(false), m_mappingManagerInitialized(false), - m_pendingFitViewport(false) + m_pendingFitViewport(false), + m_copyrightsVisible(true) { setAcceptHoverEvents(false); setAcceptedMouseButtons(Qt::LeftButton); @@ -249,6 +250,10 @@ void QDeclarativeGeoMap::onMapChildrenChanged() copyrights, SLOT(copyrightsChanged(QString))); connect(copyrights, SIGNAL(linkActivated(QString)), this, SIGNAL(copyrightLinkActivated(QString))); + + // set visibility of copyright notice + copyrights->setCopyrightsVisible(m_copyrightsVisible); + } else { // just re-set its parent. copyrights->setParent(this); @@ -503,6 +508,10 @@ void QDeclarativeGeoMap::mappingManagerInitialized() this, SLOT(mapZoomLevelChanged(qreal))); + + // set visibility of copyright notice + m_copyrights->setCopyrightsVisible(m_copyrightsVisible); + m_map->mapController()->setCenter(m_center); QList<QGeoMapType> types = m_mappingManager->supportedMapTypes(); @@ -737,6 +746,33 @@ QGeoShape QDeclarativeGeoMap::visibleRegion() const return QGeoRectangle(tl, br); } +/*! + \qmlproperty bool QtLocation::Map::copyrightsVisible + + This property holds the visibility of the copyrights notice. The notice is usually + displayed in the bottom left corner. By default, this property is set to \c true. + + \note Many map providers require the notice to be visible as part of the terms and conditions. + Please consult the relevant provider documentation before turning this notice off. +*/ +void QDeclarativeGeoMap::setCopyrightsVisible(bool visible) +{ + if (m_copyrightsVisible == visible) + return; + + if (!m_copyrights.isNull()) + m_copyrights->setCopyrightsVisible(visible); + + m_copyrightsVisible = visible; + emit copyrightsVisibleChanged(visible); +} + +bool QDeclarativeGeoMap::copyrightsVisible() const +{ + return m_copyrightsVisible; +} + + void QDeclarativeGeoMap::fitViewportToGeoShape() { if (!m_map) return; diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h index 85ae6753..737598e3 100644 --- a/src/imports/location/qdeclarativegeomap_p.h +++ b/src/imports/location/qdeclarativegeomap_p.h @@ -68,6 +68,7 @@ class QDeclarativeGeoMap : public QQuickItem Q_PROPERTY(QGeoServiceProvider::Error error READ error NOTIFY errorChanged) Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) Q_PROPERTY(QGeoShape visibleRegion READ visibleRegion WRITE setVisibleRegion) + Q_PROPERTY(bool copyrightsVisible READ copyrightsVisible WRITE setCopyrightsVisible NOTIFY copyrightsVisibleChanged) Q_INTERFACES(QQmlParserStatus) public: @@ -96,6 +97,9 @@ public: void setVisibleRegion(const QGeoShape &shape); QGeoShape visibleRegion() const; + void setCopyrightsVisible(bool visible); + bool copyrightsVisible() const; + QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes(); Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item); @@ -131,6 +135,7 @@ Q_SIGNALS: void mapItemsChanged(); void errorChanged(); void copyrightLinkActivated(const QString &link); + void copyrightsVisibleChanged(bool visible); protected: void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE ; @@ -184,6 +189,7 @@ private: bool m_mappingManagerInitialized; QGeoShape m_region; bool m_pendingFitViewport; + bool m_copyrightsVisible; friend class QDeclarativeGeoMapItem; friend class QDeclarativeGeoMapItemView; diff --git a/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp b/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp index f2c44833..8e0f3b1e 100644 --- a/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp +++ b/src/imports/location/qdeclarativegeomapcopyrightsnotice.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE QDeclarativeGeoMapCopyrightNotice::QDeclarativeGeoMapCopyrightNotice(QQuickItem *parent) -: QQuickPaintedItem(parent), m_copyrightsHtml(0) +: QQuickPaintedItem(parent), m_copyrightsHtml(0), m_copyrightsVisible(true) { QQuickAnchors *anchors = property("anchors").value<QQuickAnchors *>(); if (anchors) { @@ -92,6 +92,16 @@ void QDeclarativeGeoMapCopyrightNotice::mouseReleaseEvent(QMouseEvent *event) /*! \internal */ +void QDeclarativeGeoMapCopyrightNotice::setCopyrightsVisible(bool visible) +{ + m_copyrightsVisible = visible; + + setVisible(!m_copyrightsImage.isNull() && visible); +} + +/*! + \internal +*/ void QDeclarativeGeoMapCopyrightNotice::setCopyrightsZ(int copyrightsZ) { setZ(copyrightsZ); @@ -113,14 +123,15 @@ void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QImage ©righ setKeepMouseGrab(false); setAcceptedMouseButtons(Qt::NoButton); - setVisible(true); + setVisible(m_copyrightsVisible); update(); } void QDeclarativeGeoMapCopyrightNotice::copyrightsChanged(const QString ©rightsHtml) { - if (copyrightsHtml.isEmpty()) { + if (copyrightsHtml.isEmpty() || !m_copyrightsVisible) { + m_copyrightsImage = QImage(); setVisible(false); return; } else { diff --git a/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h b/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h index 78a0ce30..b4bd6c40 100644 --- a/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h +++ b/src/imports/location/qdeclarativegeomapcopyrightsnotice_p.h @@ -55,6 +55,8 @@ public: void setCopyrightsZ(int copyrightsZ); + void setCopyrightsVisible(bool visible); + public Q_SLOTS: void copyrightsChanged(const QImage ©rightsImage); void copyrightsChanged(const QString ©rightsHtml); @@ -71,6 +73,7 @@ private: QTextDocument *m_copyrightsHtml; QImage m_copyrightsImage; QString m_activeAnchor; + bool m_copyrightsVisible; }; QT_END_NAMESPACE |