Skip to content
Permalink
Browse files
apply patch for #1162 for timlinux
git-svn-id: http://svn.osgeo.org/qgis/trunk@9437 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 6, 2008
1 parent f53db1f commit 81132173ffa463ef315e504bdcb2771006381a7e
@@ -31,10 +31,10 @@ class QgsContinuousColorRenderer : QgsRenderer
/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@param vl the vector layer which will be associated with the renderer*/
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const;
/** Returns true*/
bool needsAttributes() const;
/**Returns a list with the index of the classification attribute*/
@@ -30,10 +30,10 @@ class QgsGraduatedSymbolRenderer : QgsRenderer
/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@param vl the vector layer which will be associated with the renderer*/
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, QgsVectorLayer& vl ) const;
/** Returns true*/
bool needsAttributes() const;
/**Returns a list with the index to the classification field*/
@@ -140,6 +140,22 @@ public:
*/
bool writeXML(QDomNode & layer_node, QDomDocument & document);

/** Read the symbology for the current layer from the Dom node supplied.
* @param QDomNode node that will contain the symbology definition for this layer.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success.
*/
virtual bool readSymbology(const QDomNode& node, QString& errorMessage) = 0;

/** Write the symbology for the layer into the docment provided.
* @param QDomNode the node that will have the style element added to it.
* @param QDomDocument the document that will have the QDomNode added.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success.
*/
virtual bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage) const = 0;


/** Copies the symbology settings from another layer. Returns true in case of success */
virtual bool copySymbologySettings(const QgsMapLayer& other) = 0;

@@ -137,7 +137,7 @@ public:
// Accessor and mutator for mInvertPixelsFlag
//
/** \brief Accessor to find out whether the histogram should be inverted. */
bool getInvertHistogramFlag();
bool getInvertHistogramFlag() const;

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

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

/** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red colour). */
void setRedBandName(const QString & theBandNameQString);
//
// Accessor and mutator for green band name
//
/** \brief Accessor for green band name mapping. */
QString getGreenBandName();
QString getGreenBandName() const;

/** \brief Mutator for green band name mapping. */
void setGreenBandName(const QString & theBandNameQString);
//
// Accessor and mutator for blue band name
//
/** \brief Accessor for blue band name mapping. */
QString getBlueBandName();
QString getBlueBandName() const;

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

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

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

/** \brief Accessor for contrast enhancement algorithm. */
QString getContrastEnhancementAlgorithmAsQString();
QString getContrastEnhancementAlgorithmAsString() const;

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

/** \brief Accessor for colour shader algorithm. */
QString getColorShadingAlgorithmAsQString();
QString getColorShadingAlgorithmAsString() const;

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

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

/** \brief Accessor for mUserDefinedRGBMinMaxFlag. */
bool getUserDefinedRGBMinMax();
bool getUserDefinedRGBMinMax() const;

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

/** \brief Accessor for mUserDefinedGrayMinMaxFlag. */
bool getUserDefinedGrayMinMax();
bool getUserDefinedGrayMinMax() const;

public slots:
/**
@@ -20,10 +20,10 @@ class QgsRenderer
/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@param vl the vector layer which will be associated with the renderer*/
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl)=0;
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl)=0;
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const=0;
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const=0;
/** Returns true, if attribute values are used by the renderer and false otherwise*/
virtual bool needsAttributes() const=0;
/**Returns a list with indexes of classification attributes*/
@@ -18,12 +18,12 @@ class QgsSingleSymbolRenderer : QgsRenderer
/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@param vl the vector layer which will be associated with the renderer*/
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file*/
/*virtual void writeXML(std::ostream& xml);*/
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const;
/**Returns false, no attributes neede for single symbol*/
bool needsAttributes() const;
/**Returns an empty list, since no classification attributes are used*/
@@ -15,10 +15,10 @@ class QgsUniqueValueRenderer : QgsRenderer
/**Reads the renderer configuration from an XML file
@param rnode the Dom node to read
@param vl the vector layer which will be associated with the renderer*/
void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
virtual int readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const;
/** Returns true, if attribute values are used by the renderer and false otherwise*/
bool needsAttributes() const;
/**Returns a list with indexes of classification attributes*/
@@ -535,37 +535,15 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
return myErrorMessage;
}

QDomElement myLayer = myRoot.firstChildElement( "maplayer" );
if ( myLayer.isNull() )
{
myErrorMessage = "Error: maplayer element could not be found in " + theURI;
theResultFlag = false;
return myErrorMessage;
}

//
// we need to ensure the data source matches the layers
// current datasource not the one specified in the qml
//
QDomElement myDataSource = myLayer.firstChildElement( "datasource" );
if ( myDataSource.isNull() )
{
myErrorMessage = "Error: datasource element could not be found in " + theURI;
theResultFlag = false;
return myErrorMessage;
}
QDomElement myNewDataSource = myDocument.createElement( "datasource" );
QDomText myDataSourceText = myDocument.createTextNode( source() );
myNewDataSource.appendChild( myDataSourceText );
myLayer.replaceChild( myNewDataSource, myLayer.firstChildElement( "datasource" ) );

//
// Now go on to parse the xml (QDomElement inherits QDomNode
// so we can just pass along the element to readXML)
//
theResultFlag = readXML( myLayer );
QString errorMsg;
theResultFlag = readSymbology(myRoot, errorMsg);
if(!theResultFlag)
{
myErrorMessage = QObject::tr( "Loading style file " ) + theURI + QObject::tr(" failed because:") + "\n" + errorMsg;
return myErrorMessage;
}

return QObject::tr( "Loaded default style file from " ) + theURI;
return "";
}

QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag )
@@ -585,7 +563,12 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
QDomElement myRootNode = myDocument.createElement( "qgis" );
myRootNode.setAttribute( "version", QString( "%1" ).arg( QGis::qgisVersion ) );
myDocument.appendChild( myRootNode );
writeXML( myRootNode, myDocument );

QString errorMsg;
if(!writeSymbology(myRootNode, myDocument, errorMsg))
{
return QObject::tr("Could not save symbology because:") + "\n" + errorMsg;
}

// check if the uri is a file or ends with .qml,
// which indicates that it should become one
@@ -244,6 +244,21 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );

/** Read the symbology for the current layer from the Dom node supplied.
* @param QDomNode node that will contain the symbology definition for this layer.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success.
*/
virtual bool readSymbology(const QDomNode& node, QString& errorMessage) = 0;

/** Write the symbology for the layer into the docment provided.
* @param QDomNode the node that will have the style element added to it.
* @param QDomDocument the document that will have the QDomNode added.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success.
*/
virtual bool writeSymbology(QDomNode&, QDomDocument& doc, QString& errorMessage) const = 0;

public slots:

/** Event handler for when a coordinate transform fails due to bad vertex error */
@@ -232,6 +232,20 @@ int QgsVectorDataProvider::fieldNameIndex( const QString& fieldName ) const
return -1;
}

QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
{
QMap<QString, int> resultMap;

const QgsFieldMap& theFields = fields();
QgsFieldMap::const_iterator field_it = theFields.constBegin();
for(; field_it != theFields.constEnd(); ++field_it)
{
resultMap.insert(field_it.value().name(), field_it.key());
}

return resultMap;
}

QgsAttributeList QgsVectorDataProvider::allAttributesList()
{
uint count = fieldCount();
@@ -267,6 +267,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
*/
int fieldNameIndex( const QString& fieldName ) const;

/**Return a map where the key is the name of the field and the value is its index*/
QMap<QString, int> fieldNameMap() const;

/**
* Return list of indexes to fetch all attributes in getNextFeature()
*/
Loading

0 comments on commit 8113217

Please sign in to comment.