diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 44adc4302..4ec049821 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -38,17 +38,23 @@ class ElementXmlRetroCompatibility { friend class Element; - static void loadSequential(const QDomElement &dom_element, const QString& seq, QStringList* list) + static void loadSequential(const QDomElement &dom_element, + const QString& seq, + QStringList* list) { int i = 0; - while (!dom_element.attribute(seq + QString::number(i+1)).isEmpty()) + while (!dom_element.attribute(seq + + QString::number(i+1)).isEmpty()) { - list->append(dom_element.attribute(seq + QString::number(i+1))); + list->append(dom_element.attribute( + seq + + QString::number(i+1))); i++; } } - static void loadSequential(const QDomElement &dom_element, Element *element) + static void loadSequential(const QDomElement &dom_element, + Element *element) { autonum::sequentialNumbers sn; @@ -69,7 +75,10 @@ class ElementXmlRetroCompatibility * @param parent, parent graphics item * @param state, state of the instanciation */ -Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *state, kind link_type) : +Element::Element(const ElementsLocation &location, + QGraphicsItem *parent, + int *state, + kind link_type) : QetGraphicsItem(parent), m_link_type (link_type), m_location (location) @@ -97,7 +106,8 @@ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *s setPrefix(autonum::elementPrefixForLocation(location)); m_uuid = QUuid::createUuid(); setZValue(10); - setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + setFlags(QGraphicsItem::ItemIsMovable + | QGraphicsItem::ItemIsSelectable); setAcceptHoverEvents(true); connect(this, &Element::rotationChanged, [this]() { @@ -149,7 +159,10 @@ void Element::editProperty() { ElementPropertiesWidget *epw = new ElementPropertiesWidget(this); PropertiesEditorDialog dialog(epw, QApplication::activeWindow()); - connect(epw, &ElementPropertiesWidget::findEditClicked, &dialog, &QDialog::reject); + connect(epw, + &ElementPropertiesWidget::findEditClicked, + &dialog, + &QDialog::reject); //Must be windowModal, else when user do a drag and drop //with the "text" tab of ElementPropertiesWidget, the ui freeze, until user press escape key dialog.setWindowModality(Qt::WindowModal); @@ -182,7 +195,9 @@ void Element::displayHelpLine(bool b) * @param options * @param widget */ -void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *) +void Element::paint(QPainter *painter, + const QStyleOptionGraphicsItem *options, + QWidget *) { if (m_must_highlight) { drawHighlight(painter, options); @@ -204,7 +219,8 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, @return Le rectangle delimitant le contour de l'element */ QRectF Element::boundingRect() const { - return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()), dimensions)); + return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()), + dimensions)); } /** @@ -271,7 +287,8 @@ QPixmap Element::pixmap() { @param painter Le QPainter a utiliser pour dessiner les axes @param options Les options de style a prendre en compte */ -void Element::drawAxes(QPainter *painter, const QStyleOptionGraphicsItem *options) { +void Element::drawAxes(QPainter *painter, + const QStyleOptionGraphicsItem *options) { Q_UNUSED(options); painter -> setPen(Qt::blue); painter -> drawLine(0, 0, 10, 0); @@ -290,7 +307,8 @@ void Element::drawAxes(QPainter *painter, const QStyleOptionGraphicsItem *option @param painter Le QPainter a utiliser pour dessiner les bornes. @param options Les options de style a prendre en compte */ -void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *options) { +void Element::drawSelection(QPainter *painter, + const QStyleOptionGraphicsItem *options) { Q_UNUSED(options); painter -> save(); // Annulation des renderhints @@ -304,7 +322,9 @@ void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *o t.setCosmetic(true); painter -> setPen(t); // Le dessin se fait a partir du rectangle delimitant - painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10); + painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), + 10, + 10); painter -> restore(); } @@ -313,11 +333,13 @@ void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *o @param painter Le QPainter a utiliser pour dessiner les bornes. @param options Les options de style a prendre en compte */ -void Element::drawHighlight(QPainter *painter, const QStyleOptionGraphicsItem *options) { +void Element::drawHighlight(QPainter *painter, + const QStyleOptionGraphicsItem *options) { Q_UNUSED(options); painter -> save(); - qreal gradient_radius = qMin(boundingRect().width(), boundingRect().height()) / 2.0; + qreal gradient_radius = qMin(boundingRect().width(), + boundingRect().height()) / 2.0; QRadialGradient gradient( boundingRect().center(), gradient_radius, @@ -330,7 +352,9 @@ void Element::drawHighlight(QPainter *painter, const QStyleOptionGraphicsItem *o painter -> setPen(Qt::NoPen); painter -> setBrush(brush); // Le dessin se fait a partir du rectangle delimitant - painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10); + painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), + 10, + 10); painter -> restore(); } @@ -352,7 +376,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) { m_state = QET::GIBuildingFromXml; - if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element") + if (xml_def_elmt.tagName() != "definition" + || xml_def_elmt.attribute("type") != "element") { if (state) *state = 4; m_state = QET::GIOK; @@ -363,7 +388,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) if (xml_def_elmt.hasAttribute("version")) { bool conv_ok; - qreal element_version = xml_def_elmt.attribute("version").toDouble(&conv_ok); + qreal element_version = xml_def_elmt.attribute( + "version").toDouble(&conv_ok); if (conv_ok && QET::version.toDouble() < element_version) { std::cerr << qPrintable( @@ -402,13 +428,19 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) setToolTip(name()); //load kind informations - m_kind_informations.fromXml(xml_def_elmt.firstChildElement("kindInformations"), "kindInformation"); + m_kind_informations.fromXml( + xml_def_elmt.firstChildElement("kindInformations"), + "kindInformation"); //load element information - m_element_informations.fromXml(xml_def_elmt.firstChildElement("elementInformations"), "elementInformation"); + m_element_informations.fromXml( + xml_def_elmt.firstChildElement("elementInformations"), + "elementInformation"); //scroll of the Children of the Definition: Parts of the Drawing int parsed_elements_count = 0; - for (QDomNode node = xml_def_elmt.firstChild() ; !node.isNull() ; node = node.nextSibling()) + for (QDomNode node = xml_def_elmt.firstChild() ; + !node.isNull() ; + node = node.nextSibling()) { QDomElement elmts = node.toElement(); if (elmts.isNull()) @@ -420,20 +452,26 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) //If not, we set the tagg "label" to the first "input. QList input_field; bool have_label = false; - for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input")) + for (QDomElement input_node = node.firstChildElement("input") ; + !input_node.isNull() ; + input_node = input_node.nextSiblingElement("input")) { if (!input_node.isNull()) { input_field << input_node; - if (input_node.attribute("tagg", "none") == "label") + if (input_node.attribute("tagg", "none") + == "label") have_label = true; } } if(!have_label && !input_field.isEmpty()) - input_field.first().setAttribute("tagg", "label"); + input_field.first().setAttribute("tagg", + "label"); //Parse the definition - for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) + for (QDomNode n = node.firstChild() ; + !n.isNull() ; + n = n.nextSibling()) { QDomElement qde = n.toElement(); if (qde.isNull()) @@ -454,7 +492,9 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) } ElementPictureFactory *epf = ElementPictureFactory::instance(); - epf->getPictures(m_location, const_cast(m_picture), const_cast(m_low_zoom_picture)); + epf->getPictures(m_location, + const_cast(m_picture), + const_cast(m_low_zoom_picture)); if(!m_picture.isNull()) ++ parsed_elements_count; @@ -512,9 +552,11 @@ bool Element::parseInput(const QDomElement &dom_element) DynamicElementTextItem *deti = new DynamicElementTextItem(this); deti->setText(dom_element.attribute("text", "_")); QFont font = deti->font(); - font.setPointSize(dom_element.attribute("size", QString::number(9)).toInt()); + font.setPointSize(dom_element.attribute("size", + QString::number(9)).toInt()); deti->setFont(font); - deti->setRotation(dom_element.attribute("rotation", QString::number(0)).toDouble()); + deti->setRotation(dom_element.attribute("rotation", + QString::number(0)).toDouble()); if(dom_element.attribute("tagg", "none") != "none") { @@ -527,12 +569,17 @@ bool Element::parseInput(const QDomElement &dom_element) //We need to use a QTransform to find the pos of this text from the saved pos of text item QTransform transform; //First make the rotation - transform.rotate(dom_element.attribute("rotation", "0").toDouble()); - QPointF pos = transform.map(QPointF(0, -deti->boundingRect().height()/2)); + transform.rotate(dom_element.attribute("rotation", + "0").toDouble()); + QPointF pos = transform.map( + QPointF(0, + -deti->boundingRect().height()/2)); transform.reset(); //Second translate to the pos - QPointF p(dom_element.attribute("x", QString::number(0)).toDouble(), - dom_element.attribute("y", QString::number(0)).toDouble()); + QPointF p(dom_element.attribute("x", + QString::number(0)).toDouble(), + dom_element.attribute("y", + QString::number(0)).toDouble()); transform.translate(p.x(), p.y()); deti->setPos(transform.map(pos)); m_converted_text_from_xml_description.insert(deti, p); @@ -546,7 +593,8 @@ bool Element::parseInput(const QDomElement &dom_element) * @param dom_element * @return */ -DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element) +DynamicElementTextItem *Element::parseDynamicText( + const QDomElement &dom_element) { DynamicElementTextItem *deti = new DynamicElementTextItem(this); //Because the xml description of a .elmt file is the same as how a dynamic text field is save to xml in a .qet file @@ -580,7 +628,10 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element) m_terminals << new_terminal; //Sort from top to bottom and left to rigth - std::sort(m_terminals.begin(), m_terminals.end(), [](Terminal *a, Terminal *b) + std::sort(m_terminals.begin(), + m_terminals.end(), + [](Terminal *a, + Terminal *b) { if(a->dockConductor().y() == b->dockConductor().y()) return (a->dockConductor().x() < b->dockConductor().x()); @@ -629,7 +680,10 @@ bool Element::valideXml(QDomElement &e) { * @param handle_inputs_rotation : apply the rotation of this element to his child text * @return */ -bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool handle_inputs_rotation) +bool Element::fromXml(QDomElement &e, + QHash &table_id_adr, + bool handle_inputs_rotation) { m_state = QET::GILoadingFromXml; /* @@ -637,7 +691,8 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool ce recensement servira lors de la mise en place des fils */ QList liste_terminals; - foreach(QDomElement qde, QET::findInDomElement(e, "terminals", "terminal")) { + foreach(QDomElement qde, + QET::findInDomElement(e, "terminals", "terminal")) { if (Terminal::valideXml(qde)) liste_terminals << qde; } @@ -648,7 +703,10 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool bool terminal_trouvee = false; foreach(QDomElement qde, liste_terminals) { if (p -> fromXml(qde)) { - priv_id_adr.insert(qde.attribute("id").toInt(), p); + priv_id_adr.insert( + qde.attribute( + "id").toInt(), + p); terminal_trouvee = true; // We used to break here, because we did not expect // several terminals to share the same position. @@ -678,13 +736,17 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool } // copie des associations id / adr foreach(int id_trouve, priv_id_adr.keys()) { - table_id_adr.insert(id_trouve, priv_id_adr.value(id_trouve)); + table_id_adr.insert(id_trouve, + priv_id_adr.value(id_trouve)); } } //load uuid of connected elements - QList uuid_list = QET::findInDomElement(e, "links_uuids", "link_uuid"); - foreach (QDomElement qdo, uuid_list) tmp_uuids_link << qdo.attribute("uuid"); + QList uuid_list = QET::findInDomElement(e, + "links_uuids", + "link_uuid"); + foreach (QDomElement qdo, uuid_list) + tmp_uuids_link << qdo.attribute("uuid"); //uuid of this element m_uuid= QUuid(e.attribute("uuid", QUuid::createUuid().toString())); @@ -696,16 +758,23 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool m_freeze_label = fl == "false"? false : true; //Load Sequential Values - if (e.hasAttribute("sequ_1") || e.hasAttribute("sequf_1") || e.hasAttribute("seqt_1") || e.hasAttribute("seqtf_1") || e.hasAttribute("seqh_1") || e.hasAttribute("sequf_1")) + if (e.hasAttribute("sequ_1") + || e.hasAttribute("sequf_1") + || e.hasAttribute("seqt_1") + || e.hasAttribute("seqtf_1") + || e.hasAttribute("seqh_1") + || e.hasAttribute("sequf_1")) ElementXmlRetroCompatibility::loadSequential(e, this); else m_autoNum_seq.fromXml(e.firstChildElement("sequentialNumbers")); //Position and selection. //We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid - QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); + QGraphicsObject::setPos(e.attribute("x").toDouble(), + e.attribute("y").toDouble()); setZValue(e.attribute("z", QString::number(this->zValue())).toDouble()); - setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + setFlags(QGraphicsItem::ItemIsMovable + | QGraphicsItem::ItemIsSelectable); // orientation bool conv_ok; @@ -726,7 +795,10 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool //************************// //***Dynamic texts item***// //************************// - for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName())) + for (const QDomElement& qde : QET::findInDomElement( + e, + "dynamic_texts", + DynamicElementTextItem::xmlTagName())) { DynamicElementTextItem *deti = new DynamicElementTextItem(this); addDynamicTextItem(deti); @@ -740,7 +812,8 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool QList inputs = QET::findInDomElement(e, "inputs", "input"); //First case, we check for the text item converted to dynamic text item - const QList conv_deti_list = m_converted_text_from_xml_description.keys(); + const QList conv_deti_list = + m_converted_text_from_xml_description.keys(); QList successfully_converted; const QList dom_inputs = inputs; @@ -751,13 +824,18 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool //we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored. //The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element //that mean this is the good text - if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), m_converted_text_from_xml_description.value(deti).x()) && - qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), m_converted_text_from_xml_description.value(deti).y())) + if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), + m_converted_text_from_xml_description.value(deti).x()) && + qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), + m_converted_text_from_xml_description.value(deti).y())) { //Once again this 'if', is only for retrocompatibility with old old old project //when element text with tagg "label" is not null, but the element information "label" is. - if((deti->textFrom() == DynamicElementTextItem::ElementInfo) && (deti->infoName() == "label")) - m_element_informations.addValue("label", dom_input.attribute("text")); + if((deti->textFrom() == DynamicElementTextItem::ElementInfo) + && (deti->infoName() == "label")) + m_element_informations.addValue( + "label", + dom_input.attribute("text")); deti->setText(dom_input.attribute("text")); @@ -782,7 +860,9 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool QTransform transform; //First make the rotation transform.rotate(rotation); - QPointF pos = transform.map(QPointF(0, -deti->boundingRect().height()/2)); + QPointF pos = transform.map( + QPointF(0, + -deti->boundingRect().height()/2)); transform.reset(); //Second translate to the pos transform.translate(xml_pos.x(), xml_pos.y()); @@ -811,15 +891,20 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool delete deti; m_converted_text_from_xml_description.clear(); - for (QDomElement qde : QET::findInDomElement(e, "texts_groups", ElementTextItemGroup::xmlTaggName())) + for (QDomElement qde : QET::findInDomElement( + e, + "texts_groups", + ElementTextItemGroup::xmlTaggName())) { - ElementTextItemGroup *group = addTextGroup("loaded_from_xml_group"); + ElementTextItemGroup *group = + addTextGroup("loaded_from_xml_group"); group->fromXml(qde); } //load informations DiagramContext dc; - dc.fromXml(e.firstChildElement("elementInformations"), "elementInformation"); + dc.fromXml(e.firstChildElement("elementInformations"), + "elementInformation"); /** * Since the commit 4791, the value used as "label" and "formula" is stored in differents keys (instead of the same key, "label" in previous version), * so, if "label" contain "%" (Use variable value), and "formula" does not exist, @@ -827,7 +912,8 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool * @TODO remove this code at version 0.7 or more (probably useless). */ #pragma message("@TODO remove this code for qet 0.7 or later") - if (dc["label"].toString().contains("%") && dc["formula"].toString().isNull()) + if (dc["label"].toString().contains("%") + && dc["formula"].toString().isNull()) { dc.addValue("formula", dc["label"]); } @@ -856,31 +942,40 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool { //#2 the element information must have label not empty and visible //and a least comment or location not empty and visible - QString label = m_element_informations.value("label").toString(); - QString comment = m_element_informations.value("comment").toString(); - QString location = m_element_informations.value("location").toString(); + QString label = m_element_informations.value( + "label").toString(); + QString comment = m_element_informations.value( + "comment").toString(); + QString location = m_element_informations.value( + "location").toString(); bool la = m_element_informations.keyMustShow("label"); bool c = m_element_informations.keyMustShow("comment"); bool lo = m_element_informations.keyMustShow("location"); if((m_link_type != Master) || ((m_link_type == Master) && - (diagram()->project()->defaultXRefProperties(m_kind_informations["type"].toString()).snapTo() == XRefProperties::Label)) + (diagram()->project()->defaultXRefProperties( + m_kind_informations["type"].toString()).snapTo() + == XRefProperties::Label)) ) { if(!label.isEmpty() && la && - ((!comment.isEmpty() && c) || (!location.isEmpty() && lo))) + ((!comment.isEmpty() && c) + || (!location.isEmpty() && lo))) { //#2 in the converted list one text must have text from = element info and info name = label - for(DynamicElementTextItem *deti : successfully_converted) + for(DynamicElementTextItem *deti + : successfully_converted) { - if(deti->textFrom() == DynamicElementTextItem::ElementInfo && deti->infoName() == "label") + if(deti->textFrom()== DynamicElementTextItem::ElementInfo + && deti->infoName() == "label") { qreal rotation = deti->rotation(); //Create the comment item DynamicElementTextItem *comment_text = nullptr; - if (m_link_type !=PreviousReport || m_link_type !=NextReport) + if (m_link_type !=PreviousReport + || m_link_type !=NextReport) { m_state = QET::GIOK; return(true); @@ -921,18 +1016,22 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool } QPointF pos = deti->pos(); - if (m_link_type !=PreviousReport || m_link_type !=NextReport) + if (m_link_type !=PreviousReport + || m_link_type !=NextReport) { m_state = QET::GIOK; return(true); } //Create the group - ElementTextItemGroup *group = addTextGroup(tr("Label + commentaire")); + ElementTextItemGroup *group = + addTextGroup(tr("Label + commentaire")); addTextToGroup(deti, group); if(comment_text) - addTextToGroup(comment_text, group); + addTextToGroup(comment_text, + group); if(location_text) - addTextToGroup(location_text, group); + addTextToGroup(location_text, + group); group->setAlignment(Qt::AlignVCenter); group->setVerticalAdjustment(-4); group->setRotation(rotation); @@ -955,7 +1054,9 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool if(!comment.isEmpty() && c) { comment_text = new DynamicElementTextItem(this); - comment_text->setTextFrom(DynamicElementTextItem::ElementInfo); + comment_text + ->setTextFrom( + DynamicElementTextItem::ElementInfo); comment_text->setInfoName("comment"); QFont font = comment_text->font(); font.setPointSize(6); @@ -969,19 +1070,24 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool if(!location.isEmpty() && lo) { location_text = new DynamicElementTextItem(this); - location_text->setTextFrom(DynamicElementTextItem::ElementInfo); + location_text + ->setTextFrom( + DynamicElementTextItem::ElementInfo); location_text->setInfoName("location"); QFont font = location_text->font(); font.setPointSize(6); location_text->setFont(font); location_text->setTextWidth(80); if(comment_text) - location_text->setPos(comment_text->x(), comment_text->y()+10); //+10 is arbitrary, location_text must be below the comment + location_text->setPos( + comment_text->x(), + comment_text->y()+10); //+10 is arbitrary, location_text must be below the comment addDynamicTextItem(location_text); } //Create the group - ElementTextItemGroup *group = addTextGroup(tr("Label + commentaire")); + ElementTextItemGroup *group = + addTextGroup(tr("Label + commentaire")); if(comment_text) addTextToGroup(comment_text, group); if(location_text) @@ -992,7 +1098,7 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool } } } - m_state = QET::GIOK; + m_state = QET::GIOK; return(true); } @@ -1012,7 +1118,9 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool \~ @return The XML element representing this electrical element \~French L'element XML representant cet element electrique */ -QDomElement Element::toXml(QDomDocument &document, QHash &table_adr_id) const +QDomElement Element::toXml(QDomDocument &document, + QHash &table_adr_id) const { QDomElement element = document.createElement("element"); @@ -1059,7 +1167,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table foreach(Terminal *t, terminals()) { // alors on enregistre la borne QDomElement terminal = t -> toXml(document); - terminal.setAttribute("id", id_terminal); // for backward compatibility + terminal.setAttribute("id", id_terminal); // for backward compatibility table_adr_id.insert(t, id_terminal ++); xml_terminals.appendChild(terminal); } @@ -1074,7 +1182,8 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table if (! isFree()) { QDomElement links_uuids = document.createElement("links_uuids"); foreach (Element *elmt, connected_elements) { - QDomElement link_uuid = document.createElement("link_uuid"); + QDomElement link_uuid = + document.createElement("link_uuid"); link_uuid.setAttribute("uuid", elmt->uuid().toString()); links_uuids.appendChild(link_uuid); } @@ -1083,14 +1192,15 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table //save information of this element if (! m_element_informations.keys().isEmpty()) { - QDomElement infos = document.createElement("elementInformations"); + QDomElement infos = + document.createElement("elementInformations"); m_element_informations.toXml(infos, "elementInformation"); element.appendChild(infos); } - + //Dynamic texts - QDomElement dyn_text = document.createElement("dynamic_texts"); - for (DynamicElementTextItem *deti : m_dynamic_text_list) + QDomElement dyn_text = document.createElement("dynamic_texts"); + for (DynamicElementTextItem *deti : m_dynamic_text_list) dyn_text.appendChild(deti->toXml(document)); QDomElement texts_group = document.createElement("texts_groups"); @@ -1131,7 +1241,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table //Append the texts group to element element.appendChild(texts_group); - return(element); + return(element); } /** @@ -1142,18 +1252,18 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table */ void Element::addDynamicTextItem(DynamicElementTextItem *deti) { - if (deti && !m_dynamic_text_list.contains(deti)) + if (deti && !m_dynamic_text_list.contains(deti)) { - m_dynamic_text_list.append(deti); + m_dynamic_text_list.append(deti); deti->setParentItem(this); emit textAdded(deti); } - else - { - DynamicElementTextItem *text = new DynamicElementTextItem(this); - m_dynamic_text_list.append(text); + else + { + DynamicElementTextItem *text = new DynamicElementTextItem(this); + m_dynamic_text_list.append(text); emit textAdded(text); - } + } } /** @@ -1164,9 +1274,9 @@ void Element::addDynamicTextItem(DynamicElementTextItem *deti) */ void Element::removeDynamicTextItem(DynamicElementTextItem *deti) { - if (m_dynamic_text_list.contains(deti)) + if (m_dynamic_text_list.contains(deti)) { - m_dynamic_text_list.removeOne(deti); + m_dynamic_text_list.removeOne(deti); deti->setParentItem(nullptr); emit textRemoved(deti); return; @@ -1207,7 +1317,8 @@ ElementTextItemGroup *Element::addTextGroup(const QString &name) { if(m_texts_group.isEmpty()) { - ElementTextItemGroup *group = new ElementTextItemGroup(name, this); + ElementTextItemGroup *group = new ElementTextItemGroup(name, + this); m_texts_group << group; emit textsGroupAdded(group); return group; @@ -1262,7 +1373,8 @@ void Element::removeTextGroup(ElementTextItemGroup *group) { if(qgi->type() == DynamicElementTextItem::Type) { - DynamicElementTextItem *deti = static_cast(qgi); + DynamicElementTextItem *deti = + static_cast(qgi); removeTextFromGroup(deti, group); } } @@ -1304,7 +1416,8 @@ QList Element::textGroups() const * The text must be a text of this element. * @return : true if the text was succesfully added to the group. */ -bool Element::addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group) +bool Element::addTextToGroup(DynamicElementTextItem *text, + ElementTextItemGroup *group) { if(!m_dynamic_text_list.contains(text)) return false; @@ -1325,7 +1438,8 @@ bool Element::addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup * Remove the text @text from the group @group, en reparent @text to this element * @return true if text was succesfully removed */ -bool Element::removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group) +bool Element::removeTextFromGroup(DynamicElementTextItem *text, + ElementTextItemGroup *group) { if(!m_texts_group.contains(group)) return false; @@ -1357,7 +1471,8 @@ QList > Element::AlignedFreeTerminals() const { if (terminal->conductors().isEmpty()) { - Terminal *other_terminal = terminal -> alignedWithTerminal(); + Terminal *other_terminal = + terminal -> alignedWithTerminal(); if (other_terminal) list << qMakePair(terminal, other_terminal); } @@ -1436,10 +1551,16 @@ void Element::setElementInformations(DiagramContext dc) bool comparPos(const Element *elmt1, const Element *elmt2) { //Compare folio first if (elmt1->diagram()->folioIndex() != elmt2->diagram()->folioIndex()) - return elmt1->diagram()->folioIndex() < elmt2->diagram()->folioIndex(); + return elmt1->diagram()->folioIndex() + < + elmt2->diagram()->folioIndex(); //Compare the row(in letter pos) in second - QString a = elmt1->diagram()->convertPosition(elmt1->scenePos()).letter(); - QString b = elmt2->diagram()->convertPosition(elmt2->scenePos()).letter(); + QString a = elmt1 + ->diagram() + ->convertPosition(elmt1->scenePos()).letter(); + QString b = elmt2 + ->diagram() + ->convertPosition(elmt2->scenePos()).letter(); if (a != b) return aproject()->elementAutoNumCurrentFormula(); + QString formula = diagram() + ->project() + ->elementAutoNumCurrentFormula(); m_element_informations.addValue("formula", formula); - QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum(); - NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum); + QString element_currentAutoNum = diagram() + ->project() + ->elementCurrentAutoNum(); + NumerotationContext nc = diagram() + ->project() + ->elementAutoNum(element_currentAutoNum); NumerotationContextCommands ncc (nc); m_autoNum_seq.clear(); - autonum::setSequential(formula, m_autoNum_seq, nc, diagram(), element_currentAutoNum); - diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next()); + autonum::setSequential(formula, + m_autoNum_seq, + nc, + diagram(), + element_currentAutoNum); + diagram()->project()->addElementAutoNum(element_currentAutoNum, + ncc.next()); if(!m_freeze_label && !formula.isEmpty()) { @@ -1573,10 +1705,11 @@ void Element::freezeLabel(bool freeze) * Freeze this label if needed */ void Element::freezeNewAddedElement() { - if (this->diagram()->freezeNewElements() || this->diagram()->project()->isFreezeNewElements()) { + if (this->diagram()->freezeNewElements() + || this->diagram()->project()->isFreezeNewElements()) { freezeLabel(true); } - else return; + else return; } /** @@ -1587,11 +1720,16 @@ void Element::freezeNewAddedElement() { */ QString Element::actualLabel() { - if (m_element_informations.value("formula").toString().isEmpty()) { - return m_element_informations.value("label").toString(); - } else { - return autonum::AssignVariables::formulaToLabel(m_element_informations.value("formula").toString(), m_autoNum_seq, diagram(), this); - } + if (m_element_informations.value("formula").toString().isEmpty()) { + return m_element_informations.value("label").toString(); + } else { + return autonum::AssignVariables::formulaToLabel( + m_element_informations.value( + "formula").toString(), + m_autoNum_seq, + diagram(), + this); + } } /** diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 6c7f4c95f..ee4c68bfa 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -48,14 +48,17 @@ class Element : public QetGraphicsItem * Used to know the kind of this element (master, slave, report ect...) */ enum kind {Simple = 1, - NextReport = 2, - PreviousReport = 4, - AllReport = 6, - Master = 8, - Slave = 16, - Terminale = 32}; + NextReport = 2, + PreviousReport = 4, + AllReport = 6, + Master = 8, + Slave = 16, + Terminale = 32}; - Element(const ElementsLocation &location, QGraphicsItem * = nullptr, int *state = nullptr, Element::kind link_type = Element::Simple); + Element(const ElementsLocation &location, + QGraphicsItem * = nullptr, + int *state = nullptr, + Element::kind link_type = Element::Simple); ~Element() override; private: Element(const Element &); @@ -71,36 +74,43 @@ class Element : public QetGraphicsItem signals: void linkedElementChanged(); //This signal is emited when the linked elements with this element change - void elementInfoChange(DiagramContext old_info, DiagramContext new_info); + void elementInfoChange(DiagramContext old_info, + DiagramContext new_info); void textAdded(DynamicElementTextItem *deti); void textRemoved(DynamicElementTextItem *deti); void textsGroupAdded(ElementTextItemGroup *group); void textsGroupAboutToBeRemoved(ElementTextItemGroup *group); - void textAddedToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group); - void textRemovedFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group); + void textAddedToGroup(DynamicElementTextItem *text, + ElementTextItemGroup *group); + void textRemovedFromGroup(DynamicElementTextItem *text, + ElementTextItemGroup *group); public: QList terminals() const; QList conductors() const; - QList > AlignedFreeTerminals () const; + QList> AlignedFreeTerminals() const; //METHODS related to information - DiagramContext elementInformations ()const {return m_element_informations;} - virtual void setElementInformations (DiagramContext dc); - DiagramContext kindInformations () const {return m_kind_informations;} //@kind_information_ is used to store more information + DiagramContext elementInformations()const + {return m_element_informations;} + virtual void setElementInformations(DiagramContext dc); + DiagramContext kindInformations() const + {return m_kind_informations;} //@kind_information_ is used to store more information //about the herited class like contactelement for know // kind of contact (simple tempo) or number of contact show by the element. - autonum::sequentialNumbers sequenceStruct () const {return m_autoNum_seq;} - autonum::sequentialNumbers& rSequenceStruct() {return m_autoNum_seq;} + autonum::sequentialNumbers sequenceStruct() const + {return m_autoNum_seq;} + autonum::sequentialNumbers& rSequenceStruct() + {return m_autoNum_seq;} void setUpFormula(bool code_letter = true); void setPrefix(QString); QString getPrefix() const; void freezeLabel(bool freeze); bool isFreezeLabel() const {return m_freeze_label;} void freezeNewAddedElement(); - QString actualLabel(); + QString actualLabel(); QString name() const override; ElementsLocation location() const; @@ -108,36 +118,43 @@ class Element : public QetGraphicsItem void displayHelpLine(bool b = true); QSize size() const; QPixmap pixmap(); - QPoint setHotspot(QPoint); - QPoint hotspot() const; - void editProperty() override; - static bool valideXml(QDomElement &); - virtual bool fromXml(QDomElement &, QHash &, bool = false); - virtual QDomElement toXml(QDomDocument &, QHash &) const; - QUuid uuid() const; - int orientation() const; + QPoint setHotspot(QPoint); + QPoint hotspot() const; + void editProperty() override; + static bool valideXml(QDomElement &); + virtual bool fromXml(QDomElement &, + QHash &, + bool = false); + virtual QDomElement toXml(QDomDocument &, + QHash &) const; + QUuid uuid() const; + int orientation() const; //METHODS related to texts - void addDynamicTextItem(DynamicElementTextItem *deti = nullptr); - void removeDynamicTextItem(DynamicElementTextItem *deti); - QList dynamicTextItems() const; + void addDynamicTextItem(DynamicElementTextItem *deti = nullptr); + void removeDynamicTextItem(DynamicElementTextItem *deti); + QList dynamicTextItems() const; ElementTextItemGroup *addTextGroup(const QString &name); void addTextGroup(ElementTextItemGroup *group); void removeTextGroup(ElementTextItemGroup *group); ElementTextItemGroup *textGroup(const QString &name) const; QList textGroups() const; - bool addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group); - bool removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group); + bool addTextToGroup(DynamicElementTextItem *text, + ElementTextItemGroup *group); + bool removeTextFromGroup(DynamicElementTextItem *text, + ElementTextItemGroup *group); //METHODS related to linked element - bool isFree () const; - virtual void linkToElement (Element *) {} - virtual void unlinkAllElements () {} - virtual void unlinkElement (Element *) {} - virtual void initLink (QETProject *); + bool isFree() const; + virtual void linkToElement(Element *) {} + virtual void unlinkAllElements() {} + virtual void unlinkElement(Element *) {} + virtual void initLink(QETProject *); QList linkedElements (); virtual kind linkType() const {return m_link_type;} // @return the linkable type - QString linkTypeToString() const; + QString linkTypeToString() const; void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element protected: @@ -145,29 +162,36 @@ class Element : public QetGraphicsItem void setSize(int, int); private: - void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); - void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); + void drawSelection(QPainter *, + const QStyleOptionGraphicsItem *); + void drawHighlight(QPainter *, + const QStyleOptionGraphicsItem *); bool buildFromXml(const QDomElement &, int * = nullptr); bool parseElement(const QDomElement &dom); bool parseInput(const QDomElement &dom_element); - DynamicElementTextItem *parseDynamicText(const QDomElement &dom_element); + DynamicElementTextItem *parseDynamicText( + const QDomElement &dom_element); Terminal *parseTerminal(const QDomElement &dom_element); //Reimplemented from QGraphicsItem public: - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; + void paint(QPainter *, + const QStyleOptionGraphicsItem *, + QWidget *) override; QRectF boundingRect() const override; protected: - void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ) override; - void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event ) override; - void hoverEnterEvent ( QGraphicsSceneHoverEvent * ) override; - void hoverLeaveEvent ( QGraphicsSceneHoverEvent * ) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent( + QGraphicsSceneMouseEvent *event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent *) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override; protected: // @m_converted_text_from_description, when a element is created from his description, the old element text item (tagged as 'input' in the xml) // are converted to dynamic text field, the QPointF is the original position of the text item, because the origin transformation point of text item // and dynamic text item are not the same, so we must to keep a track of this value, to be use in the function element::fromXml - QHash m_converted_text_from_xml_description; + QHash + m_converted_text_from_xml_description; //ATTRIBUTES related to linked element QList connected_elements; @@ -193,7 +217,7 @@ class Element : public QetGraphicsItem QPoint hotspot_coord; bool m_mouse_over = false; QString m_prefix; - QList m_dynamic_text_list; + QList m_dynamic_text_list; QList m_texts_group; }; @@ -229,7 +253,9 @@ inline QUuid Element::uuid() const { * @return the list of linked elements, the list is sorted by position */ inline QList Element::linkedElements() { - std::sort(connected_elements.begin(), connected_elements.end(), comparPos); + std::sort(connected_elements.begin(), + connected_elements.end(), + comparPos); return connected_elements; }