File indexing completed on 2025-01-05 03:59:00
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2008 Patrick Spendrin <ps_ml@gmx.de> 0004 // 0005 0006 0007 #include "GeoDataPolyStyle.h" 0008 #include "GeoDataTypes.h" 0009 #include "MarbleDirs.h" 0010 0011 #include <QDataStream> 0012 #include <QImage> 0013 0014 namespace Marble 0015 { 0016 0017 class GeoDataPolyStylePrivate 0018 { 0019 public: 0020 GeoDataPolyStylePrivate() 0021 : m_fill(true) 0022 , m_outline(true) 0023 , m_brushStyle(Qt::SolidPattern) 0024 , m_colorIndex(0) 0025 { 0026 } 0027 0028 /// whether to fill the polygon 0029 bool m_fill; 0030 /// whether to draw the outline 0031 bool m_outline; 0032 Qt::BrushStyle m_brushStyle; 0033 /// The value of colorIndex will be maped to a color for brush 0034 quint8 m_colorIndex; 0035 QString m_texturePath; 0036 QImage m_textureImage; 0037 }; 0038 0039 GeoDataPolyStyle::GeoDataPolyStyle() 0040 : d( new GeoDataPolyStylePrivate ) 0041 { 0042 } 0043 0044 GeoDataPolyStyle::GeoDataPolyStyle( const GeoDataPolyStyle& other ) 0045 : GeoDataColorStyle( other ), d( new GeoDataPolyStylePrivate( *other.d ) ) 0046 { 0047 } 0048 0049 GeoDataPolyStyle::GeoDataPolyStyle( const QColor &color ) 0050 : d( new GeoDataPolyStylePrivate ) 0051 { 0052 setColor( color ); 0053 } 0054 0055 GeoDataPolyStyle::~GeoDataPolyStyle() 0056 { 0057 delete d; 0058 } 0059 0060 GeoDataPolyStyle& GeoDataPolyStyle::operator=( const GeoDataPolyStyle& other ) 0061 { 0062 GeoDataColorStyle::operator=( other ); 0063 *d = *other.d; 0064 return *this; 0065 } 0066 0067 bool GeoDataPolyStyle::operator==( const GeoDataPolyStyle &other ) const 0068 { 0069 if ( GeoDataColorStyle::operator!=( other ) ) { 0070 return false; 0071 } 0072 0073 return d->m_fill == other.d->m_fill && 0074 d->m_outline == other.d->m_outline && 0075 d->m_brushStyle == other.d->m_brushStyle; 0076 } 0077 0078 bool GeoDataPolyStyle::operator!=( const GeoDataPolyStyle &other ) const 0079 { 0080 return !this->operator==( other ); 0081 } 0082 0083 const char* GeoDataPolyStyle::nodeType() const 0084 { 0085 return GeoDataTypes::GeoDataPolyStyleType; 0086 } 0087 0088 void GeoDataPolyStyle::setFill(bool fill) 0089 { 0090 d->m_fill = fill; 0091 } 0092 0093 bool GeoDataPolyStyle::fill() const 0094 { 0095 return d->m_fill; 0096 } 0097 0098 void GeoDataPolyStyle::setOutline(bool outline) 0099 { 0100 d->m_outline = outline; 0101 } 0102 0103 bool GeoDataPolyStyle::outline() const 0104 { 0105 return d->m_outline; 0106 } 0107 0108 void GeoDataPolyStyle::setBrushStyle( const Qt::BrushStyle style ) 0109 { 0110 d->m_brushStyle = style; 0111 } 0112 0113 Qt::BrushStyle GeoDataPolyStyle::brushStyle() const 0114 { 0115 return d->m_brushStyle; 0116 } 0117 0118 void GeoDataPolyStyle::setColorIndex( quint8 colorIndex ) 0119 { 0120 d->m_colorIndex = colorIndex; 0121 } 0122 0123 quint8 GeoDataPolyStyle::colorIndex() const 0124 { 0125 return d->m_colorIndex; 0126 } 0127 0128 void GeoDataPolyStyle::setTexturePath( const QString& texturePath ) 0129 { 0130 d->m_texturePath = texturePath; 0131 d->m_textureImage = QImage(); 0132 } 0133 0134 QString GeoDataPolyStyle::texturePath() const 0135 { 0136 return d->m_texturePath; 0137 } 0138 0139 QImage GeoDataPolyStyle::textureImage() const 0140 { 0141 if ( !d->m_textureImage.isNull() ) { 0142 return d->m_textureImage; 0143 } else if ( !d->m_texturePath.isEmpty() ) { 0144 d->m_textureImage = QImage( resolvePath( d->m_texturePath ) ); 0145 } 0146 0147 return d->m_textureImage; 0148 } 0149 0150 void GeoDataPolyStyle::pack( QDataStream& stream ) const 0151 { 0152 GeoDataColorStyle::pack( stream ); 0153 0154 stream << d->m_fill; 0155 stream << d->m_outline; 0156 stream << d->m_colorIndex; 0157 } 0158 0159 void GeoDataPolyStyle::unpack( QDataStream& stream ) 0160 { 0161 GeoDataColorStyle::unpack( stream ); 0162 0163 stream >> d->m_fill; 0164 stream >> d->m_outline; 0165 stream >> d->m_colorIndex; 0166 } 0167 0168 }