| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. | 
| 4 | ** Contact: http://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtLocation module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or later as published by the Free | 
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in | 
| 29 | ** the packaging of this file. Please review the following information to | 
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be | 
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. | 
| 32 | ** | 
| 33 | ** $QT_END_LICENSE$ | 
| 34 | ** | 
| 35 | ****************************************************************************/ | 
| 36 |  | 
| 37 | #include "qdeclarativegeomap_p.h" | 
| 38 | #include "qgeomapobject_p.h" | 
| 39 | #include "qgeomapobject_p_p.h" | 
| 40 |  | 
| 41 | QT_BEGIN_NAMESPACE | 
| 42 |  | 
| 43 | /*! | 
| 44 |     \internal | 
| 45 |  | 
| 46 |     \qmltype GeoMapObject | 
| 47 |     \instantiates QGeoMapObject | 
| 48 |     \inqmlmodule Qt.labs.location | 
| 49 |     \ingroup qml-QtLocation5-maps | 
| 50 |  | 
| 51 |     \brief The GeoObject type is a base class for geographical objects that can be added to a map. | 
| 52 |  | 
| 53 |     The difference between a GeoMapObject and a MapItem is twofold. First, GeoMapObject are always backed | 
| 54 |     by a plugin-specific implementation and do not come with a default implementation. If a plugin does | 
| 55 |     not support a specific GeoMapObject type, adding such a GeoMapObject will have no effect. | 
| 56 |     Second, GeoMapObject are not QQuickItems, thus being a much more lightweight way to add content to | 
| 57 |     a map. | 
| 58 |  | 
| 59 |     GeoMapObject support is plugin-dependent, and is documented per plugin. | 
| 60 | */ | 
| 61 |  | 
| 62 | template<> | 
| 63 | QGeoMapObjectPrivate *QExplicitlySharedDataPointer<QGeoMapObjectPrivate>::clone() | 
| 64 | { | 
| 65 |     return d->clone(); | 
| 66 | } | 
| 67 |  | 
| 68 | QGeoMapObject::~QGeoMapObject() | 
| 69 | { | 
| 70 |  | 
| 71 | } | 
| 72 |  | 
| 73 | /*! | 
| 74 |     Returns whether this geographical object and \a other are equal. | 
| 75 | */ | 
| 76 | bool QGeoMapObject::operator ==(const QGeoMapObject &other) const | 
| 77 | { | 
| 78 |     return ( (d_ptr.constData() == other.d_ptr.constData()) | 
| 79 |             || (*d_ptr) == (*other.d_ptr)); | 
| 80 | } | 
| 81 |  | 
| 82 | /*! | 
| 83 |     Returns whether this geographical object and \a other are not equal. | 
| 84 | */ | 
| 85 | bool QGeoMapObject::operator !=(const QGeoMapObject &other) const | 
| 86 | { | 
| 87 |     return !(operator==(other)); | 
| 88 | } | 
| 89 |  | 
| 90 | /*! | 
| 91 |   \internal | 
| 92 |   Returns which features are supported by the geographical object | 
| 93 | */ | 
| 94 | QGeoMapObject::Features QGeoMapObject::features() const | 
| 95 | { | 
| 96 |     return d_ptr->features(); | 
| 97 | } | 
| 98 |  | 
| 99 | QGeoMapObjectPrivate *QGeoMapObject::implementation() const | 
| 100 | { | 
| 101 |     return d_ptr.data(); | 
| 102 | } | 
| 103 |  | 
| 104 | bool QGeoMapObject::setImplementation(const QExplicitlySharedDataPointer<QGeoMapObjectPrivate> &pimpl) | 
| 105 | { | 
| 106 |     if (d_ptr->type() != pimpl->type()) | 
| 107 |         return false; | 
| 108 |     d_ptr = pimpl; | 
| 109 |     return true; | 
| 110 | } | 
| 111 |  | 
| 112 | bool QGeoMapObject::implemented() const | 
| 113 | { | 
| 114 |     return !d_ptr->engineName().isEmpty(); | 
| 115 | } | 
| 116 |  | 
| 117 | bool QGeoMapObject::visible() const | 
| 118 | { | 
| 119 |     return d_ptr->visible(); | 
| 120 | } | 
| 121 |  | 
| 122 | void QGeoMapObject::setVisible(bool visible) | 
| 123 | { | 
| 124 |     if (visible == d_ptr->m_visible) | 
| 125 |         return; | 
| 126 |  | 
| 127 |     const bool oldVisible = QGeoMapObject::visible(); | 
| 128 |     d_ptr->setVisible(visible); | 
| 129 |     if (d_ptr->m_componentCompleted) | 
| 130 |         setChildrenVisibility(); | 
| 131 |     if (QGeoMapObject::visible() != oldVisible) | 
| 132 |         emit visibleChanged(); | 
| 133 | } | 
| 134 |  | 
| 135 | void QGeoMapObject::setParentVisiblity(bool visible) | 
| 136 | { | 
| 137 |     if (visible == d_ptr->m_parentVisible) | 
| 138 |         return; | 
| 139 |  | 
| 140 |     const bool oldVisible = QGeoMapObject::visible(); | 
| 141 |     d_ptr->setParentVisibility(visible); | 
| 142 |     if (d_ptr->m_componentCompleted) | 
| 143 |         setChildrenVisibility(); | 
| 144 |     if (QGeoMapObject::visible() != oldVisible) | 
| 145 |         emit visibleChanged(); | 
| 146 | } | 
| 147 |  | 
| 148 | QGeoMapObject::Type QGeoMapObject::type() const | 
| 149 | { | 
| 150 |     return d_ptr->type(); | 
| 151 | } | 
| 152 |  | 
| 153 | QList<QGeoMapObject *> QGeoMapObject::geoMapObjectChildren() const | 
| 154 | { | 
| 155 |     return quickChildren<QGeoMapObject>(); | 
| 156 | } | 
| 157 |  | 
| 158 | QGeoMapObject::QGeoMapObject(const QExplicitlySharedDataPointer<QGeoMapObjectPrivate> &dd, QObject *parent) | 
| 159 |     : QParameterizableObject(parent), d_ptr(dd) | 
| 160 | { | 
| 161 | } | 
| 162 |  | 
| 163 | void QGeoMapObject::setChildrenVisibility() | 
| 164 | { | 
| 165 |     const bool v = visible(); | 
| 166 |     const QList<QGeoMapObject *> kids = geoMapObjectChildren(); | 
| 167 |     for (auto kid : qAsConst(t: kids)) | 
| 168 |         kid->setParentVisiblity(v); | 
| 169 | } | 
| 170 |  | 
| 171 | void QGeoMapObject::classBegin() | 
| 172 | { | 
| 173 |  | 
| 174 | } | 
| 175 |  | 
| 176 | void QGeoMapObject::completeComponent() | 
| 177 | { | 
| 178 |     d_ptr->m_componentCompleted = true; | 
| 179 |     setChildrenVisibility(); | 
| 180 | } | 
| 181 |  | 
| 182 | void QGeoMapObject::componentComplete() | 
| 183 | { | 
| 184 |     completeComponent(); | 
| 185 |     emit completed(); | 
| 186 | } | 
| 187 |  | 
| 188 | void QGeoMapObject::setMap(QGeoMap *map) | 
| 189 | { | 
| 190 |     if (d_ptr->m_map == map) | 
| 191 |         return; | 
| 192 |  | 
| 193 |     if (map) { | 
| 194 |         bool oldVisible = d_ptr->m_visible; | 
| 195 |         bool oldCmponentCompleted = d_ptr->m_componentCompleted; | 
| 196 |         if (!map->createMapObjectImplementation(obj: this)) { | 
| 197 |             if (type() != ViewType) | 
| 198 |                 qWarning() << "Unsupported type "  << type(); | 
| 199 |         } | 
| 200 |         // old implementation gets destroyed if/when d_ptr gets replaced | 
| 201 |         d_ptr->m_componentCompleted = oldCmponentCompleted; | 
| 202 |         d_ptr->setVisible(oldVisible); | 
| 203 |         d_ptr->setMap(map); | 
| 204 |     } | 
| 205 |  | 
| 206 |     const QList<QGeoMapObject *> kids = geoMapObjectChildren(); | 
| 207 |     for (auto kid : kids) | 
| 208 |         kid->setMap(map); | 
| 209 |  | 
| 210 |     // Each subclass is in charge to do the equivalent of | 
| 211 |     //    if (!map) { | 
| 212 |     //        // Map was set, now it has ben re-set to NULL, but not inside d_ptr. | 
| 213 |     //        // so m_map inside d_ptr can still be used to remove itself, inside the destructor. | 
| 214 |     //        d_ptr = new QMapCircleObjectPrivateDefault(*d); | 
| 215 |     //        // Old pimpl deleted implicitly by QExplicitlySharedDataPointer | 
| 216 |     //    } | 
| 217 |     // After this method is called. | 
| 218 | } | 
| 219 |  | 
| 220 | QGeoMap *QGeoMapObject::map() const | 
| 221 | { | 
| 222 |     return d_ptr->m_map; | 
| 223 | } | 
| 224 |  | 
| 225 | QGeoShape QGeoMapObject::geoShape() const | 
| 226 | { | 
| 227 |     return d_ptr->geoShape(); | 
| 228 | } | 
| 229 |  | 
| 230 | void QGeoMapObject::setGeoShape(const QGeoShape &shape) | 
| 231 | { | 
| 232 |     d_ptr->setGeoShape(shape); | 
| 233 | } | 
| 234 |  | 
| 235 |  | 
| 236 | // | 
| 237 | // QGeoMapObjectPrivate | 
| 238 | // | 
| 239 |  | 
| 240 | QGeoMapObjectPrivate::QGeoMapObjectPrivate() | 
| 241 | { | 
| 242 | } | 
| 243 |  | 
| 244 | QGeoMapObjectPrivate::QGeoMapObjectPrivate(QGeoMapObject *q) : q(q) | 
| 245 | { | 
| 246 | } | 
| 247 |  | 
| 248 | QGeoMapObjectPrivate::QGeoMapObjectPrivate(const QGeoMapObjectPrivate &other) | 
| 249 |     :QSharedData(other) | 
| 250 |     ,q(other.q) | 
| 251 |     ,m_componentCompleted(other.m_componentCompleted) | 
| 252 |     ,m_visible(other.m_visible) | 
| 253 | { | 
| 254 |  | 
| 255 | } | 
| 256 |  | 
| 257 | QGeoMapObjectPrivate::~QGeoMapObjectPrivate() | 
| 258 | { | 
| 259 | } | 
| 260 |  | 
| 261 | bool QGeoMapObjectPrivate::operator ==(const QGeoMapObjectPrivate &other) const | 
| 262 | { | 
| 263 |     return (type() == other.type() && engineName() == other.engineName() | 
| 264 |             && equals(other)); | 
| 265 | } | 
| 266 |  | 
| 267 | QByteArray QGeoMapObjectPrivate::engineName() const | 
| 268 | { | 
| 269 |     return QByteArray(); | 
| 270 | } | 
| 271 |  | 
| 272 | QGeoMapObject::Type QGeoMapObjectPrivate::type() const | 
| 273 | { | 
| 274 |     return QGeoMapObject::InvalidType; | 
| 275 | } | 
| 276 |  | 
| 277 | QGeoMapObject::Features QGeoMapObjectPrivate::features() const | 
| 278 | { | 
| 279 |     return QGeoMapObject::NoFeature; | 
| 280 | } | 
| 281 |  | 
| 282 | bool QGeoMapObjectPrivate::equals(const QGeoMapObjectPrivate &other) const | 
| 283 | { | 
| 284 |     return (visible() == other.visible() && type() == other.type() | 
| 285 |             && engineName() == other.engineName() && features() == other.features() | 
| 286 |             && m_map == other.m_map); | 
| 287 | } | 
| 288 |  | 
| 289 | bool QGeoMapObjectPrivate::visible() const | 
| 290 | { | 
| 291 |     return m_visible && m_parentVisible; | 
| 292 | } | 
| 293 |  | 
| 294 | void QGeoMapObjectPrivate::setVisible(bool visible) | 
| 295 | { | 
| 296 |     m_visible = visible; | 
| 297 | } | 
| 298 |  | 
| 299 | void QGeoMapObjectPrivate::setParentVisibility(bool visible) | 
| 300 | { | 
| 301 |     m_parentVisible = visible; | 
| 302 | } | 
| 303 |  | 
| 304 | void QGeoMapObjectPrivate::setMap(QGeoMap *map) | 
| 305 | { | 
| 306 |     m_map = map; | 
| 307 | } | 
| 308 |  | 
| 309 | QT_END_NAMESPACE | 
| 310 |  |