@@ -25,6 +25,7 @@ QgsConditionalStyle::QgsConditionalStyle( const QgsConditionalStyle &other )
25
25
, mBackColor( other.mBackColor )
26
26
, mTextColor( other.mTextColor )
27
27
, mIcon( other.mIcon )
28
+ , mName( other.mName )
28
29
{
29
30
if ( other.mSymbol .data () )
30
31
mSymbol .reset ( other.mSymbol ->clone () );
@@ -38,6 +39,7 @@ QgsConditionalStyle& QgsConditionalStyle::operator=( const QgsConditionalStyle &
38
39
mBackColor = other.mBackColor ;
39
40
mTextColor = other.mTextColor ;
40
41
mIcon = other.mIcon ;
42
+ mName = other.mName ;
41
43
if ( other.mSymbol .data () )
42
44
{
43
45
mSymbol .reset ( other.mSymbol ->clone () );
@@ -53,6 +55,14 @@ QgsConditionalStyle::~QgsConditionalStyle()
53
55
{
54
56
}
55
57
58
+ QString QgsConditionalStyle::displayText () const
59
+ {
60
+ if ( name ().isEmpty () )
61
+ return rule ();
62
+ else
63
+ return QString ( " %1 \n %2" ).arg ( name () ).arg ( rule () );
64
+ }
65
+
56
66
void QgsConditionalStyle::setSymbol ( QgsSymbolV2* value )
57
67
{
58
68
mValid = true ;
@@ -103,10 +113,48 @@ QPixmap QgsConditionalStyle::renderPreview()
103
113
return pixmap;
104
114
}
105
115
116
+ QList<QgsConditionalStyle> QgsConditionalStyle::matchingConditionalStyles ( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature *feature )
117
+ {
118
+ QList<QgsConditionalStyle> matchingstyles;
119
+ foreach ( QgsConditionalStyle style, styles )
120
+ {
121
+ if ( style.matches ( value, feature ) )
122
+ matchingstyles.append ( style );
123
+ }
124
+ return matchingstyles;
125
+ }
126
+
127
+ QgsConditionalStyle QgsConditionalStyle::matchingConditionalStyle ( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature *feature )
128
+ {
129
+ foreach ( QgsConditionalStyle style, styles )
130
+ {
131
+ if ( style.matches ( value, feature ) )
132
+ return style;
133
+ }
134
+ return QgsConditionalStyle ();
135
+ }
136
+
137
+ QgsConditionalStyle QgsConditionalStyle::compressStyles ( QList<QgsConditionalStyle> styles )
138
+ {
139
+ QgsConditionalStyle style;
140
+ foreach ( QgsConditionalStyle s, styles )
141
+ {
142
+ style.setFont ( s.font () );
143
+ if ( s.backgroundColor ().isValid () && s.backgroundColor ().alpha () != 0 )
144
+ style.setBackgroundColor ( s.backgroundColor () );
145
+ if ( s.textColor ().isValid () && s.textColor ().alpha () != 0 )
146
+ style.setTextColor ( s.textColor () );
147
+ if ( s.symbol () )
148
+ style.setSymbol ( s.symbol () );
149
+ }
150
+ return style;
151
+ }
152
+
106
153
bool QgsConditionalStyle::writeXml ( QDomNode &node, QDomDocument &doc )
107
154
{
108
155
QDomElement stylesel = doc.createElement ( " style" );
109
156
stylesel.setAttribute ( " rule" , mRule );
157
+ stylesel.setAttribute ( " name" , mName );
110
158
stylesel.setAttribute ( " background_color" , mBackColor .name () );
111
159
stylesel.setAttribute ( " text_color" , mTextColor .name () );
112
160
QDomElement labelFontElem = QgsFontUtils::toXmlElement ( mFont , doc, " font" );
@@ -124,6 +172,7 @@ bool QgsConditionalStyle::readXml( const QDomNode &node )
124
172
{
125
173
QDomElement styleElm = node.toElement ();
126
174
setRule ( styleElm.attribute ( " rule" ) );
175
+ setName ( styleElm.attribute ( " name" ) );
127
176
setBackgroundColor ( QColor ( styleElm.attribute ( " background_color" ) ) );
128
177
setTextColor ( QColor ( styleElm.attribute ( " text_color" ) ) );
129
178
QgsFontUtils::setFromXmlChildNode ( mFont , styleElm, " font" );
0 commit comments