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
|
||||
* Default destructor
|
||||
*/
|
||||
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()));
|
||||
}
|
||||
CrossRefItem::~CrossRefItem() {}
|
||||
|
||||
/**
|
||||
* @brief CrossRefItem::boundingRect
|
||||
@@ -163,8 +155,10 @@ void CrossRefItem::updateProperties() {
|
||||
* Update the content of the item
|
||||
*/
|
||||
void CrossRefItem::updateLabel() {
|
||||
//init the shape
|
||||
m_shape_path= QPainterPath();
|
||||
//init the shape and bounding rect
|
||||
m_shape_path = QPainterPath();
|
||||
m_bounding_rect = QRectF();
|
||||
|
||||
//init the painter
|
||||
QPainter qp;
|
||||
qp.begin(&m_drawing);
|
||||
@@ -173,12 +167,14 @@ void CrossRefItem::updateLabel() {
|
||||
qp.setPen(pen_);
|
||||
qp.setFont(QETApp::diagramTextsFont(5));
|
||||
|
||||
XRefProperties::DisplayHas dh = m_properties.displayHas();
|
||||
if (dh == XRefProperties::Cross) {
|
||||
drawHasCross(qp);
|
||||
}
|
||||
else if (dh == XRefProperties::Contacts) {
|
||||
drawHasContacts(qp);
|
||||
//Draw cross or contact, only if master element is linked.
|
||||
if (! m_element->linkedElements().isEmpty()) {
|
||||
XRefProperties::DisplayHas dh = m_properties.displayHas();
|
||||
|
||||
if (dh == XRefProperties::Cross)
|
||||
drawHasCross(qp);
|
||||
else if (dh == XRefProperties::Contacts)
|
||||
drawHasContacts(qp);
|
||||
}
|
||||
|
||||
AddExtraInfo(qp);
|
||||
@@ -371,8 +367,8 @@ void CrossRefItem::drawHasContacts(QPainter &painter) {
|
||||
else if (state == "SW") option = SW;
|
||||
|
||||
QString type = info["type"].toString();
|
||||
if (type == "power") option += Power;
|
||||
else if (type == "delayOn") option += DelayOn;
|
||||
if (type == "power") option += Power;
|
||||
else if (type == "delayOn") option += DelayOn;
|
||||
else if (type == "delayOff") option += DelayOff;
|
||||
|
||||
drawContact(painter, option, elementPositionText(elmt));
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
#include "masterelement.h"
|
||||
#include "crossrefitem.h"
|
||||
#include "commentitem.h"
|
||||
|
||||
/**
|
||||
* @brief MasterElement::MasterElement
|
||||
@@ -29,8 +28,7 @@
|
||||
*/
|
||||
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
||||
CustomElement(location, qgi, s, state),
|
||||
cri_ (nullptr),
|
||||
m_ci (nullptr)
|
||||
cri_ (nullptr)
|
||||
{
|
||||
link_type_ = Master;
|
||||
connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
||||
@@ -42,8 +40,6 @@ MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qg
|
||||
*/
|
||||
MasterElement::~MasterElement() {
|
||||
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(yChanged()), cri_, SLOT(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(yChanged()), cri_, SLOT(updateLabel()));
|
||||
|
||||
if (linkedElements().isEmpty()) {
|
||||
delete cri_;
|
||||
cri_ = nullptr;
|
||||
updateLabel();
|
||||
}
|
||||
else {
|
||||
cri_->updateLabel();
|
||||
}
|
||||
if (aboutDeleteXref()) return;
|
||||
cri_ -> updateLabel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +103,7 @@ void MasterElement::unlinkElement(Element *elmt) {
|
||||
void MasterElement::initLink(QETProject *project) {
|
||||
//Create the link with other element if needed
|
||||
CustomElement::initLink(project);
|
||||
|
||||
//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();
|
||||
updateLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,19 +120,39 @@ void MasterElement::updateLabel() {
|
||||
setTaggedText("label", "_", false):
|
||||
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,
|
||||
//but if element have comment and must be show, we add a comment item
|
||||
if (! (comment.isEmpty() || !must_show)) {
|
||||
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();
|
||||
bool must_show = elementInformations().keyMustShow("comment");
|
||||
|
||||
if (!(comment.isEmpty() || !must_show) && !m_ci) {
|
||||
m_ci = new CommentItem(this);
|
||||
}
|
||||
else if ((comment.isEmpty() || !must_show) && m_ci) {
|
||||
delete m_ci;
|
||||
m_ci = nullptr;
|
||||
//Delete Xref item if there isn't reason to display it
|
||||
if (linkedElements().isEmpty() && (comment.isEmpty() || !must_show)) {
|
||||
delete cri_;
|
||||
cri_ = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "customelement.h"
|
||||
|
||||
class CrossRefItem;
|
||||
class CommentItem;
|
||||
|
||||
/**
|
||||
* @brief The MasterElement class
|
||||
@@ -47,9 +46,11 @@ class MasterElement : public CustomElement
|
||||
public slots:
|
||||
void updateLabel();
|
||||
|
||||
private:
|
||||
bool aboutDeleteXref ();
|
||||
|
||||
private:
|
||||
CrossRefItem *cri_;
|
||||
CommentItem *m_ci;
|
||||
};
|
||||
|
||||
#endif // MASTERELEMENT_H
|
||||
|
||||
Reference in New Issue
Block a user