2018-10-29 00:11:23 +01:00
|
|
|
#ifndef STYLE_H
|
|
|
|
#define STYLE_H
|
|
|
|
|
2018-11-01 08:19:23 +01:00
|
|
|
#include <QObject>
|
2018-10-29 00:11:23 +01:00
|
|
|
#include <QString>
|
2018-11-10 19:34:45 +01:00
|
|
|
#include <QVariantHash>
|
2018-10-29 00:11:23 +01:00
|
|
|
#include <QStringList>
|
|
|
|
#include <QSet>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QBrush>
|
2018-11-06 22:35:30 +01:00
|
|
|
#include <QFont>
|
2018-11-22 21:57:21 +01:00
|
|
|
#include "text.h"
|
2018-10-29 00:11:23 +01:00
|
|
|
#include "function.h"
|
2018-11-22 21:57:21 +01:00
|
|
|
#include "sprites.h"
|
2018-10-29 00:11:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
class QPainterPath;
|
|
|
|
class Tile;
|
|
|
|
|
2018-11-01 08:19:23 +01:00
|
|
|
class Style : public QObject
|
2018-10-29 00:11:23 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-11-01 08:19:23 +01:00
|
|
|
Style(QObject *parent = 0) : QObject(parent) {}
|
|
|
|
|
2018-10-29 00:11:23 +01:00
|
|
|
bool load(const QString &fileName);
|
|
|
|
|
|
|
|
const QStringList &sourceLayers() const {return _sourceLayers;}
|
|
|
|
|
2018-11-22 21:57:21 +01:00
|
|
|
bool match(int zoom, int layer, const QVariantHash &tags) const;
|
|
|
|
|
|
|
|
void drawBackground(Tile &tile) const;
|
|
|
|
void setPainter(Tile &tile, int layer) const;
|
|
|
|
void setTextProperties(Tile &tile, int layer) const;
|
|
|
|
void drawFeature(Tile &tile, int layer, const QPainterPath &path,
|
|
|
|
const QVariantHash &tags) const;
|
2018-10-29 00:11:23 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
class Layer {
|
|
|
|
public:
|
2018-11-13 18:24:51 +01:00
|
|
|
Layer() : _type(Unknown), _minZoom(-1), _maxZoom(-1) {}
|
2018-10-29 00:11:23 +01:00
|
|
|
Layer(const QJsonObject &json);
|
|
|
|
|
|
|
|
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);}
|
|
|
|
|
2018-11-10 19:34:45 +01:00
|
|
|
bool match(int zoom, const QVariantHash &tags) const;
|
2018-11-23 23:35:28 +01:00
|
|
|
void setPathPainter(Tile &tile, const Sprites &sprites) const;
|
2018-11-22 21:57:21 +01:00
|
|
|
void setSymbolPainter(Tile &tile) const;
|
|
|
|
void setTextProperties(Tile &tile) const;
|
|
|
|
void addSymbol(Tile &tile, const QPainterPath &path,
|
|
|
|
const QVariantHash &tags, const Sprites &sprites) const;
|
2018-10-29 00:11:23 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum Type {
|
|
|
|
Unknown,
|
|
|
|
Fill,
|
|
|
|
Line,
|
|
|
|
Background,
|
|
|
|
Symbol
|
|
|
|
};
|
|
|
|
|
|
|
|
class Filter {
|
|
|
|
public:
|
|
|
|
Filter() : _type(None) {}
|
|
|
|
Filter(const QJsonArray &json);
|
|
|
|
|
2018-11-10 19:34:45 +01:00
|
|
|
bool match(const QVariantHash &tags) const;
|
2018-10-29 00:11:23 +01:00
|
|
|
private:
|
|
|
|
enum Type {
|
|
|
|
None, Unknown,
|
|
|
|
EQ, NE, GE, GT, LE, LT,
|
|
|
|
All, Any,
|
|
|
|
In, Has
|
|
|
|
};
|
|
|
|
|
|
|
|
Type _type;
|
|
|
|
bool _not;
|
|
|
|
QSet<QString> _set;
|
|
|
|
QPair<QString, QVariant> _kv;
|
|
|
|
QVector<Filter> _filters;
|
|
|
|
};
|
|
|
|
|
2018-11-22 21:57:21 +01:00
|
|
|
class Template {
|
|
|
|
public:
|
|
|
|
Template() {}
|
2018-11-23 23:35:28 +01:00
|
|
|
Template(const FunctionS &str) : _field(str) {}
|
|
|
|
QString value(int zoom, const QVariantHash &tags) const;
|
2018-11-22 21:57:21 +01:00
|
|
|
|
|
|
|
private:
|
2018-11-23 23:35:28 +01:00
|
|
|
FunctionS _field;
|
2018-11-22 21:57:21 +01:00
|
|
|
};
|
|
|
|
|
2018-10-29 00:11:23 +01:00
|
|
|
class Layout {
|
|
|
|
public:
|
2018-10-31 17:40:43 +01:00
|
|
|
Layout() : _textSize(16), _textMaxWidth(10), _textMaxAngle(45),
|
2018-11-24 09:52:54 +01:00
|
|
|
_font("Open Sans"), _capitalize(false),
|
|
|
|
_viewportAlignment(false) {}
|
2018-10-29 00:11:23 +01:00
|
|
|
Layout(const QJsonObject &json);
|
|
|
|
|
2018-11-03 19:16:08 +01:00
|
|
|
qreal maxTextWidth(int zoom) const
|
|
|
|
{return _textMaxWidth.value(zoom);}
|
|
|
|
qreal maxTextAngle(int zoom) const
|
|
|
|
{return _textMaxAngle.value(zoom);}
|
2018-11-23 23:35:28 +01:00
|
|
|
QString text(int zoom, const QVariantHash &tags) const
|
|
|
|
{return _text.value(zoom, tags);}
|
|
|
|
QString icon(int zoom, const QVariantHash &tags) const
|
|
|
|
{return _icon.value(zoom, tags);}
|
2018-10-29 00:11:23 +01:00
|
|
|
QFont font(int zoom) const;
|
2018-11-24 09:52:54 +01:00
|
|
|
Qt::PenCapStyle lineCap(int zoom) const;
|
|
|
|
Qt::PenJoinStyle lineJoin(int zoom) const;
|
|
|
|
Text::Anchor textAnchor(int zoom) const;
|
|
|
|
|
2018-11-19 23:09:34 +01:00
|
|
|
bool viewportAlignment() const {return _viewportAlignment;}
|
2018-11-24 09:52:54 +01:00
|
|
|
bool capitalize() const {return _capitalize;}
|
2018-10-29 00:11:23 +01:00
|
|
|
|
|
|
|
private:
|
2018-11-22 21:57:21 +01:00
|
|
|
Template _text;
|
|
|
|
Template _icon;
|
2018-10-29 00:11:23 +01:00
|
|
|
FunctionF _textSize;
|
|
|
|
FunctionF _textMaxWidth;
|
2018-10-31 17:40:43 +01:00
|
|
|
FunctionF _textMaxAngle;
|
2018-11-24 09:52:54 +01:00
|
|
|
FunctionS _lineCap;
|
|
|
|
FunctionS _lineJoin;
|
|
|
|
FunctionS _textAnchor;
|
2018-11-06 22:35:30 +01:00
|
|
|
QFont _font;
|
2018-10-29 18:42:04 +01:00
|
|
|
bool _capitalize;
|
2018-11-19 23:09:34 +01:00
|
|
|
bool _viewportAlignment;
|
2018-10-29 00:11:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class Paint {
|
|
|
|
public:
|
2018-11-06 22:35:30 +01:00
|
|
|
Paint() : _fillOpacity(1.0), _lineOpacity(1.0), _lineWidth(1.0) {}
|
2018-10-29 00:11:23 +01:00
|
|
|
Paint(const QJsonObject &json);
|
|
|
|
|
|
|
|
QPen pen(Layer::Type type, int zoom) const;
|
2018-11-23 23:35:28 +01:00
|
|
|
QBrush brush(Layer::Type type, int zoom, const Sprites &sprites) const;
|
2018-10-29 00:11:23 +01:00
|
|
|
qreal opacity(Layer::Type type, int zoom) const;
|
2018-11-06 22:35:30 +01:00
|
|
|
bool antialias(Layer::Type type, int zoom) const;
|
2018-11-23 23:35:28 +01:00
|
|
|
QString fillPattern(int zoom) const
|
|
|
|
{return _fillPattern.value(zoom);}
|
2018-10-29 00:11:23 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
FunctionC _textColor;
|
|
|
|
FunctionC _lineColor;
|
|
|
|
FunctionC _fillColor;
|
|
|
|
FunctionC _fillOutlineColor;
|
|
|
|
FunctionC _backgroundColor;
|
|
|
|
FunctionF _fillOpacity;
|
|
|
|
FunctionF _lineOpacity;
|
|
|
|
FunctionF _lineWidth;
|
2018-11-06 22:35:30 +01:00
|
|
|
FunctionB _fillAntialias;
|
2018-10-29 00:11:23 +01:00
|
|
|
QVector<qreal> _lineDasharray;
|
2018-11-23 23:35:28 +01:00
|
|
|
FunctionS _fillPattern;
|
2018-10-29 00:11:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Type _type;
|
|
|
|
QString _sourceLayer;
|
|
|
|
int _minZoom, _maxZoom;
|
|
|
|
Filter _filter;
|
|
|
|
Layout _layout;
|
|
|
|
Paint _paint;
|
|
|
|
};
|
|
|
|
|
2018-11-22 21:57:21 +01:00
|
|
|
QVector<Layer> _layers;
|
2018-10-29 00:11:23 +01:00
|
|
|
QStringList _sourceLayers;
|
2018-11-22 21:57:21 +01:00
|
|
|
Sprites _sprites;
|
2018-10-29 00:11:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // STYLE_H
|