mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-23 19:25:55 +01:00
Use faster data structures
This commit is contained in:
parent
8e9df6cc0e
commit
078fc93783
12
src/pbf.cpp
12
src/pbf.cpp
@ -1,7 +1,7 @@
|
||||
#include <QByteArray>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QVariantMap>
|
||||
#include <QVariantHash>
|
||||
#include "vector_tile.pb.h"
|
||||
#include "style.h"
|
||||
#include "tile.h"
|
||||
@ -40,6 +40,7 @@ static QVariant value(const vector_tile::Tile_Value &val)
|
||||
class Feature
|
||||
{
|
||||
public:
|
||||
Feature() : _data(0) {}
|
||||
Feature(const vector_tile::Tile_Feature *data, const QVector<QString> *keys,
|
||||
const QVector<QVariant> *values) : _data(data)
|
||||
{
|
||||
@ -61,11 +62,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const QVariantMap &tags() const {return _tags;}
|
||||
const QVariantHash &tags() const {return _tags;}
|
||||
const vector_tile::Tile_Feature *data() const {return _data;}
|
||||
|
||||
private:
|
||||
QVariantMap _tags;
|
||||
QVariantHash _tags;
|
||||
const vector_tile::Tile_Feature *_data;
|
||||
};
|
||||
|
||||
@ -87,17 +88,18 @@ public:
|
||||
for (int i = 0; i < data->values_size(); i++)
|
||||
values.append(value(data->values(i)));
|
||||
|
||||
_features.reserve(data->features_size());
|
||||
for (int i = 0; i < data->features_size(); i++)
|
||||
_features.append(Feature(&(data->features(i)), &keys, &values));
|
||||
qSort(_features.begin(), _features.end(), cmp);
|
||||
}
|
||||
|
||||
const QList<Feature> &features() const {return _features;}
|
||||
const QVector<Feature> &features() const {return _features;}
|
||||
const vector_tile::Tile_Layer *data() const {return _data;}
|
||||
|
||||
private:
|
||||
const vector_tile::Tile_Layer *_data;
|
||||
QList<Feature> _features;
|
||||
QVector<Feature> _features;
|
||||
};
|
||||
|
||||
static inline qint32 zigzag32decode(quint32 value)
|
||||
|
@ -96,7 +96,7 @@ Style::Layer::Filter::Filter(const QJsonArray &json)
|
||||
INVALID_FILTER(json);
|
||||
}
|
||||
|
||||
bool Style::Layer::Filter::match(const QVariantMap &tags) const
|
||||
bool Style::Layer::Filter::match(const QVariantHash &tags) const
|
||||
{
|
||||
switch (_type) {
|
||||
case None:
|
||||
@ -363,7 +363,7 @@ Style::Layer::Layer(const QJsonObject &json)
|
||||
_paint = Paint(json["paint"].toObject());
|
||||
}
|
||||
|
||||
bool Style::Layer::match(int zoom, const QVariantMap &tags) const
|
||||
bool Style::Layer::match(int zoom, const QVariantHash &tags) const
|
||||
{
|
||||
if (zoom >= 0) {
|
||||
if (_minZoom > 0 && zoom < _minZoom)
|
||||
@ -397,7 +397,7 @@ void Style::Layer::drawPath(int zoom, const QPainterPath &path,
|
||||
}
|
||||
|
||||
void Style::Layer::drawSymbol(int zoom, const QPainterPath &path,
|
||||
const QVariantMap &tags, Tile &tile) const
|
||||
const QVariantHash &tags, Tile &tile) const
|
||||
{
|
||||
if (_layout.keys().isEmpty())
|
||||
return;
|
||||
@ -455,13 +455,13 @@ bool Style::load(const QString &fileName)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Style::match(int layer, const QVariantMap &tags)
|
||||
bool Style::match(int layer, const QVariantHash &tags)
|
||||
{
|
||||
return _styles.at(layer).match(_zoom, tags);
|
||||
}
|
||||
|
||||
void Style::drawFeature(int layer, const QPainterPath &path,
|
||||
const QVariantMap &tags, Tile &tile)
|
||||
const QVariantHash &tags, Tile &tile)
|
||||
{
|
||||
const Layer &sl = _styles.at(layer);
|
||||
|
||||
|
12
src/style.h
12
src/style.h
@ -3,7 +3,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QVariantMap>
|
||||
#include <QVariantHash>
|
||||
#include <QStringList>
|
||||
#include <QSet>
|
||||
#include <QPen>
|
||||
@ -26,11 +26,11 @@ public:
|
||||
void setZoom(int zoom) {_zoom = zoom;}
|
||||
|
||||
const QStringList &sourceLayers() const {return _sourceLayers;}
|
||||
bool match(int layer, const QVariantMap &tags);
|
||||
bool match(int layer, const QVariantHash &tags);
|
||||
|
||||
void drawBackground(Tile &tile);
|
||||
void drawFeature(int layer, const QPainterPath &path,
|
||||
const QVariantMap &tags, Tile &tile);
|
||||
const QVariantHash &tags, Tile &tile);
|
||||
|
||||
private:
|
||||
class Layer {
|
||||
@ -42,10 +42,10 @@ private:
|
||||
bool isBackground() const {return (_type == Background);}
|
||||
bool isSymbol() const {return (_type == Symbol);}
|
||||
|
||||
bool match(int zoom, const QVariantMap &tags) const;
|
||||
bool match(int zoom, const QVariantHash &tags) const;
|
||||
void drawPath(int zoom, const QPainterPath &path, Tile &tile) const;
|
||||
void drawSymbol(int zoom, const QPainterPath &path,
|
||||
const QVariantMap &tags, Tile &tile) const;
|
||||
const QVariantHash &tags, Tile &tile) const;
|
||||
|
||||
private:
|
||||
enum Type {
|
||||
@ -61,7 +61,7 @@ private:
|
||||
Filter() : _type(None) {}
|
||||
Filter(const QJsonArray &json);
|
||||
|
||||
bool match(const QVariantMap &tags) const;
|
||||
bool match(const QVariantHash &tags) const;
|
||||
private:
|
||||
enum Type {
|
||||
None, Unknown,
|
||||
|
Loading…
Reference in New Issue
Block a user