QElectroTech  0.70
element.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "element.h"
19 #include "diagram.h"
20 #include "conductor.h"
21 #include "diagramcommands.h"
22 #include <utility>
23 #include "elementprovider.h"
24 #include "diagramposition.h"
25 #include "terminal.h"
29 #include "diagramcontext.h"
31 #include "dynamicelementtextitem.h"
32 #include "elementtextitemgroup.h"
33 #include "elementpicturefactory.h"
34 #include "iostream"
35 
37 {
38  friend class Element;
39 
40  static void loadSequential(const QDomElement &dom_element, const QString& seq, QStringList* list)
41  {
42  int i = 0;
43  while (!dom_element.attribute(seq + QString::number(i+1)).isEmpty())
44  {
45  list->append(dom_element.attribute(seq + QString::number(i+1)));
46  i++;
47  }
48  }
49 
50  static void loadSequential(const QDomElement &dom_element, Element *element)
51  {
53 
54  loadSequential(dom_element,"sequ_",&sn.unit);
55  loadSequential(dom_element,"sequf_",&sn.unit_folio);
56  loadSequential(dom_element,"seqt_",&sn.ten);
57  loadSequential(dom_element,"seqtf_",&sn.ten_folio);
58  loadSequential(dom_element,"seqh_",&sn.hundred);
59  loadSequential(dom_element,"seqhf_",&sn.hundred_folio);
60 
61  element->rSequenceStruct() = sn;
62  }
63 };
64 
71 Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *state, kind link_type) :
72  QetGraphicsItem(parent),
73  m_link_type (link_type),
75 {
76  if(! (location.isElement() && location.exist()))
77  {
78  if (state)
79  {
80  *state = 1;
81  return;
82  }
83  }
84  int elmt_state;
85  buildFromXml(location.xml(), &elmt_state);
86  if (state) {
87  *state = elmt_state;
88  }
89  if (elmt_state) {
90  return;
91  }
92  if (state) {
93  *state = 0;
94  }
95 
97  m_uuid = QUuid::createUuid();
98  setZValue(10);
99  setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
100  setAcceptHoverEvents(true);
101 
102  connect(this, &Element::rotationChanged, [this]() {
103  for(QGraphicsItem *qgi : childItems())
104  {
105  if (Terminal *t = qgraphicsitem_cast<Terminal *>(qgi))
106  t->updateConductor();
107  }
108  });
109 }
110 
115 {
116  qDeleteAll (m_dynamic_text_list);
117  qDeleteAll (m_terminals);
118 }
119 
124 QList<Terminal *> Element::terminals() const {
125  return m_terminals;
126 }
127 
134 QList<Conductor *> Element::conductors() const
135 {
136  QList<Conductor *> conductors;
137 
138  for (Terminal *t : m_terminals) {
139  conductors << t -> conductors();
140  }
141 
142  return(conductors);
143 }
144 
146 {
147  if (diagram() && !diagram()->isReadOnly())
148  {
150  PropertiesEditorDialog dialog(epw, QApplication::activeWindow());
151  connect(epw, &ElementPropertiesWidget::findEditClicked, &dialog, &QDialog::reject);
152  //Must be windowModal, else when user do a drag and drop
153  //with the "text" tab of ElementPropertiesWidget, the ui freeze, until user press escape key
154  dialog.setWindowModality(Qt::WindowModal);
155  dialog.exec();
156  }
157 }
158 
162 void Element::setHighlighted(bool hl) {
163  m_must_highlight = hl;
164  update();
165 }
166 
173 {
174  foreach (Terminal *t, terminals())
175  t->drawHelpLine(b);
176 }
177 
184 void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *)
185 {
186  if (m_must_highlight) {
187  drawHighlight(painter, options);
188  }
189 
190  if (options && options -> levelOfDetail < 1.0) {
191  painter->drawPicture(0, 0, m_low_zoom_picture);
192  } else {
193  painter->drawPicture(0, 0, m_picture);
194  }
195 
196  //Draw the selection rectangle
197  if ( isSelected() || m_mouse_over ) {
198  drawSelection(painter, options);
199  }
200 }
201 
205 QRectF Element::boundingRect() const {
206  return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()), dimensions));
207 }
208 
217 void Element::setSize(int wid, int hei)
218 {
219  prepareGeometryChange();
220 
221  while (wid % 10) ++ wid;
222  while (hei % 10) ++ hei;
223  dimensions = QSize(wid, hei);
224 }
225 
229 QSize Element::size() const {
230  return(dimensions);
231 }
232 
238 QPoint Element::setHotspot(QPoint hs) {
239  // la taille doit avoir ete definie
240  prepareGeometryChange();
241  if (dimensions.isNull()) hotspot_coord = QPoint(0, 0);
242  else {
243  // les coordonnees indiquees ne doivent pas depasser les dimensions de l'element
244  int hsx = qMin(hs.x(), dimensions.width());
245  int hsy = qMin(hs.y(), dimensions.height());
246  hotspot_coord = QPoint(hsx, hsy);
247  }
248  return(hotspot_coord);
249 }
250 
254 QPoint Element::hotspot() const {
255  return(hotspot_coord);
256 }
257 
262 QPixmap Element::pixmap() {
264 }
265 
266 /*** Methodes protegees ***/
267 
273 void Element::drawAxes(QPainter *painter, const QStyleOptionGraphicsItem *options) {
274  Q_UNUSED(options);
275  painter -> setPen(Qt::blue);
276  painter -> drawLine(0, 0, 10, 0);
277  painter -> drawLine(7,-3, 10, 0);
278  painter -> drawLine(7, 3, 10, 0);
279  painter -> setPen(Qt::red);
280  painter -> drawLine(0, 0, 0, 10);
281  painter -> drawLine(0, 10,-3, 7);
282  painter -> drawLine(0, 10, 3, 7);
283 }
284 
285 /*** Methodes privees ***/
286 
292 void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *options) {
293  Q_UNUSED(options);
294  painter -> save();
295  // Annulation des renderhints
296  painter -> setRenderHint(QPainter::Antialiasing, false);
297  painter -> setRenderHint(QPainter::TextAntialiasing, false);
298  painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
299  // Dessin du cadre de selection en gris
300  QPen t;
301  t.setColor(Qt::gray);
302  t.setStyle(Qt::DashDotLine);
303  t.setCosmetic(true);
304  painter -> setPen(t);
305  // Le dessin se fait a partir du rectangle delimitant
306  painter -> drawRoundRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
307  painter -> restore();
308 }
309 
315 void Element::drawHighlight(QPainter *painter, const QStyleOptionGraphicsItem *options) {
316  Q_UNUSED(options);
317  painter -> save();
318 
319  qreal gradient_radius = qMin(boundingRect().width(), boundingRect().height()) / 2.0;
320  QRadialGradient gradient(
321  boundingRect().center(),
322  gradient_radius,
323  boundingRect().center()
324  );
325  gradient.setColorAt(0.0, QColor::fromRgb(69, 137, 255, 255));
326  gradient.setColorAt(1.0, QColor::fromRgb(69, 137, 255, 0));
327  QBrush brush(gradient);
328 
329  painter -> setPen(Qt::NoPen);
330  painter -> setBrush(brush);
331  // Le dessin se fait a partir du rectangle delimitant
332  painter -> drawRoundRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
333  painter -> restore();
334 }
335 
350 bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
351 {
353 
354  if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element")
355  {
356  if (state) *state = 4;
357  m_state = QET::GIOK;
358  return(false);
359  }
360 
361  //Check if the curent version can read the xml description
362  if (xml_def_elmt.hasAttribute("version"))
363  {
364  bool conv_ok;
365  qreal element_version = xml_def_elmt.attribute("version").toDouble(&conv_ok);
366  if (conv_ok && QET::version.toDouble() < element_version)
367  {
368  std::cerr << qPrintable(
369  QObject::tr("Avertissement : l'élément "
370  " a été enregistré avec une version"
371  " ultérieure de QElectroTech.")
372  ) << std::endl;
373  }
374  }
375 
376  //This attribute must be present and valid
377  int w, h, hot_x, hot_y;
378  if (
379  !QET::attributeIsAnInteger(xml_def_elmt, QString("width"), &w) ||\
380  !QET::attributeIsAnInteger(xml_def_elmt, QString("height"), &h) ||\
381  !QET::attributeIsAnInteger(xml_def_elmt, QString("hotspot_x"), &hot_x) ||\
382  !QET::attributeIsAnInteger(xml_def_elmt, QString("hotspot_y"), &hot_y)
383  ) {
384  if (state) *state = 5;
385  m_state = QET::GIOK;
386  return(false);
387  }
388 
389  setSize(w, h);
390  setHotspot(QPoint(hot_x, hot_y));
391 
392  //the definition must have childs
393  if (xml_def_elmt.firstChild().isNull())
394  {
395  if (state) *state = 6;
396  m_state = QET::GIOK;
397  return(false);
398  }
399  //Extract the names
400  m_names.fromXml(xml_def_elmt);
401  setToolTip(name());
402 
403  //load kind informations
404  m_kind_informations.fromXml(xml_def_elmt.firstChildElement("kindInformations"), "kindInformation");
405  //load element information
406  m_element_informations.fromXml(xml_def_elmt.firstChildElement("elementInformations"), "elementInformation");
407 
408  //scroll of the Children of the Definition: Parts of the Drawing
409  int parsed_elements_count = 0;
410  for (QDomNode node = xml_def_elmt.firstChild() ; !node.isNull() ; node = node.nextSibling())
411  {
412  QDomElement elmts = node.toElement();
413  if (elmts.isNull())
414  continue;
415 
416  if (elmts.tagName() == "description")
417  {
418  //Minor workaround to find if there is a "input" tagg as label.
419  //If not, we set the tagg "label" to the first "input.
420  QList <QDomElement> input_field;
421  bool have_label = false;
422  for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input"))
423  {
424  if (!input_node.isNull())
425  {
426  input_field << input_node;
427  if (input_node.attribute("tagg", "none") == "label")
428  have_label = true;
429  }
430  }
431  if(!have_label && !input_field.isEmpty())
432  input_field.first().setAttribute("tagg", "label");
433 
434  //Parse the definition
435  for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling())
436  {
437  QDomElement qde = n.toElement();
438  if (qde.isNull())
439  continue;
440 
441  if (parseElement(qde)) {
442  ++ parsed_elements_count;
443  }
444  else
445  {
446  if (state)
447  *state = 7;
448  m_state = QET::GIOK;
449  return(false);
450  }
451  }
452  }
453  }
454 
456  epf->getPictures(m_location, const_cast<QPicture&>(m_picture), const_cast<QPicture&>(m_low_zoom_picture));
457 
458  if(!m_picture.isNull())
459  ++ parsed_elements_count;
460 
461  //They must be at least one parsed graphics part
462  if (!parsed_elements_count)
463  {
464  if (state)
465  *state = 8;
466  m_state = QET::GIOK;
467  return(false);
468  }
469  else
470  {
471  if (state)
472  *state = 0;
473  m_state = QET::GIOK;
474  return(true);
475  }
476 }
477 
484 bool Element::parseElement(const QDomElement &dom)
485 {
486  if (dom.tagName() == "terminal") return(parseTerminal(dom));
487  else if (dom.tagName() == "input") return(parseInput(dom));
488  else if (dom.tagName() == "dynamic_text") return(parseDynamicText(dom));
489  else return(true);
490 }
491 
500 bool Element::parseInput(const QDomElement &dom_element)
501 {
502  qreal pos_x, pos_y;
503  int size;
504  if (
505  !QET::attributeIsAReal(dom_element, "x", &pos_x) ||\
506  !QET::attributeIsAReal(dom_element, "y", &pos_y) ||\
507  !QET::attributeIsAnInteger(dom_element, "size", &size)
508  ) return(false);
509  else
510  {
512  deti->setText(dom_element.attribute("text", "_"));
513  QFont font = deti->font();
514  font.setPointSize(dom_element.attribute("size", QString::number(9)).toInt());
515  deti->setFont(font);
516  deti->setRotation(dom_element.attribute("rotation", QString::number(0)).toDouble());
517 
518  if(dom_element.attribute("tagg", "none") != "none")
519  {
521  deti->setInfoName(dom_element.attribute("tagg"));
522  }
523 
524  //the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
525  //The origin transformation point of ElementTextItem is the middle of left edge, and so by definition, change with the size of the font
526  //We need to use a QTransform to find the pos of this text from the saved pos of text item
527  QTransform transform;
528  //First make the rotation
529  transform.rotate(dom_element.attribute("rotation", "0").toDouble());
530  QPointF pos = transform.map(QPointF(0, -deti->boundingRect().height()/2));
531  transform.reset();
532  //Second translate to the pos
533  QPointF p(dom_element.attribute("x", QString::number(0)).toDouble(),
534  dom_element.attribute("y", QString::number(0)).toDouble());
535  transform.translate(p.x(), p.y());
536  deti->setPos(transform.map(pos));
538  return true;
539  }
540 
541  return false;
542 }
543 
550 DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element)
551 {
553  //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
554  //wa call fromXml, we just change the tagg name (.elmt = dynamic_text, .qet = dynamic_elmt_text)
555  //and the uuid (because the uuid, is the uuid of the descritpion and not the uuid of instantiated dynamic text field)
556 
557  QDomElement dom(dom_element.cloneNode(true).toElement());
558  dom.setTagName(DynamicElementTextItem::xmlTaggName());
559  deti->fromXml(dom);
560  deti->m_uuid = QUuid::createUuid();
561  this->addDynamicTextItem(deti);
562  return deti;
563 }
564 
565 Terminal *Element::parseTerminal(const QDomElement &dom_element)
566 {
567  qreal terminalx, terminaly;
568  Qet::Orientation terminalo;
569  if (!QET::attributeIsAReal(dom_element, QString("x"), &terminalx)) {
570  return(nullptr);
571  }
572  if (!QET::attributeIsAReal(dom_element, QString("y"), &terminaly)) {
573  return(nullptr);
574  }
575  if (!dom_element.hasAttribute("orientation")) {
576  return(nullptr);
577  }
578  if (dom_element.attribute("orientation") == "n") {
579  terminalo = Qet::North;
580  }
581  else if (dom_element.attribute("orientation") == "s") {
582  terminalo = Qet::South;
583  }
584  else if (dom_element.attribute("orientation") == "e") {
585  terminalo = Qet::East;
586  }
587  else if (dom_element.attribute("orientation") == "w") {
588  terminalo = Qet::West;
589  }
590  else {
591  return(nullptr);
592  }
593 
594  Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
595  m_terminals << new_terminal;
596 
597  //Sort from top to bottom and left to rigth
598  std::sort(m_terminals.begin(), m_terminals.end(), [](Terminal *a, Terminal *b)
599  {
600  if(a->dockConductor().y() == b->dockConductor().y())
601  return (a->dockConductor().x() < b->dockConductor().x());
602  else
603  return (a->dockConductor().y() < b->dockConductor().y());
604  });
605 
606  return(new_terminal);
607 }
608 
614 bool Element::valideXml(QDomElement &e) {
615  // verifie le nom du tag
616  if (e.tagName() != "element") return(false);
617 
618  // verifie la presence des attributs minimaux
619  if (!e.hasAttribute("type")) return(false);
620  if (!e.hasAttribute("x")) return(false);
621  if (!e.hasAttribute("y")) return(false);
622 
623  bool conv_ok;
624  // parse l'abscisse
625  e.attribute("x").toDouble(&conv_ok);
626  if (!conv_ok) return(false);
627 
628  // parse l'ordonnee
629  e.attribute("y").toDouble(&conv_ok);
630  if (!conv_ok) return(false);
631  return(true);
632 }
633 
647 bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool handle_inputs_rotation)
648 {
650  /*
651  les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle
652  ce recensement servira lors de la mise en place des fils
653  */
654  QList<QDomElement> liste_terminals;
655  foreach(QDomElement qde, QET::findInDomElement(e, "terminals", "terminal")) {
656  if (Terminal::valideXml(qde)) liste_terminals << qde;
657  }
658 
659  QHash<int, Terminal *> priv_id_adr;
660  int terminals_non_trouvees = 0;
661  foreach(QGraphicsItem *qgi, childItems()) {
662  if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
663  bool terminal_trouvee = false;
664  foreach(QDomElement qde, liste_terminals) {
665  if (p -> fromXml(qde)) {
666  priv_id_adr.insert(qde.attribute("id").toInt(), p);
667  terminal_trouvee = true;
668  // We used to break here, because we did not expect
669  // several terminals to share the same position.
670  // Of course, it finally happened.
671  }
672  }
673  if (!terminal_trouvee) ++ terminals_non_trouvees;
674  }
675  }
676 
677  if (terminals_non_trouvees > 0)
678  {
679  m_state = QET::GIOK;
680  return(false);
681  }
682  else
683  {
684  // verifie que les associations id / adr n'entrent pas en conflit avec table_id_adr
685  foreach(int id_trouve, priv_id_adr.keys())
686  {
687  if (table_id_adr.contains(id_trouve))
688  {
689  // cet element possede un id qui est deja reference (= conflit)
690  m_state = QET::GIOK;
691  return(false);
692  }
693  }
694  // copie des associations id / adr
695  foreach(int id_trouve, priv_id_adr.keys()) {
696  table_id_adr.insert(id_trouve, priv_id_adr.value(id_trouve));
697  }
698  }
699 
700  //load uuid of connected elements
701  QList <QDomElement> uuid_list = QET::findInDomElement(e, "links_uuids", "link_uuid");
702  foreach (QDomElement qdo, uuid_list) tmp_uuids_link << qdo.attribute("uuid");
703 
704  //uuid of this element
705  m_uuid= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
706 
707  //load prefix
708  m_prefix = e.attribute("prefix");
709 
710  QString fl = e.attribute("freezeLabel", "false");
711  m_freeze_label = fl == "false"? false : true;
712 
713  //Load Sequential Values
714  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"))
716  else
717  m_autoNum_seq.fromXml(e.firstChildElement("sequentialNumbers"));
718 
719  //Position and selection.
720  //We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
721  QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
722  setZValue(e.attribute("z", QString::number(this->zValue())).toDouble());
723  setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
724 
725  // orientation
726  bool conv_ok;
727  int read_ori = e.attribute("orientation").toInt(&conv_ok);
728  if (!conv_ok || read_ori < 0 || read_ori > 3) read_ori = 0;
729  if (handle_inputs_rotation) {
730  setRotation(rotation() + (90*read_ori));
731  } else {
732  setRotation(90*read_ori);
733  }
734 
735  //Befor load the dynamic text field,
736  //we remove the dynamic text field created from the description of this element, to avoid doublons.
738  delete deti;
739  m_dynamic_text_list.clear();
740 
741  //************************//
742  //***Dynamic texts item***//
743  //************************//
744  for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTaggName()))
745  {
747  addDynamicTextItem(deti);
748  deti->fromXml(qde);
749  }
750 
751 
752  //************************//
753  //***Element texts item***//
754  //************************//
755  QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
756 
757  //First case, we check for the text item converted to dynamic text item
758  const QList <DynamicElementTextItem *> conv_deti_list = m_converted_text_from_xml_description.keys();
759  QList <DynamicElementTextItem *> successfully_converted;
760  const QList <QDomElement> dom_inputs = inputs;
761 
762  for (DynamicElementTextItem *deti : conv_deti_list)
763  {
764  for(const QDomElement& dom_input : dom_inputs)
765  {
766  //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.
767  //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
768  //that mean this is the good text
769  if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), m_converted_text_from_xml_description.value(deti).x()) &&
770  qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), m_converted_text_from_xml_description.value(deti).y()))
771  {
772  //Once again this 'if', is only for retrocompatibility with old old old project
773  //when element text with tagg "label" is not null, but the element information "label" is.
774  if((deti->textFrom() == DynamicElementTextItem::ElementInfo) && (deti->infoName() == "label"))
775  m_element_informations.addValue("label", dom_input.attribute("text"));
776 
777  deti->setText(dom_input.attribute("text"));
778 
779  qreal rotation = deti->rotation();
780  QPointF xml_pos = m_converted_text_from_xml_description.value(deti);
781 
782  if (dom_input.attribute("userrotation").toDouble())
783  rotation = dom_input.attribute("userrotation").toDouble();
784 
785  if (dom_input.hasAttribute("userx"))
786  xml_pos.setX(dom_input.attribute("userx").toDouble());
787  if(dom_input.hasAttribute("usery"))
788  xml_pos.setY(dom_input.attribute("usery", "0").toDouble());
789 
790  //the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
791  //The origin transformation point of PartTextField is the middle of left edge, and so by definition, change with the size of the font
792  //We need to use a QTransform to find the pos of this text from the saved pos of text item
793 
794  deti->setPos(xml_pos);
795  deti->setRotation(rotation);
796 
797  QTransform transform;
798  //First make the rotation
799  transform.rotate(rotation);
800  QPointF pos = transform.map(QPointF(0, -deti->boundingRect().height()/2));
801  transform.reset();
802  //Second translate to the pos
803  transform.translate(xml_pos.x(), xml_pos.y());
804  deti->setPos(transform.map(pos));
805 
806  //dom_input and deti matched we remove the dom_input from @inputs list,
807  //to avoid unnecessary checking made below
808  //we also move deti from the m_converted_text_from_xml_description to m_dynamic_text_list
809  inputs.removeAll(dom_input);
810  m_dynamic_text_list.append(deti);
812  successfully_converted << deti;
813  }
814  }
815  }
816 
817  //###Firts case : if this is the first time the user open the project since text item are converted to dynamic text,
818  //in the previous opening of the project, every texts field present in the element description was created.
819  //At save time, the values of each of them was save in the 'input' dom element.
820  //The loop upper is made for the first case, to import the values in 'input' to the new converted dynamic texts field.
821  //###Second case : this is not the first time the user open the project since text item are converted to dynamic text.
822  //That mean, in a previous opening of the project, the text item was already converted and save as a dynamic text field.
823  //So there isn't 'input' dom element in the project, and every dynamic text item present in m_converted_text_from_xml_description
824  //need to be deleted (because already exist in m_dynamic_text_list, from a previous save)
826  delete deti;
828 
829  for (QDomElement qde : QET::findInDomElement(e, "texts_groups", ElementTextItemGroup::xmlTaggName()))
830  {
831  ElementTextItemGroup *group = addTextGroup("loaded_from_xml_group");
832  group->fromXml(qde);
833  }
834 
835  //load informations
836  DiagramContext dc;
837  dc.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
844  if (dc["label"].toString().contains("%") && dc["formula"].toString().isNull())
845  {
846  dc.addValue("formula", dc["label"]);
847  }
848  //retrocompatibility with older version
849  if(dc.value("label").toString().isEmpty() &&
850  !m_element_informations.value("label").toString().isEmpty())
851  dc.addValue("label", m_element_informations.value("label"));
852 
853  //We must to block the update of the alignment when load the information
854  //otherwise the pos of the text will not be the same as it was at save time.
856  deti->m_block_alignment = true;
859  deti->m_block_alignment = false;
860 
861 
868  //#1 There must be old text converted to dynamic text
869  if(!successfully_converted.isEmpty())
870  {
871  //#2 the element information must have label not empty and visible
872  //and a least comment or location not empty and visible
873  QString label = m_element_informations.value("label").toString();
874  QString comment = m_element_informations.value("comment").toString();
875  QString location = m_element_informations.value("location").toString();
876  bool la = m_element_informations.keyMustShow("label");
877  bool c = m_element_informations.keyMustShow("comment");
878  bool lo = m_element_informations.keyMustShow("location");
879 
880  if((m_link_type != Master) ||
881  ((m_link_type == Master) &&
882  (diagram()->project()->defaultXRefProperties(m_kind_informations["type"].toString()).snapTo() == XRefProperties::Label))
883  )
884  {
885  if(!label.isEmpty() && la &&
886  ((!comment.isEmpty() && c) || (!location.isEmpty() && lo)))
887  {
888  //#2 in the converted list one text must have text from = element info and info name = label
889  for(DynamicElementTextItem *deti : successfully_converted)
890  {
891  if(deti->textFrom() == DynamicElementTextItem::ElementInfo && deti->infoName() == "label")
892  {
893  qreal rotation = deti->rotation();
894 
895  //Create the comment item
896  DynamicElementTextItem *comment_text = nullptr;
898  {
899  m_state = QET::GIOK;
900  return(true);
901  }
902  if(!comment.isEmpty() && c)
903  {
904  comment_text = new DynamicElementTextItem(this);
906  comment_text->setInfoName("comment");
907  QFont font = comment_text->font();
908  font.setPointSize(6);
909  comment_text->setFont(font);
910  comment_text->setFrame(true);
911  if(comment_text->toPlainText().count() > 17)
912  comment_text->setTextWidth(80);
913  comment_text->setPos(deti->x(), deti->y()+10); //+10 is arbitrary, comment_text must be below deti
914  addDynamicTextItem(comment_text);
915  }
916  //create the location item
917  DynamicElementTextItem *location_text = nullptr;
919  {
920  m_state = QET::GIOK;
921  return(true);
922  }
923  if(!location.isEmpty() && lo)
924  {
925  location_text = new DynamicElementTextItem(this);
927  location_text->setInfoName("location");
928  QFont font = location_text->font();
929  font.setPointSize(6);
930  location_text->setFont(font);
931  if(location_text->toPlainText().count() > 17)
932  location_text->setTextWidth(80);
933  location_text->setPos(deti->x(), deti->y()+20); //+20 is arbitrary, location_text must be below deti and comment
934  addDynamicTextItem(location_text);
935  }
936 
937  QPointF pos = deti->pos();
939  {
940  m_state = QET::GIOK;
941  return(true);
942  }
943  //Create the group
944  ElementTextItemGroup *group = addTextGroup(tr("Label + commentaire"));
945  addTextToGroup(deti, group);
946  if(comment_text)
947  addTextToGroup(comment_text, group);
948  if(location_text)
949  addTextToGroup(location_text, group);
950  group->setAlignment(Qt::AlignVCenter);
951  group->setVerticalAdjustment(-4);
952  group->setRotation(rotation);
953  //Change the position of the group, so that the text "label" stay in the same
954  //position in scene coordinate
955  group->setPos(pos - deti->pos());
956 
957  break;
958  }
959  }
960  }
961  }
962  else
963  {
964  //This element is supposed to be a master and Xref property snap to bottom
965  if((!comment.isEmpty() && c) || (!location.isEmpty() && lo))
966  {
967  //Create the comment item
968  DynamicElementTextItem *comment_text = nullptr;
969  if(!comment.isEmpty() && c)
970  {
971  comment_text = new DynamicElementTextItem(this);
973  comment_text->setInfoName("comment");
974  QFont font = comment_text->font();
975  font.setPointSize(6);
976  comment_text->setFont(font);
977  comment_text->setFrame(true);
978  comment_text->setTextWidth(80);
979  addDynamicTextItem(comment_text);
980  }
981  //create the location item
982  DynamicElementTextItem *location_text = nullptr;
983  if(!location.isEmpty() && lo)
984  {
985  location_text = new DynamicElementTextItem(this);
987  location_text->setInfoName("location");
988  QFont font = location_text->font();
989  font.setPointSize(6);
990  location_text->setFont(font);
991  location_text->setTextWidth(80);
992  if(comment_text)
993  location_text->setPos(comment_text->x(), comment_text->y()+10); //+10 is arbitrary, location_text must be below the comment
994  addDynamicTextItem(location_text);
995  }
996 
997  //Create the group
998  ElementTextItemGroup *group = addTextGroup(tr("Label + commentaire"));
999  if(comment_text)
1000  addTextToGroup(comment_text, group);
1001  if(location_text)
1002  addTextToGroup(location_text, group);
1003  group->setAlignment(Qt::AlignVCenter);
1004  group->setVerticalAdjustment(-4);
1005  group->setHoldToBottomPage(true);
1006  }
1007  }
1008  }
1009  m_state = QET::GIOK;
1010  return(true);
1011 }
1012 
1021 QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table_adr_id) const
1022 {
1023  QDomElement element = document.createElement("element");
1024 
1025  // type
1026  element.setAttribute("type", m_location.path());
1027 
1028  // uuid
1029  element.setAttribute("uuid", uuid().toString());
1030 
1031  // prefix
1032  element.setAttribute("prefix", m_prefix);
1033 
1034  //frozen label
1035  element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
1036 
1037  // sequential num
1038  QDomElement seq = m_autoNum_seq.toXml(document);
1039  if (seq.hasChildNodes())
1040  element.appendChild(seq);
1041 
1042  // position, selection et orientation
1043  element.setAttribute("x", QString::number(pos().x()));
1044  element.setAttribute("y", QString::number(pos().y()));
1045  element.setAttribute("z", QString::number(this->zValue()));
1046  element.setAttribute("orientation", QString::number(orientation()));
1047 
1048  /* recupere le premier id a utiliser pour les bornes de cet element */
1049  int id_terminal = 0;
1050  if (!table_adr_id.isEmpty()) {
1051  // trouve le plus grand id
1052  int max_id_t = -1;
1053  foreach (int id_t, table_adr_id.values()) {
1054  if (id_t > max_id_t) max_id_t = id_t;
1055  }
1056  id_terminal = max_id_t + 1;
1057  }
1058 
1059  // enregistrement des bornes de l'appareil
1060  QDomElement xml_terminals = document.createElement("terminals");
1061  // pour chaque enfant de l'element
1062  foreach(Terminal *t, terminals()) {
1063  // alors on enregistre la borne
1064  QDomElement terminal = t -> toXml(document);
1065  terminal.setAttribute("id", id_terminal);
1066  table_adr_id.insert(t, id_terminal ++);
1067  xml_terminals.appendChild(terminal);
1068  }
1069  element.appendChild(xml_terminals);
1070 
1071  // enregistrement des champ de texte de l'appareil
1072  QDomElement inputs = document.createElement("inputs");
1073  element.appendChild(inputs);
1074 
1075  //if this element is linked to other elements,
1076  //save the uuid of each other elements
1077  if (! isFree()) {
1078  QDomElement links_uuids = document.createElement("links_uuids");
1079  foreach (Element *elmt, connected_elements) {
1080  QDomElement link_uuid = document.createElement("link_uuid");
1081  link_uuid.setAttribute("uuid", elmt->uuid().toString());
1082  links_uuids.appendChild(link_uuid);
1083  }
1084  element.appendChild(links_uuids);
1085  }
1086 
1087  //save information of this element
1088  if (! m_element_informations.keys().isEmpty()) {
1089  QDomElement infos = document.createElement("elementInformations");
1090  m_element_informations.toXml(infos, "elementInformation");
1091  element.appendChild(infos);
1092  }
1093 
1094  //Dynamic texts
1095  QDomElement dyn_text = document.createElement("dynamic_texts");
1097  dyn_text.appendChild(deti->toXml(document));
1098 
1099  QDomElement texts_group = document.createElement("texts_groups");
1100 
1101  //Dynamic texts owned by groups
1102  for(ElementTextItemGroup *group : m_texts_group)
1103  {
1104  group->blockAlignmentUpdate(true);
1105  //temporarily remove the texts from group to get the pos relative to element and not group.
1106  //Set the alignment to top, because top is not used by groupand so,
1107  //each time a text is removed from the group, the alignement is not updated
1108  Qt::Alignment al = group->alignment();
1109  group->setAlignment(Qt::AlignTop);
1110 
1111  //Remove the texts from group
1112  QList<DynamicElementTextItem *> deti_list = group->texts();
1113  for(DynamicElementTextItem *deti : deti_list)
1114  group->removeFromGroup(deti);
1115 
1116  //Save the texts to xml
1117  for (DynamicElementTextItem *deti : deti_list)
1118  dyn_text.appendChild(deti->toXml(document));
1119 
1120  //Re add texts to group
1121  for(DynamicElementTextItem *deti : deti_list)
1122  group->addToGroup(deti);
1123 
1124  //Restor the alignement
1125  group->setAlignment(al);
1126 
1127  //Save the group to xml
1128  texts_group.appendChild(group->toXml(document));
1129  group->blockAlignmentUpdate(false);
1130  }
1131 
1132  //Append the dynamic texts to element
1133  element.appendChild(dyn_text);
1134  //Append the texts group to element
1135  element.appendChild(texts_group);
1136 
1137  return(element);
1138 }
1139 
1147 {
1148  if (deti && !m_dynamic_text_list.contains(deti))
1149  {
1150  m_dynamic_text_list.append(deti);
1151  deti->setParentItem(this);
1152  emit textAdded(deti);
1153  }
1154  else
1155  {
1157  m_dynamic_text_list.append(text);
1158  emit textAdded(text);
1159  }
1160 }
1161 
1169 {
1170  if (m_dynamic_text_list.contains(deti))
1171  {
1172  m_dynamic_text_list.removeOne(deti);
1173  deti->setParentItem(nullptr);
1174  emit textRemoved(deti);
1175  return;
1176  }
1177 
1178  for(ElementTextItemGroup *group : m_texts_group)
1179  {
1180  if(group->texts().contains(deti))
1181  {
1182  removeTextFromGroup(deti, group);
1183  m_dynamic_text_list.removeOne(deti);
1184  deti->setParentItem(nullptr);
1185  emit textRemoved(deti);
1186  return;
1187  }
1188  }
1189 }
1190 
1197 QList<DynamicElementTextItem *> Element::dynamicTextItems() const {
1198  return m_dynamic_text_list;
1199 }
1200 
1210 {
1211  if(m_texts_group.isEmpty())
1212  {
1213  ElementTextItemGroup *group = new ElementTextItemGroup(name, this);
1214  m_texts_group << group;
1215  emit textsGroupAdded(group);
1216  return group;
1217  }
1218 
1219  //Set a new name if name already exist
1220  QString rename = name;
1221  int i=1;
1222  while (textGroup(rename))
1223  {
1224  rename = name+QString::number(i);
1225  i++;
1226  }
1227 
1228  //Create the group
1229  ElementTextItemGroup *group = new ElementTextItemGroup(rename, this);
1230  m_texts_group << group;
1231  emit textsGroupAdded(group);
1232  return group;
1233 }
1234 
1241 {
1242  if(group->parentElement())
1243  return;
1244 
1245  m_texts_group << group;
1246  group->setParentItem(this);
1247  emit textsGroupAdded(group);
1248 }
1249 
1258 {
1259  if(!m_texts_group.contains(group))
1260  return;
1261 
1262  const QList <QGraphicsItem *> items_list = group->childItems();
1263 
1264  for(QGraphicsItem *qgi : items_list)
1265  {
1266  if(qgi->type() == DynamicElementTextItem::Type)
1267  {
1268  DynamicElementTextItem *deti = static_cast<DynamicElementTextItem *>(qgi);
1269  removeTextFromGroup(deti, group);
1270  }
1271  }
1272 
1273 
1274  emit textsGroupAboutToBeRemoved(group);
1275  m_texts_group.removeOne(group);
1276  group->setParentItem(nullptr);
1277 }
1278 
1286 {
1287  for (ElementTextItemGroup *group : m_texts_group)
1288  if(group->name() == name)
1289  return group;
1290 
1291  return nullptr;
1292 }
1293 
1298 QList<ElementTextItemGroup *> Element::textGroups() const
1299 {
1300  return m_texts_group;
1301 }
1302 
1311 {
1312  if(!m_dynamic_text_list.contains(text))
1313  return false;
1314  if(!m_texts_group.contains(group))
1315  return false;
1316 
1317  m_dynamic_text_list.removeOne(text);
1318  emit textRemoved(text);
1319 
1320  group->addToGroup(text);
1321  emit textAddedToGroup(text, group);
1322 
1323  return true;
1324 }
1325 
1332 {
1333  if(!m_texts_group.contains(group))
1334  return false;
1335 
1336  if(group->texts().contains(text))
1337  {
1338  group->removeFromGroup(text);
1339  emit textRemovedFromGroup(text, group);
1340  addDynamicTextItem(text);
1341  return true;
1342  }
1343 
1344  return false;
1345 }
1346 
1355 QList <QPair <Terminal *, Terminal *> > Element::AlignedFreeTerminals() const
1356 {
1357  QList <QPair <Terminal *, Terminal *> > list;
1358 
1359  foreach (Terminal *terminal, terminals())
1360  {
1361  if (terminal->conductors().isEmpty())
1362  {
1363  Terminal *other_terminal = terminal -> alignedWithTerminal();
1364  if (other_terminal)
1365  list << qMakePair(terminal, other_terminal);
1366  }
1367  }
1368 
1369  return list;
1370 }
1371 
1382 {
1383  // if nothing to link return now
1384  if (tmp_uuids_link.isEmpty()) return;
1385 
1386  ElementProvider ep(prj);
1387  foreach (Element *elmt, ep.fromUuids(tmp_uuids_link)) {
1388  elmt->linkToElement(this);
1389  }
1390  tmp_uuids_link.clear();
1391 }
1392 
1400 {
1401  if (m_element_informations == dc) return;
1404  emit elementInfoChange(old_info, m_element_informations);
1405 }
1406 
1414 bool comparPos(const Element *elmt1, const Element *elmt2) {
1415  //Compare folio first
1416  if (elmt1->diagram()->folioIndex() != elmt2->diagram()->folioIndex())
1417  return elmt1->diagram()->folioIndex() < elmt2->diagram()->folioIndex();
1418  //Compare the row(in letter pos) in second
1419  QString a = elmt1->diagram()->convertPosition(elmt1->scenePos()).letter();
1420  QString b = elmt2->diagram()->convertPosition(elmt2->scenePos()).letter();
1421  if (a != b)
1422  return a<b;
1423  //In last compare the line, if line is egal, return sorted by row in real pos
1424  if (elmt1->pos().x() == elmt2->pos().x())
1425  return elmt1->y() <= elmt2->pos().y();
1426  return elmt1->pos().x() <= elmt2->pos().x();
1427 }
1428 
1433 void Element::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
1434 {
1436  foreach (Terminal *t, terminals())
1437  {
1438  t -> drawHelpLine(true);
1439  }
1440 }
1441 
1446 void Element::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
1447 {
1449  foreach (Terminal *t, terminals())
1450  {
1451  t -> drawHelpLine(false);
1452  }
1453 }
1454 
1461 void Element::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
1462  Q_UNUSED(e);
1463 
1464  foreach (Element *elmt, linkedElements())
1465  elmt -> setHighlighted(true);
1466 
1467  m_mouse_over = true;
1468  setToolTip( name() );
1469  update();
1470 }
1471 
1478 void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
1479  Q_UNUSED(e);
1480 
1481  foreach (Element *elmt, linkedElements())
1482  elmt -> setHighlighted(false);
1483 
1484  m_mouse_over = false;
1485  update();
1486 }
1487 
1494 void Element::setUpFormula(bool code_letter)
1495 {
1496  Q_UNUSED(code_letter)
1497 
1499  return;
1500 
1501  if (diagram())
1502  {
1503  QString formula = diagram()->project()->elementAutoNumCurrentFormula();
1504 
1505  m_element_informations.addValue("formula", formula);
1506 
1507  QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
1508  NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
1509  NumerotationContextCommands ncc (nc);
1510 
1511  m_autoNum_seq.clear();
1512  autonum::setSequential(formula, m_autoNum_seq, nc, diagram(), element_currentAutoNum);
1513  diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
1514 
1515  if(!m_freeze_label && !formula.isEmpty())
1516  {
1518  QString label = autonum::AssignVariables::formulaToLabel(formula, m_autoNum_seq, diagram(), this);
1519  m_element_informations.addValue("label", label);
1521  }
1522  }
1523 }
1524 
1529 QString Element::getPrefix() const{
1530  return m_prefix;
1531 }
1532 
1537 void Element::setPrefix(QString prefix) {
1538  m_prefix = std::move(prefix);
1539 }
1540 
1545 void Element::freezeLabel(bool freeze)
1546 {
1547  m_freeze_label = freeze;
1548 }
1549 
1555  if (this->diagram()->freezeNewElements() || this->diagram()->project()->isFreezeNewElements()) {
1556  freezeLabel(true);
1557  }
1558  else return;
1559 }
1560 
1565 QString Element::name() const {
1566  return m_names.name(m_location.baseName());
1567 }
1568 
1570  return m_location;
1571 }
QUuid m_uuid
Definition: element.h:173
void removeTextGroup(ElementTextItemGroup *group)
Element::removeTextGroup Remove the text group from this element, and set the parent of group to 0...
Definition: element.cpp:1257
bool attributeIsAnInteger(const QDomElement &, const QString &, int *=nullptr)
Definition: qet.cpp:200
Item is currently building from a xml description (element)
Definition: qet.h:38
QString baseName() const
ElementsLocation::baseName.
QList< QPair< Terminal *, Terminal * > > AlignedFreeTerminals() const
Element::AlignedFreeTerminals.
Definition: element.cpp:1355
virtual void linkToElement(Element *)
Definition: element.h:133
QList< Conductor * > conductors() const
Definition: terminal.cpp:677
QSize size() const
Definition: element.cpp:229
virtual kind linkType() const
Definition: element.h:138
ElementsLocation location() const
Definition: element.cpp:1569
void freezeNewAddedElement()
Element::freezeNewAddedElement Freeze this label if needed.
Definition: element.cpp:1554
QList< Element * > linkedElements()
Element::linkedElements.
Definition: element.h:229
QList< Element * > connected_elements
Definition: element.h:171
static QString formulaToLabel(QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt=nullptr)
AssignVariables::formulaToLabel Return the with variable assigned (ready to be displayed) ...
Element(const ElementsLocation &location, QGraphicsItem *=nullptr, int *state=nullptr, Element::kind link_type=Element::Simple)
Element::Element.
Definition: element.cpp:71
bool isFree() const
Definition: element.h:201
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
bool m_must_highlight
Definition: element.h:189
static void loadSequential(const QDomElement &dom_element, const QString &seq, QStringList *list)
Definition: element.cpp:40
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition: element.cpp:1461
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
QetGraphicsItem::mouseMoveEvent handle mouse movement.
kind
The kind enum Used to know the kind of this element (master, slave, report ect...) ...
Definition: element.h:50
autonum::sequentialNumbers m_autoNum_seq
Definition: element.h:178
void textsGroupAdded(ElementTextItemGroup *group)
bool parseInput(const QDomElement &dom_element)
Element::parseInput Parse the input (old text field) the parsed input are converted to dynamic text f...
Definition: element.cpp:500
Definition: qet.h:207
QRectF boundingRect() const override
Definition: element.cpp:205
NamesList m_names
Definition: element.h:183
~Element() override
Element::~Element.
Definition: element.cpp:114
void fromXml(const QDomElement &, const QHash< QString, QString > &=QHash< QString, QString >())
Definition: nameslist.cpp:120
static ElementPictureFactory * instance()
instance
QUuid uuid() const
Element::uuid.
Definition: element.h:221
QPoint setHotspot(QPoint)
Definition: element.cpp:238
NumerotationContext next()
NumerotationContextCommands::next.
int folioIndex() const
Definition: diagram.cpp:1738
QString name(const QString &=QString()) const
Definition: nameslist.cpp:205
QIcon Terminal
Definition: qeticons.cpp:164
void setAlignment(Qt::Alignment alignement)
ElementTextItemGroup::setAlignement Set the alignement of this group.
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
QetGraphicsItem::mouseReleaseEvent handle mouse release click.
autonum::sequentialNumbers & rSequenceStruct()
Definition: element.h:96
bool m_mouse_over
Definition: element.h:192
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *)
Definition: element.cpp:315
virtual void setHighlighted(bool)
Definition: element.cpp:162
QSize dimensions
Definition: element.h:190
void setUpFormula(bool code_letter=true)
Element::setUpFormula Set up the formula used to create the label of this element.
Definition: element.cpp:1494
void fromXml(QDomElement &dom_element)
ElementTextItemGroup::fromXml Import data of this group from xml.
const QPicture m_low_zoom_picture
Definition: element.h:186
void removeFromGroup(QGraphicsItem *item)
ElementTextItemGroup::removeFromGroup.
void addToGroup(QGraphicsItem *item)
ElementTextItemGroup::addToGroup.
Terminal * parseTerminal(const QDomElement &dom_element)
Definition: element.cpp:565
QString name() const override
Element::name.
Definition: element.cpp:1565
QVariant value(const QString &key) const
QDomElement toXml(QDomDocument &document, const QString &tag_name=QString("sequentialNumbers")) const
sequentialNumbers::toXml export this sequential numbers into a QDomElement.
const QPicture m_picture
Definition: element.h:185
QList< Element * > fromUuids(QList< QUuid >) const
ElementProvider::fromUuids.
bool buildFromXml(const QDomElement &, int *=nullptr)
Element::buildFromXml Build this element from an xml description.
Definition: element.cpp:350
QList< Conductor * > conductors() const
Element::conductors.
Definition: element.cpp:134
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Element::paint.
Definition: element.cpp:184
void setSequential(const QString &label, sequentialNumbers &seqStruct, NumerotationContext &context, Diagram *diagram, const QString &hashKey)
setSequential Fill seqStruct
static bool valideXml(QDomElement &)
Definition: terminal.cpp:702
bool addValue(const QString &, const QVariant &, bool show=true)
ElementTextItemGroup * textGroup(const QString &name) const
Definition: element.cpp:1285
DiagramContext m_element_informations
Definition: element.h:177
void getPictures(const ElementsLocation &location, QPicture &picture, QPicture &low_picture)
ElementPictureFactory::getPictures Set the picture of the element at location. Note, picture can be null.
void setSize(int, int)
Element::setSize Define the size of the element. The size must be a multiple of 10. If not, the dimensions indicated will be arrrondies to higher tens.
Definition: element.cpp:217
static void loadSequential(const QDomElement &dom_element, Element *element)
Definition: element.cpp:50
The PropertiesEditorDialog class Create a dialog to edit some properties of a thing. Only create a instance of this class and call exec, all is done for you in this class. The first argument (a template) must be a subclass of QWidget and provide the 3 methods bellow : QString::title() void::apply() void::reset() You can subclass the interface PropertiesEditorWidget who provide all this methods. This dialog take ownership of the editor, so the editor will be deleted by this dialog.
void setFrame(const bool frame)
virtual QDomElement toXml(QDomDocument &, QHash< Terminal *, int > &) const
Definition: element.cpp:1021
QList< Terminal * > terminals() const
Element::terminals.
Definition: element.cpp:124
const QString version
QElectroTech version (as string, used to mark projects and elements XML documents) ...
Definition: qet.h:30
QET::GraphicsItemState m_state
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group)
QList< QString > keys(KeyOrder=None) const
bool contains(const QString &) const
void textAddedToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
QET::GraphicsItemState state() const
QetGraphicsItem::state.
void setVerticalAdjustment(int v)
ElementTextItemGroup::setVerticalAdjustment Set the value of the vertical adjustment to ...
void addDynamicTextItem(DynamicElementTextItem *deti=nullptr)
Element::addDynamiqueTextItem Add as a dynamic text item of this element, is reparented to this If ...
Definition: element.cpp:1146
void removeDynamicTextItem(DynamicElementTextItem *deti)
Element::removeDynamicTextItem Remove , no matter if is a child of this element or a child of a group...
Definition: element.cpp:1168
void fromXml(const QDomElement &, const QString &="property")
void setRotation(qreal angle)
QList< ElementTextItemGroup * > m_texts_group
Definition: element.h:195
bool parseElement(const QDomElement &dom)
Element::parseElement Parse the element of the xml description of this element.
Definition: element.cpp:484
QString elementAutoNumCurrentFormula() const
QETProject::elementAutoNumCurrentFormula.
Definition: qetproject.cpp:524
void setInfoName(const QString &info_name)
DynamicElementTextItem::setInfoName Set the information name of the parent element.
QList< QUuid > tmp_uuids_link
Definition: element.h:172
virtual void initLink(QETProject *)
Element::initLink Initialise the link between this element and other elements. This method can be cal...
Definition: element.cpp:1381
virtual bool fromXml(QDomElement &, QHash< int, Terminal *> &, bool=false)
Element::fromXml Import the parameters of this element from a xml document. When call this function e...
Definition: element.cpp:647
DynamicElementTextItem * parseDynamicText(const QDomElement &dom_element)
Element::parseDynamicText Create the dynamic text field describ in .
Definition: element.cpp:550
QPixmap pixmap()
Element::pixmap.
Definition: element.cpp:262
QPointF dockConductor() const
Definition: terminal.h:154
bool removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
Element::removeTextFromGroup Remove the text from the group , en reparent to this element...
Definition: element.cpp:1331
void editProperty() override
Definition: element.cpp:145
QList< DynamicElementTextItem * > texts() const
ElementTextItemGroup::texts.
QPoint hotspot() const
Definition: element.cpp:254
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
Definition: qet.cpp:300
QString elementPrefixForLocation(const ElementsLocation &location)
elementPrefixForLocation
QIcon tr
Definition: qeticons.cpp:204
virtual void setElementInformations(DiagramContext dc)
Element::setElementInformations Set new information for this element. If new information is different...
Definition: element.cpp:1399
QList< Terminal * > m_terminals
Definition: element.h:184
QPixmap pixmap(const ElementsLocation &location)
ElementPictureFactory::pixmap.
ElementTextItemGroup * addTextGroup(const QString &name)
Definition: element.cpp:1209
void textRemovedFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
kind m_link_type
Definition: element.h:174
QDomElement xml() const
ElementsLocation::xml.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseMoveEvent.
Definition: element.cpp:1433
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition: element.cpp:1478
General state.
Definition: qet.h:37
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
DiagramPosition convertPosition(const QPointF &)
Definition: diagram.cpp:1637
Definition: qet.h:205
bool attributeIsAReal(const QDomElement &, const QString &, qreal *=nullptr)
Definition: qet.cpp:219
bool exist() const
ElementsLocation::exist.
bool m_freeze_label
Definition: element.h:179
QString m_prefix
Definition: element.h:193
Element * parentElement() const
ElementTextItemGroup::parentElement.
void toXml(QDomElement &, const QString &="property") const
void elementInfoChange(DiagramContext old_info, DiagramContext new_info)
bool comparPos(const Element *elmt1, const Element *elmt2)
comparPos Compare position of the two elements. Compare 3 points: 1 folio - 2 row - 3 line returns a ...
Definition: element.cpp:1414
QString elementCurrentAutoNum() const
QETProject::elementCurrentAutoNum.
Definition: qetproject.cpp:532
DiagramContext m_kind_informations
Definition: element.h:177
void setTextFrom(DynamicElementTextItem::TextFrom text_from)
DynamicElementTextItem::setTextFrom Set the final text is created from.
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *)
Definition: element.cpp:292
void setPos(const QPointF &pos)
QPoint hotspot_coord
Definition: element.h:191
int orientation() const
Definition: element.h:213
void setPrefix(QString)
Element::setPrefix set Element Prefix.
Definition: element.cpp:1537
static bool valideXml(QDomElement &)
Definition: element.cpp:614
void setFont(const QFont &font)
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *)
Definition: element.cpp:273
ElementsLocation m_location
Definition: element.h:182
QList< DynamicElementTextItem * > m_dynamic_text_list
Definition: element.h:194
static QString xmlTaggName()
bool keyMustShow(const QString &) const
DiagramContext::keyMustShow.
void setHoldToBottomPage(bool hold)
void textAdded(DynamicElementTextItem *deti)
void fromXml(const QDomElement &dom_elmt) override
DynamicElementTextItem::fromXml Import this text from xml.
void textRemoved(DynamicElementTextItem *deti)
void fromXml(const QDomElement &element)
sequentialNumbers::fromXml Import sequential values from a QDomElement
Item is loading her properties from a xml description.
Definition: qet.h:39
QString getPrefix() const
Element::getPrefix get Element Prefix.
Definition: element.cpp:1529
void addElementAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addElementAutoNum Add a new element numerotation context. If key already exist...
Definition: qetproject.cpp:599
bool isElement() const
ElementsLocation::isElement.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Element::mouseReleaseEvent.
Definition: element.cpp:1446
void freezeLabel(bool freeze)
Element::freezeLabel Freeze this element label.
Definition: element.cpp:1545
QHash< QString, NumerotationContext > elementAutoNum() const
QETProject::elementAutoNum.
Definition: qetproject.cpp:502
QETProject * project() const
Definition: diagram.cpp:1716
The ElementPictureFactory class This class is singleton factory, use to create and get the picture us...
QHash< DynamicElementTextItem *, QPointF > m_converted_text_from_xml_description
Definition: element.h:168
bool addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
Element::addTextToGroup Add the text to the group ; If isn&#39;t owned by this element return false...
Definition: element.cpp:1310
QList< DynamicElementTextItem * > dynamicTextItems() const
Element::dynamicTextItems.
Definition: element.cpp:1197
void displayHelpLine(bool b=true)
Element::displayHelpLine Display the help line of each terminal if b is true.
Definition: element.cpp:172
void setText(const QString &text)
DynamicElementTextItem::setText Set the text of this text.
QString path() const
ElementsLocation::path.
void drawHelpLine(bool draw=true)
Terminal::drawHelpLine.
Definition: terminal.cpp:333
QList< ElementTextItemGroup * > textGroups() const
Element::textGroups.
Definition: element.cpp:1298
Orientation
Orientation (used for electrical elements and their terminals)
Definition: qet.h:204