mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-26 13:20:52 +01:00
go on with the work
This commit is contained in:
@@ -196,11 +196,17 @@ void SingleLineProperties::drawPen(QPainter *painter, QET::ConductorSegmentType
|
||||
ajoutes a l'element e.
|
||||
@param e Element XML auquel seront ajoutes des attributs
|
||||
*/
|
||||
void SingleLineProperties::toXml(QDomElement &e) const {
|
||||
e.setAttribute("ground", hasGround ? "true" : "false");
|
||||
e.setAttribute("neutral", hasNeutral ? "true" : "false");
|
||||
e.setAttribute("phase", phases);
|
||||
if (isPen()) e.setAttribute("pen", "true");
|
||||
QDomElement SingleLineProperties::toXml(QDomDocument &doc) const {
|
||||
|
||||
QDomElement e = doc.createElement("SingleLine");
|
||||
e.appendChild(createXmlProperty(doc, "ground", hasGround));
|
||||
e.appendChild(createXmlProperty(doc, "neutral", hasNeutral));
|
||||
e.appendChild(createXmlProperty(doc, "phase", phases));
|
||||
|
||||
if (isPen())
|
||||
e.appendChild(createXmlProperty(doc, "pen", true));
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,11 +214,36 @@ void SingleLineProperties::toXml(QDomElement &e) const {
|
||||
de l'element e
|
||||
@param e Element XML dont les attributs seront lus
|
||||
*/
|
||||
void SingleLineProperties::fromXml(QDomElement &e) {
|
||||
hasGround = e.attribute("ground") == "true";
|
||||
hasNeutral = e.attribute("neutral") == "true";
|
||||
setPhasesCount(e.attribute("phase").toInt());
|
||||
is_pen = (hasGround && hasNeutral && e.attribute("pen", "false") == "true");
|
||||
bool SingleLineProperties::fromXml(const QDomElement &e) {
|
||||
if (propertyBool(e, "ground", &hasGround) != PropertyFlags::Success ||
|
||||
propertyBool(e, "neutral", &hasNeutral) != PropertyFlags::Success)
|
||||
return false;
|
||||
|
||||
int phase;
|
||||
if (propertyInteger(e, "phase", &phase) != PropertyFlags::Success)
|
||||
return false;
|
||||
setPhasesCount(phase);
|
||||
|
||||
bool pen;
|
||||
if (propertyBool(e, "pen", &pen) != PropertyFlags::Success)
|
||||
return false;
|
||||
is_pen = (hasGround && hasNeutral && pen);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SingleLineProperties::valideXml(QDomElement& e) {
|
||||
if (propertyBool(e, "ground") != PropertyFlags::Success ||
|
||||
propertyBool(e, "neutral") != PropertyFlags::Success)
|
||||
return false;
|
||||
|
||||
if (propertyInteger(e, "phase") != PropertyFlags::Success)
|
||||
return false;
|
||||
|
||||
if (propertyBool(e, "pen") != PropertyFlags::Success)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,43 +276,46 @@ ConductorProperties::~ConductorProperties() {
|
||||
* Export conductor propertie, in the XML element 'e'
|
||||
* @param e the xml element
|
||||
*/
|
||||
void ConductorProperties::toXml(QDomDocument& doc) const
|
||||
QDomElement ConductorProperties::toXml(QDomDocument& doc) const
|
||||
{
|
||||
|
||||
QDomElement conductor_elmt = xml_document.createElement("conductors");
|
||||
e.setAttribute("type", typeToString(type));
|
||||
QDomElement e = doc.createElement("defaultconductor");
|
||||
|
||||
e.appendChild(createXmlProperty(doc, "type", typeToString(type)));
|
||||
|
||||
if (color != QColor(Qt::black))
|
||||
e.setAttribute("color", color.name());
|
||||
|
||||
e.setAttribute("bicolor", m_bicolor? "true" : "false");
|
||||
e.setAttribute("color2", m_color_2.name());
|
||||
e.setAttribute("dash-size", QString::number(m_dash_size));
|
||||
e.appendChild(createXmlProperty(doc, "color", color));
|
||||
|
||||
e.appendChild(createXmlProperty(doc, "bicolor", m_bicolor));
|
||||
e.appendChild(createXmlProperty(doc, "color2", m_color_2));
|
||||
e.appendChild(createXmlProperty(doc, "dash-size", m_dash_size));
|
||||
|
||||
if (type == Single)
|
||||
singleLineProperties.toXml(e);
|
||||
e.appendChild(singleLineProperties.toXml(doc));
|
||||
|
||||
e.setAttribute("num", text);
|
||||
e.setAttribute("text_color", text_color.name());
|
||||
e.setAttribute("formula", m_formula);
|
||||
e.setAttribute("function", m_function);
|
||||
e.setAttribute("tension_protocol", m_tension_protocol);
|
||||
e.setAttribute("conductor_color", m_wire_color);
|
||||
e.setAttribute("conductor_section", m_wire_section);
|
||||
e.setAttribute("numsize", QString::number(text_size));
|
||||
e.setAttribute("condsize", QString::number(cond_size));
|
||||
e.setAttribute("displaytext", m_show_text);
|
||||
e.setAttribute("onetextperfolio", m_one_text_per_folio);
|
||||
e.setAttribute("vertirotatetext", QString::number(verti_rotate_text));
|
||||
e.setAttribute("horizrotatetext", QString::number(horiz_rotate_text));
|
||||
e.appendChild(createXmlProperty(doc, "num", text));
|
||||
e.appendChild(createXmlProperty(doc, "text_color", text_color.name()));
|
||||
e.appendChild(createXmlProperty(doc, "formula", m_formula));
|
||||
e.appendChild(createXmlProperty(doc, "function", m_function));
|
||||
e.appendChild(createXmlProperty(doc, "tension_protocol", m_tension_protocol));
|
||||
e.appendChild(createXmlProperty(doc, "conductor_color", m_wire_color));
|
||||
e.appendChild(createXmlProperty(doc, "conductor_section", m_wire_section));
|
||||
e.appendChild(createXmlProperty(doc, "numsize", text_size));
|
||||
e.appendChild(createXmlProperty(doc, "condsize", cond_size));
|
||||
e.appendChild(createXmlProperty(doc, "displaytext", m_show_text));
|
||||
e.appendChild(createXmlProperty(doc, "onetextperfolio", m_one_text_per_folio));
|
||||
e.appendChild(createXmlProperty(doc, "onetextperfolio", verti_rotate_text));
|
||||
e.appendChild(createXmlProperty(doc, "horizrotatetext", horiz_rotate_text));
|
||||
|
||||
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
e.setAttribute("horizontal-alignment", me.valueToKey(m_horizontal_alignment));
|
||||
e.setAttribute("vertical-alignment", me.valueToKey(m_vertical_alignment));
|
||||
e.appendChild(createXmlProperty(doc, "horizontal-alignment", me.valueToKey(m_horizontal_alignment)));
|
||||
e.appendChild(createXmlProperty(doc, "vertical-alignment", me.valueToKey(m_vertical_alignment)));
|
||||
|
||||
QString conductor_style = writeStyle();
|
||||
if (!conductor_style.isEmpty())
|
||||
e.setAttribute("style", conductor_style);
|
||||
e.appendChild(createXmlProperty(doc, "style", conductor_style));
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
@@ -290,24 +324,21 @@ void ConductorProperties::toXml(QDomDocument& doc) const
|
||||
* Import conductor propertie, from the attribute of the xml element 'e'
|
||||
* @param e the xml document
|
||||
*/
|
||||
void ConductorProperties::fromXml(QDomElement &e)
|
||||
bool ConductorProperties::fromXml(const QDomElement &e)
|
||||
{
|
||||
// get conductor color
|
||||
QColor xml_color= QColor(e.attribute("color"));
|
||||
color = (xml_color.isValid()? xml_color : QColor(Qt::black));
|
||||
|
||||
QString bicolor_str = e.attribute("bicolor", "false");
|
||||
m_bicolor = bicolor_str == "true"? true : false;
|
||||
|
||||
QColor xml_color_2 = QColor(e.attribute("color2"));
|
||||
m_color_2 = xml_color_2.isValid()? xml_color_2 : QColor(Qt::black);
|
||||
|
||||
m_dash_size = e.attribute("dash-size", QString::number(1)).toInt();
|
||||
propertyColor(e, "color", &color);
|
||||
propertyBool(e, "bicolor", &m_bicolor, false);
|
||||
propertyColor(e, "color2", &m_color_2);
|
||||
propertyInteger(e, "dash-size", &m_dash_size, 1);
|
||||
|
||||
// read style of conductor
|
||||
readStyle(e.attribute("style"));
|
||||
|
||||
QString type_t;
|
||||
propertyString(e, "type", &type_t);
|
||||
|
||||
if (e.attribute("type") == typeToString(Single))
|
||||
if (type_t == typeToString(Single))
|
||||
{
|
||||
// get specific properties for single conductor
|
||||
singleLineProperties.fromXml(e);
|
||||
@@ -316,30 +347,60 @@ void ConductorProperties::fromXml(QDomElement &e)
|
||||
else
|
||||
type = Multi;
|
||||
|
||||
text = e.attribute("num");
|
||||
propertyString(e, "num", &text);
|
||||
|
||||
// get text color
|
||||
QColor xml_text_color= QColor(e.attribute("text_color"));
|
||||
text_color = (xml_text_color.isValid()? xml_text_color : QColor(Qt::black));
|
||||
m_formula = e.attribute("formula");
|
||||
m_function = e.attribute("function");
|
||||
m_tension_protocol = e.attribute("tension_protocol");
|
||||
m_wire_color = e.attribute("conductor_color");
|
||||
m_wire_section = e.attribute("conductor_section");
|
||||
text_size = e.attribute("numsize", QString::number(9)).toInt();
|
||||
cond_size = e.attribute("condsize", QString::number(1)).toDouble();
|
||||
m_show_text = e.attribute("displaytext", QString::number(1)).toInt();
|
||||
m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt();
|
||||
verti_rotate_text = e.attribute("vertirotatetext").toDouble();
|
||||
horiz_rotate_text = e.attribute("horizrotatetext").toDouble();
|
||||
propertyColor(e, "text_color", &text_color);
|
||||
propertyString(e, "formula", &m_formula);
|
||||
propertyString(e, "function", &m_function);
|
||||
propertyString(e, "tension_protocol", &m_tension_protocol);
|
||||
propertyString(e, "conductor_color", &m_wire_color);
|
||||
propertyString(e, "conductor_section", &m_wire_section);
|
||||
propertyInteger(e, "numsize", &text_size, 9);
|
||||
propertyDouble(e, "condsize", &cond_size, 1);
|
||||
propertyBool(e, "displaytext", &m_show_text, true);
|
||||
propertyBool(e, "onetextperfolio", &m_one_text_per_folio, 0);
|
||||
propertyDouble(e, "vertirotatetext", &verti_rotate_text);
|
||||
propertyDouble(e, "horizrotatetext", &horiz_rotate_text);
|
||||
|
||||
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_horizontal_alignment = Qt::Alignment(me.keyToValue(e.attribute("horizontal-alignment", "AlignBottom").toStdString().data()));
|
||||
m_vertical_alignment = Qt::Alignment(me.keyToValue(e.attribute("vertical-alignment", "AlignRight").toStdString().data()));
|
||||
|
||||
QString alinment_temp;
|
||||
propertyString(e, "horizontal-alignment", &alinment_temp, "AlignBottom");
|
||||
m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data()));
|
||||
propertyString(e, "vertical-alignment", &alinment_temp, "AlignRight");
|
||||
m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data()));
|
||||
|
||||
//Keep retrocompatible with version older than 0,4
|
||||
//If the propertie @type is simple (removed since QET 0,4), we set text no visible.
|
||||
//@TODO remove this code for qet 0.6 or later
|
||||
if (e.attribute("type") == "simple") m_show_text = false;
|
||||
|
||||
if (type_t == "simple") m_show_text = false;
|
||||
}
|
||||
|
||||
bool ConductorProperties::valideXml(QDomElement& e) {
|
||||
if (propertyColor(e, "color") ||
|
||||
propertyBool(e, "bicolor") ||
|
||||
propertyColor(e, "color2") ||
|
||||
propertyInteger(e, "dash-size") ||
|
||||
propertyString(e, "type") ||
|
||||
propertyString(e, "num") ||
|
||||
propertyColor(e, "text_color") ||
|
||||
propertyString(e, "formula") ||
|
||||
propertyString(e, "function") ||
|
||||
propertyString(e, "tension_protocol") ||
|
||||
propertyString(e, "conductor_color") ||
|
||||
propertyString(e, "conductor_section") ||
|
||||
propertyInteger(e, "numsize") ||
|
||||
propertyDouble(e, "condsize") ||
|
||||
propertyBool(e, "displaytext") ||
|
||||
propertyBool(e, "onetextperfolio") ||
|
||||
propertyDouble(e, "vertirotatetext") ||
|
||||
propertyDouble(e, "horizrotatetext") ||
|
||||
propertyString(e, "horizontal-alignment") ||
|
||||
propertyString(e, "vertical-alignment"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +440,7 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix)
|
||||
@param settings Parametres a lire
|
||||
@param prefix prefixe a ajouter devant les noms des parametres
|
||||
*/
|
||||
void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix)
|
||||
void ConductorProperties::fromSettings(const QSettings &settings, const QString &prefix)
|
||||
{
|
||||
QColor settings_color = QColor(settings.value(prefix + "color").toString());
|
||||
color = (settings_color.isValid()? settings_color : QColor(Qt::black));
|
||||
@@ -823,7 +884,7 @@ void SingleLineProperties::toSettings(QSettings &settings, const QString &prefix
|
||||
@param settings Parametres a lire
|
||||
@param prefix prefix a ajouter devant les noms des parametres
|
||||
*/
|
||||
void SingleLineProperties::fromSettings(QSettings &settings, const QString &prefix) {
|
||||
void SingleLineProperties::fromSettings(const QSettings &settings, const QString &prefix) {
|
||||
hasGround = settings.value(prefix + "hasGround", true).toBool();
|
||||
hasNeutral = settings.value(prefix + "hasNeutral", true).toBool();
|
||||
phases = settings.value(prefix + "phases", 1).toInt();
|
||||
|
||||
Reference in New Issue
Block a user