Marble

GeoDataPolyStyle.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2008 Patrick Spendrin <[email protected]>
4 //
5 
6 
7 #include "GeoDataPolyStyle.h"
8 #include "GeoDataTypes.h"
9 #include "MarbleDirs.h"
10 
11 #include <QDataStream>
12 #include <QImage>
13 
14 namespace Marble
15 {
16 
17 class GeoDataPolyStylePrivate
18 {
19  public:
20  GeoDataPolyStylePrivate()
21  : m_fill(true)
22  , m_outline(true)
23  , m_brushStyle(Qt::SolidPattern)
24  , m_colorIndex(0)
25  {
26  }
27 
28  /// whether to fill the polygon
29  bool m_fill;
30  /// whether to draw the outline
31  bool m_outline;
32  Qt::BrushStyle m_brushStyle;
33  /// The value of colorIndex will be maped to a color for brush
34  quint8 m_colorIndex;
35  QString m_texturePath;
36  QImage m_textureImage;
37 };
38 
40  : d( new GeoDataPolyStylePrivate )
41 {
42 }
43 
45  : GeoDataColorStyle( other ), d( new GeoDataPolyStylePrivate( *other.d ) )
46 {
47 }
48 
50  : d( new GeoDataPolyStylePrivate )
51 {
52  setColor( color );
53 }
54 
55 GeoDataPolyStyle::~GeoDataPolyStyle()
56 {
57  delete d;
58 }
59 
61 {
63  *d = *other.d;
64  return *this;
65 }
66 
67 bool GeoDataPolyStyle::operator==( const GeoDataPolyStyle &other ) const
68 {
69  if ( GeoDataColorStyle::operator!=( other ) ) {
70  return false;
71  }
72 
73  return d->m_fill == other.d->m_fill &&
74  d->m_outline == other.d->m_outline &&
75  d->m_brushStyle == other.d->m_brushStyle;
76 }
77 
78 bool GeoDataPolyStyle::operator!=( const GeoDataPolyStyle &other ) const
79 {
80  return !this->operator==( other );
81 }
82 
83 const char* GeoDataPolyStyle::nodeType() const
84 {
85  return GeoDataTypes::GeoDataPolyStyleType;
86 }
87 
89 {
90  d->m_fill = fill;
91 }
92 
94 {
95  return d->m_fill;
96 }
97 
98 void GeoDataPolyStyle::setOutline(bool outline)
99 {
100  d->m_outline = outline;
101 }
102 
104 {
105  return d->m_outline;
106 }
107 
109 {
110  d->m_brushStyle = style;
111 }
112 
114 {
115  return d->m_brushStyle;
116 }
117 
118 void GeoDataPolyStyle::setColorIndex( quint8 colorIndex )
119 {
120  d->m_colorIndex = colorIndex;
121 }
122 
124 {
125  return d->m_colorIndex;
126 }
127 
128 void GeoDataPolyStyle::setTexturePath( const QString& texturePath )
129 {
130  d->m_texturePath = texturePath;
131  d->m_textureImage = QImage();
132 }
133 
134 QString GeoDataPolyStyle::texturePath() const
135 {
136  return d->m_texturePath;
137 }
138 
139 QImage GeoDataPolyStyle::textureImage() const
140 {
141  if ( !d->m_textureImage.isNull() ) {
142  return d->m_textureImage;
143  } else if ( !d->m_texturePath.isEmpty() ) {
144  d->m_textureImage = QImage( resolvePath( d->m_texturePath ) );
145  }
146 
147  return d->m_textureImage;
148 }
149 
150 void GeoDataPolyStyle::pack( QDataStream& stream ) const
151 {
152  GeoDataColorStyle::pack( stream );
153 
154  stream << d->m_fill;
155  stream << d->m_outline;
156  stream << d->m_colorIndex;
157 }
158 
160 {
161  GeoDataColorStyle::unpack( stream );
162 
163  stream >> d->m_fill;
164  stream >> d->m_outline;
165  stream >> d->m_colorIndex;
166 }
167 
168 }
void pack(QDataStream &stream) const override
Serialize the style to a stream.
void pack(QDataStream &stream) const override
Serialize the style to a stream.
void setColorIndex(quint8 colorIndex)
Set the color index which will be used to assign color to brush.
void setFill(bool fill)
Set whether to fill the polygon.
void unpack(QDataStream &stream) override
Unserialize the style from a stream.
GeoDataPolyStyle()
Construct a new GeoDataPolyStyle.
bool outline() const
Return true if outlines of polygons get drawn.
bool fill() const
Return true if polygons get filled.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
QColor color() const
Return the color component.
Qt::BrushStyle brushStyle() const
Return brush style.
void setOutline(bool outline)
Set whether to draw the outline.
Binds a QML item to a specific geodetic location in screen coordinates.
GeoDataColorStyle & operator=(const GeoDataColorStyle &other)
assignment operator
an abstract base class for various style classes
specifies the style how polygons are drawn
void setBrushStyle(const Qt::BrushStyle style)
Set brush style.
quint8 colorIndex() const
Return the value of color index.
void unpack(QDataStream &stream) override
Unserialize the style from a stream.
GeoDataPolyStyle & operator=(const GeoDataPolyStyle &other)
assignment operator
void setColor(const QColor &value)
Set a new color.
SolidPattern
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.