From 3287e5441175fcb2612556b30ed87d89161bba3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 6 Jan 2025 09:19:36 +0100 Subject: [PATCH] Removed Google protobuf dependency --- .appveyor.yml | 8 +- .github/workflows/android.yml | 8 +- .github/workflows/linux.yml | 2 +- .github/workflows/osx.yml | 38 ++--- pbfplugin.pro | 38 +---- protobuf/vector_tile.pri | 17 -- protobuf/vector_tile.proto | 78 --------- src/data.cpp | 294 ++++++++++++++++++++++++++++++++++ src/data.h | 43 +++++ src/pbf.cpp | 67 +++----- src/pbf.h | 23 ++- src/pbfhandler.cpp | 5 +- src/style.cpp | 16 +- 13 files changed, 405 insertions(+), 232 deletions(-) delete mode 100644 protobuf/vector_tile.pri delete mode 100644 protobuf/vector_tile.proto create mode 100644 src/data.cpp create mode 100644 src/data.h diff --git a/.appveyor.yml b/.appveyor.yml index 0b65459..4652e01 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,4 +1,4 @@ -version: 3.2.{build} +version: 4.0.{build} configuration: - Release @@ -14,16 +14,14 @@ environment: install: - cmd: |- - set PATH=%QTDIR%\bin;%VCPKGDIR%\tools\protobuf;%PATH% + set PATH=%QTDIR%\bin;%PATH% call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat - vcpkg install pkgconf:x64-windows-static-md-release - vcpkg install protobuf:x64-windows-static-md-release vcpkg install zlib:x64-windows-static-md-release copy /y %VCPKGDIR%\lib\zlib.lib %VCPKGDIR%\lib\zlibstatic.lib build_script: - cmd: |- - qmake USE_PKGCONFIG=true pbfplugin.pro + qmake ZLIB=%VCPKGDIR% pbfplugin.pro nmake release artifacts: diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index c10eba0..9af6e46 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -12,10 +12,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Install protobuf compiler - run: | - sudo apt-get update - sudo apt-get install protobuf-compiler - name: set up JDK 11 uses: actions/setup-java@v4 with: @@ -41,10 +37,8 @@ jobs: version: '6.4.0' target: 'android' arch: 'android_arm64_v8a' - - name: Install Android Google Protocol Buffers - run: git clone https://github.com/tumic0/android_protobuf.git - name: Configure build - run: qmake pbfplugin.pro PROTOBUF=android_protobuf + run: qmake pbfplugin.pro - name: Build project run: make -j2 - name: Upload artifacts diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 94a2d84..9bd84f6 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -15,7 +15,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install qtbase5-dev qtbase5-dev-tools qt5-qmake libprotobuf-dev protobuf-compiler zlib1g-dev + sudo apt-get install qtbase5-dev qtbase5-dev-tools qt5-qmake zlib1g-dev - name: Configure build run: qmake pbfplugin.pro - name: Build project diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 19251b8..7ed81d1 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -6,36 +6,22 @@ on: - master jobs: - qt5: - name: QtPBFImagePlugin Qt5 build + build: + name: QtPBFImagePlugin runs-on: macos-latest steps: - - name: Set environment variables - run: echo "PATH=/opt/homebrew/opt/qt@5/bin:/opt/homebrew/opt/protobuf@21/bin:$PATH" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 - - name: Install dependencies - run: | - brew update - brew install qt@5 protobuf@21 + - name: Install Qt + uses: jurplel/install-qt-action@v4 + with: + version: '6.8.1' - name: Configure build - run: qmake PROTOBUF=/opt/homebrew/opt/protobuf@21 pbfplugin.pro - - name: Build project - run: make -j3 - - qt6: - name: QtPBFImagePlugin Qt6 build - runs-on: macos-latest - steps: - - name: Set environment variables - run: echo "PATH=/opt/homebrew/opt/qt@6/bin:/opt/homebrew/opt/protobuf@21/bin:$PATH" >> $GITHUB_ENV - - name: Checkout - uses: actions/checkout@v4 - - name: Install dependencies - run: | - brew update - brew install qt@6 protobuf@21 - - name: Configure build - run: qmake PROTOBUF=/opt/homebrew/opt/protobuf@21 pbfplugin.pro + run: qmake pbfplugin.pro QMAKE_APPLE_DEVICE_ARCHS="x86_64h arm64" - name: Build project run: make -j3 + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + path: libpbf.dylib + name: libpbf.dylib diff --git a/pbfplugin.pro b/pbfplugin.pro index 629507a..7aafa98 100644 --- a/pbfplugin.pro +++ b/pbfplugin.pro @@ -2,13 +2,10 @@ TARGET = pbf TEMPLATE = lib CONFIG += plugin QT += gui -VERSION = 3.3 +VERSION = 4.0 -PROTOS = protobuf/vector_tile.proto -include(protobuf/vector_tile.pri) - -INCLUDEPATH += ./protobuf HEADERS += src/pbfhandler.h \ + src/data.h \ src/pbfplugin.h \ src/gzip.h \ src/pbf.h \ @@ -23,6 +20,7 @@ HEADERS += src/pbfhandler.h \ src/textitem.h \ src/sprites.h SOURCES += src/pbfplugin.cpp \ + src/data.cpp \ src/pbfhandler.cpp \ src/gzip.cpp \ src/pbf.cpp \ @@ -39,45 +37,25 @@ RESOURCES += pbfplugin.qrc DEFINES += QT_NO_DEPRECATED_WARNINGS -equals(USE_PKGCONFIG, "true") { - CONFIG += link_pkgconfig - PKGCONFIG += protobuf-lite zlib -} - unix:!macx:!android { - !equals(USE_PKGCONFIG, "true") { - LIBS += -lprotobuf-lite \ - -lz - } + LIBS += -lz target.path += $$[QT_INSTALL_PLUGINS]/imageformats INSTALLS += target } win32 { - !equals(USE_PKGCONFIG, "true") { - INCLUDEPATH += $$PROTOBUF/include \ - $$ZLIB/include - LIBS += $$PROTOBUF/lib/libprotobuf-lite.lib \ - $$ZLIB/lib/zlibstatic.lib - } + INCLUDEPATH += $$ZLIB/include + LIBS += $$ZLIB/lib/zlibstatic.lib QMAKE_TARGET_PRODUCT = QtPBFImagePlugin QMAKE_TARGET_DESCRIPTION = Qt $$QT_VERSION MVT/PBF image plugin QMAKE_TARGET_COPYRIGHT = Copyright (c) 2018-2025 Martin Tuma } macx { - !equals(USE_PKGCONFIG, "true") { - INCLUDEPATH += $$PROTOBUF/include - LIBS += $$PROTOBUF/lib/libprotobuf-lite.a \ - -lz - } + LIBS += -lz } android { - !equals(USE_PKGCONFIG, "true") { - INCLUDEPATH += $$PROTOBUF/include - LIBS += $$PROTOBUF/$$ANDROID_TARGET_ARCH/libprotobuf-lite.a \ - -lz - } + LIBS += -lz top_builddir=$$shadowed($$PWD) DESTDIR = $$top_builddir/plugins diff --git a/protobuf/vector_tile.pri b/protobuf/vector_tile.pri deleted file mode 100644 index b92e31d..0000000 --- a/protobuf/vector_tile.pri +++ /dev/null @@ -1,17 +0,0 @@ -INCLUDEPATH += $$PWD -DEPENDPATH += $$PWD - -protobuf_decl.name = protobuf headers -protobuf_decl.input = PROTOS -protobuf_decl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.h -protobuf_decl.commands = protoc --cpp_out=${QMAKE_FILE_IN_PATH} --proto_path=${QMAKE_FILE_IN_PATH} ${QMAKE_FILE_NAME} -protobuf_decl.variable_out = HEADERS -QMAKE_EXTRA_COMPILERS += protobuf_decl - -protobuf_impl.name = protobuf sources -protobuf_impl.input = PROTOS -protobuf_impl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.cc -protobuf_impl.depends = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.h -protobuf_impl.commands = $$escape_expand(\n) -protobuf_impl.variable_out = SOURCES -QMAKE_EXTRA_COMPILERS += protobuf_impl diff --git a/protobuf/vector_tile.proto b/protobuf/vector_tile.proto deleted file mode 100644 index ef3d870..0000000 --- a/protobuf/vector_tile.proto +++ /dev/null @@ -1,78 +0,0 @@ -package vector_tile; - -option optimize_for = LITE_RUNTIME; - -message Tile { - - // GeomType is described in section 4.3.4 of the specification - enum GeomType { - UNKNOWN = 0; - POINT = 1; - LINESTRING = 2; - POLYGON = 3; - } - - // Variant type encoding - // The use of values is described in section 4.1 of the specification - message Value { - // Exactly one of these values must be present in a valid message - optional string string_value = 1; - optional float float_value = 2; - optional double double_value = 3; - optional int64 int_value = 4; - optional uint64 uint_value = 5; - optional sint64 sint_value = 6; - optional bool bool_value = 7; - - extensions 8 to max; - } - - // Features are described in section 4.2 of the specification - message Feature { - optional uint64 id = 1 [ default = 0 ]; - - // Tags of this feature are encoded as repeated pairs of - // integers. - // A detailed description of tags is located in sections - // 4.2 and 4.4 of the specification - repeated uint32 tags = 2 [ packed = true ]; - - // The type of geometry stored in this feature. - optional GeomType type = 3 [ default = UNKNOWN ]; - - // Contains a stream of commands and parameters (vertices). - // A detailed description on geometry encoding is located in - // section 4.3 of the specification. - repeated uint32 geometry = 4 [ packed = true ]; - } - - // Layers are described in section 4.1 of the specification - message Layer { - // Any compliant implementation must first read the version - // number encoded in this message and choose the correct - // implementation for this version number before proceeding to - // decode other parts of this message. - required uint32 version = 15 [ default = 1 ]; - - required string name = 1; - - // The actual features in this tile. - repeated Feature features = 2; - - // Dictionary encoding for keys - repeated string keys = 3; - - // Dictionary encoding for values - repeated Value values = 4; - - // Although this is an "optional" field it is required by the specification. - // See https://github.com/mapbox/vector-tile-spec/issues/47 - optional uint32 extent = 5 [ default = 4096 ]; - - extensions 16 to max; - } - - repeated Layer layers = 3; - - extensions 16 to 8191; -} diff --git a/src/data.cpp b/src/data.cpp new file mode 100644 index 0000000..565eef7 --- /dev/null +++ b/src/data.cpp @@ -0,0 +1,294 @@ +#include "data.h" + +#define TYPE(tag) (tag & 0x07) +#define FIELD(tag) (tag >> 3) + +struct CTX +{ + CTX(const QByteArray &ba) + : bp(ba.constData()), be(bp + ba.size()) {} + + const char *bp; + const char *be; + quint64 tag; +}; + +template +static bool varint(CTX &ctx, T &val) +{ + val = 0; + uint shift = 0; + + while (ctx.bp < ctx.be) { + val |= ((quint8)*ctx.bp & 0x7F) << shift; + shift += 7; + if (!((quint8)*ctx.bp++ & 0x80)) + return true; + } + + return false; +} + +static bool str(CTX &ctx, QByteArray &val) +{ + quint64 len; + + if (!varint(ctx, len)) + return false; + if (ctx.bp + len > ctx.be) + return false; + val = QByteArray::fromRawData(ctx.bp, len); + ctx.bp += len; + + return true; +} + +static bool dbl(CTX &ctx, double &val) +{ + if (ctx.bp + sizeof(val) > ctx.be) + return false; + + memcpy(&val, ctx.bp, sizeof(val)); + + return true; +} + +static bool flt(CTX &ctx, float &val) +{ + if (ctx.bp + sizeof(val) > ctx.be) + return false; + + memcpy(&val, ctx.bp, sizeof(val)); + + return true; +} + +static bool packed(CTX &ctx, QVector &vals) +{ + quint32 v; + + if (TYPE(ctx.tag) == 2) { + quint64 len; + if (!varint(ctx, len)) + return false; + const char *ee = ctx.bp + len; + if (ee > ctx.be) + return false; + while (ctx.bp < ee) { + if (!varint(ctx, v)) + return false; + vals.append(v); + } + return (ctx.bp == ee); + } else if (TYPE(ctx.tag) == 0) { + if (!varint(ctx, v)) + return false; + vals.append(v); + return true; + } else + return false; +} + +static bool skip(CTX &ctx) +{ + quint64 len = 0; + + switch (TYPE(ctx.tag)) { + case 0: + return varint(ctx, len); + case 1: + len = 8; + break; + case 2: + if (!varint(ctx, len)) + return false; + break; + case 5: + len = 4; + break; + default: + return false; + } + + if (ctx.bp + len > ctx.be) + return false; + ctx.bp += len; + + return true; +} + +static bool value(CTX &ctx, QVariant &val) +{ + QByteArray ba; + quint64 len, num; + double dnum; + float fnum; + + if (!varint(ctx, len)) + return false; + + const char *ee = ctx.bp + len; + if (ee > ctx.be) + return false; + + while (ctx.bp < ee) { + if (!varint(ctx, ctx.tag)) + return false; + + switch (FIELD(ctx.tag)) { + case 1: + if (!str(ctx, ba)) + return false; + val = QVariant(ba); + break; + case 2: + if (!flt(ctx, fnum)) + return false; + val = QVariant(fnum); + break; + case 3: + if (!dbl(ctx, dnum)) + return false; + val = QVariant(dnum); + break; + case 4: + if (!varint(ctx, num)) + return false; + val = QVariant((qint64)num); + break; + case 5: + if (!varint(ctx, num)) + return false; + val = QVariant(num); + break; + case 6: + if (!varint(ctx, num)) + return false; + val = QVariant((qint64)((num >> 1) ^ -(num & 1))); + break; + case 7: + if (!varint(ctx, num)) + return false; + val = QVariant(num ? true : false); + break; + default: + if (!skip(ctx)) + return false; + } + } + + return (ctx.bp == ee); +} + +static bool feature(CTX &ctx, Data::Feature &f) +{ + quint64 len; + quint8 e; + if (!varint(ctx, len)) + return false; + + const char *ee = ctx.bp + len; + if (ee > ctx.be) + return false; + + while (ctx.bp < ee) { + if (!varint(ctx, ctx.tag)) + return false; + + switch (FIELD(ctx.tag)) { + case 1: + if (!varint(ctx, f.id)) + return false; + break; + case 2: + if (!packed(ctx, f.tags)) + return false; + break; + case 3: + if (!varint(ctx, e)) + return false; + if (e > Data::GeomType::POLYGON) + return false; + f.type = (Data::GeomType)e; + break; + case 4: + if (!packed(ctx, f.geometry)) + return false; + break; + default: + if (!skip(ctx)) + return false; + } + } + + return (ctx.bp == ee); +} + +static bool layer(CTX &ctx, Data::Layer &l) +{ + if (ctx.tag == 0x1a) { + quint64 len; + if (!varint(ctx, len)) + return false; + + const char *ee = ctx.bp + len; + if (ee > ctx.be) + return false; + + while (ctx.bp < ee) { + if (!varint(ctx, ctx.tag)) + return false; + + switch (FIELD(ctx.tag)) { + case 1: + if (!str(ctx, l.name)) + return false; + break; + case 2: + l.features.append(Data::Feature()); + if (!feature(ctx, l.features.last())) + return false; + break; + case 3: + l.keys.append(QByteArray()); + if (!str(ctx, l.keys.last())) + return false; + break; + case 4: + l.values.append(QVariant()); + if (!value(ctx, l.values.last())) + return false; + break; + case 5: + if (!varint(ctx, l.extent)) + return false; + break; + case 15: + if (!varint(ctx, l.version)) + return false; + break; + default: + if (!skip(ctx)) + return false; + } + } + + return (ctx.bp == ee); + } else + return skip(ctx); +} + +bool Data::load(const QByteArray &ba) +{ + CTX ctx(ba); + + while (ctx.bp < ctx.be) { + if (!varint(ctx, ctx.tag)) + return false; + _layers.append(Layer()); + if (!layer(ctx, _layers.last())) + return false; + } + + return (ctx.bp == ctx.be); +} diff --git a/src/data.h b/src/data.h new file mode 100644 index 0000000..4bf6257 --- /dev/null +++ b/src/data.h @@ -0,0 +1,43 @@ +#ifndef DATA_H +#define DATA_H + +#include +#include +#include + +class Data +{ +public: + enum GeomType { + UNKNOWN = 0, + POINT = 1, + LINESTRING = 2, + POLYGON = 3 + }; + + struct Feature + { + quint64 id; + QVector tags; + GeomType type; + QVector geometry; + }; + + struct Layer + { + quint32 version; + QByteArray name; + QVector features; + QVector keys; + QVector values; + quint32 extent; + }; + + bool load(const QByteArray &ba); + const QVector &layers() const {return _layers;} + +private: + QVector _layers; +}; + +#endif // DATA_H diff --git a/src/pbf.cpp b/src/pbf.cpp index 4d82cc3..99f07fc 100644 --- a/src/pbf.cpp +++ b/src/pbf.cpp @@ -4,7 +4,6 @@ #define LINE_TO 2 #define CLOSE_PATH 7 - static inline qint32 zigzag32decode(quint32 value) { return static_cast((value >> 1u) ^ static_cast( @@ -16,26 +15,6 @@ static inline QPoint parameters(quint32 v1, quint32 v2) return QPoint(zigzag32decode(v1), zigzag32decode(v2)); } -static QVariant value(const vector_tile::Tile_Value &val) -{ - if (val.has_bool_value()) - return QVariant(val.bool_value()); - else if (val.has_int_value()) - return QVariant((qlonglong)val.int_value()); - else if (val.has_sint_value()) - return QVariant((qlonglong)val.sint_value()); - else if (val.has_uint_value()) - return QVariant((qulonglong)val.uint_value()); - else if (val.has_float_value()) - return QVariant(val.float_value()); - else if (val.has_double_value()) - return QVariant(val.double_value()); - else if (val.has_string_value()) - return QVariant(QByteArray::fromStdString(val.string_value())); - else - return QVariant(); -} - const QVariant *PBF::Feature::value(const QByteArray &key) const { const KeyHash &keys(_layer->keys()); @@ -43,10 +22,10 @@ const QVariant *PBF::Feature::value(const QByteArray &key) const if (it == keys.constEnd()) return 0; - google::protobuf::uint32 index = *it; - for (int i = 0; i < _data->tags_size(); i = i + 2) - if (_data->tags(i) == index) - return &(_layer->values().at(_data->tags(i+1))); + quint32 index = *it; + for (int i = 0; i < _data->tags.size(); i = i + 2) + if (_data->tags.at(i) == index) + return &(_layer->values().at(_data->tags.at(i+1))); return 0; } @@ -56,15 +35,15 @@ QPainterPath PBF::Feature::path(const QSizeF &factor) const QPoint cursor; QPainterPath path; - for (int i = 0; i < _data->geometry_size(); i++) { - quint32 g = _data->geometry(i); + for (int i = 0; i < _data->geometry.size(); i++) { + quint32 g = _data->geometry.at(i); unsigned cmdId = g & 0x7; unsigned cmdCount = g >> 3; if (cmdId == MOVE_TO) { for (unsigned j = 0; j < cmdCount; j++) { - QPoint offset = parameters(_data->geometry(i+1), - _data->geometry(i+2)); + QPoint offset = parameters(_data->geometry.at(i+1), + _data->geometry.at(i+2)); i += 2; cursor += offset; path.moveTo(QPointF(cursor.x() * factor.width(), @@ -72,8 +51,8 @@ QPainterPath PBF::Feature::path(const QSizeF &factor) const } } else if (cmdId == LINE_TO) { for (unsigned j = 0; j < cmdCount; j++) { - QPoint offset = parameters(_data->geometry(i+1), - _data->geometry(i+2)); + QPoint offset = parameters(_data->geometry.at(i+1), + _data->geometry.at(i+2)); i += 2; cursor += offset; path.lineTo(QPointF(cursor.x() * factor.width(), @@ -88,27 +67,23 @@ QPainterPath PBF::Feature::path(const QSizeF &factor) const return path; } -PBF::Layer::Layer(const vector_tile::Tile_Layer *data) : _data(data) +PBF::Layer::Layer(const Data::Layer *layer) : _data(layer) { - _keys.reserve(data->keys_size()); - for (int i = 0; i < data->keys_size(); i++) - _keys.insert(QByteArray::fromStdString(data->keys(i)), i); - _values.reserve(data->values_size()); - for (int i = 0; i < data->values_size(); i++) - _values.append(value(data->values(i))); + _keys.reserve(layer->keys.size()); + for (int i = 0; i < layer->keys.size(); i++) + _keys.insert(layer->keys.at(i), i); - _features.reserve(data->features_size()); - for (int i = 0; i < data->features_size(); i++) - _features.append(Feature(&(data->features(i)), this)); + _features.reserve(layer->features.size()); + for (int i = 0; i < layer->features.size(); i++) + _features.append(Feature(&(layer->features.at(i)), this)); std::sort(_features.begin(), _features.end()); } -PBF::PBF(const vector_tile::Tile &tile) +PBF::PBF(const Data &data) { - for (int i = 0; i < tile.layers_size(); i++) { - const vector_tile::Tile_Layer &layer = tile.layers(i); - _layers.insert(QByteArray::fromStdString(layer.name()), - new Layer(&layer)); + for (int i = 0; i < data.layers().size(); i++) { + const Data::Layer &layer = data.layers().at(i); + _layers.insert(layer.name, new Layer(&layer)); } } diff --git a/src/pbf.h b/src/pbf.h index 2b1bd4d..236f9bd 100644 --- a/src/pbf.h +++ b/src/pbf.h @@ -5,10 +5,10 @@ #include #include #include -#include "vector_tile.pb.h" +#include "data.h" -typedef QHash KeyHash; +typedef QHash KeyHash; class PBF { @@ -19,17 +19,17 @@ public: { public: Feature() : _data(0), _layer(0) {} - Feature(const vector_tile::Tile_Feature *data, const Layer *layer) + Feature(const Data::Feature *data, const Layer *layer) : _data(data), _layer(layer) {} const QVariant *value(const QByteArray &key) const; - vector_tile::Tile_GeomType type() const {return _data->type();} + Data::GeomType type() const {return _data->type;} QPainterPath path(const QSizeF &factor) const; friend bool operator<(const Feature &f1, const Feature &f2); private: - const vector_tile::Tile_Feature *_data; + const Data::Feature *_data; const Layer *_layer; }; @@ -37,22 +37,21 @@ public: { public: - Layer(const vector_tile::Tile_Layer *data); + Layer(const Data::Layer *layer); const QVector &features() const {return _features;} - const QVector &values() const {return _values;} + const QVector &values() const {return _data->values;} const KeyHash &keys() const {return _keys;} - const vector_tile::Tile_Layer *data() const {return _data;} + const Data::Layer *data() const {return _data;} private: - const vector_tile::Tile_Layer *_data; + const Data::Layer *_data; QVector _features; - QVector _values; KeyHash _keys; }; - PBF(const vector_tile::Tile &tile); + PBF(const Data &data); ~PBF(); const QHash &layers() const {return _layers;} @@ -62,6 +61,6 @@ private: }; inline bool operator<(const PBF::Feature &f1, const PBF::Feature &f2) - {return f1._data->id() < f2._data->id();} + {return f1._data->id < f2._data->id;} #endif // PBF_H diff --git a/src/pbfhandler.cpp b/src/pbfhandler.cpp index 2810ea2..78abeb4 100644 --- a/src/pbfhandler.cpp +++ b/src/pbfhandler.cpp @@ -3,6 +3,7 @@ #include #include #include "gzip.h" +#include "data.h" #include "tile.h" #include "style.h" #include "pbfhandler.h" @@ -73,8 +74,8 @@ bool PBFHandler::read(QImage *image) } } else if (isPlainPBF(magic)) ba = device()->readAll(); - vector_tile::Tile data; - if (!data.ParseFromArray(ba.constData(), ba.size())) { + Data data; + if (!data.load(ba)) { qCritical() << "Invalid PBF data"; return false; } diff --git a/src/style.cpp b/src/style.cpp index f314364..b4c3cb0 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -14,16 +14,16 @@ #include "style.h" -static vector_tile::Tile_GeomType geometryType(const QString &str) +static Data::GeomType geometryType(const QString &str) { if (str == "Point") - return vector_tile::Tile_GeomType_POINT; + return Data::GeomType::POINT; else if (str == "LineString") - return vector_tile::Tile_GeomType_LINESTRING; + return Data::GeomType::LINESTRING; else if (str == "Polygon") - return vector_tile::Tile_GeomType_POLYGON; + return Data::GeomType::POLYGON; else - return vector_tile::Tile_GeomType_UNKNOWN; + return Data::GeomType::UNKNOWN; } static QVariant variant(const QJsonValue &val) @@ -680,15 +680,15 @@ void Style::drawFeature(const PBF::Feature &feature, const Layer &layer, void Style::drawLayer(const PBF::Layer &pbfLayer, const Layer &styleLayer, Tile &tile) { - if (pbfLayer.data()->version() > 2) + if (pbfLayer.data()->version > 2) return; if (!styleLayer.isVisible()) return; QSizeF factor(tile.size().width() / tile.scale().x() / - (qreal)pbfLayer.data()->extent(), tile.size().height() / tile.scale().y() - / (qreal)pbfLayer.data()->extent()); + (qreal)pbfLayer.data()->extent, tile.size().height() / tile.scale().y() + / (qreal)pbfLayer.data()->extent); tile.painter().save(); setupLayer(tile, styleLayer);