summaryrefslogtreecommitdiff
path: root/src/location
diff options
context:
space:
mode:
Diffstat (limited to 'src/location')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp44
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h4
-rw-r--r--src/location/declarativemaps/qgeomapobject.cpp6
-rw-r--r--src/location/declarativemaps/qparameterizableobject.cpp41
-rw-r--r--src/location/declarativemaps/qparameterizableobject_p.h4
-rw-r--r--src/location/labs/qmapcircleobject.cpp2
-rw-r--r--src/location/labs/qmapobjectview.cpp14
-rw-r--r--src/location/labs/qmappolygonobject.cpp2
-rw-r--r--src/location/labs/qmappolygonobject_p.h2
-rw-r--r--src/location/labs/qmappolygonobject_p_p.h2
-rw-r--r--src/location/labs/qmappolylineobject.cpp2
-rw-r--r--src/location/maps/qgeotiledmapscene.cpp2
12 files changed, 94 insertions, 31 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 7fd5f78a..6a2d82e8 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -2289,17 +2289,31 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF
}
/*!
- \qmlmethod void QtLocation::Map::fitViewportToMapItems()
+ \qmlmethod void QtLocation::Map::fitViewportToMapItems(list<MapItems> items = {})
- Fits the current viewport to the boundary of all map items. The camera is positioned
- in the center of the map items, and at the largest integral zoom level possible which
- allows all map items to be visible on screen.
+ If no argument is provided, fits the current viewport to the boundary of all map items.
+ The camera is positioned in the center of the map items, and at the largest integral zoom level
+ possible which allows all map items to be visible on screen.
+ If \a items is provided, fits the current viewport to the boundary of the specified map items only.
+
+ \note This method gained the optional \a items argument since Qt 5.15.
+ In previous releases, this method fitted the map to all map items.
\sa fitViewportToVisibleMapItems
*/
-void QDeclarativeGeoMap::fitViewportToMapItems()
+void QDeclarativeGeoMap::fitViewportToMapItems(const QVariantList &items)
{
- fitViewportToMapItemsRefine(true, false);
+ if (items.size()) {
+ QList<QPointer<QDeclarativeGeoMapItemBase> > itms;
+ for (const QVariant &i: items) {
+ QDeclarativeGeoMapItemBase *itm = qobject_cast<QDeclarativeGeoMapItemBase *>(i.value<QObject *>());
+ if (itm)
+ itms.append(itm);
+ }
+ fitViewportToMapItemsRefine(itms, true, false);
+ } else {
+ fitViewportToMapItemsRefine(m_mapItems, true, false);
+ }
}
/*!
@@ -2313,18 +2327,20 @@ void QDeclarativeGeoMap::fitViewportToMapItems()
*/
void QDeclarativeGeoMap::fitViewportToVisibleMapItems()
{
- fitViewportToMapItemsRefine(true, true);
+ fitViewportToMapItemsRefine(m_mapItems, true, true);
}
/*!
\internal
*/
-void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisible)
+void QDeclarativeGeoMap::fitViewportToMapItemsRefine(const QList<QPointer<QDeclarativeGeoMapItemBase> > &mapItems,
+ bool refine,
+ bool onlyVisible)
{
if (!m_map)
return;
- if (m_mapItems.size() == 0)
+ if (mapItems.size() == 0)
return;
double minX = qInf();
@@ -2339,10 +2355,10 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib
// find bounds of all map items
int itemCount = 0;
- for (int i = 0; i < m_mapItems.count(); ++i) {
- if (!m_mapItems.at(i))
+ for (int i = 0; i < mapItems.count(); ++i) {
+ if (!mapItems.at(i))
continue;
- QDeclarativeGeoMapItemBase *item = m_mapItems.at(i).data();
+ QDeclarativeGeoMapItemBase *item = mapItems.at(i).data();
if (!item || (onlyVisible && (!item->isVisible() || item->mapItemOpacity() <= 0.0)))
continue;
@@ -2393,7 +2409,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib
if (itemCount == 0) {
if (haveQuickItem)
- fitViewportToMapItemsRefine(false, onlyVisible);
+ fitViewportToMapItemsRefine(mapItems, false, onlyVisible);
return;
}
double bboxWidth = maxX - minX;
@@ -2423,7 +2439,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib
// as map quick items retain the same screen size after the camera zooms in/out
// we refine the viewport again to achieve better results
if (refine)
- fitViewportToMapItemsRefine(false, onlyVisible);
+ fitViewportToMapItemsRefine(mapItems, false, onlyVisible);
}
/*!
diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h
index c97c3622..ee9f8ec2 100644
--- a/src/location/declarativemaps/qdeclarativegeomap_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomap_p.h
@@ -193,7 +193,7 @@ public:
QQuickGeoMapGestureArea *gesture();
- Q_INVOKABLE void fitViewportToMapItems();
+ Q_INVOKABLE void fitViewportToMapItems(const QVariantList &items = {});
Q_INVOKABLE void fitViewportToVisibleMapItems();
Q_INVOKABLE void pan(int dx, int dy);
Q_INVOKABLE void prefetchData(); // optional hint for prefetch
@@ -280,7 +280,7 @@ private:
void setupMapView(QDeclarativeGeoMapItemView *view);
void populateMap();
void populateParameters();
- void fitViewportToMapItemsRefine(bool refine, bool onlyVisible);
+ void fitViewportToMapItemsRefine(const QList<QPointer<QDeclarativeGeoMapItemBase> > &mapItems, bool refine, bool onlyVisible);
bool isInteractive();
void attachCopyrightNotice(bool initialVisibility);
void detachCopyrightNotice(bool currentVisibility);
diff --git a/src/location/declarativemaps/qgeomapobject.cpp b/src/location/declarativemaps/qgeomapobject.cpp
index 00faac9b..b0a10806 100644
--- a/src/location/declarativemaps/qgeomapobject.cpp
+++ b/src/location/declarativemaps/qgeomapobject.cpp
@@ -193,8 +193,10 @@ void QGeoMapObject::setMap(QGeoMap *map)
if (map) {
bool oldVisible = d_ptr->m_visible;
bool oldCmponentCompleted = d_ptr->m_componentCompleted;
- if (!map->createMapObjectImplementation(this))
- qWarning() << "Unsupported type " << type();
+ if (!map->createMapObjectImplementation(this)) {
+ if (type() != ViewType)
+ qWarning() << "Unsupported type " << type();
+ }
// old implementation gets destroyed if/when d_ptr gets replaced
d_ptr->m_componentCompleted = oldCmponentCompleted;
d_ptr->setVisible(oldVisible);
diff --git a/src/location/declarativemaps/qparameterizableobject.cpp b/src/location/declarativemaps/qparameterizableobject.cpp
index 0e138b86..26d9a11e 100644
--- a/src/location/declarativemaps/qparameterizableobject.cpp
+++ b/src/location/declarativemaps/qparameterizableobject.cpp
@@ -37,13 +37,10 @@
#include "qparameterizableobject_p.h"
#include "qdeclarativegeomapparameter_p.h"
#include <QtLocation/private/qgeomapparameter_p.h>
+#include <private/qobject_p.h>
QT_BEGIN_NAMESPACE
-QParameterizableObject::QParameterizableObject(QObject *parent)
- : QObject(parent)
-{}
-
void QParameterizableObject::appendChild(QObject *v)
{
m_children.append(v);
@@ -85,4 +82,40 @@ void QParameterizableObject::clear(QQmlListProperty<QObject> *p)
object->clearChildren();
}
+class QParameterizableObjectData: public QAbstractDeclarativeData
+{
+public:
+ QParameterizableObjectData()
+ {
+ init();
+ }
+
+ static inline void init() {
+ static bool initialized = false;
+ if (!initialized) {
+ initialized = true;
+ QAbstractDeclarativeData::parentChanged = parentChanged;
+ }
+ }
+
+ static void parentChanged(QAbstractDeclarativeData *d, QObject *o, QObject *p);
+};
+
+Q_GLOBAL_STATIC(QParameterizableObjectData, parametrizableObjectData)
+
+QParameterizableObject::QParameterizableObject(QObject *parent)
+ : QObject(parent)
+{
+ QObjectPrivate::get(this)->declarativeData = parametrizableObjectData;
+}
+
+void QParameterizableObjectData::parentChanged(QAbstractDeclarativeData *d, QObject *o, QObject *p)
+{
+ Q_UNUSED(p)
+ Q_UNUSED(d)
+ QParameterizableObject *po = qobject_cast<QParameterizableObject *>(o);
+ if (po)
+ po->parentChanged();
+}
+
QT_END_NAMESPACE
diff --git a/src/location/declarativemaps/qparameterizableobject_p.h b/src/location/declarativemaps/qparameterizableobject_p.h
index e450c6ec..cf393aee 100644
--- a/src/location/declarativemaps/qparameterizableobject_p.h
+++ b/src/location/declarativemaps/qparameterizableobject_p.h
@@ -58,6 +58,7 @@ class QGeoMapParameter;
class Q_LOCATION_PRIVATE_EXPORT QParameterizableObject : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QObject *parent READ parent NOTIFY parentChanged DESIGNABLE false FINAL)
Q_PROPERTY(QQmlListProperty<QObject> quickChildren READ declarativeChildren DESIGNABLE false)
Q_CLASSINFO("DefaultProperty", "quickChildren")
@@ -76,6 +77,9 @@ public:
return res;
}
+Q_SIGNALS:
+ void parentChanged();
+
protected:
virtual void appendChild(QObject *v);
virtual void clearChildren();
diff --git a/src/location/labs/qmapcircleobject.cpp b/src/location/labs/qmapcircleobject.cpp
index 5f0db29d..fdfc834d 100644
--- a/src/location/labs/qmapcircleobject.cpp
+++ b/src/location/labs/qmapcircleobject.cpp
@@ -250,7 +250,7 @@ QColor QMapCircleObject::color() const
QDeclarativeMapLineProperties *QMapCircleObject::border()
{
if (!m_border) {
- m_border = new QDeclarativeMapLineProperties;
+ m_border = new QDeclarativeMapLineProperties(this);
connect(m_border, &QDeclarativeMapLineProperties::colorChanged, this, [this](const QColor &color){
static_cast<QMapCircleObjectPrivate*>(d_ptr.data())->setBorderColor(color);
});
diff --git a/src/location/labs/qmapobjectview.cpp b/src/location/labs/qmapobjectview.cpp
index 8cbf8ded..54d384fb 100644
--- a/src/location/labs/qmapobjectview.cpp
+++ b/src/location/labs/qmapobjectview.cpp
@@ -339,8 +339,10 @@ void QMapObjectView::modelUpdated(const QQmlChangeSet &changeSet, bool reset)
for (int idx = c.start(); idx < c.end(); idx++) {
m_instantiatedMapObjects.insert(idx, nullptr);
QGeoMapObject *mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(idx, incubationMode));
- if (mo) // if not, a createdItem signal will be emitted later, else it has been emitted already while createBlocker is in effect.
+ if (mo) {// if not, a createdItem signal will be emitted later, else it has been emitted already while createBlocker is in effect.
+ mo->setParent(this);
addMapObjectToMap(mo, idx);
+ }
}
}
}
@@ -395,10 +397,12 @@ void QMapObjectView::createdItem(int index, QObject * /*object*/)
// or else, it will be destroyed exiting this scope
QGeoMapObject *mo = nullptr;
mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(index, incubationMode));
- if (mo)
+ if (mo) {
+ mo->setParent(this);
addMapObjectToMap(mo, index);
- else
+ } else {
qWarning() << "QQmlDelegateModel::object called in createdItem for " << index << " produced a null object";
+ }
}
@@ -436,7 +440,11 @@ void QMapObjectView::setMap(QGeoMap *map)
// Map was set, now it has ben re-set to NULL
flushDelegateModel();
flushUserAddedMapObjects();
+ bool oldVisible = d_ptr->m_visible;
+ bool oldCmponentCompleted = d_ptr->m_componentCompleted;
d_ptr = new QMapObjectViewPrivateDefault(*d);
+ d_ptr->m_componentCompleted = oldCmponentCompleted;
+ d_ptr->setVisible(oldVisible);
} else if (d->m_componentCompleted) {
// Map was null, now it's set AND delegateModel is already complete.
// some delegates may have been incubated but not added to the map.
diff --git a/src/location/labs/qmappolygonobject.cpp b/src/location/labs/qmappolygonobject.cpp
index 6ccba748..5a8ce228 100644
--- a/src/location/labs/qmappolygonobject.cpp
+++ b/src/location/labs/qmappolygonobject.cpp
@@ -250,7 +250,7 @@ QColor QMapPolygonObject::color() const
QDeclarativeMapLineProperties *QMapPolygonObject::border()
{
if (!m_border) {
- m_border = new QDeclarativeMapLineProperties;
+ m_border = new QDeclarativeMapLineProperties(this);
connect(m_border, &QDeclarativeMapLineProperties::colorChanged, this, [this](const QColor &color){
static_cast<QMapPolygonObjectPrivate*>(d_ptr.data())->setBorderColor(color);
});
diff --git a/src/location/labs/qmappolygonobject_p.h b/src/location/labs/qmappolygonobject_p.h
index 03eef587..e924afab 100644
--- a/src/location/labs/qmappolygonobject_p.h
+++ b/src/location/labs/qmappolygonobject_p.h
@@ -82,7 +82,7 @@ signals:
void colorChanged();
protected:
- QDeclarativeMapLineProperties *m_border;
+ QDeclarativeMapLineProperties *m_border = nullptr;
};
QT_END_NAMESPACE
diff --git a/src/location/labs/qmappolygonobject_p_p.h b/src/location/labs/qmappolygonobject_p_p.h
index 767765df..52bbaf4c 100644
--- a/src/location/labs/qmappolygonobject_p_p.h
+++ b/src/location/labs/qmappolygonobject_p_p.h
@@ -103,7 +103,7 @@ public:
public:
QGeoPolygon m_path; // small overhead compared to plain QList<QGeoCoordinate>
- QColor m_borderColor;
+ QColor m_borderColor = Qt::transparent;
QColor m_fillColor = Qt::transparent;
qreal m_borderWidth = 0;
diff --git a/src/location/labs/qmappolylineobject.cpp b/src/location/labs/qmappolylineobject.cpp
index c6d3cdaf..81390d7c 100644
--- a/src/location/labs/qmappolylineobject.cpp
+++ b/src/location/labs/qmappolylineobject.cpp
@@ -191,7 +191,7 @@ QVariantList QMapPolylineObject::path() const
QDeclarativeMapLineProperties *QMapPolylineObject::border()
{
if (!m_border) {
- m_border = new QDeclarativeMapLineProperties;
+ m_border = new QDeclarativeMapLineProperties(this);
connect(m_border, &QDeclarativeMapLineProperties::colorChanged, this, [this](const QColor &color){
static_cast<QMapPolylineObjectPrivate*>(d_ptr.data())->setColor(color);
});
diff --git a/src/location/maps/qgeotiledmapscene.cpp b/src/location/maps/qgeotiledmapscene.cpp
index a8bee156..18d92b00 100644
--- a/src/location/maps/qgeotiledmapscene.cpp
+++ b/src/location/maps/qgeotiledmapscene.cpp
@@ -515,7 +515,7 @@ void QGeoTiledMapRootNode::updateTiles(QGeoTiledMapTileContainerNode *root,
bool ok = d->buildGeometry(it.key(), node, overzooming)
&& qgeotiledmapscene_isTileInViewport(node->rect(), root->matrix(), straight);
- QSGNode::DirtyState dirtyBits = 0;
+ QSGNode::DirtyState dirtyBits = {};
if (!ok) {
#ifdef QT_LOCATION_DEBUG