summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2018-11-08 14:34:32 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2018-11-12 22:35:15 +0200
commita4a8ae5f32191c21ea8cc3bffb4b6f6b67fd1f9c (patch)
treeab3d4bd20aa9a91186f544adfe27705057b051cc
parent41dd886ce5e0b20657d7b859b775949055129906 (diff)
downloadqtlocation-mapboxgl-upstream/tmpsantos-fs_crash.tar.gz
-rw-r--r--CMakeLists.txt5
-rw-r--r--platform/default/default_file_source.cpp1
-rw-r--r--platform/qt/app/main.cpp11
-rw-r--r--platform/qt/app/mapwindow.cpp439
-rw-r--r--platform/qt/app/mapwindow.hpp41
5 files changed, 14 insertions, 483 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b37a69a83e..4ed256e1af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -80,11 +80,6 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wno-variadic-macros -Wno-unknown-pragmas")
endif()
-if (WITH_ERROR)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
-endif()
-
if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
# -Wno-error=unused-command-line-argument is required due to https://llvm.org/bugs/show_bug.cgi?id=7798
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-command-line-argument")
diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp
index 99e5c4dff3..56634bb391 100644
--- a/platform/default/default_file_source.cpp
+++ b/platform/default/default_file_source.cpp
@@ -106,6 +106,7 @@ public:
// Try the offline database
if (resource.hasLoadingMethod(Resource::LoadingMethod::Cache)) {
auto offlineResponse = offlineDatabase->get(resource);
+ offlineResponse = {};
if (resource.loadingMethod == Resource::LoadingMethod::CacheOnly) {
if (!offlineResponse) {
diff --git a/platform/qt/app/main.cpp b/platform/qt/app/main.cpp
index 851674b5a6..69550ff4f6 100644
--- a/platform/qt/app/main.cpp
+++ b/platform/qt/app/main.cpp
@@ -10,13 +10,10 @@ int main(int argc, char **argv)
settings.setCacheDatabasePath("/tmp/mbgl-cache.db");
settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
- MapWindow window(settings);
-
- window.resize(800, 600);
- window.show();
-
- if (argc == 2 && QString("--test") == argv[1]) {
- window.selfTest();
+ for (int i = 0; i < 30; i++) {
+ auto window = new MapWindow(settings);
+ window->resize(800, 600);
+ window->show();
}
return app.exec();
diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp
index 536731929e..9be16f6d11 100644
--- a/platform/qt/app/mapwindow.cpp
+++ b/platform/qt/app/mapwindow.cpp
@@ -1,20 +1,8 @@
#include "mapwindow.hpp"
-#include <QApplication>
-#include <QColor>
-#include <QDebug>
-#include <QFile>
#include <QIcon>
-#include <QKeyEvent>
-#include <QMouseEvent>
#include <QString>
-
-#if QT_VERSION >= 0x050000
#include <QWindow>
-#endif
-
-int kAnimationDuration = 10000;
-
MapWindow::MapWindow(const QMapboxGLSettings &settings)
: m_settings(settings)
@@ -29,412 +17,8 @@ MapWindow::~MapWindow()
makeCurrent();
}
-void MapWindow::selfTest()
-{
- if (m_bearingAnimation) {
- m_bearingAnimation->setDuration(kAnimationDuration);
- m_bearingAnimation->setEndValue(m_map->bearing() + 360 * 4);
- m_bearingAnimation->start();
- }
-
- if (m_zoomAnimation) {
- m_zoomAnimation->setDuration(kAnimationDuration);
- m_zoomAnimation->setEndValue(m_map->zoom() + 3);
- m_zoomAnimation->start();
- }
-}
-
qreal MapWindow::pixelRatio() {
-#if QT_VERSION >= 0x050600
return devicePixelRatioF();
-#elif QT_VERSION >= 0x050000
- return devicePixelRatio();
-#else
- return 1;
-#endif
-}
-
-
-void MapWindow::animationFinished()
-{
- qDebug() << "Animation ticks/s: " << m_animationTicks / static_cast<float>(kAnimationDuration) * 1000.;
- qDebug() << "Frame draws/s: " << m_frameDraws / static_cast<float>(kAnimationDuration) * 1000.;
-
- qApp->quit();
-}
-
-void MapWindow::animationValueChanged()
-{
- m_animationTicks++;
-}
-
-void MapWindow::changeStyle()
-{
- static uint8_t currentStyleIndex;
-
- auto& styles = QMapbox::defaultStyles();
-
- m_map->setStyleUrl(styles[currentStyleIndex].first);
- setWindowTitle(QString("Mapbox GL: ") + styles[currentStyleIndex].second);
-
- if (++currentStyleIndex == styles.size()) {
- currentStyleIndex = 0;
- }
-
- m_sourceAdded = false;
-}
-
-void MapWindow::keyPressEvent(QKeyEvent *ev)
-{
- switch (ev->key()) {
- case Qt::Key_S:
- changeStyle();
- break;
- case Qt::Key_L: {
- if (m_sourceAdded) {
- return;
- }
-
- m_sourceAdded = true;
-
- // Not in all styles, but will work on streets
- QString before = "waterway-label";
-
- QFile geojson(":source1.geojson");
- geojson.open(QIODevice::ReadOnly);
-
- // The data source for the route line and markers
- QVariantMap routeSource;
- routeSource["type"] = "geojson";
- routeSource["data"] = geojson.readAll();
- m_map->addSource("routeSource", routeSource);
-
- // The route case, painted before the route
- QVariantMap routeCase;
- routeCase["id"] = "routeCase";
- routeCase["type"] = "line";
- routeCase["source"] = "routeSource";
- m_map->addLayer(routeCase, before);
-
- m_map->setPaintProperty("routeCase", "line-color", QColor("white"));
- m_map->setPaintProperty("routeCase", "line-width", 20.0);
- m_map->setLayoutProperty("routeCase", "line-join", "round");
- m_map->setLayoutProperty("routeCase", "line-cap", "round");
-
- // The route, painted on top of the route case
- QVariantMap route;
- route["id"] = "route";
- route["type"] = "line";
- route["source"] = "routeSource";
- m_map->addLayer(route, before);
-
- m_map->setPaintProperty("route", "line-color", QColor("blue"));
- m_map->setPaintProperty("route", "line-width", 8.0);
- m_map->setLayoutProperty("route", "line-join", "round");
- m_map->setLayoutProperty("route", "line-cap", "round");
-
- QVariantList lineDashArray;
- lineDashArray.append(1);
- lineDashArray.append(2);
-
- m_map->setPaintProperty("route", "line-dasharray", lineDashArray);
-
- // Markers at the beginning and end of the route
- m_map->addImage("label-arrow", QImage(":label-arrow.svg"));
- m_map->addImage("label-background", QImage(":label-background.svg"));
-
- QVariantMap markerArrow;
- markerArrow["id"] = "markerArrow";
- markerArrow["type"] = "symbol";
- markerArrow["source"] = "routeSource";
- m_map->addLayer(markerArrow);
-
- m_map->setLayoutProperty("markerArrow", "icon-image", "label-arrow");
- m_map->setLayoutProperty("markerArrow", "icon-size", 0.5);
- m_map->setLayoutProperty("markerArrow", "icon-ignore-placement", true);
-
- QVariantList arrowOffset;
- arrowOffset.append(0.0);
- arrowOffset.append(-15.0);
- m_map->setLayoutProperty("markerArrow", "icon-offset", arrowOffset);
-
- QVariantMap markerBackground;
- markerBackground["id"] = "markerBackground";
- markerBackground["type"] = "symbol";
- markerBackground["source"] = "routeSource";
- m_map->addLayer(markerBackground);
-
- m_map->setLayoutProperty("markerBackground", "icon-image", "label-background");
- m_map->setLayoutProperty("markerBackground", "text-field", "{name}");
- m_map->setLayoutProperty("markerBackground", "icon-text-fit", "both");
- m_map->setLayoutProperty("markerBackground", "icon-ignore-placement", true);
- m_map->setLayoutProperty("markerBackground", "text-ignore-placement", true);
- m_map->setLayoutProperty("markerBackground", "text-anchor", "left");
- m_map->setLayoutProperty("markerBackground", "text-size", 16.0);
- m_map->setLayoutProperty("markerBackground", "text-padding", 0.0);
- m_map->setLayoutProperty("markerBackground", "text-line-height", 1.0);
- m_map->setLayoutProperty("markerBackground", "text-max-width", 8.0);
-
- QVariantList iconTextFitPadding;
- iconTextFitPadding.append(15.0);
- iconTextFitPadding.append(10.0);
- iconTextFitPadding.append(15.0);
- iconTextFitPadding.append(10.0);
- m_map->setLayoutProperty("markerBackground", "icon-text-fit-padding", iconTextFitPadding);
-
- QVariantList backgroundOffset;
- backgroundOffset.append(-0.5);
- backgroundOffset.append(-1.5);
- m_map->setLayoutProperty("markerBackground", "text-offset", backgroundOffset);
-
- m_map->setPaintProperty("markerBackground", "text-color", QColor("white"));
-
- QVariantList filterExpression;
- filterExpression.append("==");
- filterExpression.append("$type");
- filterExpression.append("Point");
-
- QVariantList filter;
- filter.append(filterExpression);
-
- m_map->setFilter("markerArrow", filter);
- m_map->setFilter("markerBackground", filter);
-
- // Tilt the labels when tilting the map and make them larger
- m_map->setLayoutProperty("road-label-large", "text-size", 30.0);
- m_map->setLayoutProperty("road-label-large", "text-pitch-alignment", "viewport");
-
- m_map->setLayoutProperty("road-label-medium", "text-size", 30.0);
- m_map->setLayoutProperty("road-label-medium", "text-pitch-alignment", "viewport");
-
- m_map->setLayoutProperty("road-label-small", "text-pitch-alignment", "viewport");
- m_map->setLayoutProperty("road-label-small", "text-size", 30.0);
-
- // Buildings extrusion
- QVariantMap buildings;
- buildings["id"] = "3d-buildings";
- buildings["source"] = "composite";
- buildings["source-layer"] = "building";
- buildings["type"] = "fill-extrusion";
- buildings["minzoom"] = 15.0;
- m_map->addLayer(buildings);
-
- QVariantList buildingsFilterExpression;
- buildingsFilterExpression.append("==");
- buildingsFilterExpression.append("extrude");
- buildingsFilterExpression.append("true");
-
- QVariantList buildingsFilter;
- buildingsFilter.append(buildingsFilterExpression);
-
- m_map->setFilter("3d-buildings", buildingsFilterExpression);
-
- QString fillExtrusionColorJSON = R"JSON(
- [
- "interpolate",
- ["linear"],
- ["get", "height"],
- 0.0, "blue",
- 20.0, "royalblue",
- 40.0, "cyan",
- 60.0, "lime",
- 80.0, "yellow",
- 100.0, "red"
- ]
- )JSON";
-
- m_map->setPaintProperty("3d-buildings", "fill-extrusion-color", fillExtrusionColorJSON);
- m_map->setPaintProperty("3d-buildings", "fill-extrusion-opacity", .6);
-
- QVariantMap extrusionHeight;
- extrusionHeight["type"] = "identity";
- extrusionHeight["property"] = "height";
-
- m_map->setPaintProperty("3d-buildings", "fill-extrusion-height", extrusionHeight);
-
- QVariantMap extrusionBase;
- extrusionBase["type"] = "identity";
- extrusionBase["property"] = "min_height";
-
- m_map->setPaintProperty("3d-buildings", "fill-extrusion-base", extrusionBase);
- }
- break;
- case Qt::Key_1: {
- if (m_symbolAnnotationId.isNull()) {
- QMapbox::Coordinate coordinate = m_map->coordinate();
- QMapbox::SymbolAnnotation symbol { coordinate, "default_marker" };
- m_map->addAnnotationIcon("default_marker", QImage(":default_marker.svg"));
- m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::SymbolAnnotation>(symbol));
- } else {
- m_map->removeAnnotation(m_symbolAnnotationId.toUInt());
- m_symbolAnnotationId.clear();
- }
- }
- break;
- case Qt::Key_2: {
- if (m_lineAnnotationId.isNull()) {
- QMapbox::Coordinates coordinates;
- coordinates.push_back(m_map->coordinateForPixel({ 0, 0 }));
- coordinates.push_back(m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) }));
-
- QMapbox::CoordinatesCollection collection;
- collection.push_back(coordinates);
-
- QMapbox::CoordinatesCollections lineGeometry;
- lineGeometry.push_back(collection);
-
- QMapbox::ShapeAnnotationGeometry annotationGeometry(QMapbox::ShapeAnnotationGeometry::LineStringType, lineGeometry);
-
- QMapbox::LineAnnotation line;
- line.geometry = annotationGeometry;
- line.opacity = 0.5f;
- line.width = 1.0f;
- line.color = Qt::red;
- m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::LineAnnotation>(line));
- } else {
- m_map->removeAnnotation(m_lineAnnotationId.toUInt());
- m_lineAnnotationId.clear();
- }
- }
- break;
- case Qt::Key_3: {
- if (m_fillAnnotationId.isNull()) {
- QMapbox::Coordinates coordinates;
- coordinates.push_back(m_map->coordinateForPixel({ qreal(size().width()), 0 }));
- coordinates.push_back(m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) }));
- coordinates.push_back(m_map->coordinateForPixel({ 0, qreal(size().height()) }));
- coordinates.push_back(m_map->coordinateForPixel({ 0, 0 }));
-
- QMapbox::CoordinatesCollection collection;
- collection.push_back(coordinates);
-
- QMapbox::CoordinatesCollections fillGeometry;
- fillGeometry.push_back(collection);
-
- QMapbox::ShapeAnnotationGeometry annotationGeometry(QMapbox::ShapeAnnotationGeometry::PolygonType, fillGeometry);
-
- QMapbox::FillAnnotation fill;
- fill.geometry = annotationGeometry;
- fill.opacity = 0.5f;
- fill.color = Qt::green;
- fill.outlineColor = QVariant::fromValue<QColor>(QColor(Qt::black));
- m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::FillAnnotation>(fill));
- } else {
- m_map->removeAnnotation(m_fillAnnotationId.toUInt());
- m_fillAnnotationId.clear();
- }
- }
- break;
- case Qt::Key_5: {
- if (m_map->layerExists("circleLayer")) {
- m_map->removeLayer("circleLayer");
- m_map->removeSource("circleSource");
- } else {
- QMapbox::Coordinates coordinates;
- coordinates.push_back(m_map->coordinate());
-
- QMapbox::CoordinatesCollection collection;
- collection.push_back(coordinates);
-
- QMapbox::CoordinatesCollections point;
- point.push_back(collection);
-
- QMapbox::Feature feature(QMapbox::Feature::PointType, point, {}, {});
-
- QVariantMap circleSource;
- circleSource["type"] = "geojson";
- circleSource["data"] = QVariant::fromValue<QMapbox::Feature>(feature);
- m_map->addSource("circleSource", circleSource);
-
- QVariantMap circle;
- circle["id"] = "circleLayer";
- circle["type"] = "circle";
- circle["source"] = "circleSource";
- m_map->addLayer(circle);
-
- m_map->setPaintProperty("circleLayer", "circle-radius", 10.0);
- m_map->setPaintProperty("circleLayer", "circle-color", QColor("black"));
- }
- }
- break;
- case Qt::Key_Tab:
- m_map->cycleDebugOptions();
- break;
- default:
- break;
- }
-
- ev->accept();
-}
-
-void MapWindow::mousePressEvent(QMouseEvent *ev)
-{
-#if QT_VERSION < 0x050000
- m_lastPos = ev->posF();
-#else
- m_lastPos = ev->localPos();
-#endif
-
- if (ev->type() == QEvent::MouseButtonPress) {
- if (ev->buttons() == (Qt::LeftButton | Qt::RightButton)) {
- changeStyle();
- }
- }
-
- if (ev->type() == QEvent::MouseButtonDblClick) {
- if (ev->buttons() == Qt::LeftButton) {
- m_map->scaleBy(2.0, m_lastPos);
- } else if (ev->buttons() == Qt::RightButton) {
- m_map->scaleBy(0.5, m_lastPos);
- }
- }
-
- ev->accept();
-}
-
-void MapWindow::mouseMoveEvent(QMouseEvent *ev)
-{
-#if QT_VERSION < 0x050000
- QPointF delta = ev->posF() - m_lastPos;
-#else
- QPointF delta = ev->localPos() - m_lastPos;
-#endif
-
- if (!delta.isNull()) {
- if (ev->buttons() == Qt::LeftButton && ev->modifiers() & Qt::ShiftModifier) {
- m_map->setPitch(m_map->pitch() - delta.y());
- } else if (ev->buttons() == Qt::LeftButton) {
- m_map->moveBy(delta);
- } else if (ev->buttons() == Qt::RightButton) {
-#if QT_VERSION < 0x050000
- m_map->rotateBy(m_lastPos, ev->posF());
-#else
- m_map->rotateBy(m_lastPos, ev->localPos());
-#endif
- }
- }
-
-#if QT_VERSION < 0x050000
- m_lastPos = ev->posF();
-#else
- m_lastPos = ev->localPos();
-#endif
- ev->accept();
-}
-
-void MapWindow::wheelEvent(QWheelEvent *ev)
-{
- if (ev->orientation() == Qt::Horizontal) {
- return;
- }
-
- float factor = ev->delta() / 1200.;
- if (ev->delta() < 0) {
- factor = factor > -1 ? factor : 1 / factor;
- }
-
- m_map->scaleBy(1 + factor, ev->pos());
- ev->accept();
}
void MapWindow::initializeGL()
@@ -445,24 +29,19 @@ void MapWindow::initializeGL()
// Set default location to Helsinki.
m_map->setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14);
- QString styleUrl = qgetenv("MAPBOX_STYLE_URL");
- if (styleUrl.isEmpty()) {
- changeStyle();
- } else {
- m_map->setStyleUrl(styleUrl);
- setWindowTitle(QString("Mapbox GL: ") + styleUrl);
- }
-
- m_bearingAnimation = new QPropertyAnimation(m_map.data(), "bearing");
- m_zoomAnimation = new QPropertyAnimation(m_map.data(), "zoom");
-
- connect(m_zoomAnimation, SIGNAL(finished()), this, SLOT(animationFinished()));
- connect(m_zoomAnimation, SIGNAL(valueChanged(const QVariant&)), this, SLOT(animationValueChanged()));
+ auto& styles = QMapbox::defaultStyles();
+ m_map->setStyleUrl(styles[0].first);
}
void MapWindow::paintGL()
{
- m_frameDraws++;
+ auto move = QPointF((rand() % 40 ) - 20, (rand() % 40) - 20 );
+ auto scale1 = ((rand() % 30 ) - 14) / 30.0 + 1.0;
+ auto scale2 = QPointF(rand() % size().width(), rand() % size().height());
+
+ m_map->moveBy(move);
+ m_map->scaleBy(scale1, scale2);
+
m_map->resize(size());
#if QT_VERSION >= 0x050400
m_map->setFramebufferObject(defaultFramebufferObject(), size() * pixelRatio());
diff --git a/platform/qt/app/mapwindow.hpp b/platform/qt/app/mapwindow.hpp
index 6c05f03562..acbfa5125f 100644
--- a/platform/qt/app/mapwindow.hpp
+++ b/platform/qt/app/mapwindow.hpp
@@ -5,25 +5,10 @@
#include <QtGlobal>
-// XXX http://stackoverflow.com/questions/24899558/how-to-check-qt-version-to-include-different-header#comment59591604_29887388
-#if QT_VERSION >= 0x050400
#include <QOpenGLWidget>
-#else
-#include <QGLWidget>
-#endif // QT_VERSION
-
-#include <QPropertyAnimation>
#include <QScopedPointer>
-class QKeyEvent;
-class QMouseEvent;
-class QWheelEvent;
-
-#if QT_VERSION >= 0x050400
class MapWindow : public QOpenGLWidget
-#else
-class MapWindow : public QGLWidget
-#endif // QT_VERSION
{
Q_OBJECT
@@ -31,42 +16,16 @@ public:
MapWindow(const QMapboxGLSettings &);
~MapWindow();
- void selfTest();
-
-protected slots:
- void animationValueChanged();
- void animationFinished();
-
private:
void changeStyle();
qreal pixelRatio();
- // QWidget implementation.
- void keyPressEvent(QKeyEvent *ev) final;
- void mousePressEvent(QMouseEvent *ev) final;
- void mouseMoveEvent(QMouseEvent *ev) final;
- void wheelEvent(QWheelEvent *ev) final;
-
// Q{,Open}GLWidget implementation.
void initializeGL() final;
void paintGL() final;
- QPointF m_lastPos;
-
QMapboxGLSettings m_settings;
QScopedPointer<QMapboxGL> m_map;
-
- QPropertyAnimation *m_bearingAnimation;
- QPropertyAnimation *m_zoomAnimation;
-
- unsigned m_animationTicks = 0;
- unsigned m_frameDraws = 0;
-
- QVariant m_symbolAnnotationId;
- QVariant m_lineAnnotationId;
- QVariant m_fillAnnotationId;
-
- bool m_sourceAdded = false;
};
#endif