mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Improved the DiagramContext class.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1890 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "diagramcontext.h"
|
||||
#include <QRegExp>
|
||||
#include "qet.h"
|
||||
|
||||
/**
|
||||
@return a list containing all the keys in the context object.
|
||||
@@ -72,6 +73,13 @@ void DiagramContext::clear() {
|
||||
content_.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@return the number of key/value pairs stored in this object.
|
||||
*/
|
||||
int DiagramContext::count() {
|
||||
return(content_.count());
|
||||
}
|
||||
|
||||
bool DiagramContext::operator==(const DiagramContext &dc) const {
|
||||
return(content_ == dc.content_);
|
||||
}
|
||||
@@ -80,6 +88,62 @@ bool DiagramContext::operator!=(const DiagramContext &dc) const {
|
||||
return(!(*this == dc));
|
||||
}
|
||||
|
||||
/**
|
||||
Export this context properties under the \a e XML element, using tags
|
||||
named \a tag_name (defaults to "property").
|
||||
*/
|
||||
void DiagramContext::toXml(QDomElement &e, const QString &tag_name) const {
|
||||
foreach (QString key, keys()) {
|
||||
QDomElement property = e.ownerDocument().createElement(tag_name);
|
||||
property.setAttribute("name", key);
|
||||
QDomText value = e.ownerDocument().createTextNode(content_[key].toString());
|
||||
property.appendChild(value);
|
||||
e.appendChild(property);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Read this context properties from the \a e XML element, looking for tags named
|
||||
\a tag_name (defaults to "property").
|
||||
*/
|
||||
void DiagramContext::fromXml(const QDomElement &e, const QString &tag_name) {
|
||||
foreach (QDomElement property, QET::findInDomElement(e, tag_name)) {
|
||||
if (!property.hasAttribute("name")) continue;
|
||||
addValue(property.attribute("name"), QVariant(property.text()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Export this context properties to \a settings by creating an array named \a
|
||||
array_name.
|
||||
*/
|
||||
void DiagramContext::toSettings(QSettings &settings, const QString &array_name) const {
|
||||
settings.beginWriteArray(array_name);
|
||||
int i = 0;
|
||||
foreach (QString key, content_.keys()) {
|
||||
settings.setArrayIndex(i);
|
||||
settings.setValue("name", key);
|
||||
settings.setValue("value", content_[key].toString());
|
||||
++ i;
|
||||
}
|
||||
settings.endArray();
|
||||
}
|
||||
|
||||
/**
|
||||
Read this context properties from \a settings by running through the array
|
||||
named \a array_name.
|
||||
*/
|
||||
void DiagramContext::fromSettings(QSettings &settings, const QString &array_name) {
|
||||
int size = settings.beginReadArray(array_name);
|
||||
for (int i = 0 ; i < size; ++ i) {
|
||||
settings.setArrayIndex(i);
|
||||
QString key = settings.value("name").toString();
|
||||
if (key.isEmpty()) continue;
|
||||
addValue(key, settings.value("value").toString());
|
||||
}
|
||||
settings.endArray();
|
||||
}
|
||||
|
||||
/**
|
||||
@return the regular expression used to check whether a given key is acceptable.
|
||||
@see keyIsAcceptable()
|
||||
|
||||
Reference in New Issue
Block a user