24 #include <QDomDocument> 25 #include <QDomElement> 32 return mTransparentSingleValuePixelList;
40 return mTransparentThreeValuePixelList;
49 mTransparentSingleValuePixelList.clear();
53 myTransparentSingleValuePixel.
min = value;
54 myTransparentSingleValuePixel.
max = value;
56 mTransparentSingleValuePixelList.append( myTransparentSingleValuePixel );
65 mTransparentThreeValuePixelList.clear();
69 myTransparentThreeValuePixel.
red = redValue;
70 myTransparentThreeValuePixel.
green = greenValue;
71 myTransparentThreeValuePixel.
blue = blueValue;
73 mTransparentThreeValuePixelList.append( myTransparentThreeValuePixel );
82 mTransparentSingleValuePixelList = newList;
90 mTransparentThreeValuePixelList = newList;
102 if ( std::isnan( value ) )
108 bool myTransparentPixelFound =
false;
110 for (
int myListRunner = 0; myListRunner < mTransparentSingleValuePixelList.count(); myListRunner++ )
112 myTransparentPixel = mTransparentSingleValuePixelList[myListRunner];
113 if ( ( value >= myTransparentPixel.
min && value <= myTransparentPixel.
max ) ||
117 myTransparentPixelFound =
true;
123 if ( myTransparentPixelFound )
125 return static_cast< int >(
static_cast< float >( globalTransparency ) * ( 1.0 - ( myTransparentPixel.
percentTransparent / 100.0 ) ) );
128 return globalTransparency;
142 if ( std::isnan( redValue ) || std::isnan( greenValue ) || std::isnan( blueValue ) )
148 bool myTransparentPixelFound =
false;
150 for (
int myListRunner = 0; myListRunner < mTransparentThreeValuePixelList.count(); myListRunner++ )
152 myTransparentPixel = mTransparentThreeValuePixelList[myListRunner];
159 myTransparentPixelFound =
true;
167 if ( myTransparentPixelFound )
169 return static_cast< int >(
static_cast< float >( globalTransparency ) * ( 1.0 - ( myTransparentPixel.
percentTransparent / 100.0 ) ) );
172 return globalTransparency;
177 return mTransparentSingleValuePixelList.isEmpty() && mTransparentThreeValuePixelList.isEmpty();
182 QDomElement rasterTransparencyElem = doc.createElement( QStringLiteral(
"rasterTransparency" ) );
183 if ( !mTransparentSingleValuePixelList.isEmpty() )
185 QDomElement singleValuePixelListElement = doc.createElement( QStringLiteral(
"singleValuePixelList" ) );
186 QList<QgsRasterTransparency::TransparentSingleValuePixel>::const_iterator it = mTransparentSingleValuePixelList.constBegin();
187 for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
189 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
192 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( it->percentTransparent ) );
193 singleValuePixelListElement.appendChild( pixelListElement );
195 rasterTransparencyElem.appendChild( singleValuePixelListElement );
198 if ( !mTransparentThreeValuePixelList.isEmpty() )
200 QDomElement threeValuePixelListElement = doc.createElement( QStringLiteral(
"threeValuePixelList" ) );
201 QList<QgsRasterTransparency::TransparentThreeValuePixel>::const_iterator it = mTransparentThreeValuePixelList.constBegin();
202 for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
204 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
208 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( it->percentTransparent ) );
209 threeValuePixelListElement.appendChild( pixelListElement );
211 rasterTransparencyElem.appendChild( threeValuePixelListElement );
213 parentElem.appendChild( rasterTransparencyElem );
223 mTransparentSingleValuePixelList.clear();
224 mTransparentThreeValuePixelList.clear();
225 QDomElement currentEntryElem;
227 QDomElement singlePixelListElem = elem.firstChildElement( QStringLiteral(
"singleValuePixelList" ) );
228 if ( !singlePixelListElem.isNull() )
230 QDomNodeList entryList = singlePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
232 for (
int i = 0; i < entryList.size(); ++i )
234 currentEntryElem = entryList.at( i ).toElement();
235 sp.
percentTransparent = currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble();
237 if ( currentEntryElem.hasAttribute( QStringLiteral(
"pixelValue" ) ) )
239 sp.
min = sp.
max = currentEntryElem.attribute( QStringLiteral(
"pixelValue" ) ).toDouble();
243 sp.
min = currentEntryElem.attribute( QStringLiteral(
"min" ) ).toDouble();
244 sp.
max = currentEntryElem.attribute( QStringLiteral(
"max" ) ).toDouble();
246 mTransparentSingleValuePixelList.append( sp );
249 QDomElement threeValuePixelListElem = elem.firstChildElement( QStringLiteral(
"threeValuePixelList" ) );
250 if ( !threeValuePixelListElem.isNull() )
252 QDomNodeList entryList = threeValuePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
254 for (
int i = 0; i < entryList.size(); ++i )
256 currentEntryElem = entryList.at( i ).toElement();
257 tp.
red = currentEntryElem.attribute( QStringLiteral(
"red" ) ).toDouble();
258 tp.
green = currentEntryElem.attribute( QStringLiteral(
"green" ) ).toDouble();
259 tp.
blue = currentEntryElem.attribute( QStringLiteral(
"blue" ) ).toDouble();
260 tp.
percentTransparent = currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble();
261 mTransparentThreeValuePixelList.append( tp );
int alphaValue(double, int globalTransparency=255) const
Returns the transparency value for a single value Pixel.
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)
Mutator for transparentThreeValuePixelList.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
double percentTransparent
void readXml(const QDomElement &elem)
Reads the transparency information from an XML document.
QList< QgsRasterTransparency::TransparentSingleValuePixel > transparentSingleValuePixelList() const
Accessor for transparentSingleValuePixelList.
void setTransparentSingleValuePixelList(const QList< QgsRasterTransparency::TransparentSingleValuePixel > &newList)
Mutator for transparentSingleValuePixelList.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Writes the transparency information to an XML document.
QList< QgsRasterTransparency::TransparentThreeValuePixel > transparentThreeValuePixelList() const
Accessor for transparentThreeValuePixelList.
double percentTransparent
void initializeTransparentPixelList(double)
Reset to the transparency list to a single value.