21 #include <QDomElement>
22 #include <QTextStream>
26 , mOverriddenOriginalStyle( 0 )
34 mCurrentStyle.
clear();
39 mCurrentStyle = mgrElement.
attribute(
"current" );
48 mStyles.
insert( name, style );
63 mStyles[
name].writeXml( ch );
70 return mStyles.
keys();
75 if ( name == mCurrentStyle )
83 return mStyles.
value( name );
93 mStyles.
insert( name, style );
109 if ( mStyles.
count() == 1 )
113 if ( mCurrentStyle == name )
117 if ( newCurrent == name )
118 newCurrent = keys[1];
132 if ( name == mCurrentStyle )
133 mCurrentStyle = newName;
135 mStyles[newName] = mStyles[
name];
143 return mCurrentStyle;
151 if ( mCurrentStyle == name )
154 mStyles[mCurrentStyle].readFromLayer( mLayer );
155 mCurrentStyle =
name;
156 mStyles[mCurrentStyle].writeToLayer( mLayer );
157 mStyles[mCurrentStyle].
clear();
166 if ( mOverriddenOriginalStyle )
176 mStyles[styleDef].writeToLayer( mLayer );
194 if ( !mOverriddenOriginalStyle )
201 delete mOverriddenOriginalStyle;
202 mOverriddenOriginalStyle = 0;
214 : mXmlData( xmlData )
240 QgsDebugMsg(
"Failed to export style from layer: " + errorMsg );
254 QgsDebugMsg(
"Failed to parse XML of previously stored XML data - this should not happen!" );
261 QgsDebugMsg(
"Failed to import style to layer: " + errorMsg );
bool restoreOverrideStyle()
Restore the original store after a call to setOverrideStyle()
void clear()
Remove any stored style data (will get invalid)
QgsMapLayerStyleManager(QgsMapLayer *layer)
Construct a style manager associated with a map layer (must not be null)
Base class for all map layer types.
void currentStyleChanged(const QString ¤tName)
Emitted when the current style has been changed.
void styleRenamed(const QString &oldName, const QString &newName)
Emitted when a style has been renamed.
bool contains(const Key &key) const
QDomNode appendChild(const QDomNode &newChild)
void reset()
Reset the style manager to a basic state - with one default style which is set as current...
void readXml(const QDomElement &styleElement)
Read style configuration (for project file reading)
QString attribute(const QString &name, const QString &defValue) const
QDomElement nextSiblingElement(const QString &tagName) const
QDomElement documentElement() const
void styleAdded(const QString &name)
Emitted when a new style has been added.
void readFromLayer(QgsMapLayer *layer)
Store layer's active style information in the instance.
QList< Key > keys() const
Stores style information (renderer, transparency, labeling, diagrams etc.) applicable to a map layer...
const char * name() const
bool removeStyle(const QString &name)
Remove a stored style.
QDomDocument ownerDocument() const
void setAttribute(const QString &name, const QString &value)
void readXml(const QDomElement &mgrElement)
Read configuration (for project loading)
void styleRemoved(const QString &name)
Emitted when a style has been removed.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void triggerRepaint()
Will advice the map canvas (and any other interested party) that this layer requires to be repainted...
QString currentStyle() const
Return name of the current style.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg)
Import the properties of this layer from a QDomDocument.
bool addStyleFromLayer(const QString &name)
Add style by cloning the current one.
bool blockSignals(bool block)
QString xmlData() const
Return XML content of the style.
QgsMapLayerStyle()
construct invalid style
bool isValid() const
Tell whether the style is valid (i.e. there is something stored in it)
QgsMapLayerStyle style(const QString &name) const
Return data of a stored style - accessed by its unique name.
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg)
Export the properties of this layer as named style in a QDomDocument.
void writeXml(QDomElement &styleElement) const
Write style configuration (for project file writing)
bool renameStyle(const QString &name, const QString &newName)
Rename a stored style to a different name.
void save(QTextStream &str, int indent) const
QDomElement firstChildElement(const QString &tagName) const
void writeToLayer(QgsMapLayer *layer) const
Apply stored layer's style information to the layer.
iterator insert(const Key &key, const T &value)
bool addStyle(const QString &name, const QgsMapLayerStyle &style)
Add a style with given name and data.
bool setOverrideStyle(const QString &styleDef)
Temporarily apply a different style to the layer.
QDomElement createElement(const QString &tagName)
int count(const Key &key) const
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
const T value(const Key &key) const
int remove(const Key &key)
void writeXml(QDomElement &mgrElement) const
Write configuration (for project saving)
QStringList styles() const
Return list of all defined style names.