mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 17:50:52 +01:00
slave element: when linked to master, label is replaced by the label of master, and show the position of the master
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2946 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -711,18 +711,19 @@ ElementTextItem *CustomElement::parseInput(QDomElement &e) {
|
||||
|
||||
ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this);
|
||||
eti -> setFont(QETApp::diagramTextsFont(size));
|
||||
eti -> setTagg(e.attribute("tagg", "other"));
|
||||
|
||||
// position du champ de texte
|
||||
// position the text field
|
||||
eti -> setOriginalPos(QPointF(pos_x, pos_y));
|
||||
eti -> setPos(pos_x, pos_y);
|
||||
|
||||
// rotation du champ de texte
|
||||
// rotation of the text field
|
||||
qreal original_rotation_angle = 0.0;
|
||||
QET::attributeIsAReal(e, "rotation", &original_rotation_angle);
|
||||
eti -> setOriginalRotationAngle(original_rotation_angle);
|
||||
eti -> setRotationAngle(original_rotation_angle);
|
||||
|
||||
// comportement du champ lorsque son element parent est pivote
|
||||
// behavior when the parent element is rotated
|
||||
eti -> setFollowParentRotations(e.attribute("rotate") == "true");
|
||||
|
||||
list_texts_ << eti;
|
||||
@@ -900,3 +901,22 @@ void CustomElement::setPainterStyle(QDomElement &e, QPainter &qp) {
|
||||
// mise en place (ou non) de l'antialiasing
|
||||
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 0.
|
||||
* @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) {
|
||||
foreach (ElementTextItem *eti, list_texts_) {
|
||||
if (eti -> tagg() == tagg) {
|
||||
eti -> setPlainText(newstr);
|
||||
eti -> setNoEditable(noeditable);
|
||||
return eti;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ class CustomElement : public FixedElement {
|
||||
virtual void setQPainterAntiAliasing(QPainter &, bool);
|
||||
virtual bool validOrientationAttribute(const QDomElement &);
|
||||
virtual void setPainterStyle(QDomElement &, QPainter &);
|
||||
ElementTextItem* setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable=false);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -503,6 +503,17 @@ void Element::initLink(QETProject *prj) {
|
||||
tmp_uuids_link.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Element::setElementInformations
|
||||
* Set new information for this element.
|
||||
* This method emit @elementInfoChange
|
||||
* @param dc
|
||||
*/
|
||||
void Element::setElementInformations(DiagramContext dc) {
|
||||
element_informations_ = dc;
|
||||
emit elementInfoChange(element_informations_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief comparPos
|
||||
* Compare position of the two elements. Compare 3 points:
|
||||
|
||||
@@ -115,10 +115,13 @@ class Element : public QetGraphicsItem {
|
||||
QUuid uuid_;
|
||||
kind link_type_;
|
||||
|
||||
signals:
|
||||
void elementInfoChange(DiagramContext);
|
||||
|
||||
//METHODS related to information
|
||||
public:
|
||||
DiagramContext elementInformations()const {return element_informations_;}
|
||||
void setElementInformations(DiagramContext dc) {element_informations_ = dc;}
|
||||
void setElementInformations(DiagramContext dc);//{element_informations_ = dc; emit elementInfoChange(dc);}
|
||||
DiagramContext kindInformations() const {return kind_informations_;} //@kind_information_ is used to store more information
|
||||
//about the herited class like contactelement for know
|
||||
// kind of contact (simple tempo) or number of contact show by the element.
|
||||
|
||||
@@ -44,6 +44,7 @@ class ElementTextItem : public DiagramTextItem {
|
||||
QPointF original_position;
|
||||
qreal original_rotation_angle_;
|
||||
bool first_move_;
|
||||
QString tagg_;
|
||||
|
||||
// methods
|
||||
public:
|
||||
@@ -63,6 +64,8 @@ class ElementTextItem : public DiagramTextItem {
|
||||
void setOriginalRotationAngle(const qreal &);
|
||||
qreal originalRotationAngle() const;
|
||||
virtual void setFont(const QFont &);
|
||||
void setTagg(const QString &str) {tagg_ = str;}
|
||||
QString tagg() const {return tagg_;}
|
||||
|
||||
public slots:
|
||||
void adjustItemPosition(int = 0);
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "slaveelement.h"
|
||||
#include "diagramposition.h"
|
||||
#include "qetapp.h"
|
||||
#include "elementtextitem.h"
|
||||
|
||||
/**
|
||||
* @brief SlaveElement::SlaveElement
|
||||
@@ -28,6 +31,7 @@
|
||||
SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
||||
CustomElement(location, qgi, s, state)
|
||||
{
|
||||
Xref_item = NULL;
|
||||
link_type_ = Slave;
|
||||
}
|
||||
|
||||
@@ -50,6 +54,9 @@ void SlaveElement::linkToElement(Element *elmt) {
|
||||
if (elmt->linkType() == Master && !connected_elements.contains(elmt)) {
|
||||
if(!isFree()) unlinkAllElements();
|
||||
connected_elements << elmt;
|
||||
updateLabel();
|
||||
connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel()));
|
||||
connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
||||
elmt->linkToElement(this);
|
||||
}
|
||||
}
|
||||
@@ -76,6 +83,47 @@ void SlaveElement::unlinkElement(Element *elmt) {
|
||||
//Ensure elmt is linked to this element
|
||||
if (connected_elements.contains(elmt)) {
|
||||
connected_elements.removeOne(elmt);
|
||||
disconnect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel()));
|
||||
disconnect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
||||
delete Xref_item; Xref_item = NULL;
|
||||
updateLabel();
|
||||
elmt->unlinkElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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("_");
|
||||
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();
|
||||
|
||||
Xreflabel = "(";
|
||||
Xreflabel += QString::number(elmt->diagram()->folioIndex()+1);
|
||||
Xreflabel += "-";
|
||||
Xreflabel += elmt->diagram() -> convertPosition(elmt -> scenePos()).toString();
|
||||
Xreflabel += ")";
|
||||
}
|
||||
|
||||
// set the new label
|
||||
ElementTextItem *eti = setTaggedText("label", label, no_editable);
|
||||
if (eti && !isFree()) {
|
||||
if (Xref_item) Xref_item -> setPlainText(Xreflabel);
|
||||
else {
|
||||
Xref_item = new QGraphicsTextItem(Xreflabel, eti);
|
||||
Xref_item -> setFont(QETApp::diagramTextsFont(5));
|
||||
Xref_item -> setPos(eti -> boundingRect().bottomLeft());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,11 @@ class SlaveElement : public CustomElement
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void updateLabel();
|
||||
|
||||
private:
|
||||
QGraphicsTextItem *Xref_item;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user