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 );
bool isEmpty() const
True if there are no entries in the pixel lists except the nodata value.
static QString printValue(double value)
Print double value with all necessary significant digits.
void setTransparentThreeValuePixelList(const QList< QgsRasterTransparency::TransparentThreeValuePixel > &newList)
Sets the transparent three value pixel list, replacing the whole existing list.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void initializeTransparentPixelList(double value)
Resets the transparency list to a single value.
double percentTransparent
void readXml(const QDomElement &elem)
Reads the transparency information from an XML document.
int alphaValue(double value, int globalTransparency=255) const
Returns the transparency value for a single value pixel.
QList< QgsRasterTransparency::TransparentSingleValuePixel > transparentSingleValuePixelList() const
Returns the transparent single value pixel list.
void setTransparentSingleValuePixelList(const QList< QgsRasterTransparency::TransparentSingleValuePixel > &newList)
Sets the transparent single value pixel list, replacing the whole existing list.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Writes the transparency information to an XML document.
QList< QgsRasterTransparency::TransparentThreeValuePixel > transparentThreeValuePixelList() const
Returns the transparent three value pixel list.
double percentTransparent