24 #include <QDomDocument>
25 #include <QDomElement>
29 return mTransparentSingleValuePixelList;
34 return mTransparentThreeValuePixelList;
40 mTransparentSingleValuePixelList.clear();
44 myTransparentSingleValuePixel.
min = value;
45 myTransparentSingleValuePixel.
max = value;
47 mTransparentSingleValuePixelList.append( myTransparentSingleValuePixel );
53 mTransparentThreeValuePixelList.clear();
57 myTransparentThreeValuePixel.
red = redValue;
58 myTransparentThreeValuePixel.
green = greenValue;
59 myTransparentThreeValuePixel.
blue = blueValue;
61 mTransparentThreeValuePixelList.append( myTransparentThreeValuePixel );
66 mTransparentSingleValuePixelList = newList;
71 mTransparentThreeValuePixelList = newList;
77 if ( std::isnan( value ) )
83 bool myTransparentPixelFound =
false;
85 for (
int myListRunner = 0; myListRunner < mTransparentSingleValuePixelList.count(); myListRunner++ )
87 myTransparentPixel = mTransparentSingleValuePixelList[myListRunner];
88 if ( ( value >= myTransparentPixel.
min && value <= myTransparentPixel.
max ) ||
92 myTransparentPixelFound =
true;
98 if ( myTransparentPixelFound )
100 return static_cast< int >(
static_cast< float >( globalTransparency ) * ( 1.0 - ( myTransparentPixel.
percentTransparent / 100.0 ) ) );
103 return globalTransparency;
109 if ( std::isnan( redValue ) || std::isnan( greenValue ) || std::isnan( blueValue ) )
115 bool myTransparentPixelFound =
false;
117 for (
int myListRunner = 0; myListRunner < mTransparentThreeValuePixelList.count(); myListRunner++ )
119 myTransparentPixel = mTransparentThreeValuePixelList[myListRunner];
126 myTransparentPixelFound =
true;
134 if ( myTransparentPixelFound )
136 return static_cast< int >(
static_cast< float >( globalTransparency ) * ( 1.0 - ( myTransparentPixel.
percentTransparent / 100.0 ) ) );
139 return globalTransparency;
144 return mTransparentSingleValuePixelList.isEmpty() && mTransparentThreeValuePixelList.isEmpty();
149 QDomElement rasterTransparencyElem = doc.createElement( QStringLiteral(
"rasterTransparency" ) );
150 if ( !mTransparentSingleValuePixelList.isEmpty() )
152 QDomElement singleValuePixelListElement = doc.createElement( QStringLiteral(
"singleValuePixelList" ) );
153 QList<QgsRasterTransparency::TransparentSingleValuePixel>::const_iterator it = mTransparentSingleValuePixelList.constBegin();
154 for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
156 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
159 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( it->percentTransparent ) );
160 singleValuePixelListElement.appendChild( pixelListElement );
162 rasterTransparencyElem.appendChild( singleValuePixelListElement );
165 if ( !mTransparentThreeValuePixelList.isEmpty() )
167 QDomElement threeValuePixelListElement = doc.createElement( QStringLiteral(
"threeValuePixelList" ) );
168 QList<QgsRasterTransparency::TransparentThreeValuePixel>::const_iterator it = mTransparentThreeValuePixelList.constBegin();
169 for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
171 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
175 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( it->percentTransparent ) );
176 threeValuePixelListElement.appendChild( pixelListElement );
178 rasterTransparencyElem.appendChild( threeValuePixelListElement );
180 parentElem.appendChild( rasterTransparencyElem );
190 mTransparentSingleValuePixelList.clear();
191 mTransparentThreeValuePixelList.clear();
192 QDomElement currentEntryElem;
194 QDomElement singlePixelListElem = elem.firstChildElement( QStringLiteral(
"singleValuePixelList" ) );
195 if ( !singlePixelListElem.isNull() )
197 QDomNodeList entryList = singlePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
199 for (
int i = 0; i < entryList.size(); ++i )
201 currentEntryElem = entryList.at( i ).toElement();
202 sp.
percentTransparent = currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble();
204 if ( currentEntryElem.hasAttribute( QStringLiteral(
"pixelValue" ) ) )
206 sp.
min = sp.
max = currentEntryElem.attribute( QStringLiteral(
"pixelValue" ) ).toDouble();
210 sp.
min = currentEntryElem.attribute( QStringLiteral(
"min" ) ).toDouble();
211 sp.
max = currentEntryElem.attribute( QStringLiteral(
"max" ) ).toDouble();
213 mTransparentSingleValuePixelList.append( sp );
216 QDomElement threeValuePixelListElem = elem.firstChildElement( QStringLiteral(
"threeValuePixelList" ) );
217 if ( !threeValuePixelListElem.isNull() )
219 QDomNodeList entryList = threeValuePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
221 for (
int i = 0; i < entryList.size(); ++i )
223 currentEntryElem = entryList.at( i ).toElement();
224 tp.
red = currentEntryElem.attribute( QStringLiteral(
"red" ) ).toDouble();
225 tp.
green = currentEntryElem.attribute( QStringLiteral(
"green" ) ).toDouble();
226 tp.
blue = currentEntryElem.attribute( QStringLiteral(
"blue" ) ).toDouble();
227 tp.
percentTransparent = currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble();
228 mTransparentThreeValuePixelList.append( tp );