mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Master element: improve how the comment is displayed when there isn't linked to a slave
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3426 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -56,15 +56,7 @@ CrossRefItem::CrossRefItem(Element *elmt) :
|
|||||||
* @brief CrossRefItem::~CrossRefItem
|
* @brief CrossRefItem::~CrossRefItem
|
||||||
* Default destructor
|
* Default destructor
|
||||||
*/
|
*/
|
||||||
CrossRefItem::~CrossRefItem() {
|
CrossRefItem::~CrossRefItem() {}
|
||||||
if(m_properties.snapTo() == XRefProperties::Bottom) {
|
|
||||||
disconnect(m_element, SIGNAL(yChanged()), this, SLOT(autoPos()));
|
|
||||||
disconnect(m_element, SIGNAL(rotationChanged()), this, SLOT(autoPos()));
|
|
||||||
}
|
|
||||||
disconnect(m_element, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
|
||||||
disconnect(m_element -> diagram() -> project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
|
|
||||||
disconnect(m_element -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief CrossRefItem::boundingRect
|
* @brief CrossRefItem::boundingRect
|
||||||
@@ -163,8 +155,10 @@ void CrossRefItem::updateProperties() {
|
|||||||
* Update the content of the item
|
* Update the content of the item
|
||||||
*/
|
*/
|
||||||
void CrossRefItem::updateLabel() {
|
void CrossRefItem::updateLabel() {
|
||||||
//init the shape
|
//init the shape and bounding rect
|
||||||
m_shape_path= QPainterPath();
|
m_shape_path = QPainterPath();
|
||||||
|
m_bounding_rect = QRectF();
|
||||||
|
|
||||||
//init the painter
|
//init the painter
|
||||||
QPainter qp;
|
QPainter qp;
|
||||||
qp.begin(&m_drawing);
|
qp.begin(&m_drawing);
|
||||||
@@ -173,12 +167,14 @@ void CrossRefItem::updateLabel() {
|
|||||||
qp.setPen(pen_);
|
qp.setPen(pen_);
|
||||||
qp.setFont(QETApp::diagramTextsFont(5));
|
qp.setFont(QETApp::diagramTextsFont(5));
|
||||||
|
|
||||||
XRefProperties::DisplayHas dh = m_properties.displayHas();
|
//Draw cross or contact, only if master element is linked.
|
||||||
if (dh == XRefProperties::Cross) {
|
if (! m_element->linkedElements().isEmpty()) {
|
||||||
drawHasCross(qp);
|
XRefProperties::DisplayHas dh = m_properties.displayHas();
|
||||||
}
|
|
||||||
else if (dh == XRefProperties::Contacts) {
|
if (dh == XRefProperties::Cross)
|
||||||
drawHasContacts(qp);
|
drawHasCross(qp);
|
||||||
|
else if (dh == XRefProperties::Contacts)
|
||||||
|
drawHasContacts(qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddExtraInfo(qp);
|
AddExtraInfo(qp);
|
||||||
@@ -371,8 +367,8 @@ void CrossRefItem::drawHasContacts(QPainter &painter) {
|
|||||||
else if (state == "SW") option = SW;
|
else if (state == "SW") option = SW;
|
||||||
|
|
||||||
QString type = info["type"].toString();
|
QString type = info["type"].toString();
|
||||||
if (type == "power") option += Power;
|
if (type == "power") option += Power;
|
||||||
else if (type == "delayOn") option += DelayOn;
|
else if (type == "delayOn") option += DelayOn;
|
||||||
else if (type == "delayOff") option += DelayOff;
|
else if (type == "delayOff") option += DelayOff;
|
||||||
|
|
||||||
drawContact(painter, option, elementPositionText(elmt));
|
drawContact(painter, option, elementPositionText(elmt));
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "masterelement.h"
|
#include "masterelement.h"
|
||||||
#include "crossrefitem.h"
|
#include "crossrefitem.h"
|
||||||
#include "commentitem.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MasterElement::MasterElement
|
* @brief MasterElement::MasterElement
|
||||||
@@ -29,8 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
||||||
CustomElement(location, qgi, s, state),
|
CustomElement(location, qgi, s, state),
|
||||||
cri_ (nullptr),
|
cri_ (nullptr)
|
||||||
m_ci (nullptr)
|
|
||||||
{
|
{
|
||||||
link_type_ = Master;
|
link_type_ = Master;
|
||||||
connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
||||||
@@ -42,8 +40,6 @@ MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qg
|
|||||||
*/
|
*/
|
||||||
MasterElement::~MasterElement() {
|
MasterElement::~MasterElement() {
|
||||||
unlinkAllElements();
|
unlinkAllElements();
|
||||||
if (m_ci) delete m_ci;
|
|
||||||
disconnect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,13 +59,6 @@ void MasterElement::linkToElement(Element *elmt) {
|
|||||||
connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
||||||
connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
||||||
cri_ -> updateLabel();
|
cri_ -> updateLabel();
|
||||||
|
|
||||||
//If there is a comment item, we delete it
|
|
||||||
//because cross ref item display comment too.
|
|
||||||
if (m_ci) {
|
|
||||||
delete m_ci;
|
|
||||||
m_ci = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,14 +90,8 @@ void MasterElement::unlinkElement(Element *elmt) {
|
|||||||
disconnect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
disconnect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
||||||
disconnect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
disconnect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
||||||
|
|
||||||
if (linkedElements().isEmpty()) {
|
if (aboutDeleteXref()) return;
|
||||||
delete cri_;
|
cri_ -> updateLabel();
|
||||||
cri_ = nullptr;
|
|
||||||
updateLabel();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cri_->updateLabel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,10 +103,7 @@ 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();
|
||||||
//If no link that mean there are no cross ref item (cri)
|
|
||||||
//So we call @updateLabel for add comment item (m_ci) if needed.
|
|
||||||
if (!cri_) updateLabel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,19 +120,39 @@ void MasterElement::updateLabel() {
|
|||||||
setTaggedText("label", "_", false):
|
setTaggedText("label", "_", false):
|
||||||
setTaggedText("label", label, true);
|
setTaggedText("label", label, true);
|
||||||
|
|
||||||
if (cri_) return;
|
//Delete or update the xref
|
||||||
|
if (cri_) {
|
||||||
|
aboutDeleteXref();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QString comment = elementInformations()["comment"].toString();
|
||||||
|
bool must_show = elementInformations().keyMustShow("comment");
|
||||||
|
|
||||||
//At this point there isn't a cross ref item displayed,
|
if (! (comment.isEmpty() || !must_show)) {
|
||||||
//but if element have comment and must be show, we add a comment item
|
cri_ = new CrossRefItem(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterElement::aboutDeleteXref
|
||||||
|
* Check if Xref item must be displayed, if not, delete it.
|
||||||
|
* If Xref item is deleted or already not used (nullptr) return true;
|
||||||
|
* Else return false if Xref item is used
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool MasterElement::aboutDeleteXref() {
|
||||||
|
if(!cri_) return true;
|
||||||
|
|
||||||
QString comment = elementInformations()["comment"].toString();
|
QString comment = elementInformations()["comment"].toString();
|
||||||
bool must_show = elementInformations().keyMustShow("comment");
|
bool must_show = elementInformations().keyMustShow("comment");
|
||||||
|
|
||||||
if (!(comment.isEmpty() || !must_show) && !m_ci) {
|
//Delete Xref item if there isn't reason to display it
|
||||||
m_ci = new CommentItem(this);
|
if (linkedElements().isEmpty() && (comment.isEmpty() || !must_show)) {
|
||||||
}
|
delete cri_;
|
||||||
else if ((comment.isEmpty() || !must_show) && m_ci) {
|
cri_ = nullptr;
|
||||||
delete m_ci;
|
return true;
|
||||||
m_ci = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
#include "customelement.h"
|
#include "customelement.h"
|
||||||
|
|
||||||
class CrossRefItem;
|
class CrossRefItem;
|
||||||
class CommentItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The MasterElement class
|
* @brief The MasterElement class
|
||||||
@@ -47,9 +46,11 @@ class MasterElement : public CustomElement
|
|||||||
public slots:
|
public slots:
|
||||||
void updateLabel();
|
void updateLabel();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool aboutDeleteXref ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CrossRefItem *cri_;
|
CrossRefItem *cri_;
|
||||||
CommentItem *m_ci;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MASTERELEMENT_H
|
#endif // MASTERELEMENT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user