7#include "GeoDataIconStyle.h"
11#include "MarbleDirs.h"
12#include "MarbleDebug.h"
13#include "RemoteIconLoader.h"
15#include "GeoDataTypes.h"
17#include <QImageReader>
22class GeoDataIconStylePrivate
25 GeoDataIconStylePrivate()
34 GeoDataIconStylePrivate(
const QString& iconPath,
const QPointF &hotSpot )
38 m_iconPath( iconPath ),
44 RemoteIconLoader* remoteIconLoader()
const
46 static RemoteIconLoader *remoteIconLoader =
new RemoteIconLoader();
47 return remoteIconLoader;
54 if ( iconSize.
width()*m_scale > s_maximumIconSize.width()
55 || iconSize.
height()*m_scale > s_maximumIconSize.height() ) {
58 else if ( iconSize.
width()*m_scale < s_minimumIconSize.width()
59 || iconSize.
height()*m_scale < s_minimumIconSize.width() ) {
77 auto const imageSize = imageReader.
size();
78 auto const finalSize = imageSize.
scaled(size, m_aspectRatioMode);
82 mDebug() <<
"GeoDataIconStyle: Failed to read image " <<
path <<
": " << imageReader.
errorString();
95 return remoteIconLoader()->load(
QUrl(m_iconPath));
98 mDebug() <<
"Unable to open style icon at: " <<
path;
109 GeoDataHotSpot m_hotSpot;
113GeoDataIconStyle::GeoDataIconStyle() :
114 d( new GeoDataIconStylePrivate() )
118GeoDataIconStyle::GeoDataIconStyle(
const GeoDataIconStyle& other ) :
119 GeoDataColorStyle( other ), d( new GeoDataIconStylePrivate( *other.d ) )
123GeoDataIconStyle::GeoDataIconStyle(
const QString& iconPath,
const QPointF &hotSpot ) :
124 d( new GeoDataIconStylePrivate( iconPath, hotSpot ) )
128GeoDataIconStyle::~GeoDataIconStyle()
133GeoDataIconStyle& GeoDataIconStyle::operator=(
const GeoDataIconStyle& other )
135 GeoDataColorStyle::operator=( other );
140bool GeoDataIconStyle::operator==(
const GeoDataIconStyle &other )
const
142 if ( GeoDataColorStyle::operator!=( other ) ) {
146 return d->m_scale == other.d->m_scale &&
147 d->m_icon == other.d->m_icon &&
148 d->m_size == other.d->m_size &&
149 d->m_iconPath == other.d->m_iconPath &&
150 d->m_hotSpot == other.d->m_hotSpot &&
151 d->m_heading == other.d->m_heading;
154bool GeoDataIconStyle::operator!=(
const GeoDataIconStyle &other )
const
159const char* GeoDataIconStyle::nodeType()
const
161 return GeoDataTypes::GeoDataIconStyleType;
164void GeoDataIconStyle::setIcon(
const QImage &icon)
167 d->m_scaledIcon =
QImage();
170void GeoDataIconStyle::setIconPath(
const QString& filename )
172 d->m_iconPath = filename;
180 d->m_scaledIcon =
QImage();
183QString GeoDataIconStyle::iconPath()
const
185 return d->m_iconPath;
188QImage GeoDataIconStyle::icon()
const
190 if ( !d->m_icon.isNull() ) {
193 else if ( !d->m_iconPath.isEmpty() ) {
194 d->m_icon = d->loadIcon(resolvePath(d->m_iconPath), d->m_size);
201void GeoDataIconStyle::setHotSpot(
const QPointF& hotSpot,
202 GeoDataHotSpot::Units xunits,
203 GeoDataHotSpot::Units yunits )
205 d->m_hotSpot.setHotSpot( hotSpot, xunits, yunits );
208QPointF GeoDataIconStyle::hotSpot( GeoDataHotSpot::Units &xunits, GeoDataHotSpot::Units &yunits )
const
210 return d->m_hotSpot.hotSpot( xunits, yunits );
215 if (size == d->m_size && aspectRatioMode == d->m_aspectRatioMode) {
219 d->m_aspectRatioMode = aspectRatioMode;
221 if (!d->m_size.isNull() && !d->m_icon.isNull()) {
223 d->m_icon = d->m_icon.scaled(d->m_size);
224 }
else if (!d->m_iconPath.isEmpty()) {
227 d->m_scaledIcon =
QImage();
231QSize GeoDataIconStyle::size()
const
236void GeoDataIconStyle::setScale(
float scale)
239 d->m_scaledIcon =
QImage();
242float GeoDataIconStyle::scale()
const
247QImage GeoDataIconStyle::scaledIcon()
const
249 if (!d->m_scaledIcon.isNull()) {
250 return d->m_scaledIcon;
254 if (d->m_scale <= 0 || d->m_scale == 1.0) {
259 d->m_scaledIcon = d->loadIcon(resolvePath(d->m_iconPath), d->scaledSize(d->m_size));
261 if (d->m_scaledIcon.isNull()) {
263 QImage const image = icon();
265 QSize iconSize = d->scaledSize(image.
size());
269 return d->m_scaledIcon;
272int GeoDataIconStyle::heading()
const
277void GeoDataIconStyle::setHeading(
int heading )
279 d->m_heading = heading;
282RemoteIconLoader *GeoDataIconStyle::remoteIconLoader()
const
284 return d->remoteIconLoader();
287void GeoDataIconStyle::pack(
QDataStream& stream )
const
289 GeoDataColorStyle::pack( stream );
291 stream << d->m_scale;
293 d->m_hotSpot.pack( stream );
296void GeoDataIconStyle::unpack(
QDataStream& stream )
298 GeoDataColorStyle::unpack( stream );
300 stream >> d->m_scale;
302 d->m_hotSpot.unpack( stream );
QString path(const QString &relativePath)
bool isValid(QStringView ifopt)
Binds a QML item to a specific geodetic location in screen coordinates.
bool isNull() const const
QImage scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const const
QString errorString() const const
void setFileName(const QString &fileName)
void setScaledSize(const QSize &size)
bool isNull() const const
void scale(const QSize &size, Qt::AspectRatioMode mode)
QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const const
bool isEmpty() const const
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)