Code cleanup

This commit is contained in:
Martin Tůma 2018-11-25 11:47:14 +01:00
parent 95da309a3c
commit 2637594c0a
7 changed files with 20 additions and 30 deletions

View File

@ -310,6 +310,7 @@ QFont Style::Layer::Layout::font(int zoom) const
{
QFont font(_font);
font.setPixelSize(_textSize.value(zoom));
font.setCapitalization(textTransform(zoom));
return font;
}
@ -330,16 +331,16 @@ Text::Anchor Style::Layer::Layout::textAnchor(int zoom) const
return Text::Center;
}
Text::Transform Style::Layer::Layout::textTransform(int zoom) const
QFont::Capitalization Style::Layer::Layout::textTransform(int zoom) const
{
QString transform(_textTransform.value(zoom));
if (transform == "uppercase")
return Text::Uppercase;
return QFont::AllUppercase;
else if (transform == "lowercase")
return Text::Lowercase;
return QFont::AllLowercase;
else
return Text::None;
return QFont::MixedCase;
}
Qt::PenCapStyle Style::Layer::Layout::lineCap(int zoom) const
@ -445,7 +446,6 @@ void Style::Layer::setTextProperties(Tile &tile) const
prop.maxWidth = _layout.maxTextWidth(tile.zoom());
prop.maxAngle = _layout.maxTextAngle(tile.zoom());
prop.anchor = _layout.textAnchor(tile.zoom());
prop.transform = _layout.textTransform(tile.zoom());
tile.text().setProperties(prop);
}

View File

@ -111,11 +111,11 @@ private:
Qt::PenCapStyle lineCap(int zoom) const;
Qt::PenJoinStyle lineJoin(int zoom) const;
Text::Anchor textAnchor(int zoom) const;
Text::Transform textTransform(int zoom) const;
bool viewportAlignment() const {return _viewportAlignment;}
private:
QFont::Capitalization textTransform(int zoom) const;
Template _text;
Template _icon;
FunctionF _textSize;

View File

@ -178,19 +178,19 @@ void Text::addLabel(const QString &text, const QPainterPath &path,
if (tp.isEmpty())
return;
TextPathItem *pi = new TextPathItem(text, reverse(tp) ? tp.toReversed()
: tp, painter.font(), _properties);
if (!_sceneRect.contains(pi->boundingRect())) {
delete pi;
TextPathItem *ti = new TextPathItem(text, reverse(tp) ? tp.toReversed()
: tp, painter.font());
if (!_sceneRect.contains(ti->boundingRect())) {
delete ti;
return;
}
pi->setPen(painter.pen());
ti->setPen(painter.pen());
addItem(pi);
addItem(ti);
QList<TextItem*> ci = collidingItems(pi);
for (int j = 0; j < ci.size(); j++)
ci[j]->setVisible(false);
QList<TextItem*> ci = collidingItems(ti);
for (int i = 0; i < ci.size(); i++)
ci[i]->setVisible(false);
}
QList<TextItem*> Text::collidingItems(const TextItem *item) const

View File

@ -16,17 +16,10 @@ public:
Bottom
};
enum Transform {
None,
Uppercase,
Lowercase
};
struct Properties {
int maxWidth;
int maxAngle;
Anchor anchor;
Transform transform;
};

View File

@ -4,9 +4,7 @@
TextPathItem::TextPathItem(const QString &text, const QPainterPath &path,
const QFont &font, const Text::Properties &prop)
: TextItem(prop.transform == Text::Uppercase ? text.toUpper() : text),
_path(path), _font(font)
const QFont &font) : TextItem(text), _path(path), _font(font)
{
QPainterPathStroker s;
s.setWidth(font.pixelSize());

View File

@ -10,7 +10,7 @@ class TextPathItem : public TextItem
{
public:
TextPathItem(const QString &text, const QPainterPath &path,
const QFont &font, const Text::Properties &prop);
const QFont &font);
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _boundingRect;}

View File

@ -28,7 +28,7 @@ static QRectF fuzzyBoundingRect(const QString &str, const QFont &font,
const Text::Properties &prop)
{
int limit = font.pixelSize() * prop.maxWidth;
qreal acw = (prop.transform == Text::Uppercase) ? 0.66 : 0.55;
qreal acw = (font.capitalization() == QFont::AllUppercase) ? 0.66 : 0.55;
qreal cw = font.pixelSize() * acw;
if (font.bold())
acw *= 1.1;
@ -101,8 +101,7 @@ QRectF TextPointItem::computeTextRect(BoundingRectFunction brf) const
TextPointItem::TextPointItem(const QString &text, const QPointF &pos,
const QFont &font, const Text::Properties &prop, const QImage &icon)
: TextItem(prop.transform == Text::Uppercase ? text.toUpper() : text),
_pos(pos), _font(font), _icon(icon), _properties(prop)
: TextItem(text), _pos(pos), _font(font), _icon(icon), _properties(prop)
{
_boundingRect = computeTextRect(fuzzyBoundingRect);