add methods to save/load autonumerotation of conductor to .qet file

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2171 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2013-05-20 19:29:10 +00:00
parent 44a853a204
commit 4363fb8481
3 changed files with 72 additions and 0 deletions

View File

@@ -317,6 +317,13 @@ QDomDocument Diagram::toXml(bool whole_content) {
QDomElement default_conductor = document.createElement("defaultconductor"); QDomElement default_conductor = document.createElement("defaultconductor");
defaultConductorProperties.toXml(default_conductor); defaultConductorProperties.toXml(default_conductor);
racine.appendChild(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); document.appendChild(racine);
@@ -460,6 +467,16 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
if (!default_conductor_elmt.isNull()) { if (!default_conductor_elmt.isNull()) {
defaultConductorProperties.fromXml(default_conductor_elmt); 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) // si la racine n'a pas d'enfant : le chargement est fini (schema vide)

View File

@@ -16,6 +16,20 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "numerotationcontext.h" #include "numerotationcontext.h"
#include "qet.h"
/**
* Constructor
*/
NumerotationContext::NumerotationContext(){
}
/**
* Constructor from xml
*/
NumerotationContext::NumerotationContext(QDomElement &e) {
fromXML(e);
}
/** /**
* @brief NumerotationContext::clear, clear the content * @brief NumerotationContext::clear, clear the content
@@ -64,6 +78,14 @@ int NumerotationContext::size() const {
return (content_.size()); return (content_.size());
} }
/**
* @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 * @brief NumerotationContext::itemAt
* @return the content at position @i 1:type 2:value 3:increase * @return the content at position @i 1:type 2:value 3:increase
@@ -103,3 +125,29 @@ bool NumerotationContext::keyIsAcceptable(const QString &type) const {
bool NumerotationContext::keyIsNumber(const QString &type) const { bool NumerotationContext::keyIsNumber(const QString &type) const {
return (type.contains(QRegExp(validRegExpNumber()))); 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());
}

View File

@@ -20,6 +20,8 @@
#include <QStringList> #include <QStringList>
#include <QVariant> #include <QVariant>
#include <QDomElement>
/** /**
This class represents a numerotation context, i.e. the data (type, value, increase) 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 of a numerotation at a given time. It is notably used by conductor
@@ -28,16 +30,21 @@
class NumerotationContext class NumerotationContext
{ {
public: public:
NumerotationContext ();
NumerotationContext (QDomElement &);
void clear(); void clear();
bool addValue(const QString &, const QVariant & = QVariant(1), const int = 1); bool addValue(const QString &, const QVariant & = QVariant(1), const int = 1);
QString operator[] (const int &) const; QString operator[] (const int &) const;
void operator << (const NumerotationContext &); void operator << (const NumerotationContext &);
int size() const; int size() const;
bool isEmpty() const;
QStringList itemAt(const int) const; QStringList itemAt(const int) const;
QString validRegExpNum () const; QString validRegExpNum () const;
QString validRegExpNumber() const; QString validRegExpNumber() const;
bool keyIsAcceptable (const QString &) const; bool keyIsAcceptable (const QString &) const;
bool keyIsNumber(const QString &) const; bool keyIsNumber(const QString &) const;
QDomElement toXML(QDomDocument &, QString);
void fromXML(QDomElement &);
private: private:
QStringList content_; QStringList content_;