Compare commits

..

No commits in common. "14dada50c4df653205d17b1413c61659f470a623" and "aeed3e3848891622e879eab0f22b8aebd91d69f2" have entirely different histories.

7 changed files with 58 additions and 77 deletions

View File

@ -1,4 +1,4 @@
version: 3.2.{build}
version: 3.1.{build}
configuration:
- Release

View File

@ -2,7 +2,7 @@ TARGET = pbf
TEMPLATE = lib
CONFIG += plugin
QT += gui
VERSION = 3.2
VERSION = 3.1
PROTOS = protobuf/vector_tile.proto
include(protobuf/vector_tile.pri)

View File

@ -31,12 +31,12 @@ static QVariant value(const vector_tile::Tile_Value &val)
else if (val.has_double_value())
return QVariant(val.double_value());
else if (val.has_string_value())
return QVariant(QByteArray::fromStdString(val.string_value()));
return QVariant(QString::fromStdString(val.string_value()));
else
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());
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());
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());
for (int i = 0; i < data->values_size(); 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++) {
const vector_tile::Tile_Layer &layer = tile.layers(i);
_layers.insert(QByteArray::fromStdString(layer.name()),
new Layer(&layer));
_layers.insert(QString::fromStdString(layer.name()), new Layer(&layer));
}
}

View File

@ -8,7 +8,7 @@
#include "vector_tile.pb.h"
typedef QHash<QByteArray, google::protobuf::uint32> KeyHash;
typedef QHash<QString, google::protobuf::uint32> KeyHash;
class PBF
{
@ -22,7 +22,7 @@ public:
Feature(const vector_tile::Tile_Feature *data, const 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();}
QPainterPath path(const QSizeF &factor) const;
@ -55,10 +55,10 @@ public:
PBF(const vector_tile::Tile &tile);
~PBF();
const QHash<QByteArray, Layer*> &layers() const {return _layers;}
const QHash<QString, Layer*> &layers() const {return _layers;}
private:
QHash<QByteArray, Layer*> _layers;
QHash<QString, Layer*> _layers;
};
inline bool operator<(const PBF::Feature &f1, const PBF::Feature &f2)

View File

@ -95,25 +95,6 @@ bool Sprites::load(const QString &jsonFile, const QString &imageFile)
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()))
return QImage();
@ -137,6 +118,25 @@ QImage Sprites::icon(const QString &name, const QColor &color, qreal size)
if (name.isNull())
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);
if (it == _sprites.constEnd())
return QImage();

View File

@ -26,20 +26,6 @@ static vector_tile::Tile_GeomType geometryType(const QString &str)
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)
: _type(Unknown), _not(false)
{
@ -49,50 +35,50 @@ Style::Layer::Filter::Filter(const QJsonArray &json)
if (json.isEmpty())
INVALID_FILTER(json);
QString type(json.at(0).toString());
QString type = json.at(0).toString();
if (type == "==") {
if (json.size() != 3)
INVALID_FILTER(json);
if (json.at(1).toString() == "$type") {
_type = GeometryType;
_kv = QPair<QByteArray, QVariant>(QByteArray(),
_kv = QPair<QString, QVariant>(QString(),
QVariant(geometryType(json.at(2).toString())));
} else {
_type = EQ;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
variant(json.at(2)));
_kv = QPair<QString, QVariant>(json.at(1).toString(),
json.at(2).toVariant());
}
} else if (type == "!=") {
if (json.size() != 3)
INVALID_FILTER(json);
_type = NE;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
variant(json.at(2)));
_kv = QPair<QString, QVariant>(json.at(1).toString(),
json.at(2).toVariant());
} else if (type == "<") {
if (json.size() != 3)
INVALID_FILTER(json);
_type = LT;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
variant(json.at(2)));
_kv = QPair<QString, QVariant>(json.at(1).toString(),
json.at(2).toVariant());
} else if (type == "<=") {
if (json.size() != 3)
INVALID_FILTER(json);
_type = LE;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
variant(json.at(2)));
_kv = QPair<QString, QVariant>(json.at(1).toString(),
json.at(2).toVariant());
} else if (type == ">") {
if (json.size() != 3)
INVALID_FILTER(json);
_type = GT;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
variant(json.at(2)));
_kv = QPair<QString, QVariant>(json.at(1).toString(),
json.at(2).toVariant());
} else if (type == ">=") {
if (json.size() != 3)
INVALID_FILTER(json);
_type = GE;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
variant(json.at(2)));
_kv = QPair<QString, QVariant>(json.at(1).toString(),
json.at(2).toVariant());
} else if (type == "all") {
_type = All;
for (int i = 1; i < json.size(); i++)
@ -105,32 +91,28 @@ Style::Layer::Filter::Filter(const QJsonArray &json)
if (json.size() < 3)
INVALID_FILTER(json);
_type = In;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
QVariant());
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
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") {
if (json.size() < 3)
INVALID_FILTER(json);
_type = In;
_not = true;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
QVariant());
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
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") {
if (json.size() < 2)
INVALID_FILTER(json);
_type = Has;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
QVariant());
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
} else if (type == "!has") {
if (json.size() < 2)
INVALID_FILTER(json);
_type = Has;
_not = true;
_kv = QPair<QByteArray, QVariant>(json.at(1).toString().toUtf8(),
QVariant());
_kv = QPair<QString, QVariant>(json.at(1).toString(), QVariant());
} else
INVALID_FILTER(json);
}
@ -200,7 +182,7 @@ bool Style::Layer::Filter::match(const PBF::Feature &feature) const
if (!(v = feature.value(_kv.first)))
return _not;
else
return _set.contains((*v).toByteArray()) ^ _not;
return _set.contains((*v).toString()) ^ _not;
case Has:
return (feature.value(_kv.first) ? true : false) ^ _not;
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++) {
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() : "");
}
@ -504,7 +486,7 @@ Style::Layer::Layer(const QJsonObject &json)
_type = Symbol;
// source-layer
_sourceLayer = json["source-layer"].toString().toUtf8();
_sourceLayer = json["source-layer"].toString();
// zooms
if (json.contains("minzoom") && json["minzoom"].isDouble())
@ -590,7 +572,7 @@ static bool loadSprites(const QDir &styleDir, const QString &json,
if (QFileInfo::exists(spritesImg))
return sprites.load(spritesJSON, spritesImg);
else {
qWarning() << spritesImg << ": no such file";
qCritical() << spritesImg << ": no such file";
return false;
}
}
@ -702,7 +684,7 @@ void Style::render(const PBF &data, Tile &tile)
drawBackground(tile);
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());
if (it == data.layers().constEnd())
continue;

View File

@ -37,7 +37,7 @@ private:
Layer() : _type(Unknown), _minZoom(0), _maxZoom(24) {}
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 isBackground() const {return (_type == Background);}
bool isSymbol() const {return (_type == Symbol);}
@ -74,8 +74,8 @@ private:
Type _type;
bool _not;
QSet<QByteArray> _set;
QPair<QByteArray, QVariant> _kv;
QSet<QString> _set;
QPair<QString, QVariant> _kv;
QVector<Filter> _filters;
};
@ -167,7 +167,7 @@ private:
};
Type _type;
QByteArray _sourceLayer;
QString _sourceLayer;
int _minZoom, _maxZoom;
Filter _filter;
Layout _layout;