29 #include <QDomDocument> 30 #include <QDomElement> 31 #include <QGraphicsSceneMouseEvent> 39 m_parent_element(parent_element),
40 m_uuid(QUuid::createUuid())
44 setParentItem(parent_element);
46 setRotation(settings.value(
"dynamic_text_rotation", 0).toInt());
47 setTextWidth(settings.value(
"dynamic_text_widht", -1).toInt());
53 undo->setText(
tr(
"Éditer un texte d'élément"));
59 QTextOption option = document()->defaultTextOption();
60 option.setAlignment(Qt::AlignHCenter);
61 option.setWrapMode(QTextOption::WordWrap);
62 document()->setDefaultTextOption(option);
75 return deti.metaObject()->enumerator(deti.metaObject()->indexOfEnumerator(
"TextFrom"));
89 QDomElement root_element = dom_doc.createElement(
xmlTaggName());
91 root_element.setAttribute(
"x", QString::number(pos().x()));
92 root_element.setAttribute(
"y", QString::number(pos().y()));
93 root_element.setAttribute(
"rotation", QString::number(
QET::correctAngle(rotation())));
94 root_element.setAttribute(
"uuid",
m_uuid.toString());
95 root_element.setAttribute(
"frame",
m_frame?
"true" :
"false");
96 root_element.setAttribute(
"text_width", QString::number(
m_text_width));
97 root_element.setAttribute(
"font",
font().toString());
100 root_element.setAttribute(
"text_from", me.valueToKey(
m_text_from));
102 me = QMetaEnum::fromType<Qt::Alignment>();
104 root_element.setAttribute(
"Halignment", me.valueToKey(Qt::AlignRight));
105 else if(this->
alignment() &Qt::AlignLeft)
106 root_element.setAttribute(
"Halignment", me.valueToKey(Qt::AlignLeft));
107 else if(this->
alignment() &Qt::AlignHCenter)
108 root_element.setAttribute(
"Halignment", me.valueToKey(Qt::AlignHCenter));
111 root_element.setAttribute(
"Valignment", me.valueToKey(Qt::AlignBottom));
112 else if(this->
alignment() & Qt::AlignTop)
113 root_element.setAttribute(
"Valignment", me.valueToKey(Qt::AlignTop));
114 else if(this->
alignment() &Qt::AlignVCenter)
115 root_element.setAttribute(
"Valignment", me.valueToKey(Qt::AlignVCenter));
118 QDomElement dom_text = dom_doc.createElement(
"text");
119 dom_text.appendChild(dom_doc.createTextNode(toPlainText()));
120 root_element.appendChild(dom_text);
125 QDomElement dom_info_name = dom_doc.createElement(
"info_name");
126 dom_info_name.appendChild(dom_doc.createTextNode(
m_info_name));
127 root_element.appendChild(dom_info_name);
133 QDomElement dom_comp_text = dom_doc.createElement(
"composite_text");
135 root_element.appendChild(dom_comp_text);
139 if(
color() != QColor(Qt::black))
141 QDomElement dom_color = dom_doc.createElement(
"color");
142 dom_color.appendChild(dom_doc.createTextNode(
color().name()));
143 root_element.appendChild(dom_color);
157 qDebug() <<
"DynamicElementTextItem::fromXml : Wrong tagg name";
161 QGraphicsTextItem::setRotation(dom_elmt.attribute(
"rotation", QString::number(0)).toDouble());
163 if (dom_elmt.hasAttribute(
"font"))
166 font.fromString(dom_elmt.attribute(
"font"));
171 QFont font_(dom_elmt.attribute(
"font_family",
font().family()),
172 dom_elmt.attribute(
"font_size", QString::number(9)).toInt());
173 font_.setStyleName(dom_elmt.attribute(
"dynamicitemstyle",
font().styleName()));
177 m_uuid = QUuid(dom_elmt.attribute(
"uuid", QUuid::createUuid().toString()));
178 setFrame(dom_elmt.attribute(
"frame",
"false") ==
"true"? true :
false);
179 setTextWidth(dom_elmt.attribute(
"text_width", QString::number(-1)).toDouble());
185 me = QMetaEnum::fromType<Qt::Alignment>();
186 if(dom_elmt.hasAttribute(
"Halignment"))
187 setAlignment(Qt::Alignment(me.keyToValue(dom_elmt.attribute(
"Halignment").toStdString().data())));
188 if(dom_elmt.hasAttribute((
"Valignment")))
189 setAlignment(Qt::Alignment(me.keyToValue(dom_elmt.attribute(
"Valignment").toStdString().data())) | this->
alignment());
192 QDomElement dom_text = dom_elmt.firstChildElement(
"text");
193 if (!dom_text.isNull())
197 QDomElement dom_info_name = dom_elmt.firstChildElement(
"info_name");
198 if(!dom_info_name.isNull())
202 QDomElement dom_comp_text = dom_elmt.firstChildElement(
"composite_text");
203 if(!dom_comp_text.isNull())
207 QDomElement dom_color = dom_elmt.firstChildElement(
"color");
208 if(!dom_color.isNull())
214 QGraphicsTextItem::setPos(dom_elmt.attribute(
"x", QString::number(0)).toDouble(),
215 dom_elmt.attribute(
"y", QString::number(0)).toDouble());
403 if(old_info_name ==
"label")
411 if(old_info_name != info_name)
413 if(old_info_name ==
"label") {
416 if(info_name ==
"label")
456 if(old_composite_text.contains(
"%{label}"))
470 if(old_composite_text.contains(
"%{label}"))
545 if((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable))
557 QPointF current_parent_pos;
558 QPointF button_down_parent_pos;
559 current_parent_pos = mapToParent(mapFromScene(event->scenePos()));
560 button_down_parent_pos = mapToParent(mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
563 event->modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(
Diagram::snapToGrid(new_pos));
587 if(!(event->modifiers() & Qt::ControlModifier))
588 QGraphicsTextItem::mouseReleaseEvent(event);
626 setDefaultTextColor(Qt::blue);
658 if(
font().pointSize() >= 5)
660 w =
font().pointSizeF()*0.1;
666 pen.setColor(
color());
668 painter->setPen(pen);
669 painter->setRenderHint(QPainter::Antialiasing);
672 qreal
ro =
font().pointSizeF()/3;
686 return QGraphicsObject::itemChange(change, value);
730 return QGraphicsObject::itemChange(change, value);
732 else if (change == QGraphicsItem::ItemParentHasChanged)
738 return QGraphicsObject::itemChange(change, value);
746 if(event->type() == QEvent::GraphicsSceneHoverEnter) {
750 else if(event->type() == QEvent::GraphicsSceneHoverLeave) {
754 else if(event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
779 if (dc.
value(
"formula").toString().isEmpty())
854 bool text_have_label =
false;
858 text_have_label =
true;
895 QString
string = formula;
900 if (other_diagram &&
string.contains(
"%F"))
907 if (other_diagram && (
string.contains(
"%f") ||
string.contains(
"%id")))
912 if (
string.contains(
"%l"))
914 if (
string.contains(
"%c"))
924 QString
string = formula;
929 if (other_diagram &&
string.contains(
"%F"))
935 if (other_diagram && (
string.contains(
"%f") ||
string.contains(
"%id")))
937 if (
string.contains(
"%l"))
939 if (
string.contains(
"%c"))
966 if (
diagram && formula.contains(
"%F"))
969 formula.replace(
"%F",
m_F_str);
973 if (
diagram && (formula.contains(
"%f") || formula.contains(
"%id")))
978 if (formula.contains(
"%l"))
980 if (formula.contains(
"%c"))
1050 if(dc.
value(
"formula").toString().isEmpty())
1110 else if(!c_list.isEmpty())
1120 if (!
m_other_report.data()->terminals().first()->conductors().isEmpty())
1176 string.replace(
"%{label}", label);
1180 if(
string.contains(
"%{function}"))
1182 if(
string.contains(
"%{tension-protocol}"))
1183 string.replace(
"%{tension-protocol}",
m_watched_conductor.data()->properties().m_tension_protocol);
1200 Element *zoomed_element =
nullptr;
1222 if(scene() != zoomed_element->scene())
1224 zoomed_element->setSelected(
true);
1227 for(QGraphicsView *view : zoomed_element->scene()->views())
1229 QRectF fit = zoomed_element->sceneBoundingRect();
1230 fit.adjust(-200, -200, 200, 200);
1231 view->fitInView(fit, Qt::KeepAspectRatioByExpanding);
1291 QRectF r = boundingRect();
1317 if (toPlainText() ==
text)
1320 bool update_alignment =
true;
1322 update_alignment =
false;
1325 update_alignment =
false;
1327 if (update_alignment) {
1341 document()->setTextWidth(document()->idealWidth());
1346 if (update_alignment) {
1355 QRectF r = boundingRect();
1364 this->document()->setTextWidth(width);
The CrossRefItem class This clas provide an item, for show the cross reference, like the contacts lin...
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Qt::Alignment alignment() const
void refreshLabelConnection()
DynamicElementTextItem::refreshLabelConnection Refresh the connection of this text when the source of...
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
Item is currently building from a xml description (element)
ElementTextItemGroup * parentGroup() const
DynamicElementTextItem::parentGroup.
virtual kind linkType() const
void textEdited(const QString &old_str, const QString &new_str)
QList< Element * > linkedElements()
Element::linkedElements.
QPointer< Conductor > m_watched_conductor
static QString formulaToLabel(QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt=nullptr)
AssignVariables::formulaToLabel Return the with variable assigned (ready to be displayed) ...
void setColor(const QColor &color)
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
QMetaObject::Connection m_report_formula_con
QList< QMetaObject::Connection > m_formula_connection
void textFromChanged(DynamicElementTextItem::TextFrom text_from)
void setPotentialConductor()
DynamicElementTextItem::setPotentialConductor This function is only used when the parent element of t...
void updateReportFormulaConnection()
bool m_first_scene_change
void conductorWasAdded(Conductor *conductor)
DynamicElementTextItem::conductorWasAdded Function only use when parent element is a folio report...
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
The XRefProperties class this class store properties used by XrefItem.
DiagramContext elementInformations() const
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
DynamicElementTextItem::hoverLeaveEvent.
void setCompositeText(const QString &text)
DynamicElementTextItem::setCompositeText Set the composite text of this text item to ...
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
DynamicElementTextItem::mouseMoveEvent.
void finishAlignment()
DiagramTextItem::finishAlignment Call this function after changing the bouding rect of this text to s...
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
static QString xmlTaggName()
autonum::sequentialNumbers & rSequenceStruct()
QGraphicsTextItem * m_slave_Xref_item
void setPlainText(const QString &text)
QString slaveLabel() const
virtual void setHighlighted(bool)
void prepareAlignment()
DiagramTextItem::prepareAlignment Call this function before changing the bounding rect of this text...
void linkedElementChanged()
QVariant value(const QString &key) const
void reportFormulaChanged()
DynamicElementTextItem::reportFormulaChanged The report formula use in the project was changed...
int beginMovement(Diagram *diagram, QGraphicsItem *driver_item=nullptr)
ElementTextsMover::beginMovement Begin a movement.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
void setPlainText(const QString &text)
void conductorWasAdded(Conductor *conductor)
Element * elementUseForInfo() const
DynamicElementTextItem::elementUseForInfo.
QDomElement toXml(QDomDocument &dom_doc) const override
DynamicElementTextItem::toXml Export this text to xml.
void reportPropertiesChanged(const QString &old_str, const QString &new_str)
void titleBlockFolioChanged(const QString &)
titleBlockFolioChanged Signal emitted after Folio has changed
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
void frameChanged(bool frame)
void setAlignment(const Qt::Alignment &alignment)
void setFrame(const bool frame)
void reportChanged()
DynamicElementTextItem::reportChanged This function is only use when parent element of this text is a...
QList< Terminal * > terminals() const
Element::terminals.
void masterChanged()
DynamicElementTextItem::masterChanged This function is only use when the parent element is a slave...
~DynamicElementTextItem() override
ElementTextsMover & elementTextsMover()
void updateXref()
DynamicElementTextItem::updateXref Create or delete the Xref according to the current properties of t...
void updateReportText()
DynamicElementTextItem::updateReportText This function is only use when this text is owned by a repor...
void conductorWasRemoved(Conductor *conductor)
DynamicElementTextItem::conductorWasRemoved Function only use when parent element is a folio report...
qreal correctAngle(const qreal &)
QPointer< Element > m_parent_element
QPointer< Element > m_other_report
QString defaultReportProperties() const
void conductorPropertiesChanged()
DynamicElementTextItem::conductorPropertiesChanged This function is only used when the parent element...
void elementInfoChanged()
void setInfoName(const QString &info_name)
DynamicElementTextItem::setInfoName Set the information name of the parent element.
void zoomToLinkedElement()
DynamicElementTextItem::zoomToLinkedElement If the parent element is a folio report or a slave elemen...
QString compositeText() const
CrossRefItem * m_Xref_item
static QMetaEnum textFromMetaEnum()
DynamicElementTextItem::textFromMetaEnum.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
DiagramTextItem::mousePressEvent.
bool isFreezeLabel() const
QPointer< Element > m_master_element
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
DynamicElementTextItem::mouseDoubleClickEvent Reimplemented functions, for add extra feature when thi...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
DynamicElementTextItem::mouseReleaseEvent.
QPointF m_initial_position
static QFont dynamicTextsItemFont(qreal=-1.0)
QETApp::dynamicTextsFont the defaukt font of dynamic element text item.
void removeConnectionForReportFormula(const QString &formula)
void continueMovement(QGraphicsSceneMouseEvent *event)
Element * parentElement() const
DynamicElementTextItem::ParentElement.
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
DynamicElementTextItem::mousePressEvent.
void setConnectionForReportFormula(const QString &formula)
void textWidthChanged(qreal width)
DynamicElementTextItem::TextFrom textFrom() const
void projectDiagramsOrderChanged(QETProject *, int, int)
void elementInfoChange(DiagramContext old_info, DiagramContext new_info)
void textChanged(QString text)
void setTextFrom(DynamicElementTextItem::TextFrom text_from)
DynamicElementTextItem::setTextFrom Set the final text is created from.
void infoNameChanged(QString info)
QString reportReplacedCompositeText() const
DynamicElementTextItem::reportReplacedCompositeText This function is only used when the parent elemen...
static QPointF snapToGrid(const QPointF &p)
Diagram::snapToGrid Return a nearest snap point of p.
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
DiagramTextItem::paint Draw this text field. This method draw the text by calling QGraphicsTextItem::...
void setFont(const QFont &font)
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
DynamicElementTextItem::hoverEnterEvent If the parent element of this text is a folio report or a sla...
static QFont diagramTextsFont(qreal=-1.0)
QETApp::diagramTextsFont The font to use By default the font is "sans Serif" and size 9...
void compositeTextChanged(QString text)
QList< QMetaObject::Connection > m_update_slave_Xref_connection
void conductorWasRemoved(Conductor *conductor)
XRefProperties defaultXRefProperties(const QString &type) const
void fromXml(const QDomElement &dom_elmt) override
DynamicElementTextItem::fromXml Import this text from xml.
QRectF frameRect() const
DiagramTextItem::frameRect.
Item is loading her properties from a xml description.
DynamicElementTextItem::TextFrom m_text_from
void setupFormulaConnection()
DynamicElementTextItem::setupFormulaConnection Setup the required connection for the formula of the l...
void XRefPropertiesChanged()
void setNoEditable(bool e=true)
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
QETProject * project() const
void autoPos()
CrossRefItem::autoPos Calculate and set position automaticaly.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void setText(const QString &text)
DynamicElementTextItem::setText Set the text of this text.
void setTextWidth(qreal width)
void updateLabel()
DynamicElementTextItem::updateLabel Update the displayed text, when this dynamic text is based on the...
void diagramRemoved(QETProject *, Diagram *)
static QString replaceVariable(const QString &formula, const DiagramContext &dc)
AssignVariables::replaceVariable Replace the variables in in form %{my-var} to the corresponding val...
void clearFormulaConnection()
Diagram * diagram() const
DiagramTextItem::diagram.