Skip to content

Commit

Permalink
apply patch for #1162 for timlinux
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9437 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 6, 2008
1 parent 56f954f commit 66ae77d
Show file tree
Hide file tree
Showing 28 changed files with 573 additions and 380 deletions.
4 changes: 2 additions & 2 deletions python/core/qgscontinuouscolorrenderer.sip
Expand Up @@ -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*/
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsgraduatedsymbolrenderer.sip
Expand Up @@ -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*/
Expand Down
16 changes: 16 additions & 0 deletions python/core/qgsmaplayer.sip
Expand Up @@ -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;

Expand Down
26 changes: 13 additions & 13 deletions python/core/qgsrasterlayer.sip
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
/**
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsrenderer.sip
Expand Up @@ -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*/
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgssinglesymbolrenderer.sip
Expand Up @@ -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*/
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsuniquevaluerenderer.sip
Expand Up @@ -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*/
Expand Down
45 changes: 14 additions & 31 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -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 )
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsmaplayer.h
Expand Up @@ -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 */
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsvectordataprovider.cpp
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -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()
*/
Expand Down

0 comments on commit 66ae77d

Please sign in to comment.