QtPBFImagePlugin/src/style.h

149 lines
3.4 KiB
C
Raw Normal View History

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>
#include <QVariantMap>
#include <QStringList>
#include <QSet>
#include <QPen>
#include <QBrush>
#include "function.h"
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);
void setZoom(int zoom) {_zoom = zoom;}
const QStringList &sourceLayers() const {return _sourceLayers;}
bool match(int layer, const QVariantMap &tags);
void drawBackground(Tile &tile);
void drawFeature(int layer, const QPainterPath &path,
const QVariantMap &tags, Tile &tile);
private:
class Layer {
public:
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);}
bool match(int zoom, const QVariantMap &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;
private:
enum Type {
Unknown,
Fill,
Line,
Background,
Symbol
};
class Filter {
public:
Filter() : _type(None) {}
Filter(const QJsonArray &json);
bool match(const QVariantMap &tags) const;
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;
};
class Layout {
public:
2018-10-31 17:40:43 +01:00
Layout() : _textSize(16), _textMaxWidth(10), _textMaxAngle(45),
2018-11-03 19:16:08 +01:00
_symbolSpacing(250), _lineCap(Qt::FlatCap),
_lineJoin(Qt::MiterJoin), _capitalize(false) {}
2018-10-29 00:11:23 +01:00
Layout(const QJsonObject &json);
2018-10-29 18:42:04 +01:00
bool capitalize() const {return _capitalize;}
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);}
qreal symbolSpacing(int zoom) const
{return _symbolSpacing.value(zoom);}
2018-10-29 00:11:23 +01:00
const QString &field() const {return _textField;}
const QStringList &keys() const {return _keys;}
QFont font(int zoom) const;
Qt::PenCapStyle lineCap() const {return _lineCap;}
Qt::PenJoinStyle lineJoin() const {return _lineJoin;}
private:
QStringList _keys;
QString _textField;
FunctionF _textSize;
FunctionF _textMaxWidth;
2018-10-31 17:40:43 +01:00
FunctionF _textMaxAngle;
2018-11-03 19:16:08 +01:00
FunctionF _symbolSpacing;
2018-10-29 00:11:23 +01:00
Qt::PenCapStyle _lineCap;
Qt::PenJoinStyle _lineJoin;
2018-10-29 18:42:04 +01:00
bool _capitalize;
2018-10-29 00:11:23 +01:00
};
class Paint {
public:
2018-10-30 23:29:26 +01:00
Paint() : _fillOpacity(1.0), _lineOpacity(1.0), _lineWidth(1.0),
_fillAntialias(true) {}
2018-10-29 00:11:23 +01:00
Paint(const QJsonObject &json);
QPen pen(Layer::Type type, int zoom) const;
QBrush brush(Layer::Type type, int zoom) const;
qreal opacity(Layer::Type type, int zoom) const;
bool antialias(Layer::Type type) const;
private:
FunctionC _textColor;
FunctionC _lineColor;
FunctionC _fillColor;
FunctionC _fillOutlineColor;
FunctionC _backgroundColor;
FunctionF _fillOpacity;
FunctionF _lineOpacity;
FunctionF _lineWidth;
bool _fillAntialias;
QVector<qreal> _lineDasharray;
};
Type _type;
QString _sourceLayer;
int _minZoom, _maxZoom;
Filter _filter;
Layout _layout;
Paint _paint;
};
int _zoom;
QList<Layer> _styles;
QStringList _sourceLayers;
};
#endif // STYLE_H