[qet] [2171] add methods to save/load autonumerotation of conductor to .qet file |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2171
Author: blacksun
Date: 2013-05-20 21:29:10 +0200 (Mon, 20 May 2013)
Log Message:
-----------
add methods to save/load autonumerotation of conductor to .qet file
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/numerotationcontext.cpp
trunk/sources/numerotationcontext.h
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2013-05-20 14:06:57 UTC (rev 2170)
+++ trunk/sources/diagram.cpp 2013-05-20 19:29:10 UTC (rev 2171)
@@ -317,6 +317,13 @@
QDomElement default_conductor = document.createElement("defaultconductor");
defaultConductorProperties.toXml(default_conductor);
racine.appendChild(default_conductor);
+
+ //autonumerotation of conductor
+ if (!getNumerotation(Diagram::Conductors).isEmpty()) {
+ QDomElement autonum = document.createElement("autonum");
+ autonum.appendChild(getNumerotation(Diagram::Conductors).toXML(document, "conductor"));
+ racine.appendChild(autonum);
+ }
}
document.appendChild(racine);
@@ -460,6 +467,16 @@
if (!default_conductor_elmt.isNull()) {
defaultConductorProperties.fromXml(default_conductor_elmt);
}
+ // find the first element autonum
+ QDomElement num_auto = root.firstChildElement("autonum");
+ if (!num_auto.isNull()) {
+ QDomElement num_conductor = num_auto.firstChildElement("conductor");
+ //set the auto-numerotation of conductor
+ if (!num_conductor.isNull()) {
+ NumerotationContext nc(num_conductor);
+ setNumerotation(Diagram::Conductors, nc);
+ }
+ }
}
// si la racine n'a pas d'enfant : le chargement est fini (schema vide)
Modified: trunk/sources/numerotationcontext.cpp
===================================================================
--- trunk/sources/numerotationcontext.cpp 2013-05-20 14:06:57 UTC (rev 2170)
+++ trunk/sources/numerotationcontext.cpp 2013-05-20 19:29:10 UTC (rev 2171)
@@ -16,8 +16,22 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "numerotationcontext.h"
+#include "qet.h"
/**
+ * Constructor
+ */
+NumerotationContext::NumerotationContext(){
+}
+
+/**
+ * Constructor from xml
+ */
+NumerotationContext::NumerotationContext(QDomElement &e) {
+ fromXML(e);
+}
+
+/**
* @brief NumerotationContext::clear, clear the content
*/
void NumerotationContext::clear () {
@@ -65,6 +79,14 @@
}
/**
+ * @brief NumerotationContext::isEmpty
+ * @return true if numerotation contet is empty
+ */
+bool NumerotationContext::isEmpty() const {
+ if (content_.size() > 0) return false;
+ return true;
+}
+/**
* @brief NumerotationContext::itemAt
* @return the content at position @i 1:type 2:value 3:increase
*/
@@ -103,3 +125,29 @@
bool NumerotationContext::keyIsNumber(const QString &type) const {
return (type.contains(QRegExp(validRegExpNumber())));
}
+
+/**
+ * @brief NumerotationContext::toXML
+ * Save the numerotation context in a QDomElement under the element name @str
+ */
+QDomElement NumerotationContext::toXML(QDomDocument &d, QString str) {
+ QDomElement num_auto = d.createElement(str);
+ for (int i=0; i<content_.size(); ++i) {
+ QStringList strl = itemAt(i);
+ QDomElement part = d.createElement("part");
+ part.setAttribute("type", strl.at(0));
+ part.setAttribute("value", strl.at(1));
+ part.setAttribute("increase", strl.at(2));
+ num_auto.appendChild(part);
+ }
+ return num_auto;
+}
+
+/**
+ * @brief NumerotationContext::fromXML
+ * load numerotation context from @e
+ */
+void NumerotationContext::fromXML(QDomElement &e) {
+ clear();
+ foreach(QDomElement qde, QET::findInDomElement(e, "part")) addValue(qde.attribute("type"), qde.attribute("value"), qde.attribute("increase").toInt());
+}
Modified: trunk/sources/numerotationcontext.h
===================================================================
--- trunk/sources/numerotationcontext.h 2013-05-20 14:06:57 UTC (rev 2170)
+++ trunk/sources/numerotationcontext.h 2013-05-20 19:29:10 UTC (rev 2171)
@@ -20,6 +20,8 @@
#include <QStringList>
#include <QVariant>
+#include <QDomElement>
+
/**
This class represents a numerotation context, i.e. the data (type, value, increase)
of a numerotation at a given time. It is notably used by conductor
@@ -28,16 +30,21 @@
class NumerotationContext
{
public:
+ NumerotationContext ();
+ NumerotationContext (QDomElement &);
void clear();
bool addValue(const QString &, const QVariant & = QVariant(1), const int = 1);
QString operator[] (const int &) const;
void operator << (const NumerotationContext &);
int size() const;
+ bool isEmpty() const;
QStringList itemAt(const int) const;
QString validRegExpNum () const;
QString validRegExpNumber() const;
bool keyIsAcceptable (const QString &) const;
bool keyIsNumber(const QString &) const;
+ QDomElement toXML(QDomDocument &, QString);
+ void fromXML(QDomElement &);
private:
QStringList content_;