[QGIS Commit] r8269 - in trunk/qgis/src/core: . renderer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Mar 25 16:06:25 EDT 2008
Author: jef
Date: 2008-03-25 16:06:25 -0400 (Tue, 25 Mar 2008)
New Revision: 8269
Modified:
trunk/qgis/src/core/qgsmaplayer.cpp
trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp
trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp
trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
Log:
code reindentation
Modified: trunk/qgis/src/core/qgsmaplayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaplayer.cpp 2008-03-25 18:55:19 UTC (rev 8268)
+++ trunk/qgis/src/core/qgsmaplayer.cpp 2008-03-25 20:06:25 UTC (rev 8269)
@@ -49,29 +49,29 @@
mLayerType(type)
{
- QgsDebugMsg("QgsMapLayer::QgsMapLayer - lyrname is '" + lyrname + "'");
-
- mSRS = new QgsSpatialRefSys();
+ QgsDebugMsg("QgsMapLayer::QgsMapLayer - lyrname is '" + lyrname + "'");
- // Set the display name = internal name
- mLayerName = capitaliseLayerName(lyrname);
- QgsDebugMsg("QgsMapLayer::QgsMapLayer - layerName is '" + mLayerName + "'");
+ mSRS = new QgsSpatialRefSys();
- // Generate the unique ID of this layer
- QDateTime dt = QDateTime::currentDateTime();
- mID = lyrname + dt.toString("yyyyMMddhhmmsszzz");
- // Tidy the ID up to avoid characters that may cause problems
- // elsewhere (e.g in some parts of XML). Replaces every non-word
- // character (word characters are the alphabet, numbers and
- // underscore) with an underscore.
- // Note that the first backslashe in the regular expression is
- // there for the compiler, so the pattern is actually \W
- mID.replace(QRegExp("[\\W]"), "_");
+ // Set the display name = internal name
+ mLayerName = capitaliseLayerName(lyrname);
+ QgsDebugMsg("QgsMapLayer::QgsMapLayer - layerName is '" + mLayerName + "'");
- //set some generous defaults for scale based visibility
- mMinScale = 0;
- mMaxScale = 100000000;
- mScaleBasedVisibility = false;
+ // Generate the unique ID of this layer
+ QDateTime dt = QDateTime::currentDateTime();
+ mID = lyrname + dt.toString("yyyyMMddhhmmsszzz");
+ // Tidy the ID up to avoid characters that may cause problems
+ // elsewhere (e.g in some parts of XML). Replaces every non-word
+ // character (word characters are the alphabet, numbers and
+ // underscore) with an underscore.
+ // Note that the first backslashe in the regular expression is
+ // there for the compiler, so the pattern is actually \W
+ mID.replace(QRegExp("[\\W]"), "_");
+
+ //set some generous defaults for scale based visibility
+ mMinScale = 0;
+ mMaxScale = 100000000;
+ mScaleBasedVisibility = false;
}
@@ -83,13 +83,13 @@
int QgsMapLayer::type() const
{
- return mLayerType;
+ return mLayerType;
}
/** Get this layer's unique ID */
QString QgsMapLayer::getLayerID() const
{
- return mID;
+ return mID;
}
/** Write property of QString layerName. */
@@ -119,178 +119,178 @@
QString const & QgsMapLayer::source() const
{
- return mDataSource;
+ return mDataSource;
}
const QgsRect QgsMapLayer::extent()
{
- return mLayerExtent;
+ return mLayerExtent;
}
bool QgsMapLayer::draw(QPainter *, QgsRect &, QgsMapToPixel *, QgsCoordinateTransform *, bool)
{
- // std::cout << "In QgsMapLayer::draw" << std::endl;
- return false;
+ // std::cout << "In QgsMapLayer::draw" << std::endl;
+ return false;
}
void QgsMapLayer::drawLabels(QPainter *, QgsRect &, QgsMapToPixel *, QgsCoordinateTransform *)
{
- // std::cout << "In QgsMapLayer::draw" << std::endl;
+ // std::cout << "In QgsMapLayer::draw" << std::endl;
}
bool QgsMapLayer::readXML( QDomNode & layer_node )
{
- QDomElement element = layer_node.toElement();
+ QDomElement element = layer_node.toElement();
- // XXX not needed? QString type = element.attribute("type");
+ // XXX not needed? QString type = element.attribute("type");
- // set data source
- QDomNode mnl = layer_node.namedItem("datasource");
- QDomElement mne = mnl.toElement();
- mDataSource = mne.text();
+ // set data source
+ QDomNode mnl = layer_node.namedItem("datasource");
+ QDomElement mne = mnl.toElement();
+ mDataSource = mne.text();
- // Set the SRS so that we don't ask the user.
- // Make it the saved SRS to have WMS layer projected correctly.
- // We will still overwrite whatever GDAL etc picks up anyway
- // further down this function.
- QDomNode srsNode = layer_node.namedItem("srs");
- mSRS->readXML(srsNode);
+ // Set the SRS so that we don't ask the user.
+ // Make it the saved SRS to have WMS layer projected correctly.
+ // We will still overwrite whatever GDAL etc picks up anyway
+ // further down this function.
+ QDomNode srsNode = layer_node.namedItem("srs");
+ mSRS->readXML(srsNode);
- // now let the children grab what they need from the DOM node.
- if (!readXML_( layer_node ))
- {
- return false;
- }
+ // now let the children grab what they need from the DOM node.
+ if (!readXML_( layer_node ))
+ {
+ return false;
+ }
- // the internal name is just the data source basename
- QFileInfo dataSourceFileInfo( mDataSource );
- //internalName = dataSourceFileInfo.baseName();
+ // the internal name is just the data source basename
+ QFileInfo dataSourceFileInfo( mDataSource );
+ //internalName = dataSourceFileInfo.baseName();
- // set ID
- mnl = layer_node.namedItem("id");
- if ( ! mnl.isNull() )
+ // set ID
+ mnl = layer_node.namedItem("id");
+ if ( ! mnl.isNull() )
+ {
+ mne = mnl.toElement();
+ if ( ! mne.isNull() && mne.text().length() > 10 ) // should be at least 17 (yyyyMMddhhmmsszzz)
{
- mne = mnl.toElement();
- if ( ! mne.isNull() && mne.text().length() > 10 ) // should be at least 17 (yyyyMMddhhmmsszzz)
- {
- mID = mne.text();
- }
+ mID = mne.text();
}
+ }
- // use scale dependent visibility flag
- QString scaleBasedVisibility = element.attribute("scaleBasedVisibilityFlag");
- if ( "1" == scaleBasedVisibility )
- {
- setScaleBasedVisibility(true);
- }
- else
- {
- setScaleBasedVisibility(false);
- }
- setMinScale(element.attribute("minScale").toFloat());
- setMaxScale(element.attribute("maxScale").toFloat());
+ // use scale dependent visibility flag
+ QString scaleBasedVisibility = element.attribute("scaleBasedVisibilityFlag");
+ if ( "1" == scaleBasedVisibility )
+ {
+ setScaleBasedVisibility(true);
+ }
+ else
+ {
+ setScaleBasedVisibility(false);
+ }
+ setMinScale(element.attribute("minScale").toFloat());
+ setMaxScale(element.attribute("maxScale").toFloat());
- // set name
- mnl = layer_node.namedItem("layername");
- mne = mnl.toElement();
- setLayerName( mne.text() );
+ // set name
+ mnl = layer_node.namedItem("layername");
+ mne = mnl.toElement();
+ setLayerName( mne.text() );
- // overwrite srs
- // FIXME: is this necessary?
- mSRS->readXML(srsNode);
-
- //read transparency level
- QDomNode transparencyNode = layer_node.namedItem("transparencyLevelInt");
- if ( ! transparencyNode.isNull() )
- {
- // set transparency level only if it's in project
- // (otherwise it sets the layer transparent)
- QDomElement myElement = transparencyNode.toElement();
- setTransparency(myElement.text().toInt());
- }
+ // overwrite srs
+ // FIXME: is this necessary?
+ mSRS->readXML(srsNode);
- return true;
+ //read transparency level
+ QDomNode transparencyNode = layer_node.namedItem("transparencyLevelInt");
+ if ( ! transparencyNode.isNull() )
+ {
+ // set transparency level only if it's in project
+ // (otherwise it sets the layer transparent)
+ QDomElement myElement = transparencyNode.toElement();
+ setTransparency(myElement.text().toInt());
+ }
+
+ return true;
} // void QgsMapLayer::readXML
bool QgsMapLayer::readXML_( QDomNode & layer_node )
{
- // NOP by default; children will over-ride with behavior specific to them
+ // NOP by default; children will over-ride with behavior specific to them
- return true;
+ return true;
} // void QgsMapLayer::readXML_
bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
{
- // general layer metadata
- QDomElement maplayer = document.createElement( "maplayer" );
+ // general layer metadata
+ QDomElement maplayer = document.createElement( "maplayer" );
- // use scale dependent visibility flag
- if ( scaleBasedVisibility() )
- {
- maplayer.setAttribute( "scaleBasedVisibilityFlag", 1 );
- }
- else
- {
- maplayer.setAttribute( "scaleBasedVisibilityFlag", 0 );
- }
- maplayer.setAttribute( "minScale", minScale() );
- maplayer.setAttribute( "maxScale", maxScale() );
+ // use scale dependent visibility flag
+ if ( scaleBasedVisibility() )
+ {
+ maplayer.setAttribute( "scaleBasedVisibilityFlag", 1 );
+ }
+ else
+ {
+ maplayer.setAttribute( "scaleBasedVisibilityFlag", 0 );
+ }
+ maplayer.setAttribute( "minScale", minScale() );
+ maplayer.setAttribute( "maxScale", maxScale() );
- // ID
- QDomElement id = document.createElement( "id" );
- QDomText idText = document.createTextNode( getLayerID() );
- id.appendChild( idText );
+ // ID
+ QDomElement id = document.createElement( "id" );
+ QDomText idText = document.createTextNode( getLayerID() );
+ id.appendChild( idText );
- maplayer.appendChild( id );
+ maplayer.appendChild( id );
- // data source
- QDomElement dataSource = document.createElement( "datasource" );
- QDomText dataSourceText = document.createTextNode( source() );
- dataSource.appendChild( dataSourceText );
+ // data source
+ QDomElement dataSource = document.createElement( "datasource" );
+ QDomText dataSourceText = document.createTextNode( source() );
+ dataSource.appendChild( dataSourceText );
- maplayer.appendChild( dataSource );
+ maplayer.appendChild( dataSource );
- // layer name
- QDomElement layerName = document.createElement( "layername" );
- QDomText layerNameText = document.createTextNode( name() );
- layerName.appendChild( layerNameText );
+ // layer name
+ QDomElement layerName = document.createElement( "layername" );
+ QDomText layerNameText = document.createTextNode( name() );
+ layerName.appendChild( layerNameText );
- maplayer.appendChild( layerName );
+ maplayer.appendChild( layerName );
- // zorder
- // This is no longer stored in the project file. It is superflous since the layers
- // are written and read in the proper order.
+ // zorder
+ // This is no longer stored in the project file. It is superflous since the layers
+ // are written and read in the proper order.
- // spatial reference system id
- QDomElement mySrsElement = document.createElement( "srs" );
- mSRS->writeXML(mySrsElement, document);
- maplayer.appendChild(mySrsElement);
-
- // <transparencyLevelInt>
- QDomElement transparencyLevelIntElement = document.createElement( "transparencyLevelInt" );
- QDomText transparencyLevelIntText = document.createTextNode( QString::number(getTransparency()) );
- transparencyLevelIntElement.appendChild( transparencyLevelIntText );
- maplayer.appendChild( transparencyLevelIntElement );
- // now append layer node to map layer node
+ // spatial reference system id
+ QDomElement mySrsElement = document.createElement( "srs" );
+ mSRS->writeXML(mySrsElement, document);
+ maplayer.appendChild(mySrsElement);
- layer_node.appendChild( maplayer );
+ // <transparencyLevelInt>
+ QDomElement transparencyLevelIntElement = document.createElement( "transparencyLevelInt" );
+ QDomText transparencyLevelIntText = document.createTextNode( QString::number(getTransparency()) );
+ transparencyLevelIntElement.appendChild( transparencyLevelIntText );
+ maplayer.appendChild( transparencyLevelIntElement );
+ // now append layer node to map layer node
- return writeXML_( maplayer, document );
+ layer_node.appendChild( maplayer );
+ return writeXML_( maplayer, document );
+
} // bool QgsMapLayer::writeXML
bool QgsMapLayer::writeXML_( QDomNode & layer_node, QDomDocument & document )
{
- // NOP by default; children will over-ride with behavior specific to them
+ // NOP by default; children will over-ride with behavior specific to them
- return true;
+ return true;
} // void QgsMapLayer::writeXML_
@@ -298,7 +298,7 @@
bool QgsMapLayer::isValid()
{
- return mValid;
+ return mValid;
}
@@ -321,7 +321,7 @@
void QgsMapLayer::connectNotify( const char * signal )
{
- QgsDebugMsg("QgsMapLayer connected to " + QString(signal));
+ QgsDebugMsg("QgsMapLayer connected to " + QString(signal));
} // QgsMapLayer::connectNotify
@@ -365,12 +365,12 @@
void QgsMapLayer::setLayerOrder(QStringList layers)
{
- // NOOP
+ // NOOP
}
void QgsMapLayer::setSubLayerVisibility(QString name, bool vis)
{
- // NOOP
+ // NOOP
}
const QgsSpatialRefSys& QgsMapLayer::srs()
@@ -410,7 +410,6 @@
QString QgsMapLayer::loadDefaultStyle ( bool & theResultFlag )
{
-
QString myURI = publicSource();
QFileInfo myFileInfo ( myURI );
//get the file name for our .qml style file
@@ -426,7 +425,7 @@
QFileInfo myFileInfo ( theURI );
if ( !myFileInfo.isFile() )
{
- return QObject::tr( "Currently only filebased datasets are supported" );
+ return QObject::tr( "Currently only filebased datasets are supported" );
}
QFile myFile ( theURI );
if ( myFile.open(QFile::ReadOnly ) )
@@ -439,7 +438,7 @@
{
myFile.close();
return myErrorMessage + " at line " + QString::number( line ) +
- " column " + QString::number( column );
+ " column " + QString::number( column );
}
else //dom parsed in ok
{
@@ -450,17 +449,17 @@
QDomElement myRoot = myDocument.firstChildElement("qgis");
if (myRoot.isNull())
{
- myErrorMessage = "Error: qgis element could not be found in " + theURI;
- return myErrorMessage;
+ myErrorMessage = "Error: qgis element could not be found in " + theURI;
+ return myErrorMessage;
}
QDomElement myLayer = myRoot.firstChildElement("maplayer");
if (myLayer.isNull())
{
- myErrorMessage = "Error: maplayer element could not be found in " + theURI;
- return myErrorMessage;
+ myErrorMessage = "Error: maplayer element could not be found in " + theURI;
+ return myErrorMessage;
}
-
+
//
// we need to ensure the data source matches the layers
// current datasource not the one specified in the qml
@@ -468,14 +467,14 @@
QDomElement myDataSource = myLayer.firstChildElement("datasource");
if (myDataSource.isNull())
{
- myErrorMessage = "Error: datasource element could not be found in " + theURI;
- return myErrorMessage;
+ myErrorMessage = "Error: datasource element could not be found in " + theURI;
+ return myErrorMessage;
}
QDomElement myNewDataSource = myDocument.createElement( "datasource" );
QDomText myDataSourceText = myDocument.createTextNode( source() );
myNewDataSource.appendChild( myDataSourceText );
myLayer.replaceChild( myNewDataSource ,
- myLayer.firstChildElement("datasource") );
+ myLayer.firstChildElement("datasource") );
//
// Now go on to parse the xml (QDomElement inherits QDomNode
@@ -489,7 +488,6 @@
}
QString QgsMapLayer::saveDefaultStyle ( bool & theResultFlag )
{
-
QString myURI = publicSource();
QFileInfo myFileInfo ( myURI );
//get the file name for our .qml style file
@@ -537,5 +535,4 @@
return QObject::tr( "ERROR: Failed to created default style file as " ) + myFileName +
tr( " Check file permissions and retry." );
}
-
}
Modified: trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp 2008-03-25 18:55:19 UTC (rev 8268)
+++ trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp 2008-03-25 20:06:25 UTC (rev 8269)
@@ -32,60 +32,60 @@
QgsGraduatedSymbolRenderer::QgsGraduatedSymbolRenderer(QGis::VectorType type)
{
- mVectorType=type;
+ mVectorType=type;
}
QgsGraduatedSymbolRenderer::QgsGraduatedSymbolRenderer(const QgsGraduatedSymbolRenderer& other)
{
- mVectorType = other.mVectorType;
+ mVectorType = other.mVectorType;
+ mClassificationField = other.mClassificationField;
+ const QList<QgsSymbol*> s = other.symbols();
+ for(QList<QgsSymbol*>::const_iterator it=s.begin(); it!=s.end(); ++it)
+ {
+ addSymbol(new QgsSymbol(**it));
+ }
+ updateSymbolAttributes();
+}
+
+QgsGraduatedSymbolRenderer& QgsGraduatedSymbolRenderer::operator=(const QgsGraduatedSymbolRenderer& other)
+{
+ if(this != &other)
+ {
+ mVectorType = other.mVectorType;
mClassificationField = other.mClassificationField;
+ removeSymbols();
const QList<QgsSymbol*> s = other.symbols();
for(QList<QgsSymbol*>::const_iterator it=s.begin(); it!=s.end(); ++it)
{
- addSymbol(new QgsSymbol(**it));
+ addSymbol(new QgsSymbol(**it));
}
updateSymbolAttributes();
-}
+ }
-QgsGraduatedSymbolRenderer& QgsGraduatedSymbolRenderer::operator=(const QgsGraduatedSymbolRenderer& other)
-{
- if(this != &other)
- {
- mVectorType = other.mVectorType;
- mClassificationField = other.mClassificationField;
- removeSymbols();
- const QList<QgsSymbol*> s = other.symbols();
- for(QList<QgsSymbol*>::const_iterator it=s.begin(); it!=s.end(); ++it)
- {
- addSymbol(new QgsSymbol(**it));
- }
- updateSymbolAttributes();
- }
-
- return *this;
+ return *this;
}
QgsGraduatedSymbolRenderer::~QgsGraduatedSymbolRenderer()
{
-
+
}
const QList<QgsSymbol*> QgsGraduatedSymbolRenderer::symbols() const
{
- return mSymbols;
+ return mSymbols;
}
void QgsGraduatedSymbolRenderer::removeSymbols()
{
- //free the memory first
- for (QList<QgsSymbol*>::iterator it = mSymbols.begin(); it != mSymbols.end(); ++it)
- {
- delete *it;
- }
+ //free the memory first
+ for (QList<QgsSymbol*>::iterator it = mSymbols.begin(); it != mSymbols.end(); ++it)
+ {
+ delete *it;
+ }
- //and remove the pointers then
- mSymbols.clear();
- updateSymbolAttributes();
+ //and remove the pointers then
+ mSymbols.clear();
+ updateSymbolAttributes();
}
bool QgsGraduatedSymbolRenderer::willRenderFeature(QgsFeature *f)
@@ -98,18 +98,18 @@
{
QgsSymbol* theSymbol = symbolForFeature(&f);
if(!theSymbol)
+ {
+ if ( img && mVectorType == QGis::Point )
{
- if ( img && mVectorType == QGis::Point )
- {
- img->fill(0);
- }
- else if ( mVectorType != QGis::Point )
- {
- p->setPen(Qt::NoPen);
- p->setBrush(Qt::NoBrush);
- }
- return;
+ img->fill(0);
}
+ else if ( mVectorType != QGis::Point )
+ {
+ p->setPen(Qt::NoPen);
+ p->setBrush(Qt::NoBrush);
+ }
+ return;
+ }
//set the qpen and qpainter to the right values
// Point
@@ -132,30 +132,30 @@
QgsDebugMsg(QString("Feature has rotation factor %1").arg(rotation));
}
*img = theSymbol->getPointSymbolAsImage( widthScale, selected, mSelectionColor,
- *scalefactor * fieldScale, rotation);
+ *scalefactor * fieldScale, rotation);
}
// Line, polygon
if ( mVectorType != QGis::Point )
+ {
+ if( !selected )
{
- if( !selected )
- {
- QPen pen=theSymbol->pen();
- pen.setWidthF ( widthScale * pen.width() );
- p->setPen(pen);
- p->setBrush(theSymbol->brush());
- }
- else
- {
- QPen pen=theSymbol->pen();
- pen.setColor(mSelectionColor);
- pen.setWidthF ( widthScale * pen.width() );
- QBrush brush=theSymbol->brush();
- brush.setColor(mSelectionColor);
- p->setPen(pen);
- p->setBrush(brush);
- }
+ QPen pen=theSymbol->pen();
+ pen.setWidthF ( widthScale * pen.width() );
+ p->setPen(pen);
+ p->setBrush(theSymbol->brush());
}
+ else
+ {
+ QPen pen=theSymbol->pen();
+ pen.setColor(mSelectionColor);
+ pen.setWidthF ( widthScale * pen.width() );
+ QBrush brush=theSymbol->brush();
+ brush.setColor(mSelectionColor);
+ p->setPen(pen);
+ p->setBrush(brush);
+ }
+ }
}
@@ -176,31 +176,31 @@
}
if (it == mSymbols.end()) //only draw features which are covered by a render item
- {
- return 0;
- }
+ {
+ return 0;
+ }
return (*it);
}
void QgsGraduatedSymbolRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)
{
- mVectorType = vl.vectorType();
- QDomNode classnode = rnode.namedItem("classificationfield");
- int classificationfield = classnode.toElement().text().toInt();
-
- this->setClassificationField(classificationfield);
+ mVectorType = vl.vectorType();
+ QDomNode classnode = rnode.namedItem("classificationfield");
+ int classificationfield = classnode.toElement().text().toInt();
- QDomNode symbolnode = rnode.namedItem("symbol");
- while (!symbolnode.isNull())
- {
- QgsSymbol* sy = new QgsSymbol(mVectorType);
- sy->readXML ( symbolnode );
- this->addSymbol(sy);
+ this->setClassificationField(classificationfield);
- symbolnode = symbolnode.nextSibling();
- }
- updateSymbolAttributes();
- vl.setRenderer(this);
+ QDomNode symbolnode = rnode.namedItem("symbol");
+ while (!symbolnode.isNull())
+ {
+ QgsSymbol* sy = new QgsSymbol(mVectorType);
+ sy->readXML ( symbolnode );
+ this->addSymbol(sy);
+
+ symbolnode = symbolnode.nextSibling();
+ }
+ updateSymbolAttributes();
+ vl.setRenderer(this);
}
QgsAttributeList QgsGraduatedSymbolRenderer::classificationAttributes() const
@@ -238,30 +238,30 @@
QString QgsGraduatedSymbolRenderer::name() const
{
- return "Graduated Symbol";
+ return "Graduated Symbol";
}
bool QgsGraduatedSymbolRenderer::writeXML( QDomNode & layer_node, QDomDocument & document ) const
{
- bool returnval=true;
- QDomElement graduatedsymbol=document.createElement("graduatedsymbol");
- layer_node.appendChild(graduatedsymbol);
- QDomElement classificationfield=document.createElement("classificationfield");
- QDomText classificationfieldtxt=document.createTextNode(QString::number(mClassificationField));
- classificationfield.appendChild(classificationfieldtxt);
- graduatedsymbol.appendChild(classificationfield);
- for (QList<QgsSymbol*>::const_iterator it = mSymbols.begin(); it != mSymbols.end(); ++it)
+ bool returnval=true;
+ QDomElement graduatedsymbol=document.createElement("graduatedsymbol");
+ layer_node.appendChild(graduatedsymbol);
+ QDomElement classificationfield=document.createElement("classificationfield");
+ QDomText classificationfieldtxt=document.createTextNode(QString::number(mClassificationField));
+ classificationfield.appendChild(classificationfieldtxt);
+ graduatedsymbol.appendChild(classificationfield);
+ for (QList<QgsSymbol*>::const_iterator it = mSymbols.begin(); it != mSymbols.end(); ++it)
+ {
+ if(!(*it)->writeXML(graduatedsymbol,document))
{
- if(!(*it)->writeXML(graduatedsymbol,document))
- {
- returnval=false;
- }
+ returnval=false;
}
- return returnval;
+ }
+ return returnval;
}
QgsRenderer* QgsGraduatedSymbolRenderer::clone() const
{
- QgsGraduatedSymbolRenderer* r = new QgsGraduatedSymbolRenderer(*this);
- return r;
+ QgsGraduatedSymbolRenderer* r = new QgsGraduatedSymbolRenderer(*this);
+ return r;
}
Modified: trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp 2008-03-25 18:55:19 UTC (rev 8268)
+++ trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp 2008-03-25 20:06:25 UTC (rev 8269)
@@ -33,60 +33,60 @@
QgsSingleSymbolRenderer::QgsSingleSymbolRenderer(QGis::VectorType type)
{
- mVectorType=type;
-
- //initial setting based on random color
- QgsSymbol* sy = new QgsSymbol(mVectorType);
-
- //random fill colors for points and polygons and pen colors for lines
- int red = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
- int green = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
- int blue = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
+ mVectorType=type;
- if (type == QGis::Line)
- {
- sy->setColor(QColor(red, green, blue));
- }
- else
- {
- sy->setFillColor(QColor(red, green, blue));
- sy->setFillStyle(Qt::SolidPattern);
- sy->setColor(QColor(0, 0, 0));
- }
- sy->setLineWidth(1);
- mSymbol=sy;
- updateSymbolAttributes();
+ //initial setting based on random color
+ QgsSymbol* sy = new QgsSymbol(mVectorType);
+
+ //random fill colors for points and polygons and pen colors for lines
+ int red = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
+ int green = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
+ int blue = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
+
+ if (type == QGis::Line)
+ {
+ sy->setColor(QColor(red, green, blue));
+ }
+ else
+ {
+ sy->setFillColor(QColor(red, green, blue));
+ sy->setFillStyle(Qt::SolidPattern);
+ sy->setColor(QColor(0, 0, 0));
+ }
+ sy->setLineWidth(1);
+ mSymbol=sy;
+ updateSymbolAttributes();
}
QgsSingleSymbolRenderer::QgsSingleSymbolRenderer(const QgsSingleSymbolRenderer& other)
{
- mVectorType = other.mVectorType;
- mSymbol = new QgsSymbol(*other.mSymbol);
- updateSymbolAttributes();
+ mVectorType = other.mVectorType;
+ mSymbol = new QgsSymbol(*other.mSymbol);
+ updateSymbolAttributes();
}
QgsSingleSymbolRenderer& QgsSingleSymbolRenderer::operator=(const QgsSingleSymbolRenderer& other)
{
- if(this!=&other)
- {
- mVectorType = other.mVectorType;
- delete mSymbol;
- mSymbol = new QgsSymbol(*other.mSymbol);
- }
- updateSymbolAttributes();
- return *this;
+ if(this!=&other)
+ {
+ mVectorType = other.mVectorType;
+ delete mSymbol;
+ mSymbol = new QgsSymbol(*other.mSymbol);
+ }
+ updateSymbolAttributes();
+ return *this;
}
QgsSingleSymbolRenderer::~QgsSingleSymbolRenderer()
{
- delete mSymbol;
+ delete mSymbol;
}
void QgsSingleSymbolRenderer::addSymbol(QgsSymbol* sy)
{
- delete mSymbol;
- mSymbol=sy;
- updateSymbolAttributes();
+ delete mSymbol;
+ mSymbol=sy;
+ updateSymbolAttributes();
}
void QgsSingleSymbolRenderer::renderFeature(QPainter * p, QgsFeature & f, QImage* img,
@@ -145,25 +145,25 @@
void QgsSingleSymbolRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)
{
- mVectorType = vl.vectorType();
- QgsSymbol* sy = new QgsSymbol(mVectorType);
+ mVectorType = vl.vectorType();
+ QgsSymbol* sy = new QgsSymbol(mVectorType);
- QDomNode synode = rnode.namedItem("symbol");
-
- if ( synode.isNull() )
- {
- QgsDebugMsg("No symbol node in project file's renderitem DOM");
- // XXX abort?
- }
- else
- {
- sy->readXML ( synode );
- }
- updateSymbolAttributes();
+ QDomNode synode = rnode.namedItem("symbol");
- //create a renderer and add it to the vector layer
- this->addSymbol(sy);
- vl.setRenderer(this);
+ if ( synode.isNull() )
+ {
+ QgsDebugMsg("No symbol node in project file's renderitem DOM");
+ // XXX abort?
+ }
+ else
+ {
+ sy->readXML ( synode );
+ }
+ updateSymbolAttributes();
+
+ //create a renderer and add it to the vector layer
+ this->addSymbol(sy);
+ vl.setRenderer(this);
}
bool QgsSingleSymbolRenderer::writeXML( QDomNode & layer_node, QDomDocument & document ) const
Modified: trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp 2008-03-25 18:55:19 UTC (rev 8268)
+++ trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp 2008-03-25 20:06:25 UTC (rev 8269)
@@ -30,71 +30,71 @@
QgsUniqueValueRenderer::QgsUniqueValueRenderer(QGis::VectorType type): mClassificationField(0)
{
- mVectorType = type;
+ mVectorType = type;
}
QgsUniqueValueRenderer::QgsUniqueValueRenderer(const QgsUniqueValueRenderer& other)
{
- mVectorType = other.mVectorType;
- mClassificationField = other.mClassificationField;
- QMap<QString, QgsSymbol*> s = other.mSymbols;
- for(QMap<QString, QgsSymbol*>::iterator it=s.begin(); it!=s.end(); ++it)
- {
- QgsSymbol* s = new QgsSymbol(* it.value());
- insertValue(it.key(), s);
- }
- updateSymbolAttributes();
+ mVectorType = other.mVectorType;
+ mClassificationField = other.mClassificationField;
+ QMap<QString, QgsSymbol*> s = other.mSymbols;
+ for(QMap<QString, QgsSymbol*>::iterator it=s.begin(); it!=s.end(); ++it)
+ {
+ QgsSymbol* s = new QgsSymbol(* it.value());
+ insertValue(it.key(), s);
+ }
+ updateSymbolAttributes();
}
QgsUniqueValueRenderer& QgsUniqueValueRenderer::operator=(const QgsUniqueValueRenderer& other)
{
- if(this != &other)
+ if(this != &other)
+ {
+ mVectorType = other.mVectorType;
+ mClassificationField = other.mClassificationField;
+ clearValues();
+ for(QMap<QString, QgsSymbol*>::iterator it=mSymbols.begin(); it!=mSymbols.end(); ++it)
{
- mVectorType = other.mVectorType;
- mClassificationField = other.mClassificationField;
- clearValues();
- for(QMap<QString, QgsSymbol*>::iterator it=mSymbols.begin(); it!=mSymbols.end(); ++it)
- {
- QgsSymbol* s = new QgsSymbol(*it.value());
- insertValue(it.key(), s);
- }
- updateSymbolAttributes();
+ QgsSymbol* s = new QgsSymbol(*it.value());
+ insertValue(it.key(), s);
}
- return *this;
+ updateSymbolAttributes();
+ }
+ return *this;
}
QgsUniqueValueRenderer::~QgsUniqueValueRenderer()
{
- for(QMap<QString,QgsSymbol*>::iterator it=mSymbols.begin();it!=mSymbols.end();++it)
- {
- delete it.value();
- }
+ for(QMap<QString,QgsSymbol*>::iterator it=mSymbols.begin();it!=mSymbols.end();++it)
+ {
+ delete it.value();
+ }
}
const QList<QgsSymbol*> QgsUniqueValueRenderer::symbols() const
{
- QList <QgsSymbol*> symbollist;
- for(QMap<QString, QgsSymbol*>::const_iterator it = mSymbols.begin(); it!=mSymbols.end(); ++it)
- {
- symbollist.append(it.value());
- }
- return symbollist;
+ QList <QgsSymbol*> symbollist;
+ for(QMap<QString, QgsSymbol*>::const_iterator it = mSymbols.begin(); it!=mSymbols.end(); ++it)
+ {
+ symbollist.append(it.value());
+ }
+ return symbollist;
}
void QgsUniqueValueRenderer::insertValue(QString name, QgsSymbol* symbol)
{
- mSymbols.insert(name, symbol);
- updateSymbolAttributes();
+ mSymbols.insert(name, symbol);
+ updateSymbolAttributes();
}
void QgsUniqueValueRenderer::setClassificationField(int field)
{
- mClassificationField=field;
+ mClassificationField=field;
}
int QgsUniqueValueRenderer::classificationField() const
{
- return mClassificationField;
+ return mClassificationField;
}
bool QgsUniqueValueRenderer::willRenderFeature(QgsFeature *f)
@@ -107,19 +107,19 @@
{
QgsSymbol* symbol = symbolForFeature(&f);
if(!symbol) //no matching symbol
+ {
+ if ( img && mVectorType == QGis::Point )
{
- if ( img && mVectorType == QGis::Point )
- {
- img->fill(0);
- }
- else if ( mVectorType != QGis::Point )
- {
- p->setPen(Qt::NoPen);
- p->setBrush(Qt::NoBrush);
- }
- return;
+ img->fill(0);
}
-
+ else if ( mVectorType != QGis::Point )
+ {
+ p->setPen(Qt::NoPen);
+ p->setBrush(Qt::NoBrush);
+ }
+ return;
+ }
+
// Point
if ( img && mVectorType == QGis::Point )
{
@@ -140,29 +140,29 @@
QgsDebugMsg(QString("Feature has rotation factor %1").arg(rotation));
}
*img = symbol->getPointSymbolAsImage( widthScale, selected, mSelectionColor,
- *scalefactor * fieldScale, rotation);
-}
+ *scalefactor * fieldScale, rotation);
+ }
// Line, polygon
else if ( mVectorType != QGis::Point )
+ {
+ if( !selected )
{
- if( !selected )
- {
- QPen pen=symbol->pen();
- pen.setWidthF ( widthScale * pen.width() );
- p->setPen(pen);
- p->setBrush(symbol->brush());
- }
- else
- {
- QPen pen=symbol->pen();
- pen.setWidthF ( widthScale * pen.width() );
- pen.setColor(mSelectionColor);
- QBrush brush=symbol->brush();
- brush.setColor(mSelectionColor);
- p->setPen(pen);
- p->setBrush(brush);
- }
+ QPen pen=symbol->pen();
+ pen.setWidthF ( widthScale * pen.width() );
+ p->setPen(pen);
+ p->setBrush(symbol->brush());
}
+ else
+ {
+ QPen pen=symbol->pen();
+ pen.setWidthF ( widthScale * pen.width() );
+ pen.setColor(mSelectionColor);
+ QBrush brush=symbol->brush();
+ brush.setColor(mSelectionColor);
+ p->setPen(pen);
+ p->setBrush(brush);
+ }
+ }
}
QgsSymbol* QgsUniqueValueRenderer::symbolForFeature(const QgsFeature* f)
@@ -170,44 +170,44 @@
//first find out the value
const QgsAttributeMap& attrs = f->attributeMap();
QString value = attrs[mClassificationField].toString();
-
+
QMap<QString,QgsSymbol*>::iterator it=mSymbols.find(value);
if(it == mSymbols.end())
- {
- return 0;
- }
+ {
+ return 0;
+ }
else
- {
- return it.value();
- }
+ {
+ return it.value();
+ }
}
void QgsUniqueValueRenderer::readXML(const QDomNode& rnode, QgsVectorLayer& vl)
{
- mVectorType = vl.vectorType();
- QDomNode classnode = rnode.namedItem("classificationfield");
- int classificationfield = classnode.toElement().text().toInt();
- this->setClassificationField(classificationfield);
+ mVectorType = vl.vectorType();
+ QDomNode classnode = rnode.namedItem("classificationfield");
+ int classificationfield = classnode.toElement().text().toInt();
+ this->setClassificationField(classificationfield);
- QDomNode symbolnode = rnode.namedItem("symbol");
- while (!symbolnode.isNull())
- {
- QgsSymbol* msy = new QgsSymbol(mVectorType);
- msy->readXML ( symbolnode );
- this->insertValue(msy->lowerValue(),msy);
- symbolnode = symbolnode.nextSibling();
+ QDomNode symbolnode = rnode.namedItem("symbol");
+ while (!symbolnode.isNull())
+ {
+ QgsSymbol* msy = new QgsSymbol(mVectorType);
+ msy->readXML ( symbolnode );
+ this->insertValue(msy->lowerValue(),msy);
+ symbolnode = symbolnode.nextSibling();
vl.setRenderer(this);
- }
+ }
}
void QgsUniqueValueRenderer::clearValues()
{
- for(QMap<QString,QgsSymbol*>::iterator it=mSymbols.begin();it!=mSymbols.end();++it)
- {
- delete it.value();
- }
- mSymbols.clear();
- updateSymbolAttributes();
+ for(QMap<QString,QgsSymbol*>::iterator it=mSymbols.begin();it!=mSymbols.end();++it)
+ {
+ delete it.value();
+ }
+ mSymbols.clear();
+ updateSymbolAttributes();
}
void QgsUniqueValueRenderer::updateSymbolAttributes()
@@ -240,35 +240,35 @@
QgsAttributeList QgsUniqueValueRenderer::classificationAttributes() const
{
- QgsAttributeList list(mSymbolAttributes);
- if ( ! list.contains(mClassificationField) )
- {
- list.append(mClassificationField);
- }
- return list;
+ QgsAttributeList list(mSymbolAttributes);
+ if ( ! list.contains(mClassificationField) )
+ {
+ list.append(mClassificationField);
+ }
+ return list;
}
bool QgsUniqueValueRenderer::writeXML( QDomNode & layer_node, QDomDocument & document ) const
{
- bool returnval=true;
- QDomElement uniquevalue=document.createElement("uniquevalue");
- layer_node.appendChild(uniquevalue);
- QDomElement classificationfield=document.createElement("classificationfield");
- QDomText classificationfieldtxt=document.createTextNode(QString::number(mClassificationField));
- classificationfield.appendChild(classificationfieldtxt);
- uniquevalue.appendChild(classificationfield);
- for(QMap<QString,QgsSymbol*>::const_iterator it=mSymbols.begin();it!=mSymbols.end();++it)
+ bool returnval=true;
+ QDomElement uniquevalue=document.createElement("uniquevalue");
+ layer_node.appendChild(uniquevalue);
+ QDomElement classificationfield=document.createElement("classificationfield");
+ QDomText classificationfieldtxt=document.createTextNode(QString::number(mClassificationField));
+ classificationfield.appendChild(classificationfieldtxt);
+ uniquevalue.appendChild(classificationfield);
+ for(QMap<QString,QgsSymbol*>::const_iterator it=mSymbols.begin();it!=mSymbols.end();++it)
+ {
+ if(!(it.value()->writeXML(uniquevalue,document)))
{
- if(!(it.value()->writeXML(uniquevalue,document)))
- {
- returnval=false;
- }
+ returnval=false;
}
- return returnval;
+ }
+ return returnval;
}
QgsRenderer* QgsUniqueValueRenderer::clone() const
{
- QgsUniqueValueRenderer* r = new QgsUniqueValueRenderer(*this);
- return r;
+ QgsUniqueValueRenderer* r = new QgsUniqueValueRenderer(*this);
+ return r;
}
More information about the QGIS-commit
mailing list