Remove the class element text item.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5276 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2018-03-25 14:33:49 +00:00
parent 8193687894
commit a7917bb5bb
31 changed files with 27 additions and 1330 deletions

View File

@ -24,7 +24,6 @@
#include "diagramcommands.h" #include "diagramcommands.h"
#include "diagramcontent.h" #include "diagramcontent.h"
#include "diagramposition.h" #include "diagramposition.h"
#include "qetgraphicsitem/elementtextitem.h"
#include "elementsmover.h" #include "elementsmover.h"
#include "exportdialog.h" #include "exportdialog.h"
#include "qetgraphicsitem/ghostelement.h" #include "qetgraphicsitem/ghostelement.h"
@ -1228,12 +1227,10 @@ void Diagram::invertSelection() {
* Update elements and conductors that reference folio field * Update elements and conductors that reference folio field
* in their labels. * in their labels.
*/ */
void Diagram::updateLabels() { void Diagram::updateLabels()
foreach (Element *elmt, elements()) { {
if (elmt->elementInformations()["label"].toString().contains(("%F"))) for (Conductor *cnd : content().conductors())
elmt->updateLabel(); {
}
foreach (Conductor *cnd, content().conductors()) {
cnd->refreshText(); cnd->refreshText();
} }
} }
@ -1783,7 +1780,6 @@ bool Diagram::canRotateSelection() const
if (qgi->type() == IndependentTextItem::Type || if (qgi->type() == IndependentTextItem::Type ||
qgi->type() == ConductorTextItem::Type || qgi->type() == ConductorTextItem::Type ||
qgi->type() == DiagramImageItem::Type || qgi->type() == DiagramImageItem::Type ||
qgi->type() == ElementTextItem::Type ||
qgi->type() == Element::Type || qgi->type() == Element::Type ||
qgi->type() == DynamicElementTextItem::Type) qgi->type() == DynamicElementTextItem::Type)
return true; return true;

View File

@ -20,7 +20,6 @@
#include "qetgraphicsitem/conductor.h" #include "qetgraphicsitem/conductor.h"
#include "qetgraphicsitem/conductortextitem.h" #include "qetgraphicsitem/conductortextitem.h"
#include "diagram.h" #include "diagram.h"
#include "qetgraphicsitem/elementtextitem.h"
#include "qetgraphicsitem/independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "qgimanager.h" #include "qgimanager.h"
#include "diagram.h" #include "diagram.h"
@ -101,22 +100,6 @@ void PasteDiagramCommand::redo()
//make new uuid, because old uuid are the uuid of the copied element //make new uuid, because old uuid are the uuid of the copied element
e -> newUuid(); e -> newUuid();
//Reset the text of report element
if (e -> linkType() & Element::AllReport)
{
//Befor commit 3559 there isn't text field tagged label,
//so if not found we take the first text field
if (ElementTextItem *eti = e->taggedText("label"))
eti->setPlainText("/");
else if (e->texts().size())
e->texts().first()->setPlainText("/");
if (ElementTextItem *eti = e->taggedText("function"))
eti->setPlainText("_");
if (ElementTextItem *eti = e->taggedText("tension-protocol"))
eti->setPlainText("_");
}
if (settings.value("diagramcommands/save-label", true).toBool()) if (settings.value("diagramcommands/save-label", true).toBool())
{ {
//Reset the information about the label, the comment and location //Reset the information about the label, the comment and location
@ -125,10 +108,6 @@ void PasteDiagramCommand::redo()
e -> rElementInformations().addValue("comment", ""); e -> rElementInformations().addValue("comment", "");
e -> rElementInformations().addValue("location", ""); e -> rElementInformations().addValue("location", "");
//Reset the text field tagged "label
if (ElementTextItem *eti = e ->taggedText("label"))
eti -> setPlainText("_");
//Reset the text of conductors //Reset the text of conductors
const QList <Conductor *> conductors_list = content.m_conductors_to_move.toList(); const QList <Conductor *> conductors_list = content.m_conductors_to_move.toList();
for (Conductor *c : conductors_list) for (Conductor *c : conductors_list)
@ -138,11 +117,6 @@ void PasteDiagramCommand::redo()
c -> setProperties(cp); c -> setProperties(cp);
} }
} }
else
{
//We call update label, notably to setup the connection required by the formula of the element
e->updateLabel();
}
} }
} }
else else

View File

@ -30,7 +30,6 @@
class DiagramTextItem; class DiagramTextItem;
class Element; class Element;
class ElementTextItem;
class IndependentTextItem; class IndependentTextItem;
class DiagramImageItem; class DiagramImageItem;
class QetGraphicsItem; class QetGraphicsItem;

View File

@ -21,7 +21,6 @@
#include "independenttextitem.h" #include "independenttextitem.h"
#include "conductor.h" #include "conductor.h"
#include "diagramimageitem.h" #include "diagramimageitem.h"
#include "elementtextitem.h"
#include "qetshapeitem.h" #include "qetshapeitem.h"
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
#include "elementtextitemgroup.h" #include "elementtextitemgroup.h"
@ -128,7 +127,6 @@ QList<DiagramTextItem *> DiagramContent::selectedTexts() const
for(QGraphicsItem *qgi : m_selected_items) for(QGraphicsItem *qgi : m_selected_items)
{ {
if (qgi->type() == ConductorTextItem::Type || if (qgi->type() == ConductorTextItem::Type ||
qgi->type() == ElementTextItem::Type ||
qgi->type() == IndependentTextItem::Type || qgi->type() == IndependentTextItem::Type ||
qgi->type() == DynamicElementTextItem::Type) qgi->type() == DynamicElementTextItem::Type)
selected_texts << static_cast<DiagramTextItem *>(qgi); selected_texts << static_cast<DiagramTextItem *>(qgi);

View File

@ -25,7 +25,6 @@ class Conductor;
class Element; class Element;
class IndependentTextItem; class IndependentTextItem;
class DiagramImageItem; class DiagramImageItem;
class ElementTextItem;
class QetShapeItem; class QetShapeItem;
class DynamicElementTextItem; class DynamicElementTextItem;
class ElementTextItemGroup; class ElementTextItemGroup;

View File

@ -190,7 +190,7 @@ bool DiagramEventAddElement::buildElement()
//Everything is good //Everything is good
return true; return true;
} }
#include "elementtextitem.h"
/** /**
* @brief DiagramEventAddElement::addElement * @brief DiagramEventAddElement::addElement
* Add an element at the current pos en current rotation, * Add an element at the current pos en current rotation,
@ -243,6 +243,5 @@ void DiagramEventAddElement::addElement()
m_diagram -> undoStack().push(undo_object); m_diagram -> undoStack().push(undo_object);
element->setUpFormula(); element->setUpFormula();
element->updateLabel();
element->freezeNewAddedElement(); element->freezeNewAddedElement();
} }

View File

@ -24,7 +24,6 @@
#include "diagramposition.h" #include "diagramposition.h"
#include "conductorpropertieswidget.h" #include "conductorpropertieswidget.h"
#include "qetgraphicsitem/conductortextitem.h" #include "qetgraphicsitem/conductortextitem.h"
#include "qetgraphicsitem/elementtextitem.h"
#include "qetgraphicsitem/independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "qetgraphicsitem/diagramimageitem.h" #include "qetgraphicsitem/diagramimageitem.h"
#include "templatelocation.h" #include "templatelocation.h"
@ -543,7 +542,6 @@ void DiagramView::keyPressEvent(QKeyEvent *e)
if (!hasTextItems()) { if (!hasTextItems()) {
if ( if (
qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) || qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<ElementTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) || qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<DiagramTextItem *>(m_diagram->focusItem()) qgraphicsitem_cast<DiagramTextItem *>(m_diagram->focusItem())
) )
@ -556,7 +554,6 @@ void DiagramView::keyPressEvent(QKeyEvent *e)
if (!hasTextItems()) { if (!hasTextItems()) {
if ( if (
qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) || qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<ElementTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) || qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<DiagramTextItem *>(m_diagram->focusItem()) qgraphicsitem_cast<DiagramTextItem *>(m_diagram->focusItem())
) )
@ -735,7 +732,6 @@ bool DiagramView::hasTextItems() {
foreach(QGraphicsItem *qgi, m_diagram -> selectedItems()) { foreach(QGraphicsItem *qgi, m_diagram -> selectedItems()) {
if ( if (
qgraphicsitem_cast<IndependentTextItem *>(qgi) || qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
qgraphicsitem_cast<ElementTextItem *>(qgi) ||
qgraphicsitem_cast<ConductorTextItem *>(qgi) || qgraphicsitem_cast<ConductorTextItem *>(qgi) ||
qgraphicsitem_cast<DiagramTextItem *>(qgi) qgraphicsitem_cast<DiagramTextItem *>(qgi)
) { ) {

View File

@ -23,7 +23,6 @@
#include "element.h" #include "element.h"
#include "independenttextitem.h" #include "independenttextitem.h"
#include "diagramimageitem.h" #include "diagramimageitem.h"
#include "elementtextitem.h"
#include "conductorautonumerotation.h" #include "conductorautonumerotation.h"
/** /**

View File

@ -16,7 +16,6 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "elementtextsmover.h" #include "elementtextsmover.h"
#include "elementtextitem.h"
#include "diagram.h" #include "diagram.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h" #include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
@ -56,7 +55,7 @@ int ElementTextsMover::beginMovement(Diagram *diagram, QGraphicsItem *driver_ite
for(QGraphicsItem *item : diagram->selectedItems()) for(QGraphicsItem *item : diagram->selectedItems())
{ {
if(item->type() == ElementTextItem::Type || item->type() == DynamicElementTextItem::Type) if(item->type() == DynamicElementTextItem::Type)
{ {
m_items_hash.insert(item, item->pos()); m_items_hash.insert(item, item->pos());
m_text_count++; m_text_count++;

View File

@ -28,7 +28,6 @@
#include "qetgraphicsitem/diagramtextitem.h" #include "qetgraphicsitem/diagramtextitem.h"
#include "qetgraphicsitem/conductortextitem.h" #include "qetgraphicsitem/conductortextitem.h"
#include "qetgraphicsitem/customelement.h" #include "qetgraphicsitem/customelement.h"
#include "qetgraphicsitem/elementtextitem.h"
#include "qetgraphicsitem/ghostelement.h" #include "qetgraphicsitem/ghostelement.h"
#include "qetgraphicsitem/independenttextitem.h" #include "qetgraphicsitem/independenttextitem.h"
#include "qetgraphicsitem/diagramimageitem.h" #include "qetgraphicsitem/diagramimageitem.h"
@ -496,40 +495,6 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee
qreal hotspot_x = (elem_pos_x) * Createdxf::xScale; qreal hotspot_x = (elem_pos_x) * Createdxf::xScale;
qreal hotspot_y = Createdxf::sheetHeight - (elem_pos_y) * Createdxf::yScale; qreal hotspot_y = Createdxf::sheetHeight - (elem_pos_y) * Createdxf::yScale;
QList<ElementTextItem *> elmt_text = elmt -> texts();
foreach(ElementTextItem *dti, elmt_text) {
qreal fontSize = dti -> font().pointSizeF();
if (fontSize < 0)
fontSize = dti -> font().pixelSize();
fontSize *= Createdxf::yScale;
qreal x = elem_pos_x + dti -> pos().x();
qreal y = elem_pos_y + dti -> pos().y();
x *= Createdxf::xScale;
y = Createdxf::sheetHeight - (y * Createdxf::yScale);// - fontSize;
QPointF transformed_point = rotation_transformed(x, y, hotspot_x, hotspot_y, rotation_angle);
x = transformed_point.x();
y = transformed_point.y();
QStringList lines = dti -> toPlainText().split('\n');
y += (fontSize/2) * (lines.count()-1);
foreach (QString line, lines) {
qreal angle = 360 - (dti -> rotationAngle() + rotation_angle);
if (line.size() > 0 && line != "_" )
Createdxf::drawText(file_path, line, x, y, fontSize, angle, 0);
angle += 1080;
// coordinates for next line
if (int(angle) % 360 == 0) // no rotation
y -= fontSize*1.06;
else if (int(angle - 180) % 360 == 0) // 180 degrees rotation
y += fontSize*1.06;
else if (int(angle - 270) % 360 == 0) // 270 degrees rotation
x -= fontSize*1.06;
else // ((angle - 90) % 360 == 0) 90 degrees rotation
x += fontSize*1.06;
}
}
QList<QLineF *> elmt_line = elmt -> lines(); QList<QLineF *> elmt_line = elmt -> lines();
foreach(QLineF *line, elmt_line) { foreach(QLineF *line, elmt_line) {
qreal x1 = (elem_pos_x + line -> p1().x()) * Createdxf::xScale; qreal x1 = (elem_pos_x + line -> p1().x()) * Createdxf::xScale;

View File

@ -44,7 +44,6 @@
#include "autonumberingdockwidget.h" #include "autonumberingdockwidget.h"
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
#include "conductortextitem.h" #include "conductortextitem.h"
#include "elementtextitem.h"
#include "undocommand/rotateselectioncommand.h" #include "undocommand/rotateselectioncommand.h"
#include "rotatetextscommand.h" #include "rotatetextscommand.h"
#include "diagramcommands.h" #include "diagramcommands.h"
@ -1432,7 +1431,6 @@ void QETDiagramEditor::slot_updateComplexActions()
QList<ElementTextItemGroup *> groups = DiagramContent(diagram_).selectedTextsGroup(); QList<ElementTextItemGroup *> groups = DiagramContent(diagram_).selectedTextsGroup();
int selected_texts = texts.count(); int selected_texts = texts.count();
int selected_conductor_texts = 0; for(DiagramTextItem *dti : texts) {if(dti->type() == ConductorTextItem::Type) selected_conductor_texts++;} int selected_conductor_texts = 0; for(DiagramTextItem *dti : texts) {if(dti->type() == ConductorTextItem::Type) selected_conductor_texts++;}
int selected_element_texts = 0; for(DiagramTextItem *dti : texts) {if(dti->type() == ElementTextItem::Type) selected_element_texts++;}
int selected_dynamic_elmt_text = 0; for(DiagramTextItem *dti : texts) {if(dti->type() == DynamicElementTextItem::Type) selected_dynamic_elmt_text++;} int selected_dynamic_elmt_text = 0; for(DiagramTextItem *dti : texts) {if(dti->type() == DynamicElementTextItem::Type) selected_dynamic_elmt_text++;}
m_rotate_texts->setEnabled(!ro && (selected_texts || groups.size())); m_rotate_texts->setEnabled(!ro && (selected_texts || groups.size()));
@ -1441,7 +1439,7 @@ void QETDiagramEditor::slot_updateComplexActions()
int selected_shape = dc.count(DiagramContent::Shapes); int selected_shape = dc.count(DiagramContent::Shapes);
int selected_editable = selected_elements_count + int selected_editable = selected_elements_count +
(selected_texts - selected_conductor_texts - selected_element_texts - selected_dynamic_elmt_text) + (selected_texts - selected_conductor_texts - selected_dynamic_elmt_text) +
selected_image + selected_image +
selected_shape + selected_shape +
selected_conductors_count; selected_conductors_count;

View File

@ -19,7 +19,6 @@
#include "element.h" #include "element.h"
#include "qetapp.h" #include "qetapp.h"
#include "diagram.h" #include "diagram.h"
#include "elementtextitem.h"
#include "qgraphicsitemutility.h" #include "qgraphicsitemutility.h"
#include <QPainter> #include <QPainter>
@ -93,14 +92,6 @@ void CommentItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
* else return false, the element is the parent of this comment item * else return false, the element is the parent of this comment item
*/ */
bool CommentItem::setTextParent() { bool CommentItem::setTextParent() {
if (ElementTextItem *eti = m_element->taggedText("label")) {
setParentItem(eti);
m_text_parent = true;
return true;
}
qDebug() << "Comment item: can't found text tagged 'label' from actual parent element to set has parent, "
"comment will be displayed at bottom of diagram";
return false; return false;
} }

View File

@ -19,7 +19,6 @@
#include "element.h" #include "element.h"
#include "qetapp.h" #include "qetapp.h"
#include "diagramposition.h" #include "diagramposition.h"
#include "elementtextitem.h"
#include "diagram.h" #include "diagram.h"
#include "qgraphicsitemutility.h" #include "qgraphicsitemutility.h"
#include "assignvariables.h" #include "assignvariables.h"

View File

@ -16,7 +16,6 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "customelement.h" #include "customelement.h"
#include "elementtextitem.h"
#include "diagram.h" #include "diagram.h"
#include "qetapp.h" #include "qetapp.h"
#include "partline.h" #include "partline.h"
@ -242,7 +241,6 @@ CustomElement::~CustomElement() {
qDeleteAll (m_circles); qDeleteAll (m_circles);
qDeleteAll (m_polygons); qDeleteAll (m_polygons);
qDeleteAll (m_arcs); qDeleteAll (m_arcs);
qDeleteAll (m_texts);
qDeleteAll (m_terminals); qDeleteAll (m_terminals);
} }
@ -258,11 +256,6 @@ QList<Conductor *> CustomElement::conductors() const {
return(conductors); return(conductors);
} }
/// @return la liste des textes de cet element
QList<ElementTextItem *> CustomElement::texts() const {
return(m_texts);
}
/// @return the list of lines /// @return the list of lines
QList<QLineF *> CustomElement::lines() const { QList<QLineF *> CustomElement::lines() const {
return(m_lines); return(m_lines);
@ -685,20 +678,6 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp, bool addtolist) {
text_document.setDefaultFont(used_font); text_document.setDefaultFont(used_font);
text_document.setPlainText(e.attribute("text")); text_document.setPlainText(e.attribute("text"));
if (addtolist){
//Add element to list of texts.
ElementTextItem *eti = new ElementTextItem(e.attribute("text"));
eti -> setFont(QETApp::diagramTextsFont(size));
eti -> setOriginalPos(QPointF(pos_x, pos_y));
eti -> setPos(pos_x, pos_y);
qreal original_rotation_angle = 0.0;
QET::attributeIsAReal(e, "rotation", &original_rotation_angle);
eti -> setOriginalRotationAngle(original_rotation_angle);
eti -> setRotationAngle(original_rotation_angle);
eti -> setFollowParentRotations(e.attribute("rotate") == "true");
m_texts << eti;
}
// Se positionne aux coordonnees indiquees dans la description du texte // Se positionne aux coordonnees indiquees dans la description du texte
qp.setTransform(QTransform(), false); qp.setTransform(QTransform(), false);
qp.translate(pos_x, pos_y); qp.translate(pos_x, pos_y);
@ -751,37 +730,6 @@ bool CustomElement::parseInput(QDomElement &dom_element) {
!QET::attributeIsAReal(dom_element, "y", &pos_y) ||\ !QET::attributeIsAReal(dom_element, "y", &pos_y) ||\
!QET::attributeIsAnInteger(dom_element, "size", &size) !QET::attributeIsAnInteger(dom_element, "size", &size)
) return(false); ) return(false);
// //The text have a tagg, we create an element text item
// if (dom_element.attribute("tagg", "none") != "none")
// {
// ElementTextItem *eti = new ElementTextItem(dom_element.attribute("text"), this);
// eti -> setFont(QETApp::diagramTextsFont(size));
// eti -> setTagg(dom_element.attribute("tagg", "other"));
// m_element_informations.addValue(dom_element.attribute("tagg", "other"), dom_element.attribute("text"));
// // position the text field
// eti -> setOriginalPos(QPointF(pos_x, pos_y));
// eti -> setPos(pos_x, pos_y);
// // rotation of the text field
// qreal original_rotation_angle = 0.0;
// QET::attributeIsAReal(dom_element, "rotation", &original_rotation_angle);
// eti -> setOriginalRotationAngle(original_rotation_angle);
// eti -> setRotationAngle(original_rotation_angle);
// // behavior when the parent element is rotated
// eti -> setFollowParentRotations(dom_element.attribute("rotate") == "true");
// m_texts << eti;
// connect(eti, &ElementTextItem::diagramTextChanged, this, &Element::textItemChanged);
// return(eti);
// }
//The text haven't got a tagg, so we convert it to a dynamic text item
//and store it to m_converted_text_from_xml_description, instead of m_dynamic_text_list
//because these dynamic text need post treatement
else else
{ {
DynamicElementTextItem *deti = new DynamicElementTextItem(this); DynamicElementTextItem *deti = new DynamicElementTextItem(this);
@ -1079,34 +1027,3 @@ void CustomElement::setPainterStyle(QDomElement &e, QPainter &qp) {
// mise en place (ou non) de l'antialiasing // mise en place (ou non) de l'antialiasing
setQPainterAntiAliasing(qp, e.attribute("antialias") == "true"); setQPainterAntiAliasing(qp, e.attribute("antialias") == "true");
} }
/**
* @brief CustomElement::setTaggedText
* Set text @newstr to the text tagged with @tagg.
* If tagg is found return the text item, else return NULL.
* @param tagg required tagg
* @param newstr new label
* @param noeditable set editable or not (by default, set editable)
*/
ElementTextItem* CustomElement::setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable) {
ElementTextItem *eti = taggedText(tagg);
if (eti) {
eti -> setPlainText(newstr);
eti -> setNoEditable(noeditable);
}
return eti;
}
/**
* @brief CustomElement::taggedText
* return the text field tagged with @tagg or NULL if text field isn't found
* Some of available taggs :
* function, tension-protocol, label, comment, location
* @param tagg
*/
ElementTextItem* CustomElement::taggedText(const QString &tagg) const {
foreach (ElementTextItem *eti, m_texts) {
if (eti -> tagg() == tagg) return eti;
}
return nullptr;
}

View File

@ -22,7 +22,6 @@
#include "elementslocation.h" #include "elementslocation.h"
#include <QPicture> #include <QPicture>
class ElementTextItem;
class Terminal; class Terminal;
/** /**
@ -50,7 +49,6 @@ class CustomElement : public FixedElement
QPicture drawing; QPicture drawing;
QPicture low_zoom_drawing; QPicture low_zoom_drawing;
QList<Terminal *> m_terminals; QList<Terminal *> m_terminals;
QList<ElementTextItem *> m_texts;
QList<DynamicElementTextItem *> m_dynamic_texts; QList<DynamicElementTextItem *> m_dynamic_texts;
bool forbid_antialiasing; bool forbid_antialiasing;
@ -65,7 +63,6 @@ class CustomElement : public FixedElement
public: public:
QList<Terminal *> terminals() const override; QList<Terminal *> terminals() const override;
QList<Conductor *> conductors() const override; QList<Conductor *> conductors() const override;
QList<ElementTextItem *> texts() const override;
QList<QLineF *> lines() const override; QList<QLineF *> lines() const override;
QList<QRectF *> rectangles() const override; QList<QRectF *> rectangles() const override;
QList<QRectF *> circles() const override; QList<QRectF *> circles() const override;
@ -76,7 +73,6 @@ class CustomElement : public FixedElement
QString typeId() const override; QString typeId() const override;
ElementsLocation location() const; ElementsLocation location() const;
QString name() const override; QString name() const override;
ElementTextItem* taggedText(const QString &tagg) const override;
protected: protected:
virtual bool buildFromXml(const QDomElement &, int * = nullptr); virtual bool buildFromXml(const QDomElement &, int * = nullptr);
@ -95,8 +91,6 @@ class CustomElement : public FixedElement
virtual void setQPainterAntiAliasing(QPainter &, bool); virtual void setQPainterAntiAliasing(QPainter &, bool);
virtual bool validOrientationAttribute(const QDomElement &); virtual bool validOrientationAttribute(const QDomElement &);
virtual void setPainterStyle(QDomElement &, QPainter &); virtual void setPainterStyle(QDomElement &, QPainter &);
ElementTextItem* setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable=false);
}; };
/** /**

View File

@ -18,7 +18,6 @@
#include "element.h" #include "element.h"
#include "diagram.h" #include "diagram.h"
#include "conductor.h" #include "conductor.h"
#include "elementtextitem.h"
#include "diagramcommands.h" #include "diagramcommands.h"
#include <QtDebug> #include <QtDebug>
#include "elementprovider.h" #include "elementprovider.h"
@ -237,24 +236,6 @@ void Element::rotateBy(const qreal &angle) {
p -> updateConductor(); p -> updateConductor();
} }
} }
// repositionne les textes de l'element qui ne comportent pas l'option "FollowParentRotations"
foreach(ElementTextItem *eti, texts()) {
if (!eti -> followParentRotations()) {
// on souhaite pivoter le champ de texte par rapport a son centre
QPointF eti_center = eti -> boundingRect().center();
// pour ce faire, on repere la position de son centre par rapport a son parent
QPointF parent_eti_center_before = eti -> mapToParent(eti_center);
// on applique ensuite une simple rotation contraire, qui sera donc appliquee sur le milieu du cote gauche du champ de texte
eti -> rotateBy(-applied_angle);
// on regarde ensuite la nouvelle position du centre du champ de texte par rapport a son parent
QPointF parent_eti_center_after = eti -> mapToParent(eti_center);
// on determine la translation a appliquer
QPointF eti_translation = parent_eti_center_before - parent_eti_center_after;
// on applique cette translation
eti -> setPos(eti -> pos() + eti_translation);
}
}
} }
/*** Methodes protegees ***/ /*** Methodes protegees ***/
@ -344,25 +325,6 @@ void Element::updatePixmap() {
paint(&p, nullptr); paint(&p, nullptr);
} }
/**
This class is used to retrieve label and function information from element
and add it to Diagram Context. Used to make older versions work correctly
@param Element Text item to check information
*/
void Element::etiToElementLabels(ElementTextItem *eti) {
if (eti->tagg() == "label" && eti->toPlainText()!= "_") {
DiagramContext &dc = this->rElementInformations();
dc.addValue("label", eti->toPlainText());
this->setElementInformations(dc);
this->setTaggedText("label", eti->toPlainText());
}
else if(eti->tagg() == "function" && eti->toPlainText() != "_") {
DiagramContext &dc = this->rElementInformations();
dc.addValue("function", eti->toPlainText());
this->setElementInformations(dc);
}
}
/** /**
Permet de savoir si un element XML (QDomElement) represente bien un element Permet de savoir si un element XML (QDomElement) represente bien un element
@param e Le QDomElement a valide @param e Le QDomElement a valide
@ -580,20 +542,6 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
delete deti; delete deti;
m_converted_text_from_xml_description.clear(); m_converted_text_from_xml_description.clear();
//For the moment the text item with a tagg are not converted to dynamic text item
//so we must to check it
foreach(QGraphicsItem *qgi, childItems())
{
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi))
{
foreach(QDomElement input, inputs)
{
eti -> fromXml(input);
etiToElementLabels(eti);
}
}
}
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");
@ -620,30 +568,6 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
setElementInformations(dc); setElementInformations(dc);
/**
* At the start of the 0.51 devel, if the text item with tagg "label" was edited directly in the diagram,
* the text was not write to the element information value "formula".
* During the devel, this behavior change, when user edit the text item direclty in the diagram,
* the text was also write in the element information.
* Then when open a .qet file, the text item with tagg "label", is write with the value stored in the element information.
* The mistake is :
* if user write directly in the diagram with a version befor the change (so the text is not in the element information),
* and open the project with a version after the change, then the text item with tagg "label" is empty.
* The code below fix this.
*/
if (saved_version > -1 && saved_version <= 0.51)
{
if (ElementTextItem *eti = taggedText("label"))
{
if (m_element_informations["label"].toString().isEmpty() &&
m_element_informations["formula"].toString().isEmpty() &&
!eti->toPlainText().isEmpty())
{
m_element_informations.addValue("formula", eti->toPlainText());
}
}
}
/** /**
During the devel of the version 0.7, the "old text" was replaced by the dynamic element text item. During the devel of the version 0.7, the "old text" was replaced by the dynamic element text item.
When open a project made befor the 0.7, we must to reproduce the same visual when the label are not empty and visible, When open a project made befor the 0.7, we must to reproduce the same visual when the label are not empty and visible,
@ -837,9 +761,6 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
// enregistrement des champ de texte de l'appareil // enregistrement des champ de texte de l'appareil
QDomElement inputs = document.createElement("inputs"); QDomElement inputs = document.createElement("inputs");
foreach(ElementTextItem *eti, texts()) {
inputs.appendChild(eti -> toXml(document));
}
element.appendChild(inputs); element.appendChild(inputs);
//if this element is linked to other elements, //if this element is linked to other elements,
@ -1261,6 +1182,8 @@ void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
*/ */
void Element::setUpFormula(bool code_letter) void Element::setUpFormula(bool code_letter)
{ {
Q_UNUSED(code_letter)
if (linkType() == Element::Slave || linkType() & Element::AllReport) if (linkType() == Element::Slave || linkType() & Element::AllReport)
return; return;
@ -1268,22 +1191,6 @@ void Element::setUpFormula(bool code_letter)
{ {
QString formula = diagram()->project()->elementAutoNumCurrentFormula(); QString formula = diagram()->project()->elementAutoNumCurrentFormula();
if (formula.isEmpty())
{
if (code_letter && !m_prefix.isEmpty())
{
if (ElementTextItem *eti = taggedText("label"))
{
QString text = eti->toPlainText();
if (text.isEmpty() || text == "_")
{
m_element_informations.addValue("formula", "%prefix");
}
}
}
}
else
{
m_element_informations.addValue("formula", formula); m_element_informations.addValue("formula", formula);
QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum(); QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
@ -1292,7 +1199,7 @@ void Element::setUpFormula(bool code_letter)
autonum::setSequential(formula, m_autoNum_seq, nc, diagram(), element_currentAutoNum); autonum::setSequential(formula, m_autoNum_seq, nc, diagram(), element_currentAutoNum);
diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next()); diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
}
if(!m_freeze_label && !formula.isEmpty()) if(!m_freeze_label && !formula.isEmpty())
{ {
DiagramContext dc = m_element_informations; DiagramContext dc = m_element_informations;
@ -1303,57 +1210,6 @@ void Element::setUpFormula(bool code_letter)
} }
} }
/**
* @brief ElementTextItem::setTaggedText
* Set text @newstr to the text tagged with @tagg.
* If tagg is found return the text item, else return NULL.
* @param tagg required tagg
* @param newstr new label
* @param noeditable set editable or not (by default, set editable)
*/
ElementTextItem* Element::setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable) {
ElementTextItem *eti = taggedText(tagg);
if (eti) {
eti -> setPlainText(newstr);
eti -> setNoEditable(noeditable);
}
return eti;
}
/**
* @brief Element::textItemChanged
* Use to keep up to date the element information when text item changed.
* @param dti
* @param old_str
* @param new_str
*/
void Element::textItemChanged(DiagramTextItem *dti, QString old_str, QString new_str)
{
Q_UNUSED(new_str)
if (!diagram())
return;
ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(dti);
if (!eti)
return;
QString tagg = eti->tagg();
if (m_element_informations.contains(tagg))
{
DiagramContext dc = m_element_informations;
dc.addValue(tagg, eti->toPlainText(), dc.keyMustShow(tagg));
if (tagg == "label")
dc.addValue("formula", eti->toPlainText(), dc.keyMustShow("formula"));
diagram()->undoStack().push(new ChangeElementInformationCommand(this, m_element_informations, dc));
}
else
{
diagram()->undoStack().push(new ChangeDiagramTextCommand(eti, old_str, eti->toPlainText()));
}
}
/** /**
* @brief Element::getPrefix * @brief Element::getPrefix
* get Element Prefix * get Element Prefix
@ -1376,15 +1232,7 @@ void Element::setPrefix(QString prefix) {
*/ */
void Element::freezeLabel(bool freeze) void Element::freezeLabel(bool freeze)
{ {
if (m_freeze_label != freeze)
{
m_freeze_label = freeze; m_freeze_label = freeze;
QString f = m_element_informations["formula"].toString();
setUpConnectionForFormula(f,f);
if (m_freeze_label == true)
updateLabel();
}
} }
/** /**
@ -1397,45 +1245,3 @@ void Element::freezeNewAddedElement() {
} }
else return; else return;
} }
/**
* @brief Element::setUpConnectionForFormula
* setup connection according to the variable of formula
* @param old_formula
* @param new_formula
*/
void Element::setUpConnectionForFormula(QString old_formula, QString new_formula)
{
//Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id
if (diagram() && old_formula.contains("%F"))
{
disconnect(&diagram()->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &Element::updateLabel);
old_formula.replace("%F", m_F_str);
}
if (diagram() && (old_formula.contains("%f") || old_formula.contains("%id")))
disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel);
if (old_formula.contains("%l"))
disconnect(this, &Element::yChanged, this, &Element::updateLabel);
if (old_formula.contains("%c"))
disconnect(this, &Element::xChanged, this, &Element::updateLabel);
//Label is frozen, so we don't update it.
if (m_freeze_label == true)
return;
if (diagram() && new_formula.contains("%F"))
{
m_F_str = diagram()->border_and_titleblock.folio();
new_formula.replace("%F", m_F_str);
connect(&diagram()->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &Element::updateLabel);
}
if (diagram() && (new_formula.contains("%f") || new_formula.contains("%id")))
connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &Element::updateLabel);
if (new_formula.contains("%l"))
connect(this, &Element::yChanged, this, &Element::updateLabel);
if (new_formula.contains("%c"))
connect(this, &Element::xChanged, this, &Element::updateLabel);
}

View File

@ -24,7 +24,6 @@
#include "assignvariables.h" #include "assignvariables.h"
#include <algorithm> #include <algorithm>
class ElementTextItem;
class QETProject; class QETProject;
class Terminal; class Terminal;
class Conductor; class Conductor;
@ -81,10 +80,6 @@ class Element : public QetGraphicsItem
virtual QList<Terminal *> terminals() const = 0; virtual QList<Terminal *> terminals() const = 0;
/// @return the list of conductors attached to this element /// @return the list of conductors attached to this element
virtual QList<Conductor *> conductors() const = 0; virtual QList<Conductor *> conductors() const = 0;
/// @return the list of text items attached to this element
virtual QList<ElementTextItem *> texts() const = 0;
/// @return the text field tagged with @tagg or NULL if text field isn't found
virtual ElementTextItem* taggedText(const QString &tagg) const = 0;
/// @return the list of lines items in this element /// @return the list of lines items in this element
virtual QList<QLineF *> lines() const = 0; virtual QList<QLineF *> lines() const = 0;
/// @return the list of rectangles items in this element /// @return the list of rectangles items in this element
@ -126,12 +121,10 @@ class Element : public QetGraphicsItem
QList <QUuid> tmp_uuids_link; QList <QUuid> tmp_uuids_link;
QUuid uuid_; QUuid uuid_;
kind m_link_type; kind m_link_type;
ElementTextItem* setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable=false);
signals: signals:
void linkedElementChanged(); //This signal is emited when the linked elements with this element change 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 updateLabel(); //This signal is emited to update element's label
void textAdded(DynamicElementTextItem *deti); void textAdded(DynamicElementTextItem *deti);
void textRemoved(DynamicElementTextItem *deti); void textRemoved(DynamicElementTextItem *deti);
void textsGroupAdded(ElementTextItemGroup *group); void textsGroupAdded(ElementTextItemGroup *group);
@ -141,7 +134,6 @@ class Element : public QetGraphicsItem
//METHODS related to information //METHODS related to information
public: public:
void textItemChanged(DiagramTextItem *dti, QString old_str, QString new_str);
DiagramContext elementInformations ()const {return m_element_informations;} DiagramContext elementInformations ()const {return m_element_informations;}
DiagramContext& rElementInformations () {return m_element_informations;} DiagramContext& rElementInformations () {return m_element_informations;}
virtual void setElementInformations (DiagramContext dc); virtual void setElementInformations (DiagramContext dc);
@ -159,9 +151,6 @@ class Element : public QetGraphicsItem
bool isFreezeLabel() const {return m_freeze_label;} bool isFreezeLabel() const {return m_freeze_label;}
void freezeNewAddedElement(); void freezeNewAddedElement();
protected:
virtual void setUpConnectionForFormula(QString old_formula, QString new_formula);
//ATTRIBUTES //ATTRIBUTES
protected: protected:
DiagramContext m_element_informations, m_kind_informations; DiagramContext m_element_informations, m_kind_informations;
@ -224,7 +213,6 @@ class Element : public QetGraphicsItem
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
void updatePixmap(); void updatePixmap();
void etiToElementLabels(ElementTextItem*);
protected: protected:
void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ) override; void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ) override;

View File

@ -1,373 +0,0 @@
/*
Copyright 2006-2017 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "elementtextitem.h"
#include "element.h"
#include <QTextDocument>
#include "diagram.h"
#include "diagramcommands.h"
/**
Constructeur
@param parent_element Le QGraphicsItem parent du champ de texte
@param parent_diagram Le schema auquel appartient le champ de texte
*/
ElementTextItem::ElementTextItem(Element *parent_element) :
DiagramTextItem(parent_element),
parent_element_(parent_element),
follow_parent_rotations(false),
original_rotation_angle_(0.0)
{build();}
/**
Constructeur
@param parent_element L'element parent du champ de texte
@param parent_diagram Le schema auquel appartient le champ de texte
@param text Le texte affiche par le champ de texte
*/
ElementTextItem::ElementTextItem(const QString &text, Element *parent_element) :
DiagramTextItem(text, parent_element),
parent_element_(parent_element),
follow_parent_rotations(false),
original_rotation_angle_(0.0)
{build();}
void ElementTextItem::build() {
adjustItemPosition(1);
// ajuste la position du QGraphicsItem lorsque le QTextDocument change
connect(document(), SIGNAL(blockCountChanged(int)), this, SLOT(adjustItemPosition(int)));
connect(document(), SIGNAL(contentsChanged()), this, SLOT(adjustItemPosition()));
}
/// Destructeur
ElementTextItem::~ElementTextItem() {
}
/**
@return L'element parent de ce champ de texte, ou 0 si celui-ci n'en a pas.
*/
Element *ElementTextItem::parentElement() const {
return(parent_element_);
}
/**
Permet de lire le texte a mettre dans le champ a partir d'un element XML.
Cette methode se base sur la position du champ pour assigner ou non la
valeur a ce champ.
@param e L'element XML representant le champ de texte
*/
void ElementTextItem::fromXml(const QDomElement &e) {
QPointF _pos = pos();
if (
qFuzzyCompare(qreal(e.attribute("x").toDouble()), _pos.x()) &&
qFuzzyCompare(qreal(e.attribute("y").toDouble()), _pos.y())
) {
setPlainText(e.attribute("text"));
qreal user_pos_x, user_pos_y;
if (
QET::attributeIsAReal(e, "userx", &user_pos_x) &&
QET::attributeIsAReal(e, "usery", &user_pos_y)
) {
setPos(user_pos_x, user_pos_y);
}
qreal xml_rotation_angle;
if (QET::attributeIsAReal(e, "userrotation", &xml_rotation_angle)) {
setRotationAngle(xml_rotation_angle);
}
}
}
/**
@param document Le document XML a utiliser
@return L'element XML representant ce champ de texte
*/
QDomElement ElementTextItem::toXml(QDomDocument &document) const {
QDomElement result = document.createElement("input");
result.setAttribute("x", QString("%1").arg(originalPos().x()));
result.setAttribute("y", QString("%1").arg(originalPos().y()));
if (pos() != originalPos()) {
result.setAttribute("userx", QString("%1").arg(pos().x()));
result.setAttribute("usery", QString("%1").arg(pos().y()));
}
result.setAttribute("text", toPlainText());
if (rotationAngle() != originalRotationAngle()) {
result.setAttribute("userrotation", QString("%1").arg(rotationAngle()));
}
return(result);
}
/**
@param p Position originale / de reference pour ce champ
Cette position est utilisee lors de l'export en XML
*/
void ElementTextItem::setOriginalPos(const QPointF &p) {
original_position = p;
}
/**
@return la position originale / de reference pour ce champ
*/
QPointF ElementTextItem::originalPos() const {
return(original_position);
}
/**
Definit l'angle de rotation original de ce champ de texte
@param rotation_angle un angle de rotation
*/
void ElementTextItem::setOriginalRotationAngle(const qreal &rotation_angle) {
original_rotation_angle_ = QET::correctAngle(rotation_angle);
}
/**
@return l'angle de rotation original de ce champ de texte
*/
qreal ElementTextItem::originalRotationAngle() const {
return(original_rotation_angle_);
}
/**
Set the font used to render the text item to \a font.
*/
void ElementTextItem::setFont(const QFont &font) {
DiagramTextItem::setFont(font);
adjustItemPosition(1);
}
/**
Cette methode s'assure que la position de l'ElementTextItem est coherente
en ajustant :
* la transformation de base qui permet de considerer que l'origine
correspond au milieu du bord gauche du champ de texte
* l'origine utilisee lors des appels a setRotation et setScale
@param new_block_count Nombre de blocs dans l'ElementTextItem
*/
void ElementTextItem::adjustItemPosition(int new_block_count) {
Q_UNUSED(new_block_count);
qreal origin_offset = boundingRect().bottom() / 2.0;
QTransform base_translation;
base_translation.translate(0.0, -origin_offset);
setTransform(base_translation, false);
setTransformOriginPoint(0.0, origin_offset);
}
/**
* @brief ElementTextItem::mouseDoubleClickEvent
* @param event
*/
void ElementTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
/*
* Before revision 3559, report element haven't got text tagged label
* so if parent is a report and haven't got text tagged label,
* we know if this text is used has tagged label.
*/
bool report_text = false;
if (parent_element_ -> linkType() & Element::AllReport && !parent_element_ -> taggedText("label"))
{
//This is the first of list, so this text is used to display
//pos of linked report.
if (parent_element_ -> texts().first() == this)
report_text = true;
}
if ( (tagg_ == "label" || report_text) && !parent_element_ -> isFree())
{
//If parent is linked, show the linked element
if ( parent_element_ -> linkType() & (Element::AllReport | Element::Slave) )
{
//Unselect and ungrab mouse to prevent unwanted
//move when linked element is in the same scene of this.
setSelected(false);
ungrabMouse();
//Show and select the linked element
Element *linked = parent_element_ -> linkedElements().first();
if (scene() != linked -> scene())
linked -> diagram() -> showMe();
linked -> setSelected(true);
//Zoom to the linked element
foreach(QGraphicsView *view, linked -> diagram() -> views()) {
QRectF fit = linked -> sceneBoundingRect();
fit.adjust(-200, -200, 200, 200);
view -> fitInView(fit, Qt::KeepAspectRatioByExpanding);
}
}
}
else
{
DiagramTextItem::mouseDoubleClickEvent(event);
}
}
/**
* @brief ElementTextItem::mouseMoveEvent
* @param e
*/
void ElementTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
if (textInteractionFlags() & Qt::TextEditable) {
DiagramTextItem::mouseMoveEvent(event);
} else if ((flags() & QGraphicsItem::ItemIsMovable) && (event -> buttons() & Qt::LeftButton)) {
QPointF old_pos = pos();
/*
* Use e -> pos() directly will be have for behavior to pos the origin
* of the text field to the position pointed by the cursor, that isn't the wanted effect.
* Instead of this, we apply to the actual pos,
* the vector defined by the movement of cursor since the last pos clicked by left button
*/
QPointF movement = event -> pos() - event -> buttonDownPos(Qt::LeftButton);
/*
* the method pos() and setPos() always work with coordinate of parent item
* (or scene if there isn't parent) we don't forget to map the movemement to parent
* before applyRotation
*/
QPointF new_pos = pos() + mapMovementToParent(movement);
event -> modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
Diagram *diagram_ptr = diagram();
if (diagram_ptr) {
if (m_first_move) {
//We signal the beginning of movement to the parent diagram
int moved_texts_count = diagram_ptr -> beginMoveElementTexts(this);
parent_element_ -> setHighlighted(true);
//If there is one texte to move, we highlight the parent element.
if (moved_texts_count == 1 && parent_element_) {
parent_element_ -> setHighlighted(true);
parent_element_ -> update();
}
}
/*
Comme setPos() n'est pas oblige d'appliquer exactement la
valeur qu'on lui fournit, on calcule le mouvement reellement
applique.
*/
QPointF effective_movement = pos() - old_pos;
QPointF scene_effective_movement = mapMovementToScene(mapMovementFromParent(effective_movement));
// on applique le mouvement subi aux autres textes a deplacer
diagram_ptr -> continueMoveElementTexts(event);
}
} else event -> ignore();
if (m_first_move) {
m_first_move = false;
}
}
/**
* @brief ElementTextItem::mouseReleaseEvent
* @param e
*/
void ElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
if (Diagram *diagram_ptr = diagram()) {
if (parent_element_) {
if (parent_element_ -> isHighlighted()) {
parent_element_ -> setHighlighted(false);
}
}
diagram_ptr -> endMoveElementTexts();
}
if (!(event -> modifiers() & Qt::ControlModifier)) {
QGraphicsTextItem::mouseReleaseEvent(event);
}
}
/**
* @brief ElementTextItem::hoverEnterEvent
* @param event
*/
void ElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
/*
* Before revision 3559, report element haven't got text tagged label
* so if parent is a report and haven't got text tagged label,
* we know if this text is used has tagged label.
*/
bool report_text = false;
if (parent_element_ -> linkType() & Element::AllReport && !parent_element_ -> taggedText("label"))
{
//This is the first of list, so this text is used to display
//pos of linked report.
if (parent_element_ -> texts().first() == this)
report_text = true;
}
if (tagg_ == "label" || report_text)
{
if (parent_element_ -> linkType() & (Element::AllReport | Element::Slave) && !parent_element_->isFree()) {
setDefaultTextColor(Qt::blue);
//Also color the child text if parent is a slave and linked
if (parent_element_-> linkType() == Element::Slave && !parent_element_ -> isFree())
foreach (QGraphicsItem *qgi, childItems())
if (QGraphicsTextItem *qgti = qgraphicsitem_cast<QGraphicsTextItem *> (qgi))
qgti -> setDefaultTextColor(Qt::blue);
}
}
DiagramTextItem::hoverEnterEvent(event);
}
/**
* @brief ElementTextItem::hoverLeaveEvent
* @param event
*/
void ElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
/*
* Before revision 3559, report element haven't got text tagged label
* so if parent is a report and haven't got text tagged label,
* we know if this text is used has tagged label.
*/
bool report_text = false;
if (parent_element_ -> linkType() & Element::AllReport && !parent_element_ -> taggedText("label"))
{
//This is the first of list, so this text is used to display
//pos of linked report.
if (parent_element_ -> texts().first() == this)
report_text = true;
}
if (tagg_ == "label" || report_text)
{
if (defaultTextColor() != Qt::black)
setDefaultTextColor(Qt::black);
//Also color the child text if parent is a slave and linked
if (parent_element_-> linkType() == Element::Slave && !parent_element_ -> isFree())
foreach (QGraphicsItem *qgi, childItems())
if (QGraphicsTextItem *qgti = qgraphicsitem_cast<QGraphicsTextItem *> (qgi))
qgti -> setDefaultTextColor(Qt::black);
}
DiagramTextItem::hoverLeaveEvent(event);
}

View File

@ -1,98 +0,0 @@
/*
Copyright 2006-2017 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ELEMENT_TEXT_ITEM_H
#define ELEMENT_TEXT_ITEM_H
#include "diagramtextitem.h"
class Element;
/**
This class represents a text item attached to an element. Users can change its
value, adjust its position (defined relatively to its parent element), and
direct it to any angle.
*/
class ElementTextItem : public DiagramTextItem {
Q_OBJECT
// constructors, destructor
public:
ElementTextItem(Element * = nullptr);
ElementTextItem(const QString &, Element * = nullptr);
~ElementTextItem() override;
// attributes
public:
enum { Type = UserType + 1003 };
int type () const override { return Type; }
private:
Element *parent_element_;
bool follow_parent_rotations;
QPointF original_position;
qreal original_rotation_angle_;
QString tagg_;
// methods
public:
Element *parentElement () const;
void fromXml ( const QDomElement & ) override;
QDomElement toXml ( QDomDocument & ) const override;
void setOriginalPos ( const QPointF & );
QPointF originalPos () const;
void setOriginalRotationAngle ( const qreal & );
qreal originalRotationAngle () const;
virtual void setFont ( const QFont & );
void setTagg ( const QString &str ) {tagg_ = str;}
QString tagg () const {return tagg_;}
void setFollowParentRotations ( bool fpr);
bool followParentRotations () const;
public slots:
void adjustItemPosition(int = 0);
protected:
void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *event ) override;
void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ) override;
void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event ) override;
void hoverEnterEvent ( QGraphicsSceneHoverEvent *event ) override;
void hoverLeaveEvent ( QGraphicsSceneHoverEvent *event ) override;
private:
void build ();
};
/**
Element text items can optionally be applied a counter-rotation when their
parent element is rotated, thus preserving their readability.
@return whether this text item follows the rotations of its parent element.
*/
inline bool ElementTextItem::followParentRotations() const {
return(follow_parent_rotations);
}
/**
Element text items can optionally be applied a counter-rotation when their
parent element is rotated, thus preserving their readability.
@param frp whether this text item should follow the rotations of its parent
element.
*/
inline void ElementTextItem::setFollowParentRotations(bool frp) {
follow_parent_rotations = frp;
}
#endif

View File

@ -18,7 +18,6 @@
#include "ghostelement.h" #include "ghostelement.h"
#include "qet.h" #include "qet.h"
#include "terminal.h" #include "terminal.h"
#include "elementtextitem.h"
#include "diagramcommands.h" #include "diagramcommands.h"
/** /**

View File

@ -17,7 +17,6 @@
*/ */
#include "masterelement.h" #include "masterelement.h"
#include "crossrefitem.h" #include "crossrefitem.h"
#include "elementtextitem.h"
#include "diagram.h" #include "diagram.h"
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
#include <QRegularExpression> #include <QRegularExpression>
@ -34,9 +33,6 @@ MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qg
CustomElement(location, qgi, state) CustomElement(location, qgi, state)
{ {
m_link_type = Element::Master; m_link_type = Element::Master;
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
connect(this, &Element::updateLabel, [this]() {this->updateLabel(this->elementInformations(), this->elementInformations());});
} }
/** /**
@ -114,7 +110,6 @@ void MasterElement::unlinkElement(Element *elmt)
void MasterElement::initLink(QETProject *project) { void MasterElement::initLink(QETProject *project) {
//Create the link with other element if needed //Create the link with other element if needed
CustomElement::initLink(project); CustomElement::initLink(project);
updateLabel(DiagramContext(), elementInformations());
} }
/** /**
@ -130,38 +125,6 @@ QRectF MasterElement::XrefBoundingRect() const
return QRectF(); return QRectF();
} }
/**
* @brief MasterElement::updateLabel
* update label of this element
* and the comment item if he's displayed.
*/
void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
{
QString old_formula = old_info["formula"].toString();
QString new_formula = new_info["formula"].toString();
setUpConnectionForFormula(old_formula, new_formula);
QString label = autonum::AssignVariables::formulaToLabel(new_formula, m_autoNum_seq, diagram(), this);
if (label.isEmpty())
{
setTaggedText("label", new_info["label"].toString());
}
else
{
bool visible = m_element_informations.contains("label") ? m_element_informations.keyMustShow("label") : true;
m_element_informations.addValue("label", label, visible);
setTaggedText("label", label);
}
if (ElementTextItem *eti = taggedText("label"))
{
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
}
}
QVariant MasterElement::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant MasterElement::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if(change == QGraphicsItem::ItemSceneHasChanged && m_first_scene_change) if(change == QGraphicsItem::ItemSceneHasChanged && m_first_scene_change)

View File

@ -42,9 +42,6 @@ class MasterElement : public CustomElement
void initLink (QETProject *project) override; void initLink (QETProject *project) override;
QRectF XrefBoundingRect() const; QRectF XrefBoundingRect() const;
public slots:
void updateLabel(DiagramContext old_info, DiagramContext new_info);
protected: protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;

View File

@ -16,7 +16,6 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "reportelement.h" #include "reportelement.h"
#include "elementtextitem.h"
#include "diagramposition.h" #include "diagramposition.h"
#include "qetproject.h" #include "qetproject.h"
#include "diagram.h" #include "diagram.h"
@ -25,31 +24,10 @@
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
ReportElement::ReportElement(const ElementsLocation &location, QString link_type,QGraphicsItem *qgi, int *state) : ReportElement::ReportElement(const ElementsLocation &location, QString link_type,QGraphicsItem *qgi, int *state) :
CustomElement(location, qgi, state), CustomElement(location, qgi, state)
m_text_field (nullptr),
m_watched_conductor(nullptr)
{ {
/*
* Get text tagged label. This is work for report
* create after the revision 3559.
* for report create before, we take the first text field
* because report haven't got a text field tagged label
*/
m_text_field = taggedText("label");
if (!m_text_field && !texts().isEmpty())
m_text_field = texts().first();
if (m_text_field)
m_text_field -> setNoEditable();
link_type == "next_report"? m_link_type=NextReport : m_link_type=PreviousReport; link_type == "next_report"? m_link_type=NextReport : m_link_type=PreviousReport;
link_type == "next_report"? m_inverse_report=PreviousReport : m_inverse_report=NextReport; link_type == "next_report"? m_inverse_report=PreviousReport : m_inverse_report=NextReport;
//We make these connections, to be always aware about the conductor properties
if (terminals().size())
{
connect (terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
connect (terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
}
} }
/** /**
@ -61,8 +39,6 @@ ReportElement::~ReportElement()
unlinkAllElements(); unlinkAllElements();
if (terminals().size()) if (terminals().size())
disconnect(terminals().first(), nullptr, nullptr, nullptr); disconnect(terminals().first(), nullptr, nullptr, nullptr);
if (m_watched_conductor)
disconnect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
} }
/** /**
@ -89,24 +65,7 @@ void ReportElement::linkToElement(Element * elmt)
{ {
unlinkAllElements(); unlinkAllElements();
connected_elements << elmt; connected_elements << elmt;
m_formula = diagram()->project()->defaultReportProperties();
setConnectionForFormula(m_formula);
connect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange);
connect(diagram()->project(), &QETProject::diagramRemoved, this, &ReportElement::updateLabel);
if (elmt->terminals().size())
{
connect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
connect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
}
if (!m_watched_conductor && elmt->conductors().size())
conductorWasAdded(elmt->conductors().first());
else
updateLabel();
elmt->linkToElement(this); elmt->linkToElement(this);
emit linkedElementChanged(); emit linkedElementChanged();
} }
} }
@ -123,22 +82,7 @@ void ReportElement::unlinkAllElements()
const QList <Element *> tmp_elmt = connected_elements; const QList <Element *> tmp_elmt = connected_elements;
for (Element *elmt : tmp_elmt) for (Element *elmt : tmp_elmt)
{
removeConnectionForFormula(m_formula);
disconnect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange);
disconnect(diagram()->project(), &QETProject::diagramRemoved, this, &ReportElement::updateLabel);
if (elmt->terminals().size())
{
disconnect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
disconnect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
}
connected_elements.removeAll(elmt); connected_elements.removeAll(elmt);
//if elmt is the owner of m_watched_conductor, we remove it
if (elmt->conductors().contains(m_watched_conductor))
conductorWasRemoved(m_watched_conductor);
}
updateLabel();
for(Element *elmt : tmp_elmt) for(Element *elmt : tmp_elmt)
{ {
@ -159,151 +103,3 @@ void ReportElement::unlinkElement(Element *elmt) {
Q_UNUSED (elmt); Q_UNUSED (elmt);
unlinkAllElements(); unlinkAllElements();
} }
/**
* @brief ReportElement::conductorWasAdded
* This method is called when a conduxtor is added to the potential
* @param conductor : added conductor
*/
void ReportElement::conductorWasAdded(Conductor *conductor)
{
if (m_watched_conductor) return;
m_watched_conductor = conductor;
connect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
updateLabel();
}
/**
* @brief ReportElement::conductorWasRemoved
* This method is called when a conductor is removed to the potential
* @param conductor : removed conductor
*/
void ReportElement::conductorWasRemoved(Conductor *conductor)
{
if (m_watched_conductor != conductor) return;
disconnect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
m_watched_conductor = nullptr;
//Get another conductor to be always up to date about the properties of the potential.
//Get a conducteur docked to this report
if (conductors().size())
conductorWasAdded(conductors().first());
//Else we get a conductor of the linked report (if any)
else if (linkedElements().size() && linkedElements().first()->conductors().size())
conductorWasAdded(linkedElements().first()->conductors().first());
else
updateLabel();
}
/**
* @brief ReportElement::setFormula
* Set new Formula and call updatelabel
* @param formula : the new formula
*/
void ReportElement::setFormula(QString formula)
{
removeConnectionForFormula(m_formula);
m_formula = formula;
setConnectionForFormula(m_formula);
updateLabel();
}
/**
* @brief ReportElement::updateLabel
* Update the displayed label.
* ie the folio and position of the linked folio report
*/
void ReportElement::updateLabel()
{
if (!m_text_field) return;
if (!connected_elements.isEmpty())
{
Element *elmt = connected_elements.at(0);
QString label = m_formula;
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
m_text_field -> setPlainText(label);
}
else
m_text_field -> setPlainText("/");
setTaggedText("function", (m_watched_conductor? m_watched_conductor->properties().m_function : ""));
setTaggedText("tension-protocol", (m_watched_conductor? m_watched_conductor->properties().m_tension_protocol : ""));
}
void ReportElement::reportPropertiesChange(const QString &old_str, const QString &new_str)
{
Q_UNUSED(old_str);
setFormula(new_str);
}
/**
* @brief ReportElement::setConnectionForFormula
* Set up the required connection for the formula @str.
* @param str
*/
void ReportElement::setConnectionForFormula(const QString &str)
{
if (connected_elements.isEmpty() || str.isEmpty())
return;
QString string = str;
Element *other_elmt = connected_elements.first();
Diagram *other_diagram = other_elmt->diagram();
//Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id
if (other_diagram && string.contains("%F"))
{
m_F_str = other_diagram->border_and_titleblock.folio();
string.replace("%F", m_F_str);
connect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &ReportElement::updateFormulaConnection);
}
if (other_diagram && (string.contains("%f") || string.contains("%id")))
connect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &ReportElement::updateLabel);
if (string.contains("%l"))
connect(other_elmt, &Element::yChanged, this, &ReportElement::updateLabel);
if (string.contains("%c"))
connect(other_elmt, &Element::xChanged, this, &ReportElement::updateLabel);
}
/**
* @brief ReportElement::removeConnectionForFormula
* Remove the existing connection made for the formula @str
* @param str
*/
void ReportElement::removeConnectionForFormula(const QString &str)
{
if (connected_elements.isEmpty() || str.isEmpty())
return;
QString string = str;
Element *other_element = connected_elements.first();
Diagram *other_diagram = other_element->diagram();
//Because the variable %F is a reference to another text which can contain variables,
//we must to replace %F by the real text, to check if the real text contain the variable %id
if (other_diagram && string.contains("%F"))
{
string.replace("%F", m_F_str);
disconnect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &ReportElement::updateFormulaConnection);
}
if (other_diagram && (string.contains("%f") || string.contains("%id")))
disconnect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &ReportElement::updateLabel);
if (string.contains("%l"))
disconnect(other_element, &Element::yChanged, this, &ReportElement::updateLabel);
if (string.contains("%c"))
disconnect(other_element, &Element::xChanged, this, &ReportElement::updateLabel);
}
void ReportElement::updateFormulaConnection()
{
removeConnectionForFormula(m_formula);
setConnectionForFormula(m_formula);
updateLabel();
}

View File

@ -20,8 +20,6 @@
#include "customelement.h" #include "customelement.h"
class ElementTextItem;
/** /**
* @brief The ReportElement class * @brief The ReportElement class
*this class represent an element that can be linked to an other ReportElement *this class represent an element that can be linked to an other ReportElement
@ -38,21 +36,8 @@ class ReportElement : public CustomElement
void unlinkAllElements() override; void unlinkAllElements() override;
void unlinkElement(Element *elmt) override; void unlinkElement(Element *elmt) override;
private:
void conductorWasAdded(Conductor *conductor);
void conductorWasRemoved(Conductor *conductor);
void setFormula (QString label);
void updateLabel();
void reportPropertiesChange(const QString &old_str, const QString &new_str);
void setConnectionForFormula(const QString &str);
void removeConnectionForFormula(const QString &str);
void updateFormulaConnection();
private: private:
int m_inverse_report; int m_inverse_report;
QString m_formula;
ElementTextItem *m_text_field;
Conductor *m_watched_conductor;
}; };
#endif // REPORTELEMENT_H #endif // REPORTELEMENT_H

View File

@ -17,7 +17,6 @@
*/ */
#include "simpleelement.h" #include "simpleelement.h"
#include "commentitem.h" #include "commentitem.h"
#include "elementtextitem.h"
#include "diagram.h" #include "diagram.h"
/** /**
@ -33,8 +32,6 @@ SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qg
m_location_item (nullptr) m_location_item (nullptr)
{ {
m_link_type = Simple; m_link_type = Simple;
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
connect(this, &Element::updateLabel, [this]() {this->updateLabel(this->elementInformations(), this->elementInformations());});
} }
/** /**
@ -52,49 +49,4 @@ SimpleElement::~SimpleElement() {
*/ */
void SimpleElement::initLink(QETProject *project) { void SimpleElement::initLink(QETProject *project) {
CustomElement::initLink(project); CustomElement::initLink(project);
updateLabel(DiagramContext(), elementInformations());
}
/**
* @brief SimpleElement::updateLabel
* update label of this element
*/
void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
{
QString old_formula = old_info["formula"].toString();
QString new_formula = new_info["formula"].toString();
setUpConnectionForFormula(old_formula, new_formula);
QString label = autonum::AssignVariables::formulaToLabel(new_formula, m_autoNum_seq, diagram(), this);
if (label.isEmpty())
{
setTaggedText("label", new_info["label"].toString());
}
else
{
bool visible = m_element_informations.contains("label") ? m_element_informations.keyMustShow("label") : true;
m_element_informations.addValue("label", label, visible);
setTaggedText("label", label);
}
if (ElementTextItem *eti = taggedText("label"))
{
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
}
// //Comment and Location of element
// QString comment = new_info["comment"].toString();
// bool must_show = new_info.keyMustShow("comment");
// QString location = new_info["location"].toString();
// bool must_show_location = new_info.keyMustShow("location");
// if ((!(comment.isEmpty() || !must_show) && !m_comment_item)||(!(location.isEmpty() || !must_show_location) && !m_comment_item)) {
// m_comment_item = new CommentItem(this);
// }
// else if (((comment.isEmpty() || !must_show) && m_comment_item) && ((location.isEmpty() || !must_show_location) && m_comment_item)) {
// delete m_comment_item;
// m_comment_item = nullptr;
// }
} }

View File

@ -37,9 +37,6 @@ class SimpleElement : public CustomElement {
void initLink(QETProject *project) override; void initLink(QETProject *project) override;
public slots:
void updateLabel(DiagramContext old_info, DiagramContext new_info);
private: private:
CommentItem *m_comment_item; CommentItem *m_comment_item;
CommentItem *m_location_item; CommentItem *m_location_item;

View File

@ -18,7 +18,6 @@
#include "slaveelement.h" #include "slaveelement.h"
#include "diagramposition.h" #include "diagramposition.h"
#include "qetapp.h" #include "qetapp.h"
#include "elementtextitem.h"
#include "diagram.h" #include "diagram.h"
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
@ -35,8 +34,6 @@ SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi,
{ {
m_xref_item = nullptr; m_xref_item = nullptr;
m_link_type = Slave; m_link_type = Slave;
connect(this, SIGNAL(updateLabel()), this, SLOT(updateLabel()));
} }
/** /**
@ -61,22 +58,8 @@ void SlaveElement::linkToElement(Element *elmt)
if(!isFree()) if(!isFree())
unlinkAllElements(); unlinkAllElements();
for(QMetaObject::Connection c : m_connections)
this->disconnect(c);
m_connections.clear();
connected_elements << elmt; connected_elements << elmt;
QETProject *project = elmt->diagram()->project();
m_connections << connect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel()));
m_connections << connect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
m_connections << connect(elmt, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel()));
m_connections << connect(project, SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
m_connections << connect(project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
m_connections << connect(project, SIGNAL(XRefPropertiesChanged()), this, SLOT(updateLabel()));
m_connections << connect(elmt, SIGNAL(updateLabel()), this, SLOT(updateLabel()));
updateLabel();
elmt -> linkToElement(this); elmt -> linkToElement(this);
emit linkedElementChanged(); emit linkedElementChanged();
} }
@ -109,66 +92,8 @@ void SlaveElement::unlinkElement(Element *elmt)
{ {
connected_elements.removeOne(elmt); connected_elements.removeOne(elmt);
disconnect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel()));
disconnect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
disconnect(elmt, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)),this, SLOT(updateLabel()));
disconnect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
disconnect(diagram()->project(), SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
disconnect(elmt -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateLabel()));
disconnect(elmt, SIGNAL(updateLabel()), this, SLOT(updateLabel()));
delete m_xref_item; m_xref_item = nullptr;
if (ElementTextItem *eti = this->taggedText("label"))
eti->setPlainText("_");
updateLabel();
elmt -> unlinkElement (this) ; elmt -> unlinkElement (this) ;
elmt -> setHighlighted (false); elmt -> setHighlighted (false);
emit linkedElementChanged(); emit linkedElementChanged();
} }
} }
/**
* @brief SlaveElement::updateLabel
* update the label (tagged with label) of this element.
* If this element is connected to a master,
* the label show the string tagged by "label" of the master
* and add a qgraphicstextitem for show the position of the master
*/
void SlaveElement::updateLabel()
{
QString label;
if (ElementTextItem *eti = this->taggedText("label"))
label = eti->toPlainText();
QString Xreflabel;
bool no_editable = false;
//must be linked to set the label of master
if (linkedElements().count())
{
no_editable = true;
Element *elmt = linkedElements().first();
label = elmt->elementInformations()["label"].toString();
XRefProperties xrp = elmt->diagram()->project()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
Xreflabel = xrp.slaveLabel();
Xreflabel = autonum::AssignVariables::formulaToLabel(Xreflabel, elmt->rSequenceStruct(), elmt->diagram(), elmt);
}
else
label = autonum::AssignVariables::formulaToLabel(label, m_autoNum_seq, diagram(), this);
// set the new label
ElementTextItem *eti = setTaggedText("label", label, no_editable);
if (eti && !isFree())
{
if (m_xref_item)
m_xref_item->setPlainText(Xreflabel);
else
{
m_xref_item = new QGraphicsTextItem(Xreflabel, eti);
m_xref_item->setFont(QETApp::diagramTextsFont(5));
m_xref_item->setPos(eti -> boundingRect().bottomLeft());
}
}
}

View File

@ -31,14 +31,8 @@ class SlaveElement : public CustomElement
void unlinkAllElements() override; void unlinkAllElements() override;
void unlinkElement(Element *elmt) override; void unlinkElement(Element *elmt) override;
signals:
private slots:
void updateLabel();
private: private:
QGraphicsTextItem *m_xref_item; QGraphicsTextItem *m_xref_item;
QList<QMetaObject::Connection> m_connections;
}; };
#endif // SLAVEELEMENT_H #endif // SLAVEELEMENT_H

View File

@ -17,7 +17,6 @@
*/ */
#include "terminalelement.h" #include "terminalelement.h"
#include "commentitem.h" #include "commentitem.h"
#include "elementtextitem.h"
/** /**
* @brief TerminalElement::TerminalElement * @brief TerminalElement::TerminalElement
@ -33,9 +32,6 @@ TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem
m_location_item (nullptr) m_location_item (nullptr)
{ {
m_link_type = Terminale; m_link_type = Terminale;
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
connect(this, &Element::updateLabel, [this]() {this->updateLabel(this->elementInformations(), this->elementInformations());});
} }
TerminalElement::~TerminalElement() { TerminalElement::~TerminalElement() {
@ -48,50 +44,5 @@ if (m_comment_item) delete m_comment_item;
*/ */
void TerminalElement::initLink(QETProject *project) { void TerminalElement::initLink(QETProject *project) {
CustomElement::initLink(project); CustomElement::initLink(project);
updateLabel(DiagramContext(), elementInformations());
}
/**
* @brief SimpleElement::updateLabel
* update label of this element
*/
void TerminalElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
{
QString old_formula = old_info["formula"].toString();
QString new_formula = new_info["formula"].toString();
setUpConnectionForFormula(old_formula, new_formula);
QString label = autonum::AssignVariables::formulaToLabel(new_formula, m_autoNum_seq, diagram(), this);
if (label.isEmpty())
{
setTaggedText("label", new_info["label"].toString());
}
else
{
bool visible = m_element_informations.contains("label") ? m_element_informations.keyMustShow("label") : true;
m_element_informations.addValue("label", label, visible);
setTaggedText("label", label);
}
if (ElementTextItem *eti = taggedText("label"))
{
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
}
// //Comment and Location of element
// QString comment = new_info["comment"].toString();
// bool must_show = new_info.keyMustShow("comment");
// QString location = new_info["location"].toString();
// bool must_show_location = new_info.keyMustShow("location");
// if ((!(comment.isEmpty() || !must_show) && !m_comment_item)||(!(location.isEmpty() || !must_show_location) && !m_comment_item)) {
// m_comment_item = new CommentItem(this);
// }
// else if (((comment.isEmpty() || !must_show) && m_comment_item) && ((location.isEmpty() || !must_show_location) && m_comment_item)) {
// delete m_comment_item;
// m_comment_item = nullptr;
// }
} }

View File

@ -31,9 +31,6 @@ class TerminalElement : public CustomElement
~TerminalElement() override; ~TerminalElement() override;
void initLink(QETProject *project) override; void initLink(QETProject *project) override;
public slots:
void updateLabel(DiagramContext old_info, DiagramContext new_info);
private: private:
CommentItem *m_comment_item; CommentItem *m_comment_item;
CommentItem *m_location_item; CommentItem *m_location_item;

View File

@ -19,7 +19,6 @@
#include "element.h" #include "element.h"
#include "conductortextitem.h" #include "conductortextitem.h"
#include "independenttextitem.h" #include "independenttextitem.h"
#include "elementtextitem.h"
#include "dynamicelementtextitem.h" #include "dynamicelementtextitem.h"
#include "elementtextitemgroup.h" #include "elementtextitemgroup.h"
#include "diagramimageitem.h" #include "diagramimageitem.h"
@ -50,10 +49,6 @@ m_angle(angle)
case IndependentTextItem::Type: case IndependentTextItem::Type:
m_text << static_cast<DiagramTextItem *>(item); m_text << static_cast<DiagramTextItem *>(item);
break; break;
case ElementTextItem::Type:
if(item->parentItem() && !item->parentItem()->isSelected())
m_text << static_cast<DiagramTextItem *>(item);
break;
case DynamicElementTextItem::Type: case DynamicElementTextItem::Type:
if(item->parentItem() && !item->parentItem()->isSelected()) if(item->parentItem() && !item->parentItem()->isSelected())
m_text << static_cast<DiagramTextItem *>(item); m_text << static_cast<DiagramTextItem *>(item);