Element text item with are now converted to dynamic element text item.

From now, the class ElementTextItem is not anymore use in qet. Every texts in a diagram are DynamicElementTextItem.
the Xref item was adapted to dynamic text.
Previously, the comment and location, displayed as a "static text" below the "old text" tagged "label" are now automaticaly converted to DynamicElementTextItem, so visually, these texts stay unchanged 


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5216 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-01-19 12:17:20 +00:00
parent 649f8519c6
commit d85e395b46
17 changed files with 856 additions and 305 deletions

View File

@@ -23,6 +23,8 @@
#include "diagram.h"
#include "qgraphicsitemutility.h"
#include "assignvariables.h"
#include "dynamicelementtextitem.h"
#include "elementtextitemgroup.h"
//define the height of the header.
static int header = 5;
@@ -31,38 +33,34 @@ static int cross_min_heigth = 33;
/**
* @brief CrossRefItem::CrossRefItem
* Default constructor
* @param elmt element to display the cross ref and also parent item.
* elmt must be in a diagram
*/
/**
* @brief CrossRefItem::CrossRefItem
* @param elmt
* @param elmt : element to display the cross ref
*/
CrossRefItem::CrossRefItem(Element *elmt) :
QGraphicsObject(elmt),
m_element (elmt)
{
Q_ASSERT_X(elmt->diagram(), "CrossRefItem constructor", "Parent element is not in a diagram");
m_element(elmt)
{init();}
m_properties = elmt->diagram()->project()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
setAcceptHoverEvents(true);
/**
* @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref
* @param text : If the Xref must be displayed under a text, the text.
*/
CrossRefItem::CrossRefItem(Element *elmt, DynamicElementTextItem *text) :
QGraphicsObject(text),
m_element (elmt),
m_text(text)
{init();}
QETProject *project = elmt->diagram()->project();
connect(project, &QETProject::projectDiagramsOrderChanged, this, &CrossRefItem::updateLabel);
connect(project, &QETProject::diagramRemoved, this, &CrossRefItem::updateLabel);
connect(project, &QETProject::XRefPropertiesChanged, this, &CrossRefItem::updateProperties);
//set specific behavior related to the parent item.
if(m_properties.snapTo() == XRefProperties::Bottom)
{
connect(elmt, SIGNAL(yChanged()), this, SLOT(autoPos()));
connect(elmt, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
} else {
setTextParent();
}
updateLabel();
}
/**
* @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref
* @param group : If the Xref must be displayed under a group, the group.
*/
CrossRefItem::CrossRefItem(Element *elmt, ElementTextItemGroup *group) :
QGraphicsObject(group),
m_element(elmt),
m_group(group)
{init();}
/**
* @brief CrossRefItem::~CrossRefItem
@@ -70,6 +68,61 @@ CrossRefItem::CrossRefItem(Element *elmt) :
*/
CrossRefItem::~CrossRefItem() {}
/**
* @brief CrossRefItem::init
* init this Xref
*/
void CrossRefItem::init()
{
if(!m_element->diagram())
{
qDebug() << "CrossRefItem constructor", "element is not in a diagram";
return;
}
QETProject *project = m_element->diagram()->project();
connect(project, &QETProject::XRefPropertiesChanged, this, &CrossRefItem::updateProperties);
m_properties = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
setAcceptHoverEvents(true);
setUpConnection();
linkedChanged();
updateLabel();
}
/**
* @brief CrossRefItem::setUpConnection
* Set up several connection to keep up to date the Xref
*/
void CrossRefItem::setUpConnection()
{
for(QMetaObject::Connection c : m_update_connection)
disconnect(c);
m_update_connection.clear();
QETProject *project = m_element->diagram()->project();
bool set=false;
if(m_properties.snapTo() == XRefProperties::Label && (m_text || m_group)) //Snap to label and parent is a text or a group
set=true;
else if(m_properties.snapTo() == XRefProperties::Bottom && !m_text && !m_group) //Snap to bottom of element and parent is the element itself
{
m_update_connection << connect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos()));
m_update_connection << connect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
set=true;
}
if(set)
{
m_update_connection << connect(project, &QETProject::projectDiagramsOrderChanged, this, &CrossRefItem::updateLabel);
m_update_connection << connect(project, &QETProject::diagramRemoved, this, &CrossRefItem::updateLabel);
m_update_connection << connect(m_element, &Element::linkedElementChanged, this, &CrossRefItem::linkedChanged);
linkedChanged();
updateLabel();
}
}
/**
* @brief CrossRefItem::boundingRect
* @return the bounding rect of this item
@@ -115,25 +168,17 @@ QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_p
void CrossRefItem::updateProperties()
{
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
if (m_properties != xrp)
{
if (m_properties.snapTo() != xrp.snapTo())
{
if (xrp.snapTo() == XRefProperties::Bottom)
{
setParentItem(m_element);
connect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos()));
connect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
}
else
{
setTextParent();
disconnect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos()));
disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
}
}
m_properties = xrp;
hide();
if(m_properties.snapTo() == XRefProperties::Label && (m_text || m_group)) //Snap to label and parent is text or group
show();
else if((m_properties.snapTo() == XRefProperties::Bottom && !m_text && !m_group)) //Snap to bottom of element is the parent
show();
setUpConnection();
updateLabel();
}
}
@@ -168,11 +213,12 @@ void CrossRefItem::updateLabel()
drawAsContacts(qp);
}
AddExtraInfo(qp, "comment");
AddExtraInfo(qp, "location");
// AddExtraInfo(qp, "comment");
// AddExtraInfo(qp, "location");
qp.end();
autoPos();
update();
}
/**
@@ -187,6 +233,34 @@ void CrossRefItem::autoPos() {
centerToParentBottom(this);
}
bool CrossRefItem::sceneEvent(QEvent *event)
{
//By default when a QGraphicsItem is a child of a QGraphicsItemGroup
//all events are forwarded to group.
//We override it, when this Xref is in a group
if(m_group)
{
switch (event->type())
{
case QEvent::GraphicsSceneHoverEnter:
hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
break;
case QEvent::GraphicsSceneHoverMove:
hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
break;
case QEvent::GraphicsSceneHoverLeave:
hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
break;
case QEvent::GraphicsSceneMouseDoubleClick:
mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
break;
}
return true;
}
return QGraphicsObject::sceneEvent(event);
}
/**
* @brief CrossRefItem::paint
* Paint this item
@@ -229,7 +303,7 @@ void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
void CrossRefItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
m_hovered_contact = nullptr;
QGraphicsObject::hoverEnterEvent(event);
QGraphicsObject::hoverEnterEvent(event);
}
void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
@@ -293,6 +367,25 @@ void CrossRefItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QGraphicsObject::hoverLeaveEvent(event);
}
void CrossRefItem::linkedChanged()
{
for(QMetaObject::Connection c : m_slave_connection)
disconnect(c);
m_slave_connection.clear();
if(!isVisible())
return;
for(Element *elmt : m_element->linkedElements())
{
m_slave_connection << connect(elmt, &Element::xChanged, this, &CrossRefItem::updateLabel);
m_slave_connection << connect(elmt, &Element::yChanged, this, &CrossRefItem::updateLabel);
}
updateLabel();
}
/**
* @brief CrossRefItem::buildHeaderContact
* Draw the QPicture of m_hdr_no_ctc and m_hdr_nc_ctc
@@ -718,17 +811,6 @@ void CrossRefItem::AddExtraInfo(QPainter &painter, QString type)
}
}
/**
* @brief CrossRefItem::setTextParent
* Set the text field tagged "label" of m_element
* parent of this item
*/
void CrossRefItem::setTextParent() {
ElementTextItem *eti = m_element->taggedText("label");
if (eti) setParentItem(eti);
else qDebug() << "CrossRefItem,no text tagged 'label' found to set has parent";
}
/**
* @brief CrossRefItem::NOElements
* @return The linked elements of @m_element wich are open or switch contact.