24 #include <QDomDocument>
25 #include <QDomElement>
37 return mTransparentSingleValuePixelList;
45 return mTransparentThreeValuePixelList;
54 mTransparentSingleValuePixelList.clear();
58 myTransparentSingleValuePixel.
min = theValue;
59 myTransparentSingleValuePixel.
max = theValue;
61 mTransparentSingleValuePixelList.append( myTransparentSingleValuePixel );
70 mTransparentThreeValuePixelList.clear();
74 myTransparentThreeValuePixel.
red = theRedValue;
75 myTransparentThreeValuePixel.
green = theGreenValue;
76 myTransparentThreeValuePixel.
blue = theBlueValue;
78 mTransparentThreeValuePixelList.append( myTransparentThreeValuePixel );
87 mTransparentSingleValuePixelList = theNewList;
95 mTransparentThreeValuePixelList = theNewList;
107 if ( qIsNaN( theValue ) )
113 bool myTransparentPixelFound =
false;
115 for (
int myListRunner = 0; myListRunner < mTransparentSingleValuePixelList.count(); myListRunner++ )
117 myTransparentPixel = mTransparentSingleValuePixelList[myListRunner];
118 if (( theValue >= myTransparentPixel.
min && theValue <= myTransparentPixel.
max ) ||
122 myTransparentPixelFound =
true;
128 if ( myTransparentPixelFound )
130 return (
int )(( float )theGlobalTransparency *( 1.0 - ( myTransparentPixel.
percentTransparent / 100.0 ) ) );
133 return theGlobalTransparency;
147 if ( qIsNaN( theRedValue ) || qIsNaN( theGreenValue ) || qIsNaN( theBlueValue ) )
153 bool myTransparentPixelFound =
false;
155 for (
int myListRunner = 0; myListRunner < mTransparentThreeValuePixelList.count(); myListRunner++ )
157 myTransparentPixel = mTransparentThreeValuePixelList[myListRunner];
158 if ( myTransparentPixel.
red == theRedValue )
160 if ( myTransparentPixel.
green == theGreenValue )
162 if ( myTransparentPixel.
blue == theBlueValue )
164 myTransparentPixelFound =
true;
172 if ( myTransparentPixelFound )
174 return (
int )(( float )theGlobalTransparency *( 1.0 - ( myTransparentPixel.
percentTransparent / 100.0 ) ) );
177 return theGlobalTransparency;
182 return mTransparentSingleValuePixelList.isEmpty() && mTransparentThreeValuePixelList.isEmpty();
187 QDomElement rasterTransparencyElem = doc.createElement(
"rasterTransparency" );
188 if ( mTransparentSingleValuePixelList.count() > 0 )
190 QDomElement singleValuePixelListElement = doc.createElement(
"singleValuePixelList" );
191 QList<QgsRasterTransparency::TransparentSingleValuePixel>::const_iterator it = mTransparentSingleValuePixelList.constBegin();
192 for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
194 QDomElement pixelListElement = doc.createElement(
"pixelListEntry" );
197 pixelListElement.setAttribute(
"percentTransparent", QString::number( it->percentTransparent ) );
198 singleValuePixelListElement.appendChild( pixelListElement );
200 rasterTransparencyElem.appendChild( singleValuePixelListElement );
203 if ( mTransparentThreeValuePixelList.count() > 0 )
205 QDomElement threeValuePixelListElement = doc.createElement(
"threeValuePixelList" );
206 QList<QgsRasterTransparency::TransparentThreeValuePixel>::const_iterator it = mTransparentThreeValuePixelList.constBegin();
207 for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
209 QDomElement pixelListElement = doc.createElement(
"pixelListEntry" );
213 pixelListElement.setAttribute(
"percentTransparent", QString::number( it->percentTransparent ) );
214 threeValuePixelListElement.appendChild( pixelListElement );
216 rasterTransparencyElem.appendChild( threeValuePixelListElement );
218 parentElem.appendChild( rasterTransparencyElem );
228 mTransparentSingleValuePixelList.clear();
229 mTransparentThreeValuePixelList.clear();
230 QDomElement currentEntryElem;
232 QDomElement singlePixelListElem = elem.firstChildElement(
"singleValuePixelList" );
233 if ( !singlePixelListElem.isNull() )
235 QDomNodeList entryList = singlePixelListElem.elementsByTagName(
"pixelListEntry" );
237 for (
int i = 0; i < entryList.size(); ++i )
239 currentEntryElem = entryList.at( i ).toElement();
240 sp.
percentTransparent = currentEntryElem.attribute(
"percentTransparent" ).toDouble();
242 if ( currentEntryElem.hasAttribute(
"pixelValue" ) )
244 sp.
min = sp.
max = currentEntryElem.attribute(
"pixelValue" ).toDouble();
248 sp.
min = currentEntryElem.attribute(
"min" ).toDouble();
249 sp.
max = currentEntryElem.attribute(
"max" ).toDouble();
251 mTransparentSingleValuePixelList.append( sp );
254 QDomElement threeValuePixelListElem = elem.firstChildElement(
"threeValuePixelList" );
255 if ( !threeValuePixelListElem.isNull() )
257 QDomNodeList entryList = threeValuePixelListElem.elementsByTagName(
"pixelListEntry" );
259 for (
int i = 0; i < entryList.size(); ++i )
261 currentEntryElem = entryList.at( i ).toElement();
262 tp.
red = currentEntryElem.attribute(
"red" ).toDouble();
263 tp.
green = currentEntryElem.attribute(
"green" ).toDouble();
264 tp.
blue = currentEntryElem.attribute(
"blue" ).toDouble();
265 tp.
percentTransparent = currentEntryElem.attribute(
"percentTransparent" ).toDouble();
266 mTransparentThreeValuePixelList.append( tp );