diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-04-28 14:00:39 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-05-21 08:13:17 +0000 |
commit | 3c674e0ec3fcbb1acebd27580ef005d7f6726719 (patch) | |
tree | 970902e2baa57b31bd2851ec1b987e4f70eeb4b1 /src/plugins | |
parent | 52b887a8004029cf18942b5d16b1dcf396feabc0 (diff) | |
download | qtlocation-3c674e0ec3fcbb1acebd27580ef005d7f6726719.tar.gz |
Fix missing guarded pointers for mapping engine
Since mapping engine is going to be destroyed
on geoseriveprovider change/plugin unload use
QPointer to track engine existence before
making calls.
This commit refactors a bit QGeoTileRequestManager
to handle all the calls to the enigne. Check for
null pointer before calling the engine. Move
registerMap method to base class.
Update QGeoTiledMapNokia class accordingly.
Change-Id: I886e85e660b2c515e4a617e98e9cc0c3c13781b6
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp | 38 | ||||
-rw-r--r-- | src/plugins/geoservices/nokia/qgeotiledmap_nokia.h | 14 |
2 files changed, 29 insertions, 23 deletions
diff --git a/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp index fa8a7831..bf58ad34 100644 --- a/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp @@ -56,7 +56,8 @@ QT_BEGIN_NAMESPACE */ QGeoTiledMapNokia::QGeoTiledMapNokia(QGeoTiledMappingManagerEngineNokia *engine, QObject *parent /*= 0*/) : QGeoTiledMap(engine, parent), - logo(":/images/logo.png") // HERE logo image + m_logo(":/images/logo.png"), // HERE logo image + m_engine(engine) {} QGeoTiledMapNokia::~QGeoTiledMapNokia() {} @@ -67,10 +68,12 @@ void QGeoTiledMapNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTile const int blurRate = 1; const int fontSize = 10; - QGeoTiledMappingManagerEngineNokia *engineNokia = static_cast<QGeoTiledMappingManagerEngineNokia *>(engine()); - const QString copyrightsString = engineNokia->evaluateCopyrightsText(activeMapType(), mapController()->zoom(), visibleTiles); + if (m_engine.isNull()) + return; - if (width() > 0 && height() > 0 && ((copyrightsString.isNull() && copyrightsSlab.isNull()) || copyrightsString != lastCopyrightsString)) { + const QString copyrightsString = m_engine->evaluateCopyrightsText(activeMapType(), mapController()->zoom(), visibleTiles); + + if (width() > 0 && height() > 0 && ((copyrightsString.isNull() && m_copyrightsSlab.isNull()) || copyrightsString != m_lastCopyrightsString)) { QFont font("Sans Serif"); font.setPixelSize(fontSize); font.setStyleHint(QFont::SansSerif); @@ -78,39 +81,42 @@ void QGeoTiledMapNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTile QRect textBounds = QFontMetrics(font).boundingRect(0, 0, width(), height(), Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, copyrightsString); - copyrightsSlab = QImage(logo.width() + textBounds.width() + spaceToLogo + blurRate * 2, - qMax(logo.height(), textBounds.height() + blurRate * 2), + m_copyrightsSlab = QImage(m_logo.width() + textBounds.width() + spaceToLogo + blurRate * 2, + qMax(m_logo.height(), textBounds.height() + blurRate * 2), QImage::Format_ARGB32_Premultiplied); - copyrightsSlab.fill(Qt::transparent); + m_copyrightsSlab.fill(Qt::transparent); - QPainter painter(©rightsSlab); - painter.drawImage(QPoint(0, copyrightsSlab.height() - logo.height()), logo); + QPainter painter(&m_copyrightsSlab); + painter.drawImage(QPoint(0, m_copyrightsSlab.height() - m_logo.height()), m_logo); painter.setFont(font); painter.setPen(QColor(0, 0, 0, 64)); - painter.translate(spaceToLogo + logo.width(), -blurRate); + painter.translate(spaceToLogo + m_logo.width(), -blurRate); for (int x=-blurRate; x<=blurRate; ++x) { for (int y=-blurRate; y<=blurRate; ++y) { - painter.drawText(x, y, textBounds.width(), copyrightsSlab.height(), + painter.drawText(x, y, textBounds.width(), m_copyrightsSlab.height(), Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, copyrightsString); } } painter.setPen(Qt::white); - painter.drawText(0, 0, textBounds.width(), copyrightsSlab.height(), + painter.drawText(0, 0, textBounds.width(), m_copyrightsSlab.height(), Qt::AlignBottom | Qt::AlignLeft | Qt::TextWordWrap, copyrightsString); painter.end(); - lastCopyrightsString = copyrightsString; + m_lastCopyrightsString = copyrightsString; } - emit copyrightsChanged(copyrightsSlab); + emit copyrightsChanged(m_copyrightsSlab); } int QGeoTiledMapNokia::mapVersion() { - QGeoTiledMappingManagerEngineNokia *engineNokia = static_cast<QGeoTiledMappingManagerEngineNokia *>(engine()); - return engineNokia->mapVersion(); + if (!m_engine.isNull()) + return m_engine->mapVersion(); + else + return QGeoTiledMap::mapVersion(); + } QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeotiledmap_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmap_nokia.h index 776c9322..d0253343 100644 --- a/src/plugins/geoservices/nokia/qgeotiledmap_nokia.h +++ b/src/plugins/geoservices/nokia/qgeotiledmap_nokia.h @@ -38,8 +38,8 @@ #define QGEOMAP_NOKIA_H #include "qgeotiledmap_p.h" -#include <QImage> -#include <QSize> +#include <QtGui/QImage> +#include <QtCore/QPointer> QT_BEGIN_NAMESPACE @@ -56,13 +56,13 @@ public: void evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles); int mapVersion(); - private: - Q_DISABLE_COPY(QGeoTiledMapNokia) + QImage m_logo; + QImage m_copyrightsSlab; + QString m_lastCopyrightsString; + QPointer<QGeoTiledMappingManagerEngineNokia> m_engine; - QImage logo; - QImage copyrightsSlab; - QString lastCopyrightsString; + Q_DISABLE_COPY(QGeoTiledMapNokia) }; QT_END_NAMESPACE |