#include <kgamesvgdocument.h>

Public Types | |
| enum | MatrixOption { ApplyToCurrentMatrix = 0x01, ReplaceCurrentMatrix = 0x02 } |
| enum | StylePropertySortOption { Unsorted = 0x01, UseInkscapeOrder = 0x02 } |
| Options for sorting style properties when building a style attribute. More... | |
| typedef QFlags < MatrixOption > | MatrixOptions |
| typedef QFlags < StylePropertySortOption > | StylePropertySortOptions |
Public Member Functions | |
| KGameSvgDocument () | |
| KGameSvgDocument (const KGameSvgDocument &doc) | |
| virtual | ~KGameSvgDocument () |
| KGameSvgDocument & | operator= (const KGameSvgDocument &doc) |
| QDomNode | elementByUniqueAttributeValue (const QString &attributeName, const QString &attributeValue) |
| QDomNode | elementById (const QString &attributeValue) |
| void | load () |
| void | load (const QString &svgFilename) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| void | rotate (double degrees, const MatrixOptions &options=ApplyToCurrentMatrix) |
| void | translate (int xPixels, int yPixels, const MatrixOptions &options=ApplyToCurrentMatrix) |
| void | shear (double xRadians, double yRadians, const MatrixOptions &options=ApplyToCurrentMatrix) |
| void | skew (double xDegrees, double yDegrees, const MatrixOptions &options=ApplyToCurrentMatrix) |
| void | scale (double xFactor, double yFactor, const MatrixOptions &options=ApplyToCurrentMatrix) |
| QDomNode | currentNode () const |
| void | setCurrentNode (const QDomNode &node) |
| QString | svgFilename () const |
| void | setSvgFilename (const QString &svgFilename) |
| QString | styleProperty (const QString &propertyName) const |
| void | setStyleProperty (const QString &propertyName, const QString &propertyValue) |
| QString | nodeToSvg () const |
| QByteArray | nodeToByteArray () const |
| QString | style () const |
| void | setStyle (const QString &styleAttribute) |
| QDomNodeList | patterns () const |
| QDomNodeList | linearGradients () const |
| QDomNodeList | radialGradients () const |
| QDomNodeList | defs () const |
| QDomNode | def () const |
| QString | transform () const |
| void | setTransform (const QString &transformAttribute) |
| QHash< QString, QString > | styleProperties () const |
| void | setStyleProperties (const QHash< QString, QString > &_styleProperties, const StylePropertySortOptions &options=Unsorted) |
| QMatrix | transformMatrix () const |
| void | setTransformMatrix (QMatrix &matrix, const MatrixOptions &options=ApplyToCurrentMatrix) |
To read an SVG file into DOM:
KGameSvgDocument svgDom; svgDom.load("/path/to/svgFile.svg");
To find a node with a specific value in its id attribute, for example where id="playerOneGamepiece":
QDomNode playerOneGamepiece = svgDom.elementById("playerOneGamepiece"); // This works too QDomNode playerOneGamepiece = svgDom.elementByUniqueAttributeValue("id", "playerOneGamepiece");
Most methods operate on the last node found by elementById() or elementByUniqueAttributeValue(). If the methods are working on the wrong node, then you are mistaken about which node was the last node (or you found a bug). Try calling setCurrentNode() with the node you are wanting to modify to see if this is the issue. Consider the following code for example:
QDomNode playerOneGamepiece = svgDom.elementById("playerOneGamepiece"); QDomNode playerTwoGamepiece = svgDom.elementById("playerTwoGamepiece"); // Set player one's game piece to have a white fill svgDom.setStyleProperty("fill", "#ffffff"); // INCORRECT: playerTwoGamepiece is the last node, not playerOneGamepiece svgDom.setCurrentNode(playerOneGamepiece); // CORRECT: Set current node to the node we want, svgDom.setStyleProperty("fill", "#ffffff"); // then we modify the node
To skew the currentNode():
// Skew the horizontal axis 7.5 degrees svgDom.skew(-7.5, 0, KGameSvgDocument::ReplaceCurrentMatrix);
x^2, and you will very quickly run into overflow issues.currentNode() to be rendered: KSvgRenderer svgRenderer; QByteArray svg = svgDom.nodeToByteArray(); svgRenderer.load(svg);
To output the whole document to be rendered (See QDomDocument::toByteArray()):
KSvgRenderer svgRenderer; QByteArray svg = svgDom.toByteArray(); svgRenderer.load(svg);
Definition at line 113 of file kgamesvgdocument.h.
| typedef QFlags<MatrixOption> KGameSvgDocument::MatrixOptions |
Q_DECLARE_FLAGS macro confuses doxygen, so create typedef's manually
Definition at line 150 of file kgamesvgdocument.h.
| typedef QFlags<StylePropertySortOption> KGameSvgDocument::StylePropertySortOptions |
Q_DECLARE_FLAGS macro confuses doxygen, so create typedef's manually
Definition at line 166 of file kgamesvgdocument.h.
Options for applying (multiplying) or replacing the current matrix
| ApplyToCurrentMatrix | Apply to current matrix. |
| ReplaceCurrentMatrix | Replace the current matrix. |
Definition at line 139 of file kgamesvgdocument.h.
Options for sorting style properties when building a style attribute.
| Unsorted | When building a style attribute, do not sort. |
| UseInkscapeOrder | When building a style attribute, sort properties the same way Inkscape does. |
Definition at line 155 of file kgamesvgdocument.h.
| KGameSvgDocument::KGameSvgDocument | ( | ) | [explicit] |
Constructor
Definition at line 143 of file kgamesvgdocument.cpp.
| KGameSvgDocument::KGameSvgDocument | ( | const KGameSvgDocument & | doc | ) |
Copy Constructor
Definition at line 147 of file kgamesvgdocument.cpp.
| KGameSvgDocument::~KGameSvgDocument | ( | ) | [virtual] |
Destructor
Definition at line 152 of file kgamesvgdocument.cpp.
| KGameSvgDocument & KGameSvgDocument::operator= | ( | const KGameSvgDocument & | doc | ) |
| QDomNode KGameSvgDocument::elementByUniqueAttributeValue | ( | const QString & | attributeName, | |
| const QString & | attributeValue | |||
| ) |
Returns the node with the given value for the given attribute.
Returns the element whose attribute given in attributeName is equal to the value given in attributeValue.
QDomDocument::elementById() always returns a null node because TT says they can't know which attribute is the id attribute. Here, we allow the id attribute to be specified.
This function also sets m_currentNode to this node.
| attributeName | The name of the identifing attribute, such as "id" to find. | |
| attributeValue | The value to look for in the attribute attributeName The values held in this attribute must be unique in the document, or the consequences may be unpredictably incorrect. You've been warned. ;-) |
Definition at line 164 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::findElementById(), and setCurrentNode().
Referenced by elementById().

| QDomNode KGameSvgDocument::elementById | ( | const QString & | attributeValue | ) |
Returns a node with the given id.
This is a convenience function. We call elementByUniqueAttributeValue(), but we assume that the name of the attribute is "id". This assumption will be correct for valid SVG files.
Returns the element whose ID is equal to elementId. If no element with the ID was found, this function returns a null element.
| attributeValue | The value of the id attribute to find |
Definition at line 177 of file kgamesvgdocument.cpp.
References elementByUniqueAttributeValue().

| void KGameSvgDocument::load | ( | ) |
Reads the SVG file svgFilename() into DOM.
Definition at line 182 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_svgFilename.
Referenced by load().
| void KGameSvgDocument::load | ( | const QString & | svgFilename | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This function permits specifying the svg file and loading it at once.
| svgFilename | The filename of the SVG file to open. |
Definition at line 213 of file kgamesvgdocument.cpp.
References load(), and setSvgFilename().

| void KGameSvgDocument::rotate | ( | double | degrees, | |
| const MatrixOptions & | options = ApplyToCurrentMatrix | |||
| ) |
Rotates the origin of the current node counterclockwise.
| degrees | The amount in degrees to rotate by. | |
| options | Apply to current matrix or replace current matrix. |
Definition at line 219 of file kgamesvgdocument.cpp.
References ApplyToCurrentMatrix, ReplaceCurrentMatrix, setTransformMatrix(), and transformMatrix().

| void KGameSvgDocument::translate | ( | int | xPixels, | |
| int | yPixels, | |||
| const MatrixOptions & | options = ApplyToCurrentMatrix | |||
| ) |
Moves the origin of the current node
| xPixels | The number of pixels to move the x-axis by. | |
| yPixels | The number of pixels to move the y-axis by. | |
| options | Apply to current matrix or replace current matrix. |
Definition at line 235 of file kgamesvgdocument.cpp.
References ApplyToCurrentMatrix, ReplaceCurrentMatrix, setTransformMatrix(), and transformMatrix().

| void KGameSvgDocument::shear | ( | double | xRadians, | |
| double | yRadians, | |||
| const MatrixOptions & | options = ApplyToCurrentMatrix | |||
| ) |
Shears the origin of the current node.
| xRadians | The amount in radians to shear (skew) the x-axis by. | |
| yRadians | The amount in radians to shear (skew) the y-axis by. | |
| options | Apply to current matrix or replace current matrix. |
Definition at line 251 of file kgamesvgdocument.cpp.
References ApplyToCurrentMatrix, ReplaceCurrentMatrix, setTransformMatrix(), and transformMatrix().
Referenced by skew().

| void KGameSvgDocument::skew | ( | double | xDegrees, | |
| double | yDegrees, | |||
| const MatrixOptions & | options = ApplyToCurrentMatrix | |||
| ) |
Skews the origin of the current node.
This is a convenience function. It simply coverts it's arguments to radians, then calls shear().
| xDegrees | The amount in degrees to shear (skew) the x-axis by. | |
| yDegrees | The amount in degrees to shear (skew) the y-axis by. | |
| options | Apply to current matrix or replace current matrix. |
Definition at line 267 of file kgamesvgdocument.cpp.
References shear().

| void KGameSvgDocument::scale | ( | double | xFactor, | |
| double | yFactor, | |||
| const MatrixOptions & | options = ApplyToCurrentMatrix | |||
| ) |
Scales the origin of the current node.
xFactor nor yFactor may be zero, otherwise you scale the element into nonexistence.| xFactor | The factor to scale the x-axis by. | |
| yFactor | The factor to scale the y-axis by. | |
| options | Apply to current matrix or replace current matrix. |
Definition at line 275 of file kgamesvgdocument.cpp.
References ApplyToCurrentMatrix, ReplaceCurrentMatrix, setTransformMatrix(), and transformMatrix().

| QDomNode KGameSvgDocument::currentNode | ( | ) | const |
Returns the last node found by elementById, or null if node not found
Definition at line 295 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_currentNode.
Referenced by nodeToSvg().
| void KGameSvgDocument::setCurrentNode | ( | const QDomNode & | node | ) |
Sets the current node.
| node | The node to set currentNode to. |
Definition at line 300 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_currentNode, and KGameSvgDocumentPrivate::setCurrentElement().
Referenced by elementByUniqueAttributeValue().

| QString KGameSvgDocument::svgFilename | ( | ) | const |
Returns the name of the SVG file this DOM represents.
Definition at line 306 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_svgFilename.
| void KGameSvgDocument::setSvgFilename | ( | const QString & | svgFilename | ) |
Sets the current SVG filename.
| svgFilename | The filename of the SVG file to open. |
Definition at line 311 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_svgFilename.
Referenced by load().
| QString KGameSvgDocument::styleProperty | ( | const QString & | propertyName | ) | const |
Returns the value of the style property given for the current node.
styleProperties, then return the value of the propertyName property. As such, if you need the values of multiple properties, it will be more efficient to call styleProperties() and then use the hash directly.
| propertyName | the name of the property to return |
Definition at line 316 of file kgamesvgdocument.cpp.
References styleProperties().
Referenced by styleProperties().

| void KGameSvgDocument::setStyleProperty | ( | const QString & | propertyName, | |
| const QString & | propertyValue | |||
| ) |
Sets the value of the style property given for the current node.
styleProperties, then update the propertyName to propertyValue, before finally applying the hash to DOM via setStyleProperties(). Because of this, if you need to set multiple properties per node, it will be more efficient to call styleProperties(), modify the hash it returns, and then apply the hash with setStyleProperties().| propertyName | The name of the property to set. | |
| propertyValue | The value of the property to set. |
Definition at line 321 of file kgamesvgdocument.cpp.
References setStyleProperties(), styleProperties(), and UseInkscapeOrder.

| QString KGameSvgDocument::nodeToSvg | ( | ) | const |
Returns the current node and it's children as a new xml svg document.
Definition at line 331 of file kgamesvgdocument.cpp.
References currentNode(), def(), defs(), KGameSvgDocumentPrivate::findElementById(), KGameSvgDocumentPrivate::SVG_XML_APPEND, and KGameSvgDocumentPrivate::SVG_XML_PREPEND.
Referenced by nodeToByteArray().

| QByteArray KGameSvgDocument::nodeToByteArray | ( | ) | const |
Builds a new svg document and returns a QByteArray suitable for passing to KSvgRenderer::load().
Internally, we call nodeToSvg() and then convert to a QByteArray, so this method should be called instead of nodeToSvg().
Definition at line 382 of file kgamesvgdocument.cpp.
References nodeToSvg().

| QString KGameSvgDocument::style | ( | ) | const |
Returns the style attribute of the current node.
Unless you are parsing your own style attribute for some reason, you probably want to use styleProperty() or styleProperties().
Definition at line 387 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_currentElement.
Referenced by styleProperties().
| void KGameSvgDocument::setStyle | ( | const QString & | styleAttribute | ) |
Sets the style attribute of the current node.
Unless you are parsing your own style attribute for some reason, you probably want to use setStyleProperty() or setStyleProperties().
| styleAttribute | The style attribute to apply. |
Definition at line 392 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_currentElement.
Referenced by setStyleProperties().
| QDomNodeList KGameSvgDocument::patterns | ( | ) | const |
Returns the patterns in the document
Definition at line 397 of file kgamesvgdocument.cpp.
| QDomNodeList KGameSvgDocument::linearGradients | ( | ) | const |
Returns the linearGradients in the document
Definition at line 402 of file kgamesvgdocument.cpp.
| QDomNodeList KGameSvgDocument::radialGradients | ( | ) | const |
Returns the radialGradients in the document
Definition at line 407 of file kgamesvgdocument.cpp.
| QDomNodeList KGameSvgDocument::defs | ( | ) | const |
Returns the defs in the document
Definition at line 412 of file kgamesvgdocument.cpp.
Referenced by def(), and nodeToSvg().
| QDomNode KGameSvgDocument::def | ( | ) | const |
Returns the first def in the document
Definition at line 417 of file kgamesvgdocument.cpp.
References defs().
Referenced by nodeToSvg().

| QString KGameSvgDocument::transform | ( | ) | const |
Returns the transform attribute of the current node.
Definition at line 422 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_currentElement.
Referenced by setTransformMatrix(), and transformMatrix().
| void KGameSvgDocument::setTransform | ( | const QString & | transformAttribute | ) |
Sets the transform attribute of the current node.
As this function works on QStrings, it replaces the existing transform attribute. If you need to multiply, use setTransformMatrix() instead.
| transformAttribute | The transform attribute to apply. |
Definition at line 427 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_currentElement.
Referenced by setTransformMatrix().
| QHash< QString, QString > KGameSvgDocument::styleProperties | ( | ) | const |
Returns a hash of the style properties of the current node.
Definition at line 432 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::setStyleHasTrailingSemicolon(), style(), and styleProperty().
Referenced by setStyleProperties(), setStyleProperty(), and styleProperty().

| void KGameSvgDocument::setStyleProperties | ( | const QHash< QString, QString > & | _styleProperties, | |
| const StylePropertySortOptions & | options = Unsorted | |||
| ) |
Sets the style properties of the current node.
The only(?) reason to set useInkscapeOrder to true is if you are saving the svg xml to a file that may be human-edited later, for consistency. There is a performance hit, since hashes store their data unsorted.
| _styleProperties | The hash of style properties to apply. | |
| options | Apply the hash so the properties are in the same order as Inkscape writes them. |
Definition at line 459 of file kgamesvgdocument.cpp.
References KGameSvgDocumentPrivate::m_inkscapeOrder, setStyle(), KGameSvgDocumentPrivate::styleHasTrailingSemicolon(), styleProperties(), and UseInkscapeOrder.
Referenced by setStyleProperty().

| QMatrix KGameSvgDocument::transformMatrix | ( | ) | const |
Returns the transform attribute of the current node as a matrix.
Definition at line 499 of file kgamesvgdocument.cpp.
References transform().
Referenced by rotate(), scale(), setTransformMatrix(), shear(), and translate().

| void KGameSvgDocument::setTransformMatrix | ( | QMatrix & | matrix, | |
| const MatrixOptions & | options = ApplyToCurrentMatrix | |||
| ) |
Sets the transform attribute of the current node.
| matrix | The matrix to apply. | |
| options | Should we apply matrix to the current matrix? We modify matrix internally if options includes ApplyToCurrentMatrix, so it can't be passed as const. Normally we want to apply the existing matrix. If we apply the matrix, we potentially end up squaring with each call, e.g. x^2. |
Definition at line 613 of file kgamesvgdocument.cpp.
References ApplyToCurrentMatrix, setTransform(), transform(), and transformMatrix().
Referenced by rotate(), scale(), shear(), and translate().

1.5.3