QtPBFImagePlugin/src/style.h

147 lines
3.3 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>
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>
#include <QFont>
2018-10-29 00:11:23 +01:00
#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;}
2018-11-10 19:34:45 +01:00
bool match(int layer, const QVariantHash &tags);
2018-10-29 00:11:23 +01:00
void drawBackground(Tile &tile);
void drawFeature(int layer, const QPainterPath &path,
2018-11-10 19:34:45 +01:00
const QVariantHash &tags, Tile &tile);
2018-10-29 00:11:23 +01:00
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);}
2018-11-10 19:34:45 +01:00
bool match(int zoom, const QVariantHash &tags) const;
2018-10-29 00:11:23 +01:00
void drawPath(int zoom, const QPainterPath &path, Tile &tile) const;
void drawSymbol(int zoom, const QPainterPath &path,
2018-11-10 19:34:45 +01:00
const QVariantHash &tags, Tile &tile) 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;
};
class Layout {
public:
2018-10-31 17:40:43 +01:00
Layout() : _textSize(16), _textMaxWidth(10), _textMaxAngle(45),
2018-11-04 23:54:34 +01:00
_lineCap(Qt::FlatCap), _lineJoin(Qt::MiterJoin),
2018-11-07 22:04:11 +01:00
_font("Open Sans"), _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);}
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-10-29 00:11:23 +01:00
Qt::PenCapStyle _lineCap;
Qt::PenJoinStyle _lineJoin;
QFont _font;
2018-10-29 18:42:04 +01:00
bool _capitalize;
2018-10-29 00:11:23 +01:00
};
class Paint {
public:
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;
QBrush brush(Layer::Type type, int zoom) const;
qreal opacity(Layer::Type type, int zoom) const;
bool antialias(Layer::Type type, int zoom) const;
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;
FunctionB _fillAntialias;
2018-10-29 00:11:23 +01:00
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