mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 11:45:54 +01:00
Compare commits
No commits in common. "14dada50c4df653205d17b1413c61659f470a623" and "aeed3e3848891622e879eab0f22b8aebd91d69f2" have entirely different histories.
14dada50c4
...
aeed3e3848
@ -1,4 +1,4 @@
|
|||||||
version: 3.2.{build}
|
version: 3.1.{build}
|
||||||
|
|
||||||
configuration:
|
configuration:
|
||||||
- Release
|
- Release
|
||||||
|
@ -2,7 +2,7 @@ TARGET = pbf
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin
|
CONFIG += plugin
|
||||||
QT += gui
|
QT += gui
|
||||||
VERSION = 3.2
|
VERSION = 3.1
|
||||||
|
|
||||||
PROTOS = protobuf/vector_tile.proto
|
PROTOS = protobuf/vector_tile.proto
|
||||||
include(protobuf/vector_tile.pri)
|
include(protobuf/vector_tile.pri)
|
||||||
|
@ -31,12 +31,12 @@ static QVariant value(const vector_tile::Tile_Value &val)
|
|||||||
else if (val.has_double_value())
|
else if (val.has_double_value())
|
||||||
return QVariant(val.double_value());
|
return QVariant(val.double_value());
|
||||||
else if (val.has_string_value())
|
else if (val.has_string_value())
|
||||||
return QVariant(QByteArray::fromStdString(val.string_value()));
|
return QVariant(QString::fromStdString(val.string_value()));
|
||||||
else
|
else
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVariant *PBF::Feature::value(const QByteArray &key) const
|
const QVariant *PBF::Feature::value(const QString &key) const
|
||||||
{
|
{
|
||||||
const KeyHash &keys(_layer->keys());
|
const KeyHash &keys(_layer->keys());
|
||||||
KeyHash::const_iterator it(keys.find(key));
|
KeyHash::const_iterator it(keys.find(key));
|
||||||
@ -92,7 +92,7 @@ PBF::Layer::Layer(const vector_tile::Tile_Layer *data) : _data(data)
|
|||||||
{
|
{
|
||||||
_keys.reserve(data->keys_size());
|
_keys.reserve(data->keys_size());
|
||||||
for (int i = 0; i < data->keys_size(); i++)
|
for (int i = 0; i < data->keys_size(); i++)
|
||||||
_keys.insert(QByteArray::fromStdString(data->keys(i)), i);
|
_keys.insert(QString::fromStdString(data->keys(i)), i);
|
||||||
_values.reserve(data->values_size());
|
_values.reserve(data->values_size());
|
||||||
for (int i = 0; i < data->values_size(); i++)
|
for (int i = 0; i < data->values_size(); i++)
|
||||||
_values.append(value(data->values(i)));
|
_values.append(value(data->values(i)));
|
||||||
@ -107,8 +107,7 @@ PBF::PBF(const vector_tile::Tile &tile)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < tile.layers_size(); i++) {
|
for (int i = 0; i < tile.layers_size(); i++) {
|
||||||
const vector_tile::Tile_Layer &layer = tile.layers(i);
|
const vector_tile::Tile_Layer &layer = tile.layers(i);
|
||||||
_layers.insert(QByteArray::fromStdString(layer.name()),
|
_layers.insert(QString::fromStdString(layer.name()), new Layer(&layer));
|
||||||
new Layer(&layer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "vector_tile.pb.h"
|
#include "vector_tile.pb.h"
|
||||||
|
|
||||||
|
|
||||||
typedef QHash<QByteArray, google::protobuf::uint32> KeyHash;
|
typedef QHash<QString, google::protobuf::uint32> KeyHash;
|
||||||
|
|
||||||
class PBF
|
class PBF
|
||||||
{
|
{
|
||||||
@ -22,7 +22,7 @@ public:
|
|||||||
Feature(const vector_tile::Tile_Feature *data, const Layer *layer)
|
Feature(const vector_tile::Tile_Feature *data, const Layer *layer)
|
||||||
: _data(data), _layer(layer) {}
|
: _data(data), _layer(layer) {}
|
||||||
|
|
||||||
const QVariant *value(const QByteArray &key) const;
|
const QVariant *value(const QString &key) const;
|
||||||
vector_tile::Tile_GeomType type() const {return _data->type();}
|
vector_tile::Tile_GeomType type() const {return _data->type();}
|
||||||
QPainterPath path(const QSizeF &factor) const;
|
QPainterPath path(const QSizeF &factor) const;
|
||||||
|
|
||||||
@ -55,10 +55,10 @@ public:
|
|||||||
PBF(const vector_tile::Tile &tile);
|
PBF(const vector_tile::Tile &tile);
|
||||||
~PBF();
|
~PBF();
|
||||||
|
|
||||||
const QHash<QByteArray, Layer*> &layers() const {return _layers;}
|
const QHash<QString, Layer*> &layers() const {return _layers;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QByteArray, Layer*> _layers;
|
QHash<QString, Layer*> _layers;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator<(const PBF::Feature &f1, const PBF::Feature &f2)
|
inline bool operator<(const PBF::Feature &f1, const PBF::Feature &f2)
|
||||||
|
@ -95,25 +95,6 @@ bool Sprites::load(const QString &jsonFile, const QString &imageFile)
|
|||||||
|
|
||||||
QImage Sprites::sprite(const Sprite &sprite, const QColor &color, qreal scale)
|
QImage Sprites::sprite(const Sprite &sprite, const QColor &color, qreal scale)
|
||||||
{
|
{
|
||||||
_lock.lock();
|
|
||||||
if (_init <= 0) {
|
|
||||||
if (_init < 0) {
|
|
||||||
_lock.unlock();
|
|
||||||
return QImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
_img = QImage(_imageFile);
|
|
||||||
if (_img.isNull()) {
|
|
||||||
qWarning() << _imageFile << ": invalid sprite atlas image";
|
|
||||||
_init = -1;
|
|
||||||
_lock.unlock();
|
|
||||||
return QImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
_init = 1;
|
|
||||||
}
|
|
||||||
_lock.unlock();
|
|
||||||
|
|
||||||
if (!_img.rect().contains(sprite.rect()))
|
if (!_img.rect().contains(sprite.rect()))
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
@ -137,6 +118,25 @@ QImage Sprites::icon(const QString &name, const QColor &color, qreal size)
|
|||||||
if (name.isNull())
|
if (name.isNull())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
|
_lock.lock();
|
||||||
|
if (_init <= 0) {
|
||||||
|
if (_init < 0) {
|
||||||
|
_lock.unlock();
|
||||||
|
return QImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
_img = QImage(_imageFile);
|
||||||
|
if (_img.isNull()) {
|
||||||
|
qWarning() << _imageFile << ": invalid sprite atlas image";
|
||||||
|
_init = -1;
|
||||||
|
_lock.unlock();
|
||||||
|
return QImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
_init = 1;
|
||||||
|
}
|
||||||
|
_lock.unlock();
|
||||||
|
|
||||||
QMap<QString, Sprite>::const_iterator it = _sprites.constFind(name);
|
QMap<QString, Sprite>::const_iterator it = _sprites.constFind(name);
|
||||||
if (it == _sprites.constEnd())
|
if (it == _sprites.constEnd())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
@ -26,20 +26,6 @@ static vector_tile::Tile_GeomType geometryType(const QString &str)
|
|||||||
return vector_tile::Tile_GeomType_UNKNOWN;
|
return vector_tile::Tile_GeomType_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVariant variant(const QJsonValue &val)
|
|
||||||
{
|
|
||||||
switch (val.type()) {
|
|
||||||
case QJsonValue::String:
|
|
||||||
return QVariant(val.toString().toUtf8());
|
|
||||||
case QJsonValue::Double:
|
|
||||||
case QJsonValue::Bool:
|
|
||||||
return val.toVariant();
|
|
||||||
default:
|
|
||||||
qWarning() << val << ": invalid filter value";
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Style::Layer::Filter::Filter(const QJsonArray &json)
|
Style::Layer::Filter::Filter(const QJsonArray &json)
|
||||||
: _type(Unknown), _not(false)
|
: _type(Unknown), _not(false)
|
||||||
{
|
{
|
||||||
@ -49,50 +35,50 @@ Style::Layer::Filter::Filter(const QJsonArray &json)
|
|||||||
if (json.isEmpty())
|
if (json.isEmpty())
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
|
|
||||||
QString type(json.at(0).toString());
|
QString type = json.at(0).toString();
|
||||||
|
|
||||||
if (type == "==") {
|
if (type == "==") {
|
||||||
if (json.size() != 3)
|
if (json.size() != 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
if (json.at(1).toString() == "$type") {
|
if (json.at(1).toString() == "$type") {
|
||||||
_type = GeometryType;
|
_type = GeometryType;
|
||||||
_kv = QPair<QByteArray, QVariant>(QByteArray(),
|
_kv = QPair<QString, QVariant>(QString(),
|
||||||
QVariant(geometryType(json.at(2).toString())));
|
QVariant(geometryType(json.at(2).toString())));
|
||||||
} else {
|
} else {
|
||||||
_type = EQ;
|
_type = EQ;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
variant(json.at(2)));
|
json.at(2).toVariant());
|
||||||
}
|
}
|
||||||
} else if (type == "!=") {
|
} else if (type == "!=") {
|
||||||
if (json.size() != 3)
|
if (json.size() != 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = NE;
|
_type = NE;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
variant(json.at(2)));
|
json.at(2).toVariant());
|
||||||
} else if (type == "<") {
|
} else if (type == "<") {
|
||||||
if (json.size() != 3)
|
if (json.size() != 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = LT;
|
_type = LT;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
variant(json.at(2)));
|
json.at(2).toVariant());
|
||||||
} else if (type == "<=") {
|
} else if (type == "<=") {
|
||||||
if (json.size() != 3)
|
if (json.size() != 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = LE;
|
_type = LE;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
variant(json.at(2)));
|
json.at(2).toVariant());
|
||||||
} else if (type == ">") {
|
} else if (type == ">") {
|
||||||
if (json.size() != 3)
|
if (json.size() != 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = GT;
|
_type = GT;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
variant(json.at(2)));
|
json.at(2).toVariant());
|
||||||
} else if (type == ">=") {
|
} else if (type == ">=") {
|
||||||
if (json.size() != 3)
|
if (json.size() != 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = GE;
|
_type = GE;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(),
|
||||||
variant(json.at(2)));
|
json.at(2).toVariant());
|
||||||
} else if (type == "all") {
|
} else if (type == "all") {
|
||||||
_type = All;
|
_type = All;
|
||||||
for (int i = 1; i < json.size(); i++)
|
for (int i = 1; i < json.size(); i++)
|
||||||
@ -105,32 +91,28 @@ Style::Layer::Filter::Filter(const QJsonArray &json)
|
|||||||
if (json.size() < 3)
|
if (json.size() < 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = In;
|
_type = In;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
QVariant());
|
|
||||||
for (int i = 2; i < json.size(); i++)
|
for (int i = 2; i < json.size(); i++)
|
||||||
_set.insert(json.at(i).toString().toUtf8());
|
_set.insert(json.at(i).toString());
|
||||||
} else if (type == "!in") {
|
} else if (type == "!in") {
|
||||||
if (json.size() < 3)
|
if (json.size() < 3)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = In;
|
_type = In;
|
||||||
_not = true;
|
_not = true;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
QVariant());
|
|
||||||
for (int i = 2; i < json.size(); i++)
|
for (int i = 2; i < json.size(); i++)
|
||||||
_set.insert(json.at(i).toString().toUtf8());
|
_set.insert(json.at(i).toString());
|
||||||
} else if (type == "has") {
|
} else if (type == "has") {
|
||||||
if (json.size() < 2)
|
if (json.size() < 2)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = Has;
|
_type = Has;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
QVariant());
|
|
||||||
} else if (type == "!has") {
|
} else if (type == "!has") {
|
||||||
if (json.size() < 2)
|
if (json.size() < 2)
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
_type = Has;
|
_type = Has;
|
||||||
_not = true;
|
_not = true;
|
||||||
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
|
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
|
||||||
QVariant());
|
|
||||||
} else
|
} else
|
||||||
INVALID_FILTER(json);
|
INVALID_FILTER(json);
|
||||||
}
|
}
|
||||||
@ -200,7 +182,7 @@ bool Style::Layer::Filter::match(const PBF::Feature &feature) const
|
|||||||
if (!(v = feature.value(_kv.first)))
|
if (!(v = feature.value(_kv.first)))
|
||||||
return _not;
|
return _not;
|
||||||
else
|
else
|
||||||
return _set.contains((*v).toByteArray()) ^ _not;
|
return _set.contains((*v).toString()) ^ _not;
|
||||||
case Has:
|
case Has:
|
||||||
return (feature.value(_kv.first) ? true : false) ^ _not;
|
return (feature.value(_kv.first) ? true : false) ^ _not;
|
||||||
case All:
|
case All:
|
||||||
@ -234,7 +216,7 @@ QString Style::Layer::Template::value(int zoom, const PBF::Feature &feature) con
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < keys.size(); i++) {
|
for (int i = 0; i < keys.size(); i++) {
|
||||||
const QString &key = keys.at(i);
|
const QString &key = keys.at(i);
|
||||||
const QVariant *val = feature.value(key.toUtf8());
|
const QVariant *val = feature.value(key);
|
||||||
text.replace(QString("{%1}").arg(key), val ? val->toString() : "");
|
text.replace(QString("{%1}").arg(key), val ? val->toString() : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +486,7 @@ Style::Layer::Layer(const QJsonObject &json)
|
|||||||
_type = Symbol;
|
_type = Symbol;
|
||||||
|
|
||||||
// source-layer
|
// source-layer
|
||||||
_sourceLayer = json["source-layer"].toString().toUtf8();
|
_sourceLayer = json["source-layer"].toString();
|
||||||
|
|
||||||
// zooms
|
// zooms
|
||||||
if (json.contains("minzoom") && json["minzoom"].isDouble())
|
if (json.contains("minzoom") && json["minzoom"].isDouble())
|
||||||
@ -590,7 +572,7 @@ static bool loadSprites(const QDir &styleDir, const QString &json,
|
|||||||
if (QFileInfo::exists(spritesImg))
|
if (QFileInfo::exists(spritesImg))
|
||||||
return sprites.load(spritesJSON, spritesImg);
|
return sprites.load(spritesJSON, spritesImg);
|
||||||
else {
|
else {
|
||||||
qWarning() << spritesImg << ": no such file";
|
qCritical() << spritesImg << ": no such file";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -702,7 +684,7 @@ void Style::render(const PBF &data, Tile &tile)
|
|||||||
drawBackground(tile);
|
drawBackground(tile);
|
||||||
|
|
||||||
for (int i = 0; i < _layers.size(); i++) {
|
for (int i = 0; i < _layers.size(); i++) {
|
||||||
QHash<QByteArray, PBF::Layer*>::const_iterator it = data.layers().find(
|
QHash<QString, PBF::Layer*>::const_iterator it = data.layers().find(
|
||||||
_layers.at(i).sourceLayer());
|
_layers.at(i).sourceLayer());
|
||||||
if (it == data.layers().constEnd())
|
if (it == data.layers().constEnd())
|
||||||
continue;
|
continue;
|
||||||
|
@ -37,7 +37,7 @@ private:
|
|||||||
Layer() : _type(Unknown), _minZoom(0), _maxZoom(24) {}
|
Layer() : _type(Unknown), _minZoom(0), _maxZoom(24) {}
|
||||||
Layer(const QJsonObject &json);
|
Layer(const QJsonObject &json);
|
||||||
|
|
||||||
const QByteArray &sourceLayer() const {return _sourceLayer;}
|
const QString &sourceLayer() const {return _sourceLayer;}
|
||||||
bool isPath() const {return (_type == Line || _type == Fill);}
|
bool isPath() const {return (_type == Line || _type == Fill);}
|
||||||
bool isBackground() const {return (_type == Background);}
|
bool isBackground() const {return (_type == Background);}
|
||||||
bool isSymbol() const {return (_type == Symbol);}
|
bool isSymbol() const {return (_type == Symbol);}
|
||||||
@ -74,8 +74,8 @@ private:
|
|||||||
|
|
||||||
Type _type;
|
Type _type;
|
||||||
bool _not;
|
bool _not;
|
||||||
QSet<QByteArray> _set;
|
QSet<QString> _set;
|
||||||
QPair<QByteArray, QVariant> _kv;
|
QPair<QString, QVariant> _kv;
|
||||||
QVector<Filter> _filters;
|
QVector<Filter> _filters;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Type _type;
|
Type _type;
|
||||||
QByteArray _sourceLayer;
|
QString _sourceLayer;
|
||||||
int _minZoom, _maxZoom;
|
int _minZoom, _maxZoom;
|
||||||
Filter _filter;
|
Filter _filter;
|
||||||
Layout _layout;
|
Layout _layout;
|
||||||
|
Loading…
Reference in New Issue
Block a user