mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Fixed various drawing & style issues
This commit is contained in:
parent
f41ac3bd54
commit
61868b9544
147
src/style.cpp
147
src/style.cpp
@ -11,6 +11,40 @@
|
|||||||
#include "style.h"
|
#include "style.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void jsonColor(const QJsonObject &json, const char *name, FunctionC &var)
|
||||||
|
{
|
||||||
|
if (json.contains(name)) {
|
||||||
|
const QJsonValue value = json[name];
|
||||||
|
if (value.isString())
|
||||||
|
var = FunctionC(Color::fromJsonString(value.toString()));
|
||||||
|
else if (value.isObject())
|
||||||
|
var = FunctionC(value.toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void jsonFloat(const QJsonObject &json, const char *name, FunctionF &var)
|
||||||
|
{
|
||||||
|
if (json.contains(name)) {
|
||||||
|
const QJsonValue value = json[name];
|
||||||
|
if (value.isDouble())
|
||||||
|
var = FunctionF(value.toDouble());
|
||||||
|
else if (value.isObject())
|
||||||
|
var = FunctionF(value.toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void jsonBool(const QJsonObject &json, const char *name, FunctionB &var)
|
||||||
|
{
|
||||||
|
if (json.contains(name)) {
|
||||||
|
QJsonValue value = json[name];
|
||||||
|
if (value.isBool())
|
||||||
|
var = FunctionB(value.toBool());
|
||||||
|
else if (value.isObject())
|
||||||
|
var = FunctionB(value.toObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Style::Layer::Filter::Filter(const QJsonArray &json)
|
Style::Layer::Filter::Filter(const QJsonArray &json)
|
||||||
: _type(Unknown), _not(false)
|
: _type(Unknown), _not(false)
|
||||||
{
|
{
|
||||||
@ -137,65 +171,32 @@ bool Style::Layer::Filter::match(const QVariantHash &tags) const
|
|||||||
Style::Layer::Paint::Paint(const QJsonObject &json)
|
Style::Layer::Paint::Paint(const QJsonObject &json)
|
||||||
: _fillOpacity(1.0), _lineOpacity(1.0), _lineWidth(1.0)
|
: _fillOpacity(1.0), _lineOpacity(1.0), _lineWidth(1.0)
|
||||||
{
|
{
|
||||||
if (json.contains("fill-opacity") && json["fill-opacity"].isDouble())
|
// fill
|
||||||
_fillOpacity = FunctionF(json["fill-opacity"].toDouble());
|
jsonFloat(json, "fill-opacity", _fillOpacity);
|
||||||
else if (json.contains("fill-opacity") && json["fill-opacity"].isObject())
|
jsonColor(json, "fill-color", _fillColor);
|
||||||
_fillOpacity = FunctionF(json["fill-opacity"].toObject());
|
_fillOutlineColor = _fillColor;
|
||||||
if (json.contains("fill-color") && json["fill-color"].isString()) {
|
jsonColor(json, "fill-outline-color", _fillOutlineColor);
|
||||||
_fillColor = FunctionC(Color::fromJsonString(
|
jsonBool(json, "fill-antialias",_fillAntialias);
|
||||||
json["fill-color"].toString()));
|
|
||||||
_fillOutlineColor = _fillColor;
|
|
||||||
} else if (json.contains("fill-color") && json["fill-color"].isObject()) {
|
|
||||||
_fillColor = FunctionC(json["fill-color"].toObject());
|
|
||||||
_fillOutlineColor = _fillColor;
|
|
||||||
}
|
|
||||||
if (json.contains("fill-outline-color")
|
|
||||||
&& json["fill-outline-color"].isString())
|
|
||||||
_fillOutlineColor = FunctionC(Color::fromJsonString(
|
|
||||||
json["fill-outline-color"].toString()));
|
|
||||||
if (json.contains("fill-outline-color")
|
|
||||||
&& json["fill-outline-color"].isObject())
|
|
||||||
_fillOutlineColor = FunctionC(json["fill-outline-color"].toObject());
|
|
||||||
if (json.contains("fill-antialias") && json["fill-antialias"].isBool())
|
|
||||||
_fillAntialias = FunctionB(json["fill-antialias"].toBool());
|
|
||||||
else if (json.contains("fill-antialias") && json["fill-antialias"].isObject())
|
|
||||||
_fillAntialias = FunctionB(json["fill-antialias"].toObject());
|
|
||||||
if (json.contains("fill-pattern")) {
|
if (json.contains("fill-pattern")) {
|
||||||
_fillColor = FunctionC(QColor());
|
_fillColor = FunctionC(QColor());
|
||||||
_fillOutlineColor = FunctionC(QColor());
|
_fillOutlineColor = FunctionC(QColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// line
|
||||||
if (json.contains("line-color") && json["line-color"].isString())
|
jsonColor(json, "line-color", _lineColor);
|
||||||
_lineColor = FunctionC(Color::fromJsonString(json["line-color"]
|
jsonFloat(json, "line-width", _lineWidth);
|
||||||
.toString()));
|
jsonFloat(json, "line-opacity", _lineOpacity);
|
||||||
if (json.contains("line-color") && json["line-color"].isObject())
|
|
||||||
_lineColor = FunctionC(json["line-color"].toObject());
|
|
||||||
if (json.contains("line-width") && json["line-width"].isObject())
|
|
||||||
_lineWidth = FunctionF(json["line-width"].toObject());
|
|
||||||
else if (json.contains("line-width") && json["line-width"].isDouble())
|
|
||||||
_lineWidth = FunctionF(json["line-width"].toDouble());
|
|
||||||
if (json.contains("line-opacity") && json["line-opacity"].isDouble())
|
|
||||||
_lineOpacity = FunctionF(json["line-opacity"].toDouble());
|
|
||||||
else if (json.contains("line-opacity") && json["line-opacity"].isObject())
|
|
||||||
_lineOpacity = FunctionF(json["line-opacity"].toObject());
|
|
||||||
if (json.contains("line-dasharray") && json["line-dasharray"].isArray()) {
|
if (json.contains("line-dasharray") && json["line-dasharray"].isArray()) {
|
||||||
QJsonArray array = json["line-dasharray"].toArray();
|
QJsonArray array = json["line-dasharray"].toArray();
|
||||||
for (int i = 0; i < array.size(); i++)
|
for (int i = 0; i < array.size(); i++)
|
||||||
_lineDasharray.append(array.at(i).toDouble());
|
_lineDasharray.append(array.at(i).toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains("background-color") && json["background-color"].isString())
|
// background
|
||||||
_backgroundColor = FunctionC(Color::fromJsonString(
|
jsonColor(json, "background-color", _backgroundColor);
|
||||||
json["background-color"].toString()));
|
|
||||||
if (json.contains("background-color") && json["background-color"].isObject())
|
|
||||||
_backgroundColor = FunctionC(json["background-color"].toObject());
|
|
||||||
|
|
||||||
if (json.contains("text-color") && json["text-color"].isString())
|
// text
|
||||||
_textColor = FunctionC(Color::fromJsonString(json["text-color"]
|
jsonColor(json, "text-color", _textColor);
|
||||||
.toString()));
|
|
||||||
if (json.contains("text-color") && json["text-color"].isObject())
|
|
||||||
_textColor = FunctionC(json["text-color"].toObject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPen Style::Layer::Paint::pen(Type type, int zoom) const
|
QPen Style::Layer::Paint::pen(Type type, int zoom) const
|
||||||
@ -275,36 +276,6 @@ Style::Layer::Layout::Layout(const QJsonObject &json)
|
|||||||
: _textSize(16), _textMaxWidth(10), _textMaxAngle(45), _lineCap(Qt::FlatCap),
|
: _textSize(16), _textMaxWidth(10), _textMaxAngle(45), _lineCap(Qt::FlatCap),
|
||||||
_lineJoin(Qt::MiterJoin), _font("Open Sans"), _capitalize(false)
|
_lineJoin(Qt::MiterJoin), _font("Open Sans"), _capitalize(false)
|
||||||
{
|
{
|
||||||
if (!(json.contains("text-field") && json["text-field"].isString()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_textField = json["text-field"].toString();
|
|
||||||
|
|
||||||
QRegExp rx("\\{[^\\}]*\\}");
|
|
||||||
int pos = 0;
|
|
||||||
while ((pos = rx.indexIn(_textField, pos)) != -1) {
|
|
||||||
QString match = rx.capturedTexts().first();
|
|
||||||
_keys.append(match.mid(1, match.size() - 2));
|
|
||||||
pos += rx.matchedLength();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.contains("text-size") && json["text-size"].isObject())
|
|
||||||
_textSize = FunctionF(json["text-size"].toObject());
|
|
||||||
else if (json.contains("text-size") && json["text-size"].isDouble())
|
|
||||||
_textSize = json["text-size"].toDouble();
|
|
||||||
if (json.contains("text-max-width") && json["text-max-width"].isObject())
|
|
||||||
_textMaxWidth = FunctionF(json["text-max-width"].toObject());
|
|
||||||
else if (json.contains("text-max-width") && json["text-max-width"].isDouble())
|
|
||||||
_textMaxWidth = json["text-max-width"].toDouble();
|
|
||||||
if (json.contains("text-max-angle") && json["text-max-angle"].isObject())
|
|
||||||
_textMaxWidth = FunctionF(json["text-max-angle"].toObject());
|
|
||||||
else if (json.contains("text-max-angle") && json["text-max-angle"].isDouble())
|
|
||||||
_textMaxWidth = json["text-max-angle"].toDouble();
|
|
||||||
if (json.contains("text-font") && json["text-font"].isArray())
|
|
||||||
_font = Font::fromJsonArray(json["text-font"].toArray());
|
|
||||||
if (json.contains("text-transform") && json["text-transform"].isString())
|
|
||||||
_capitalize = json["text-transform"].toString() == "uppercase";
|
|
||||||
|
|
||||||
if (json.contains("line-cap") && json["line-cap"].isString()) {
|
if (json.contains("line-cap") && json["line-cap"].isString()) {
|
||||||
if (json["line-cap"].toString() == "round")
|
if (json["line-cap"].toString() == "round")
|
||||||
_lineCap = Qt::RoundCap;
|
_lineCap = Qt::RoundCap;
|
||||||
@ -317,6 +288,26 @@ Style::Layer::Layout::Layout(const QJsonObject &json)
|
|||||||
else if (json["line-join"].toString() == "round")
|
else if (json["line-join"].toString() == "round")
|
||||||
_lineJoin = Qt::RoundJoin;
|
_lineJoin = Qt::RoundJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(json.contains("text-field") && json["text-field"].isString()))
|
||||||
|
return;
|
||||||
|
_textField = json["text-field"].toString();
|
||||||
|
|
||||||
|
QRegExp rx("\\{[^\\}]*\\}");
|
||||||
|
int pos = 0;
|
||||||
|
while ((pos = rx.indexIn(_textField, pos)) != -1) {
|
||||||
|
QString match = rx.capturedTexts().first();
|
||||||
|
_keys.append(match.mid(1, match.size() - 2));
|
||||||
|
pos += rx.matchedLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonFloat(json, "text-size", _textSize);
|
||||||
|
jsonFloat(json, "text-max-width", _textMaxWidth);
|
||||||
|
jsonFloat(json, "text-max-angle", _textMaxAngle);
|
||||||
|
if (json.contains("text-font") && json["text-font"].isArray())
|
||||||
|
_font = Font::fromJsonArray(json["text-font"].toArray());
|
||||||
|
if (json.contains("text-transform") && json["text-transform"].isString())
|
||||||
|
_capitalize = json["text-transform"].toString() == "uppercase";
|
||||||
}
|
}
|
||||||
|
|
||||||
QFont Style::Layer::Layout::font(int zoom) const
|
QFont Style::Layer::Layout::font(int zoom) const
|
||||||
@ -389,11 +380,13 @@ void Style::Layer::drawPath(int zoom, const QPainterPath &path,
|
|||||||
pen.setCapStyle(_layout.lineCap());
|
pen.setCapStyle(_layout.lineCap());
|
||||||
|
|
||||||
QPainter &p = tile.painter();
|
QPainter &p = tile.painter();
|
||||||
|
p.save();
|
||||||
p.setRenderHint(QPainter::Antialiasing, _paint.antialias(_type, zoom));
|
p.setRenderHint(QPainter::Antialiasing, _paint.antialias(_type, zoom));
|
||||||
p.setPen(pen);
|
p.setPen(pen);
|
||||||
p.setBrush(brush);
|
p.setBrush(brush);
|
||||||
p.setOpacity(_paint.opacity(_type, zoom));
|
p.setOpacity(_paint.opacity(_type, zoom));
|
||||||
p.drawPath(path);
|
p.drawPath(path);
|
||||||
|
p.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Style::Layer::drawSymbol(int zoom, const QPainterPath &path,
|
void Style::Layer::drawSymbol(int zoom, const QPainterPath &path,
|
||||||
|
Loading…
Reference in New Issue
Block a user