Commit b256a1f4 authored by Dennis Nienhüser's avatar Dennis Nienhüser

Use StyleBuilder from MarbleModel in PlacemarkLayout/VisiblePlacemark

parent 28a120d6
......@@ -164,7 +164,7 @@ MarbleMapPrivate::MarbleMapPrivate( MarbleMap *parent, MarbleModel *model ) :
m_customPaintLayer( parent ),
m_geometryLayer(model->treeModel(), &m_styleBuilder),
m_textureLayer( model->downloadManager(), model->pluginManager(), model->sunLocator(), model->groundOverlayModel() ),
m_placemarkLayer( model->placemarkModel(), model->placemarkSelectionModel(), model->clock() ),
m_placemarkLayer( model->placemarkModel(), model->placemarkSelectionModel(), model->clock(), &m_styleBuilder ),
m_vectorTileLayer( model->downloadManager(), model->pluginManager(), model->treeModel() ),
m_isLockedToSubSolarPoint( false ),
m_isSubSolarPointIconVisible( false )
......
......@@ -38,6 +38,7 @@
#include "TileCoordsPyramid.h"
#include "VisiblePlacemark.h"
#include "MathHelper.h"
#include <StyleBuilder.h>
namespace
{ //Helper function that checks for available room for the label
......@@ -154,6 +155,7 @@ QSet<GeoDataFeature::GeoDataVisualCategory> acceptedVisualCategories()
PlacemarkLayout::PlacemarkLayout( QAbstractItemModel *placemarkModel,
QItemSelectionModel *selectionModel,
MarbleClock *clock,
const StyleBuilder *styleBuilder,
QObject* parent )
: QObject( parent ),
m_placemarkModel(placemarkModel),
......@@ -168,7 +170,8 @@ PlacemarkLayout::PlacemarkLayout( QAbstractItemModel *placemarkModel,
m_showCraters( false ),
m_showMaria( false ),
m_maxLabelHeight(maxLabelHeight()),
m_styleResetRequested( true )
m_styleResetRequested( true ),
m_styleBuilder(styleBuilder)
{
Q_ASSERT(m_placemarkModel);
......@@ -549,11 +552,25 @@ QString PlacemarkLayout::runtimeTrace() const
bool PlacemarkLayout::layoutPlacemark( const GeoDataPlacemark *placemark, qreal x, qreal y, bool selected )
{
// Find the corresponding visible placemark
VisiblePlacemark *mark = m_visiblePlacemarks.value( placemark );
if ( !mark ) {
// If there is no visible placemark yet for this index,
// create a new one...
StyleParameters parameters;
// @todo: Set / adjust to tile level
parameters.feature = placemark;
mark = new VisiblePlacemark(placemark, m_styleBuilder->createStyle(parameters));
m_visiblePlacemarks.insert( placemark, mark );
connect( mark, SIGNAL(updateNeeded()), this, SIGNAL(repaintNeeded()) );
}
GeoDataStyle::ConstPtr style = mark->style();
// Choose Section
// Find out whether the area around the placemark is covered already.
// If there's not enough space free don't add a VisiblePlacemark here.
GeoDataStyle::ConstPtr style = placemark->style();
QRectF labelRect;
if( !placemark->displayName().isEmpty() ) {
......@@ -563,16 +580,6 @@ bool PlacemarkLayout::layoutPlacemark( const GeoDataPlacemark *placemark, qreal
}
}
// Find the corresponding visible placemark
VisiblePlacemark *mark = m_visiblePlacemarks.value( placemark );
if ( !mark ) {
// If there is no visible placemark yet for this index,
// create a new one...
mark = new VisiblePlacemark( placemark );
m_visiblePlacemarks.insert( placemark, mark );
connect( mark, SIGNAL(updateNeeded()), this, SIGNAL(repaintNeeded()) );
}
// Finally save the label position on the map.
QPointF hotSpot = mark->hotSpot();
......
......@@ -44,6 +44,7 @@ class PlacemarkPainter;
class TileId;
class VisiblePlacemark;
class ViewportParams;
class StyleBuilder;
/**
* Layouts the place marks with a passed QPainter.
......@@ -62,6 +63,7 @@ class PlacemarkLayout : public QObject
PlacemarkLayout( QAbstractItemModel *placemarkModel,
QItemSelectionModel *selectionModel,
MarbleClock *clock,
const StyleBuilder* styleBuilder,
QObject *parent = 0 );
/**
......@@ -160,6 +162,7 @@ class PlacemarkLayout : public QObject
int m_maxLabelHeight;
bool m_styleResetRequested;
const StyleBuilder* m_styleBuilder;
};
}
......
......@@ -24,11 +24,11 @@
using namespace Marble;
VisiblePlacemark::VisiblePlacemark( const GeoDataPlacemark *placemark )
VisiblePlacemark::VisiblePlacemark( const GeoDataPlacemark *placemark, const GeoDataStyle::ConstPtr &style )
: m_placemark( placemark ),
m_selected( false )
m_selected( false ),
m_style(style)
{
GeoDataStyle::ConstPtr style = m_placemark->style();
const RemoteIconLoader *remoteLoader = style->iconStyle().remoteIconLoader();
QObject::connect( remoteLoader, SIGNAL(iconReady()),
this, SLOT(setSymbolPixmap()) );
......@@ -65,11 +65,11 @@ const QPoint& VisiblePlacemark::symbolPosition() const
const QPointF VisiblePlacemark::hotSpot() const
{
const QSize iconSize = m_placemark->style()->iconStyle().scaledIcon().size();
const QSize iconSize = m_style->iconStyle().scaledIcon().size();
GeoDataHotSpot::Units xunits;
GeoDataHotSpot::Units yunits;
QPointF pixelHotSpot = m_placemark->style()->iconStyle().hotSpot( xunits, yunits );
QPointF pixelHotSpot = m_style->iconStyle().hotSpot( xunits, yunits );
switch ( xunits ) {
case GeoDataHotSpot::Fraction:
......@@ -110,10 +110,8 @@ const QPixmap& VisiblePlacemark::labelPixmap() const
void VisiblePlacemark::setSymbolPixmap()
{
GeoDataStyle::ConstPtr style = m_placemark->style();
if ( style ) {
m_symbolPixmap = QPixmap::fromImage( style->iconStyle().scaledIcon() );
if (m_style) {
m_symbolPixmap = QPixmap::fromImage(m_style->iconStyle().scaledIcon() );
emit updateNeeded();
}
else {
......@@ -131,30 +129,40 @@ void VisiblePlacemark::setLabelRect( const QRectF& labelRect )
m_labelRect = labelRect;
}
void VisiblePlacemark::drawLabelPixmap()
void VisiblePlacemark::setStyle(const GeoDataStyle::ConstPtr &style)
{
m_style = style;
drawLabelPixmap();
setSymbolPixmap();
}
GeoDataStyle::ConstPtr VisiblePlacemark::style() const
{
GeoDataStyle::ConstPtr style = m_placemark->style();
return m_style;
}
void VisiblePlacemark::drawLabelPixmap()
{
QString labelName = m_placemark->displayName();
if ( labelName.isEmpty() || style->labelStyle().color() == QColor(Qt::transparent) ) {
if ( labelName.isEmpty() || m_style->labelStyle().color() == QColor(Qt::transparent) ) {
m_labelPixmap = QPixmap();
return;
}
QFont labelFont = style->labelStyle().scaledFont();
QColor labelColor = style->labelStyle().color();
QFont labelFont = m_style->labelStyle().scaledFont();
QColor labelColor = m_style->labelStyle().color();
LabelStyle labelStyle = Normal;
if ( m_selected ) {
labelStyle = Selected;
} else if ( style->labelStyle().glow() ) {
} else if ( m_style->labelStyle().glow() ) {
labelStyle = Glow;
}
int textHeight = QFontMetrics( labelFont ).height();
int textWidth;
if ( style->labelStyle().glow() ) {
if ( m_style->labelStyle().glow() ) {
labelFont.setWeight( 75 ); // Needed to calculate the correct pixmap size;
textWidth = ( QFontMetrics( labelFont ).width( labelName )
+ qRound( 2 * s_labelOutlineWidth ) );
......
......@@ -22,6 +22,8 @@
#include <QRectF>
#include <QString>
#include <GeoDataStyle.h>
namespace Marble
{
......@@ -40,7 +42,7 @@ class VisiblePlacemark : public QObject
Q_OBJECT
public:
explicit VisiblePlacemark( const GeoDataPlacemark *placemark );
explicit VisiblePlacemark(const GeoDataPlacemark *placemark, const GeoDataStyle::ConstPtr &style);
/**
* Returns the index of the place mark model which
......@@ -99,6 +101,10 @@ class VisiblePlacemark : public QObject
Selected
};
void setStyle(const GeoDataStyle::ConstPtr &style);
GeoDataStyle::ConstPtr style() const;
Q_SIGNALS:
void updateNeeded();
......@@ -118,6 +124,7 @@ private Q_SLOTS:
QRectF m_labelRect; // bounding box of label
mutable QPixmap m_symbolPixmap; // cached value
GeoDataStyle::ConstPtr m_style;
};
}
......
......@@ -28,12 +28,12 @@ using namespace Marble;
bool PlacemarkLayer::m_useXWorkaround = false;
PlacemarkLayer::PlacemarkLayer( QAbstractItemModel *placemarkModel,
PlacemarkLayer::PlacemarkLayer(QAbstractItemModel *placemarkModel,
QItemSelectionModel *selectionModel,
MarbleClock *clock,
MarbleClock *clock, const StyleBuilder *styleBuilder,
QObject *parent ) :
QObject( parent ),
m_layout( placemarkModel, selectionModel, clock )
m_layout( placemarkModel, selectionModel, clock, styleBuilder )
{
m_useXWorkaround = testXBug();
mDebug() << "Use workaround: " << ( m_useXWorkaround ? "1" : "0" );
......
......@@ -38,6 +38,7 @@ class GeoSceneLayer;
class MarbleClock;
class ViewportParams;
class VisiblePlacemark;
class StyleBuilder;
class PlacemarkLayer : public QObject, public LayerInterface
{
......@@ -47,6 +48,7 @@ class PlacemarkLayer : public QObject, public LayerInterface
PlacemarkLayer( QAbstractItemModel *placemarkModel,
QItemSelectionModel *selectionModel,
MarbleClock *clock,
const StyleBuilder *styleBuilder,
QObject *parent = 0 );
~PlacemarkLayer();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment