TEST a Merge branch 'XMLProperties'

it gets built let's test it for bugs

 Conflicts:
	sources/ElementsCollection/fileelementcollectionitem.cpp
	sources/QetGraphicsItemModeler/qetgraphicshandleritem.h
	sources/borderproperties.cpp
	sources/conductorproperties.cpp
	sources/conductorproperties.h
	sources/diagram.cpp
	sources/diagram.h
	sources/diagramprintdialog.cpp
	sources/diagramprintdialog.h
	sources/editor/graphicspart/customelementgraphicpart.cpp
	sources/editor/graphicspart/partarc.cpp
	sources/editor/graphicspart/partdynamictextfield.cpp
	sources/editor/graphicspart/partdynamictextfield.h
	sources/editor/graphicspart/partellipse.cpp
	sources/editor/graphicspart/partline.cpp
	sources/editor/graphicspart/partpolygon.cpp
	sources/editor/graphicspart/partrectangle.cpp
	sources/editor/graphicspart/partterminal.cpp
	sources/editor/graphicspart/partterminal.h
	sources/editor/graphicspart/parttext.cpp
	sources/properties/propertiesinterface.cpp
	sources/properties/propertiesinterface.h
	sources/properties/terminaldata.cpp
	sources/properties/terminaldata.h
	sources/properties/xrefproperties.cpp
	sources/properties/xrefproperties.h
	sources/qetgraphicsitem/conductor.cpp
	sources/qetgraphicsitem/conductor.h
	sources/qetgraphicsitem/conductortextitem.h
	sources/qetgraphicsitem/dynamicelementtextitem.h
	sources/qetgraphicsitem/element.cpp
	sources/qetgraphicsitem/element.h
	sources/qetgraphicsitem/elementtextitemgroup.h
	sources/qetgraphicsitem/slaveelement.cpp
	sources/qetgraphicsitem/slaveelement.h
	sources/qetgraphicsitem/terminal.cpp
	sources/qetgraphicsitem/terminal.h
	sources/qetproject.cpp
	sources/titleblockproperties.cpp
This commit is contained in:
Simon De Backer
2020-10-13 21:51:34 +02:00
67 changed files with 2095 additions and 1486 deletions

View File

@@ -23,11 +23,7 @@
/**
Constructeur par defaut
*/
SingleLineProperties::SingleLineProperties() :
hasGround(true),
hasNeutral(true),
is_pen(false),
phases(1)
SingleLineProperties::SingleLineProperties()
{
}
@@ -123,9 +119,9 @@ void SingleLineProperties::draw(QPainter *painter,
@param size taille du segment
*/
void SingleLineProperties::drawGround(QPainter *painter,
QET::ConductorSegmentType direction,
QPointF center,
qreal size) {
QET::ConductorSegmentType direction,
QPointF center,
qreal size) {
painter -> save();
// prepare le QPainter
@@ -211,16 +207,21 @@ void SingleLineProperties::drawPen(QPainter *painter,
}
/**
Exporte les parametres du conducteur unifilaire sous formes d'attributs XML
ajoutes a l'element e.
@param e Element XML auquel seront ajoutes des attributs
@brief SingleLineProperties::toXml
@param doc
@return
*/
void SingleLineProperties::toXml(QDomElement &e) const
QDomElement SingleLineProperties::toXml(QDomDocument &doc) const
{
e.setAttribute("ground", hasGround ? "true" : "false");
e.setAttribute("neutral", hasNeutral ? "true" : "false");
e.setAttribute("phase", phases);
if (isPen()) e.setAttribute("pen", "true");
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;
}
/**
@@ -228,11 +229,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;
}
/**
@@ -266,116 +292,142 @@ ConductorProperties::~ConductorProperties()
Export conductor propertie, in the XML element 'e'
@param e the xml element
*/
void ConductorProperties::toXml(QDomElement &e) const
QDomElement ConductorProperties::toXml(QDomDocument& doc) const
{
e.setAttribute("type", typeToString(type));
QDomElement e = doc.createElement("defaultconductor");
if (color != QColor(Qt::black))
e.setAttribute("color", color.name());
e.appendChild(createXmlProperty(doc, "type", typeToString(type)));
e.appendChild(createXmlProperty(doc, "color", color));
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, "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("cable", m_cable);
e.setAttribute("bus", m_bus);
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));
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;
}
/**
/** RETURNS True
@brief ConductorProperties::fromXml
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));
// get conductor color
propertyColor(e, "color", &color);
propertyBool(e, "bicolor", &m_bicolor);
propertyColor(e, "color2", &m_color_2);
propertyInteger(e, "dash-size", &m_dash_size);
QString bicolor_str = e.attribute("bicolor", "false");
m_bicolor = bicolor_str == "true"? true : false;
// read style of conductor
QString style_string;
propertyString(e, "style", &style_string);
readStyle(style_string);
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();
// read style of conductor
readStyle(e.attribute("style"));
if (e.attribute("type") == typeToString(Single))
QString type_t;
if (propertyString(e, "type", &type_t) == PropertyFlags::Success)
{
if (type_t == typeToString(Single))
{
// get specific properties for single conductor
singleLineProperties.fromXml(e);
type = Single;
}
else
type = Multi;
text = e.attribute("num");
// 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_cable = e.attribute("cable");
m_bus = e.attribute("bus");
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();
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()));
//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
singleLineProperties.fromXml(e);
type = Single;
}
else if (type_t == typeToString(Multi))
type = Multi;
else {
//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 TODO_LIST
#pragma message("@TODO remove this code for qet 0.6 or later")
#endif
if (e.attribute("type") == "simple") m_show_text = false;
if (type_t == "simple") m_show_text = false;
}
}
propertyString(e, "num", &text);
// get text color
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);
propertyDouble(e, "condsize", &cond_size);
propertyBool(e, "displaytext", &m_show_text);
propertyBool(e, "onetextperfolio", &m_one_text_per_folio);
propertyDouble(e, "vertirotatetext", &verti_rotate_text);
propertyDouble(e, "horizrotatetext", &horiz_rotate_text);
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
QString alinment_temp;
if (propertyString(e, "horizontal-alignment", &alinment_temp) == PropertyFlags::Success)
m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data()));
if (propertyString(e, "vertical-alignment", &alinment_temp) == PropertyFlags::Success)
m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data()));
return true;
}
/**
@brief ConductorProperties::valideXml
@param e
@return
*/
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;
}
/**
@@ -393,8 +445,8 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix)
settings.setValue(prefix + "text", text);
settings.setValue(prefix + "text_color", text_color.name());
settings.setValue(prefix + "formula", m_formula);
settings.setValue(prefix + "cable", m_cable);
settings.setValue(prefix + "bus", m_bus);
//settings.setValue(prefix + "cable", m_cable);
//settings.setValue(prefix + "bus", m_bus);
settings.setValue(prefix + "function", m_function);
settings.setValue(prefix + "tension_protocol", m_tension_protocol);
settings.setValue(prefix + "conductor_color", m_wire_color);
@@ -417,7 +469,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));
@@ -437,8 +489,8 @@ void ConductorProperties::fromSettings(QSettings &settings, const QString &prefi
QColor settings_text_color = QColor(settings.value(prefix + "text_color").toString());
text_color = (settings_text_color.isValid()? settings_text_color : QColor(Qt::black));
m_formula = settings.value(prefix + "formula", "").toString();
m_cable = settings.value(prefix + "cable", "").toString();
m_bus = settings.value(prefix + "bus", "").toString();
//m_cable = settings.value(prefix + "cable", "").toString();
//m_bus = settings.value(prefix + "bus", "").toString();
m_function = settings.value(prefix + "function", "").toString();
m_tension_protocol = settings.value(prefix + "tension_protocol", "").toString();
m_wire_color = settings.value(prefix + "conductor_color", "").toString();
@@ -448,7 +500,7 @@ void ConductorProperties::fromSettings(QSettings &settings, const QString &prefi
m_show_text = settings.value(prefix + "displaytext", true).toBool();
m_one_text_per_folio = settings.value(prefix + "onetextperfolio", false).toBool();
verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble();
horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble();
horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble();
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
m_horizontal_alignment = Qt::Alignment(me.keyToValue(settings.value(prefix + "horizontal-alignment", "AlignBottom").toString().toStdString().data()));
@@ -493,8 +545,8 @@ void ConductorProperties::applyForEqualAttributes(QList<ConductorProperties> lis
text = cp.text;
text_color = cp.text_color;
m_formula = cp.m_formula;
m_cable = cp.m_cable;
m_bus = cp.m_bus;
//m_cable = cp.m_cable;
//m_bus = cp.m_bus;
m_function = cp.m_function;
m_tension_protocol = cp.m_tension_protocol;
m_wire_color = cp.m_wire_color;
@@ -596,27 +648,27 @@ void ConductorProperties::applyForEqualAttributes(QList<ConductorProperties> lis
m_formula = s_value;
equal = true;
//cable
s_value = clist.first().m_cable;
for(ConductorProperties cp : clist)
{
if (cp.m_cable != s_value)
equal = false;
}
if (equal)
m_cable = s_value;
equal = true;
// //cable
// s_value = clist.first().m_cable;
// for(ConductorProperties cp : clist)
// {
// if (cp.m_cable != s_value)
// equal = false;
// }
// if (equal)
// m_cable = s_value;
// equal = true;
//bus
s_value = clist.first().m_bus;
for(ConductorProperties cp : clist)
{
if (cp.m_bus != s_value)
equal = false;
}
if (equal)
m_bus = s_value;
equal = true;
// //bus
// s_value = clist.first().m_bus;
// for(ConductorProperties cp : clist)
// {
// if (cp.m_bus != s_value)
// equal = false;
// }
// if (equal)
// m_bus = s_value;
// equal = true;
//function
s_value = clist.first().m_function;
@@ -783,8 +835,9 @@ bool ConductorProperties::operator==(const ConductorProperties &other) const
other.text == text &&\
other.text_color == text_color &&\
other.m_formula == m_formula &&\
other.m_cable == m_cable &&\
/* other.m_cable == m_cable &&\
other.m_bus == m_bus &&\
*/
other.m_function == m_function &&\
other.m_tension_protocol == m_tension_protocol &&\
other.m_wire_color == m_wire_color && \
@@ -842,7 +895,7 @@ void ConductorProperties::readStyle(const QString &style_string) {
if (!match.hasMatch())
{
qDebug()<<"no Match"
<<style_str;
<<style_str;
} else {
QString style_name = match.captured("name");
QString style_value = match.captured("value");
@@ -902,7 +955,7 @@ int SingleLineProperties::operator!=(const SingleLineProperties &other) const
@param prefix prefix a ajouter devant les noms des parametres
*/
void SingleLineProperties::toSettings(QSettings &settings,
const QString &prefix) const
const QString &prefix) const
{
settings.setValue(prefix + "hasGround", hasGround);
settings.setValue(prefix + "hasNeutral", hasNeutral);
@@ -914,8 +967,9 @@ void SingleLineProperties::toSettings(QSettings &settings,
@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();