File indexing completed on 2024-05-12 03:50:14

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 "GeoDataLineStyle.h"
0008 
0009 #include "GeoDataTypes.h"
0010 
0011 #include <QDataStream>
0012 
0013 namespace Marble
0014 {
0015 
0016 class GeoDataLineStylePrivate
0017 {
0018   public:
0019     GeoDataLineStylePrivate() 
0020         : m_width( 1.0 ), m_physicalWidth( 0.0 ),
0021           m_capStyle( Qt::FlatCap ), m_penStyle( Qt::SolidLine ),
0022           m_cosmeticOutline( false ), m_background( false )
0023     {
0024     }
0025 
0026     /// The current width of the line
0027     float  m_width;
0028     /// The current real width of the line
0029     float  m_physicalWidth;
0030     Qt::PenCapStyle m_capStyle;
0031     Qt::PenStyle m_penStyle;
0032     bool m_cosmeticOutline;
0033     bool m_background;
0034     QVector< qreal > m_pattern;
0035 };
0036 
0037 GeoDataLineStyle::GeoDataLineStyle()
0038     : d (new GeoDataLineStylePrivate )
0039 {
0040 }
0041 
0042 GeoDataLineStyle::GeoDataLineStyle( const GeoDataLineStyle& other )
0043     : GeoDataColorStyle( other ), d (new GeoDataLineStylePrivate( *other.d ) )
0044 {
0045 }
0046 
0047 GeoDataLineStyle::GeoDataLineStyle( const QColor &color )
0048     : d ( new GeoDataLineStylePrivate )
0049 {
0050     setColor( color );
0051 }
0052 
0053 GeoDataLineStyle::~GeoDataLineStyle()
0054 {
0055     delete d;
0056 }
0057 
0058 GeoDataLineStyle& GeoDataLineStyle::operator=( const GeoDataLineStyle& other )
0059 {
0060     GeoDataColorStyle::operator=( other );
0061     *d = *other.d;
0062     return *this;
0063 }
0064 
0065 bool GeoDataLineStyle::operator==( const GeoDataLineStyle &other ) const
0066 {
0067     if ( GeoDataColorStyle::operator!=( other ) ) {
0068         return false;
0069     }
0070 
0071     return d->m_width == other.d->m_width &&
0072            d->m_physicalWidth == other.d->m_physicalWidth &&
0073            d->m_capStyle == other.d->m_capStyle &&
0074            d->m_penStyle == other.d->m_penStyle &&
0075            d->m_background == other.d->m_background &&
0076            d->m_pattern == other.d->m_pattern;
0077 }
0078 
0079 bool GeoDataLineStyle::operator!=( const GeoDataLineStyle &other ) const
0080 {
0081     return !this->operator==( other );
0082 }
0083 
0084 const char* GeoDataLineStyle::nodeType() const
0085 {
0086     return GeoDataTypes::GeoDataLineStyleType;
0087 }
0088 
0089 void GeoDataLineStyle::setWidth(float width)
0090 {
0091     d->m_width = width;
0092 }
0093 
0094 float GeoDataLineStyle::width() const
0095 {
0096     return d->m_width;
0097 }
0098 
0099 float GeoDataLineStyle::physicalWidth() const
0100 {
0101     return d->m_physicalWidth;
0102 }
0103 
0104 void GeoDataLineStyle::setPhysicalWidth(float realWidth)
0105 {
0106     d->m_physicalWidth = realWidth;
0107 }
0108 
0109 bool GeoDataLineStyle::cosmeticOutline() const
0110 {
0111     return d->m_cosmeticOutline;
0112 }
0113 
0114 void GeoDataLineStyle::setCosmeticOutline(bool enabled)
0115 {
0116     d->m_cosmeticOutline = enabled;
0117 }
0118 
0119 Qt::PenCapStyle GeoDataLineStyle::capStyle() const
0120 {
0121     return d->m_capStyle;
0122 }
0123 
0124 void GeoDataLineStyle::setCapStyle( Qt::PenCapStyle style )
0125 {
0126     d->m_capStyle = style;
0127 }
0128 
0129 Qt::PenStyle GeoDataLineStyle::penStyle() const
0130 {
0131     return d->m_penStyle;
0132 }
0133 
0134 void GeoDataLineStyle::setPenStyle( Qt::PenStyle style )
0135 {
0136    d->m_penStyle = style;
0137 }
0138 
0139 bool GeoDataLineStyle::background() const
0140 {
0141     return d->m_background;
0142 }
0143 
0144 void GeoDataLineStyle::setBackground( bool background )
0145 {
0146     d->m_background = background;
0147 }
0148 
0149 QVector< qreal > GeoDataLineStyle::dashPattern() const
0150 {
0151     return d->m_pattern;
0152 }
0153 
0154 void GeoDataLineStyle::setDashPattern( const QVector< qreal >& pattern )
0155 {
0156     d->m_pattern = pattern;
0157 }
0158 
0159 void GeoDataLineStyle::pack( QDataStream& stream ) const
0160 {
0161     GeoDataColorStyle::pack( stream );
0162     
0163     stream << d->m_width;
0164     stream << d->m_physicalWidth;
0165     stream << (int)d->m_penStyle;
0166     stream << (int)d->m_capStyle;
0167     stream << d->m_background;
0168 }
0169 
0170 void GeoDataLineStyle::unpack( QDataStream& stream )
0171 {
0172     GeoDataColorStyle::unpack( stream );
0173     
0174     stream >> d->m_width;
0175     stream >> d->m_physicalWidth;
0176     int style;
0177     stream >> style;
0178     d->m_penStyle = ( Qt::PenStyle ) style;
0179     stream >> style;
0180     d->m_capStyle = ( Qt::PenCapStyle ) style;
0181     stream >> d->m_background;
0182 }
0183 
0184 }