Skip to content

Commit 66ae77d

Browse files

28 files changed

+573
-380
lines changed
 

‎python/core/qgscontinuouscolorrenderer.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class QgsContinuousColorRenderer : QgsRenderer
3131
/**Reads the renderer configuration from an XML file
3232
@param rnode the Dom node to read
3333
@param vl the vector layer which will be associated with the renderer*/
34-
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
34+
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
3535
/**Writes the contents of the renderer to a configuration file
3636
@ return true in case of success*/
37-
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
37+
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const;
3838
/** Returns true*/
3939
bool needsAttributes() const;
4040
/**Returns a list with the index of the classification attribute*/

‎python/core/qgsgraduatedsymbolrenderer.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class QgsGraduatedSymbolRenderer : QgsRenderer
3030
/**Reads the renderer configuration from an XML file
3131
@param rnode the Dom node to read
3232
@param vl the vector layer which will be associated with the renderer*/
33-
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
33+
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
3434
/**Writes the contents of the renderer to a configuration file
3535
@ return true in case of success*/
36-
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
36+
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, QgsVectorLayer& vl ) const;
3737
/** Returns true*/
3838
bool needsAttributes() const;
3939
/**Returns a list with the index to the classification field*/

‎python/core/qgsmaplayer.sip

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ public:
140140
*/
141141
bool writeXML(QDomNode & layer_node, QDomDocument & document);
142142

143+
/** Read the symbology for the current layer from the Dom node supplied.
144+
* @param QDomNode node that will contain the symbology definition for this layer.
145+
* @param errorMessage reference to string that will be updated with any error messages
146+
* @return true in case of success.
147+
*/
148+
virtual bool readSymbology(const QDomNode& node, QString& errorMessage) = 0;
149+
150+
/** Write the symbology for the layer into the docment provided.
151+
* @param QDomNode the node that will have the style element added to it.
152+
* @param QDomDocument the document that will have the QDomNode added.
153+
* @param errorMessage reference to string that will be updated with any error messages
154+
* @return true in case of success.
155+
*/
156+
virtual bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage) const = 0;
157+
158+
143159
/** Copies the symbology settings from another layer. Returns true in case of success */
144160
virtual bool copySymbologySettings(const QgsMapLayer& other) = 0;
145161

‎python/core/qgsrasterlayer.sip

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public:
137137
// Accessor and mutator for mInvertPixelsFlag
138138
//
139139
/** \brief Accessor to find out whether the histogram should be inverted. */
140-
bool getInvertHistogramFlag();
140+
bool getInvertHistogramFlag() const;
141141

142142
/** \brief Mutator to alter the state of the invert histogram flag. */
143143
void setInvertHistogramFlag(bool theFlag);
@@ -146,7 +146,7 @@ public:
146146
// Accessor and mutator for mStandardDeviations
147147
//
148148
/** \brief Accessor to find out how many standard deviations are being plotted. */
149-
double getStdDevsToPlot();
149+
double getStdDevsToPlot() const;
150150

151151
/** \brief Mutator to alter the number of standard deviations that should be plotted. */
152152
void setStdDevsToPlot(double the);
@@ -173,23 +173,23 @@ public:
173173
/** \brief Call any inline image manipulation filters */
174174
void filterLayer(QImage * theQImage);
175175
/** \brief Accessor for red band name (allows alternate mappings e.g. map blue as red colour). */
176-
QString getRedBandName();
176+
QString getRedBandName() const;
177177

178178
/** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red colour). */
179179
void setRedBandName(const QString & theBandNameQString);
180180
//
181181
// Accessor and mutator for green band name
182182
//
183183
/** \brief Accessor for green band name mapping. */
184-
QString getGreenBandName();
184+
QString getGreenBandName() const;
185185

186186
/** \brief Mutator for green band name mapping. */
187187
void setGreenBandName(const QString & theBandNameQString);
188188
//
189189
// Accessor and mutator for blue band name
190190
//
191191
/** \brief Accessor for blue band name mapping. */
192-
QString getBlueBandName();
192+
QString getBlueBandName() const;
193193

194194
/** \brief Mutator for blue band name mapping. */
195195
void setBlueBandName(const QString & theBandNameQString);
@@ -203,7 +203,7 @@ public:
203203
// Accessor and mutator for transparent band name
204204
//
205205
/** \brief Accessor for transparent band name mapping. */
206-
QString getTransparentBandName();
206+
QString getTransparentBandName() const;
207207

208208
/** \brief Mutator for transparent band name mapping. */
209209
void setTransparentBandName(const QString & theBandNameQString);
@@ -212,7 +212,7 @@ public:
212212
// Accessor and mutator for gray band name
213213
//
214214
/** \brief Accessor for gray band name mapping. */
215-
QString getGrayBandName();
215+
QString getGrayBandName() const;
216216

217217
/** \brief Mutator for gray band name mapping. */
218218
void setGrayBandName(const QString & theBandNameQString);
@@ -249,7 +249,7 @@ public:
249249
QgsContrastEnhancement::CONTRAST_ENHANCEMENT_ALGORITHM getContrastEnhancementAlgorithm();
250250

251251
/** \brief Accessor for contrast enhancement algorithm. */
252-
QString getContrastEnhancementAlgorithmAsQString();
252+
QString getContrastEnhancementAlgorithmAsString() const;
253253

254254
/** \brief Mutator for contrast enhancement algorithm. */
255255
void setContrastEnhancementAlgorithm(QgsContrastEnhancement::CONTRAST_ENHANCEMENT_ALGORITHM theAlgorithm, bool theGenerateLookupTableFlag=true);
@@ -276,10 +276,10 @@ public:
276276
// Accessor and mutator for the color shader algorithm
277277
//
278278
/** \brief Accessor for colour shader algorithm. */
279-
COLOR_SHADING_ALGORITHM getColorShadingAlgorithm();
279+
COLOR_SHADING_ALGORITHM getColorShadingAlgorithm() const;
280280

281281
/** \brief Accessor for colour shader algorithm. */
282-
QString getColorShadingAlgorithmAsQString();
282+
QString getColorShadingAlgorithmAsString() const;
283283

284284
/** \brief Mutator for color shader algorithm. */
285285
void setColorShadingAlgorithm(COLOR_SHADING_ALGORITHM theShaderAlgorithm);
@@ -319,7 +319,7 @@ public:
319319
* Implementaed mainly for serialisation / deserialisation of settings to xml.
320320
* NOTE: May be deprecated in the future!. Use alternate implementation above rather.
321321
* */
322-
QString getDrawingStyleAsQString();
322+
QString getDrawingStyleAsString() const;
323323

324324
/** \brief Mutator for drawing style. */
325325
void setDrawingStyle(const DRAWING_STYLE & theDrawingStyle);
@@ -435,13 +435,13 @@ public:
435435
void setUserDefinedRGBMinMax(bool theBool);
436436

437437
/** \brief Accessor for mUserDefinedRGBMinMaxFlag. */
438-
bool getUserDefinedRGBMinMax();
438+
bool getUserDefinedRGBMinMax() const;
439439

440440
/** \brief Mutator for mUserDefinedGrayMinMaxFlag */
441441
void setUserDefinedGrayMinMax(bool theBool);
442442

443443
/** \brief Accessor for mUserDefinedGrayMinMaxFlag. */
444-
bool getUserDefinedGrayMinMax();
444+
bool getUserDefinedGrayMinMax() const;
445445

446446
public slots:
447447
/**

‎python/core/qgsrenderer.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class QgsRenderer
2020
/**Reads the renderer configuration from an XML file
2121
@param rnode the Dom node to read
2222
@param vl the vector layer which will be associated with the renderer*/
23-
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl)=0;
23+
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl)=0;
2424
/**Writes the contents of the renderer to a configuration file
2525
@ return true in case of success*/
26-
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const=0;
26+
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const=0;
2727
/** Returns true, if attribute values are used by the renderer and false otherwise*/
2828
virtual bool needsAttributes() const=0;
2929
/**Returns a list with indexes of classification attributes*/

‎python/core/qgssinglesymbolrenderer.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class QgsSingleSymbolRenderer : QgsRenderer
1818
/**Reads the renderer configuration from an XML file
1919
@param rnode the Dom node to read
2020
@param vl the vector layer which will be associated with the renderer*/
21-
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
21+
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
2222
/**Writes the contents of the renderer to a configuration file*/
2323
/*virtual void writeXML(std::ostream& xml);*/
2424
/**Writes the contents of the renderer to a configuration file
2525
@ return true in case of success*/
26-
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
26+
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const;
2727
/**Returns false, no attributes neede for single symbol*/
2828
bool needsAttributes() const;
2929
/**Returns an empty list, since no classification attributes are used*/

‎python/core/qgsuniquevaluerenderer.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class QgsUniqueValueRenderer : QgsRenderer
1515
/**Reads the renderer configuration from an XML file
1616
@param rnode the Dom node to read
1717
@param vl the vector layer which will be associated with the renderer*/
18-
void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
18+
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
1919
/**Writes the contents of the renderer to a configuration file
2020
@ return true in case of success*/
21-
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
21+
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const;
2222
/** Returns true, if attribute values are used by the renderer and false otherwise*/
2323
bool needsAttributes() const;
2424
/**Returns a list with indexes of classification attributes*/

‎src/core/qgsmaplayer.cpp

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -535,37 +535,15 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
535535
return myErrorMessage;
536536
}
537537

538-
QDomElement myLayer = myRoot.firstChildElement( "maplayer" );
539-
if ( myLayer.isNull() )
540-
{
541-
myErrorMessage = "Error: maplayer element could not be found in " + theURI;
542-
theResultFlag = false;
543-
return myErrorMessage;
544-
}
545-
546-
//
547-
// we need to ensure the data source matches the layers
548-
// current datasource not the one specified in the qml
549-
//
550-
QDomElement myDataSource = myLayer.firstChildElement( "datasource" );
551-
if ( myDataSource.isNull() )
552-
{
553-
myErrorMessage = "Error: datasource element could not be found in " + theURI;
554-
theResultFlag = false;
555-
return myErrorMessage;
556-
}
557-
QDomElement myNewDataSource = myDocument.createElement( "datasource" );
558-
QDomText myDataSourceText = myDocument.createTextNode( source() );
559-
myNewDataSource.appendChild( myDataSourceText );
560-
myLayer.replaceChild( myNewDataSource, myLayer.firstChildElement( "datasource" ) );
561-
562-
//
563-
// Now go on to parse the xml (QDomElement inherits QDomNode
564-
// so we can just pass along the element to readXML)
565-
//
566-
theResultFlag = readXML( myLayer );
538+
QString errorMsg;
539+
theResultFlag = readSymbology(myRoot, errorMsg);
540+
if(!theResultFlag)
541+
{
542+
myErrorMessage = QObject::tr( "Loading style file " ) + theURI + QObject::tr(" failed because:") + "\n" + errorMsg;
543+
return myErrorMessage;
544+
}
567545

568-
return QObject::tr( "Loaded default style file from " ) + theURI;
546+
return "";
569547
}
570548

571549
QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag )
@@ -585,7 +563,12 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
585563
QDomElement myRootNode = myDocument.createElement( "qgis" );
586564
myRootNode.setAttribute( "version", QString( "%1" ).arg( QGis::qgisVersion ) );
587565
myDocument.appendChild( myRootNode );
588-
writeXML( myRootNode, myDocument );
566+
567+
QString errorMsg;
568+
if(!writeSymbology(myRootNode, myDocument, errorMsg))
569+
{
570+
return QObject::tr("Could not save symbology because:") + "\n" + errorMsg;
571+
}
589572

590573
// check if the uri is a file or ends with .qml,
591574
// which indicates that it should become one

‎src/core/qgsmaplayer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,21 @@ class CORE_EXPORT QgsMapLayer : public QObject
244244
*/
245245
virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );
246246

247+
/** Read the symbology for the current layer from the Dom node supplied.
248+
* @param QDomNode node that will contain the symbology definition for this layer.
249+
* @param errorMessage reference to string that will be updated with any error messages
250+
* @return true in case of success.
251+
*/
252+
virtual bool readSymbology(const QDomNode& node, QString& errorMessage) = 0;
253+
254+
/** Write the symbology for the layer into the docment provided.
255+
* @param QDomNode the node that will have the style element added to it.
256+
* @param QDomDocument the document that will have the QDomNode added.
257+
* @param errorMessage reference to string that will be updated with any error messages
258+
* @return true in case of success.
259+
*/
260+
virtual bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage) const = 0;
261+
247262
public slots:
248263

249264
/** Event handler for when a coordinate transform fails due to bad vertex error */

‎src/core/qgsvectordataprovider.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ int QgsVectorDataProvider::fieldNameIndex( const QString& fieldName ) const
232232
return -1;
233233
}
234234

235+
QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
236+
{
237+
QMap<QString, int> resultMap;
238+
239+
const QgsFieldMap& theFields = fields();
240+
QgsFieldMap::const_iterator field_it = theFields.constBegin();
241+
for(; field_it != theFields.constEnd(); ++field_it)
242+
{
243+
resultMap.insert(field_it.value().name(), field_it.key());
244+
}
245+
246+
return resultMap;
247+
}
248+
235249
QgsAttributeList QgsVectorDataProvider::allAttributesList()
236250
{
237251
uint count = fieldCount();

‎src/core/qgsvectordataprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
267267
*/
268268
int fieldNameIndex( const QString& fieldName ) const;
269269

270+
/**Return a map where the key is the name of the field and the value is its index*/
271+
QMap<QString, int> fieldNameMap() const;
272+
270273
/**
271274
* Return list of indexes to fetch all attributes in getNextFeature()
272275
*/

0 commit comments

Comments
 (0)
Please sign in to comment.