Skip to content

Commit fa7dae9

Browse files
author
timlinux
committedJan 13, 2004
First pass at raster layer properties persistance when saving project. This is still pretty buggy at the moment. Stand by for a bug fix update in the near future...
git-svn-id: http://svn.osgeo.org/qgis/trunk@471 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 11cb31c commit fa7dae9

File tree

3 files changed

+153
-11
lines changed

3 files changed

+153
-11
lines changed
 

‎qgis.dtd‎

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
* This DTD describes the maplayers and their symbology and
33
* is used when saving/restoring a QGIS project.
44
-->
5+
6+
<!--
7+
-- Project Properties
8+
--
9+
-->
510
<!ELEMENT qgis (title, extent, projectlayers) >
611
<!ELEMENT projectlayers (maplayer*) >
712
<!ELEMENT extent (xmin, ymin, xmax, ymax) >
@@ -10,20 +15,31 @@
1015
<!ELEMENT xmax (#PCDATA) >
1116
<!ELEMENT ymax (#PCDATA) >
1217
<!ELEMENT title (#PCDATA) >
18+
<!-- Attribute Lists -->
19+
<!ATTLIST qgis projectname CDATA #REQUIRED >
20+
<!ATTLIST projectlayers layercount CDATA #REQUIRED >
21+
<!--
22+
-- General Map Layer Properties
23+
-- (apply to both vector and raster)
24+
-->
1325
<!ELEMENT maplayer (layername, datasource, zorder, symbol) >
1426
<!ELEMENT layername (#PCDATA) >
1527
<!ELEMENT datasource (#PCDATA) >
1628
<!ELEMENT zorder (#PCDATA) >
17-
<!ELEMENT symbol (linewidth, outlinecolor, fillcolor) >
18-
<!ELEMENT linewidth (#PCDATA) >
19-
<!ELEMENT fillcolor EMPTY>
20-
<!ELEMENT outlinecolor EMPTY>
21-
<!ATTLIST qgis projectname CDATA #REQUIRED >
29+
<!-- Attribute Lists -->
2230
<!ATTLIST maplayer
2331
type (vector|raster|database) "vector"
2432
visible (1|0) "0"
2533
>
26-
<!ATTLIST projectlayers layercount CDATA #REQUIRED >
34+
<!--
35+
-- Vector Layer Properties
36+
--
37+
-->
38+
<!ELEMENT symbol (linewidth, outlinecolor, fillcolor) >
39+
<!ELEMENT linewidth (#PCDATA) >
40+
<!ELEMENT fillcolor EMPTY>
41+
<!ELEMENT outlinecolor EMPTY>
42+
<!-- Attribute Lists -->
2743
<!ATTLIST fillcolor
2844
red CDATA #IMPLIED
2945
green CDATA #IMPLIED
@@ -33,4 +49,33 @@
3349
red CDATA #IMPLIED
3450
green CDATA #IMPLIED
3551
blue CDATA #IMPLIED
36-
>
52+
>
53+
<!--
54+
-- Raster Layer Properties
55+
--
56+
-->
57+
<!ELEMENT rasterproperties (showDebugOverlayFlag, showGrayAsColorFlag, invertHistogramFlag, stdDevsToPlotDouble, transparencyLevelInt, redBandNameQString, greenBandNameQString, blueBandNameQString, grayBandNameQString) >
58+
<!--Raster flag to indicate whether debug infor overlay should be rendered onto the raster -->
59+
<!ELEMENT showDebugOverlayFlag>
60+
<!--Raster flag indicating whether grayscale images should be rendered as pseudocolor -->
61+
<!ELEMENT showGrayAsColorFlag>
62+
<!--Raster : flag indicating whether the histogram should be inverted or not -->
63+
<!ELEMENT invertHistogramFlag>
64+
<!--Raster : Number of stddev to plot (0) to ignore -->
65+
<!ELEMENT stdDevsToPlotDouble>
66+
<!--Raster transparency for this layer should be 0-255 -->
67+
<!ELEMENT transparencyLevelInt>
68+
<!--Raster : the band to be associated with the color red - usually red -->
69+
<!ELEMENT redBandNameQString (#CDATA)>
70+
<!--Raster : the band to be associated with the color green - usually green -->
71+
<!ELEMENT greenBandNameQString (#CDATA)>
72+
<!--Raster : the band to be associated with the color blue - usually blue -->
73+
<!ELEMENT blueBandNameQString (#CDATA)>
74+
<!--Raster : the band to be associated with the grayscale only ouput - usually gray -->
75+
<!ELEMENT grayBandNameQString (#CDATA)>
76+
<!-- Attribute Lists -->
77+
<!ATTLIST showDebugOverlayFlag boolean (1|0|true|false) "false">
78+
<!ATTLIST showGrayAsColorFlag boolean (1|0|true|false) "false">
79+
<!ATTLIST invertHistogramFlag boolean (1|0|true|false) "false">
80+
<!ATTLIST stdDevsToPlotDouble value CDATA "0">
81+
<!ATTLIST transparencyLevelInt value CDATA "0">

‎src/qgsprojectio.cpp‎

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15-
/* qgsprojectio.cpp,v 1.12 2003/12/26 15:56:30 stevehalasz Exp */
15+
/* qgsprojectio.cpp,v 1.13 2004/01/13 15:15:31 timlinux Exp */
1616
#include <iostream>
1717
#include <fstream>
1818
#include <qfiledialog.h>
@@ -21,6 +21,7 @@
2121
#include <qmessagebox.h>
2222
#include <qcolor.h>
2323
#include "qgsmaplayer.h"
24+
#include "qvariant.h"
2425
#ifdef POSTGRESQL
2526
#include "qgsdatabaselayer.h"
2627
#endif
@@ -176,10 +177,51 @@ bool QgsProjectIo::read(){
176177
shpl->setSymbol(sym);
177178
shpl->setVisible(visible == "1");
178179
} else if ( type == "raster" ) {
179-
QgsRasterLayer *rastl = new QgsRasterLayer(dataSource, layerName);
180+
QgsRasterLayer *myRasterLayer = new QgsRasterLayer(dataSource, layerName);
180181

181-
map->addLayer(rastl);
182-
rastl->setVisible(visible == "1");
182+
map->addLayer(myRasterLayer);
183+
184+
myRasterLayer->setVisible(visible == "1");
185+
186+
mnl = node.namedItem("rasterproperties");
187+
188+
QDomNode snode = mnl.namedItem("showDebugOverlayFlag");
189+
QDomElement myElement = snode.toElement();
190+
QVariant myQVariant = (QVariant) myElement.attribute("boolean");
191+
myRasterLayer->setShowDebugOverlayFlag(myQVariant.toBool());
192+
193+
snode = mnl.namedItem("showGrayAsColorFlag");
194+
myElement = snode.toElement();
195+
myQVariant = (QVariant) myElement.attribute("boolean");
196+
myRasterLayer->setShowGrayAsColorFlag(myQVariant.toBool());
197+
snode = mnl.namedItem("invertHistogramFlag");
198+
myElement = snode.toElement();
199+
myQVariant = (QVariant) myElement.attribute("boolean");
200+
myRasterLayer->setInvertHistogramFlag(myQVariant.toBool());
201+
202+
snode = mnl.namedItem("stdDevsToPlotDouble");
203+
myElement = snode.toElement();
204+
myRasterLayer->setStdDevsToPlot(myElement.text().toDouble());
205+
206+
snode = mnl.namedItem("transparencyLevelInt");
207+
myElement = snode.toElement();
208+
myRasterLayer->slot_setTransparency(myElement.text().toInt());
209+
210+
snode = mnl.namedItem("redBandNameQString");
211+
myElement = snode.toElement();
212+
myRasterLayer->setRedBandName(myElement.text());
213+
snode = mnl.namedItem("greenBandNameQString");
214+
myElement = snode.toElement();
215+
myRasterLayer->setGreenBandName(myElement.text());
216+
217+
snode = mnl.namedItem("blueBandNameQString");
218+
myElement = snode.toElement();
219+
myRasterLayer->setBlueBandName(myElement.text());
220+
221+
snode = mnl.namedItem("grayBandNameQString");
222+
myElement = snode.toElement();
223+
myRasterLayer->setGrayBandName(myElement.text());
224+
183225
}
184226
map->setExtent(savedExtent);
185227
}
@@ -204,12 +246,17 @@ switch(action){
204246
}
205247
return fullPath;
206248
}
249+
207250
void QgsProjectIo::setFileName(QString fn){
208251
fullPath = fn;
209252
}
253+
210254
QString QgsProjectIo::fullPathName(){
211255
return fullPath;
212256
}
257+
258+
259+
213260
void QgsProjectIo::writeXML(){
214261
std::ofstream xml(fullPath);
215262
if(!xml.fail()){
@@ -278,6 +325,55 @@ void QgsProjectIo::writeXML(){
278325

279326
xml << "\t\t</symbol>\n";
280327
}
328+
else //raster layer properties
329+
{
330+
//cast the maplayer to rasterlayer
331+
QgsRasterLayer *myRasterLayer = (QgsRasterLayer *) lyr;
332+
//Raster flag to indicate whether debug infor overlay should be rendered onto the raster
333+
xml << "\t\t<rasterproperties>\n";
334+
xml << "\t\t\t<showDebugOverlayFlag boolean=\"" ;
335+
if (myRasterLayer->getShowDebugOverlayFlag())
336+
{
337+
xml << "true\"/>\n";
338+
}
339+
else
340+
{
341+
xml << "true\"/>\n";
342+
}
343+
// Raster flag indicating whether grayscale images should be rendered as pseudocolor
344+
xml << "\t\t\t<showGrayAsColorFlag boolean=\"" ;
345+
if (myRasterLayer->getShowGrayAsColorFlag())
346+
{
347+
xml << "true\"/>\n";
348+
}
349+
else
350+
{
351+
xml << "true\"/>\n";
352+
}
353+
//Raster : flag indicating whether the histogram should be inverted or not
354+
xml << "\t\t\t<invertHistogramFlag boolean=\"" ;
355+
if (myRasterLayer->getInvertHistogramFlag())
356+
{
357+
xml << "true\"/>\n";
358+
}
359+
else
360+
{
361+
xml << "true\"/>\n";
362+
}
363+
//Raster : Number of stddev to plot (0) to ignore -->
364+
xml << "\t\t\t<stdDevsToPlotDouble>" << myRasterLayer->getStdDevsToPlot() << "</stdDevsToPlotDouble>\n" ;
365+
//Raster transparency for this layer should be 0-255 -->
366+
xml << "\t\t\t<transparencyLevelInt>" << myRasterLayer->getTransparency() << "</transparencyLevelInt>\n" ;
367+
//Raster : the band to be associated with the color red - usually red -->
368+
xml << "\t\t\t<redBandNameQString>" << myRasterLayer->getRedBandName() << "</redBandNameQString>\n" ;
369+
//Raster : the band to be associated with the color green - usually green -->
370+
xml << "\t\t\t<greenBandNameQString>" << myRasterLayer->getGreenBandName() << "</greenBandNameQString>\n" ;
371+
//Raster : the band to be associated with the color blue - usually blue -->
372+
xml << "\t\t\t<blueBandNameQString>" << myRasterLayer->getBlueBandName() << "</blueBandNameQString>\n" ;
373+
//Raster : the band to be associated with the grayscale only ouput - usually gray -->
374+
xml << "\t\t\t<grayBandNameQString>" << myRasterLayer->getGrayBandName() << "</grayBandNameQString>\n" ;
375+
xml << "\t\t</rasterproperties>\n";
376+
}
281377
xml << "\t</maplayer>\n";
282378
}
283379
xml << "</projectlayers>\n";

‎src/qgsrasterlayer.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ QgsRasterLayer::QgsRasterLayer(QString path, QString baseName)
6161
redBandNameQString="Red"; // sensible default
6262
greenBandNameQString="Green"; // sensible default
6363
blueBandNameQString="Blue"; // sensible default
64+
blueBandNameQString="Gray"; // sensible default
6465
showGrayAsColorFlag=false; // sensible default
6566
invertHistogramFlag=false; // sensible default
6667
stdDevsToPlotDouble = 0; // sensible default

0 commit comments

Comments
 (0)
Please sign in to comment.