summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-02-20 15:06:26 +0100
committerKonstantin Käfer <mail@kkaefer.com>2018-02-21 14:50:13 +0100
commit021e1ae596440cfdee5ffe75907b76069ae44307 (patch)
treeebf15ff8a72e5f14291ba37b6f297ca9a738eea4 /platform/qt
parent06213d9145d3b20b63e235cc25678fd76dc296d0 (diff)
downloadqtlocation-mapboxgl-upstream/blob.tar.gz
[core] introduce Blob for compressed and uncompressed dataupstream/blob
- Blob is a wrapper type for a shared_ptr<const string> that has accessor functions for getting compressed and uncompressed data - Moved util::writeFile, util::readFile, util::compress, util::uncompress, decodeImage, and encodePNG to the Blob interface - Added Blob support to Request and file sources - Added Blob support to VectorTile objects - Added support for gzip decoding to util::uncompress - We're no longer compressing WebP, PNG, and JPEG data when storing in the OfflineDatabase - Android's HTTPRequest returns compressed Blobs by default One caveat is that our previous decompress function didn't support gzip, so once users upgrade to this version, their offline cache may contain both zlib-compressed data and gzip-compressed data, but older versions won't be able to decompress gzip data. On the other hand, we don't support downgrading SDKs anyway, so this shouldn't be a problem. To be on the safe side, we could bump the user_version of the SQLite DB.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/http_request.cpp4
-rw-r--r--platform/qt/src/qmapboxgl.cpp4
-rw-r--r--platform/qt/src/qt_image.cpp11
-rw-r--r--platform/qt/test/qmapboxgl.test.cpp2
4 files changed, 11 insertions, 10 deletions
diff --git a/platform/qt/src/http_request.cpp b/platform/qt/src/http_request.cpp
index ea3f388bd5..4e2143ba8e 100644
--- a/platform/qt/src/http_request.cpp
+++ b/platform/qt/src/http_request.cpp
@@ -99,9 +99,9 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply, const QByteArray& dat
switch(responseCode) {
case 200: {
if (data.isEmpty()) {
- response.data = std::make_shared<std::string>();
+ response.data = Blob{ "", false };
} else {
- response.data = std::make_shared<std::string>(data.constData(), data.size());
+ response.data = Blob{ std::string{ data.constData(), static_cast<size_t>(data.size()) }, false };
}
break;
}
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 414b65255c..e054d88489 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -585,12 +585,12 @@ void QMapboxGL::cycleDebugOptions()
*/
QString QMapboxGL::styleJson() const
{
- return QString::fromStdString(d_ptr->mapObj->getStyle().getJSON());
+ return QString::fromStdString(*d_ptr->mapObj->getStyle().getJSON().uncompressedData());
}
void QMapboxGL::setStyleJson(const QString &style)
{
- d_ptr->mapObj->getStyle().loadJSON(style.toStdString());
+ d_ptr->mapObj->getStyle().loadJSON(mbgl::Blob{ style.toStdString(), false });
}
/*!
diff --git a/platform/qt/src/qt_image.cpp b/platform/qt/src/qt_image.cpp
index a5c92514c1..ff45b02ef1 100644
--- a/platform/qt/src/qt_image.cpp
+++ b/platform/qt/src/qt_image.cpp
@@ -6,7 +6,7 @@
namespace mbgl {
-std::string encodePNG(const PremultipliedImage& pre) {
+Blob encodePNG(const PremultipliedImage& pre) {
QImage image(pre.data.get(), pre.size.width, pre.size.height,
QImage::Format_ARGB32_Premultiplied);
@@ -16,7 +16,7 @@ std::string encodePNG(const PremultipliedImage& pre) {
buffer.open(QIODevice::WriteOnly);
image.rgbSwapped().save(&buffer, "PNG");
- return std::string(array.constData(), array.size());
+ return { std::string(array.constData(), array.size()), false };
}
#if !defined(QT_IMAGE_DECODERS)
@@ -24,9 +24,10 @@ PremultipliedImage decodeJPEG(const uint8_t*, size_t);
PremultipliedImage decodeWebP(const uint8_t*, size_t);
#endif
-PremultipliedImage decodeImage(const std::string& string) {
- const uint8_t* data = reinterpret_cast<const uint8_t*>(string.data());
- const size_t size = string.size();
+PremultipliedImage decodeImage(Blob blob) {
+ const auto uncompressed = blob.uncompressedData();
+ const uint8_t* data = reinterpret_cast<const uint8_t*>(uncompressed->data());
+ const size_t size = uncompressed->size();
#if !defined(QT_IMAGE_DECODERS)
if (size >= 12) {
diff --git a/platform/qt/test/qmapboxgl.test.cpp b/platform/qt/test/qmapboxgl.test.cpp
index 2a56b346a3..607cdd6ba9 100644
--- a/platform/qt/test/qmapboxgl.test.cpp
+++ b/platform/qt/test/qmapboxgl.test.cpp
@@ -47,7 +47,7 @@ void QMapboxGLTest::onNeedsRendering() {
TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleJson)) {
QString json = QString::fromStdString(
- mbgl::util::read_file("test/fixtures/resources/style_vector.json"));
+ *mbgl::util::readFile("test/fixtures/resources/style_vector.json").uncompressedData());
map.setStyleJson(json);
ASSERT_EQ(map.styleJson(), json);