Element : edit an element text item (with tagg) directly on the folio, also update the information of the element.

For exemple, edit the element text item tagged "label", update the value with key "label" of element information. 


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4804 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-12-08 16:54:41 +00:00
parent 9f014d55af
commit ae2afe8424
5 changed files with 72 additions and 102 deletions

View File

@@ -1011,14 +1011,6 @@ void Diagram::addItem(QGraphicsItem *item)
switch (item->type()) switch (item->type())
{ {
case Element::Type:
{
Element *elmt = static_cast<Element*>(item);
foreach(ElementTextItem *eti, elmt->texts())
connect (eti, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
}
break;
case Conductor::Type: case Conductor::Type:
{ {
Conductor *conductor = static_cast<Conductor *>(item); Conductor *conductor = static_cast<Conductor *>(item);
@@ -1048,15 +1040,6 @@ void Diagram::removeItem(QGraphicsItem *item)
switch (item->type()) switch (item->type())
{ {
case Element::Type:
{
Element *elmt = static_cast<Element *>(item);
elmt->unlinkAllElements();
foreach(ElementTextItem *text, elmt->texts())
disconnect(text, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
}
break;
case Conductor::Type: case Conductor::Type:
{ {
Conductor *conductor = static_cast<Conductor *>(item); Conductor *conductor = static_cast<Conductor *>(item);

View File

@@ -265,59 +265,6 @@ void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *options)
} }
} }
/**
Retrieves the element label stored in file ./elements/ * /qet_labels.xml
The labels are applied to all elements inside a folder. If an element
has a specific label, it will be applied. See qet_labels.xml for more
instructions.
*/
void CustomElement::parseLabels()
{
QString formula = location().project()->elementAutoNumCurrentFormula();
DiagramContext &dc = rElementInformations();
//element is being added
if (taggedText("label") && (location().projectId()!=-1) && (taggedText("label")->toPlainText()=="_"))
{
if (getPrefix().isEmpty())
{
if (!formula.isEmpty() && (this->linkType() != Element::Slave))
{
dc.addValue("label", formula);
this->setTaggedText("label",formula);
}
}
else
{
//if there is a formula to assign, assign it
if (!formula.isEmpty() && (this->linkType() != Element::Slave))
{
dc.addValue("label", formula);
this->setTaggedText("label",formula);
}
else
{ //assign only prefix
dc.addValue("label", "%prefix");
this->setTaggedText("label", getPrefix());
}
}
}
//apply formula to specific label - This condition specify elements which have different labels e.g KM
//that are already specified in the element label (inside .elmt file). This method is not called if elements
//are being loaded at first time or being pasted
else if ((this->taggedText("label")!= NULL) && (location().projectId()!=-1) &&
(!location().project()->elementAutoNumCurrentFormula().isEmpty()) &&
(this->linkType()!=Element::Slave) && !this->diagram()->item_paste)
{
QString prefix = this->taggedText("label")->toPlainText();
this->setPrefix(prefix);
dc.addValue("label", formula);
this->setTaggedText("label",formula);
this->setElementInformations(dc);
}
}
/** /**
Analyse et prend en compte un element XML decrivant une partie du dessin Analyse et prend en compte un element XML decrivant une partie du dessin
de l'element perso. Si l'analyse reussit, la partie est ajoutee au dessin. de l'element perso. Si l'analyse reussit, la partie est ajoutee au dessin.
@@ -767,6 +714,8 @@ ElementTextItem *CustomElement::parseInput(QDomElement &e) {
list_texts_ << eti; list_texts_ << eti;
connect(eti, &ElementTextItem::diagramTextChanged, this, &Element::textItemChanged);
return(eti); return(eti);
} }

View File

@@ -72,7 +72,6 @@ class CustomElement : public FixedElement
virtual QList<QVector<qreal> *> arcs() const; virtual QList<QVector<qreal> *> arcs() const;
virtual int terminalsCount() const; virtual int terminalsCount() const;
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *); virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
virtual void parseLabels();
QString typeId() const; QString typeId() const;
ElementsLocation location() const; ElementsLocation location() const;
QString name() const; QString name() const;

View File

@@ -28,6 +28,7 @@
#include "elementpropertieswidget.h" #include "elementpropertieswidget.h"
#include "numerotationcontextcommands.h" #include "numerotationcontextcommands.h"
#include "diagramcontext.h" #include "diagramcontext.h"
#include "changeelementinformationcommand.h"
class ElementXmlRetroCompatibility class ElementXmlRetroCompatibility
{ {
@@ -437,11 +438,14 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
} }
} }
// importe les valeurs des champs de texte //import text filed value
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input"); QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
foreach(QGraphicsItem *qgi, childItems()) { foreach(QGraphicsItem *qgi, childItems())
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) { {
foreach(QDomElement input, inputs) { if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi))
{
foreach(QDomElement input, inputs)
{
eti -> fromXml(input); eti -> fromXml(input);
etiToElementLabels(eti); etiToElementLabels(eti);
} }
@@ -778,6 +782,40 @@ ElementTextItem* Element::setTaggedText(const QString &tagg, const QString &news
return eti; 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

View File

@@ -28,6 +28,7 @@ class QETProject;
class Terminal; class Terminal;
class Conductor; class Conductor;
class NumerotationContext; class NumerotationContext;
class DiagramTextItem;
/** /**
This is the base class for electrical elements. This is the base class for electrical elements.
@@ -46,8 +47,7 @@ class Element : public QetGraphicsItem
// attributes // attributes
public: public:
/** /**
* Enable the use of qgraphicsitem_cast to safely cast * Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into an Element.
* a QGraphicsItem into an Element.
* @return the QGraphicsItem type * @return the QGraphicsItem type
*/ */
enum { Type = UserType + 1000 }; enum { Type = UserType + 1000 };
@@ -72,30 +72,30 @@ class Element : public QetGraphicsItem
// methods // methods
public: public:
/// @return the list of terminals for this element /// @return the list of terminals for this element
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 /// @return the list of text items attached to this element
virtual QList<ElementTextItem *> texts() const = 0; virtual QList<ElementTextItem *> texts() const = 0;
/// @return the text field tagged with @tagg or NULL if text field isn't found /// @return the text field tagged with @tagg or NULL if text field isn't found
virtual ElementTextItem* taggedText(const QString &tagg) const = 0; 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
virtual QList<QRectF *> rectangles() const = 0; virtual QList<QRectF *> rectangles() const = 0;
/// @return the list of bounding rectangles for circles items in this element /// @return the list of bounding rectangles for circles items in this element
virtual QList<QRectF *> circles() const = 0; virtual QList<QRectF *> circles() const = 0;
/// @return the list of polygons in this element /// @return the list of polygons in this element
virtual QList<QVector<QPointF> *> polygons() const = 0; virtual QList<QVector<QPointF> *> polygons() const = 0;
/// @return the list of arcs in this element /// @return the list of arcs in this element
virtual QList<QVector<qreal> *> arcs() const = 0; virtual QList<QVector<qreal> *> arcs() const = 0;
/// @return the current number of terminals of this element /// @return the current number of terminals of this element
virtual int terminalsCount() const = 0; virtual int terminalsCount() const = 0;
/// @return the minimum number of terminals for this element /// @return the minimum number of terminals for this element
virtual int minTerminalsCount() const = 0; virtual int minTerminalsCount() const = 0;
/// @return the maximum number of terminals for this element /// @return the maximum number of terminals for this element
virtual int maxTerminalsCount() const = 0; virtual int maxTerminalsCount() const = 0;
QList <QPair <Terminal *, Terminal *> > AlignedFreeTerminals () const; QList <QPair <Terminal *, Terminal *> > AlignedFreeTerminals () const;
@@ -130,6 +130,7 @@ 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);