mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Cross ref item : change how some methods work
Master element : minor change related to the change of cross ref item git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3539 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -32,14 +32,20 @@
|
|||||||
* @brief CrossRefItem::CrossRefItem
|
* @brief CrossRefItem::CrossRefItem
|
||||||
* Default constructor
|
* Default constructor
|
||||||
* @param elmt element to display the cross ref and also parent item.
|
* @param elmt element to display the cross ref and also parent item.
|
||||||
|
* elmt must be in a diagram
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @brief CrossRefItem::CrossRefItem
|
||||||
|
* @param elmt
|
||||||
*/
|
*/
|
||||||
CrossRefItem::CrossRefItem(Element *elmt) :
|
CrossRefItem::CrossRefItem(Element *elmt) :
|
||||||
QGraphicsObject(elmt),
|
QGraphicsObject(elmt),
|
||||||
m_element (elmt)
|
m_element (elmt)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT_X(elmt->diagram(), "CrossRefItem constructor", "Parent element is not in a diagram");
|
||||||
|
|
||||||
m_properties = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
|
m_properties = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
|
||||||
|
|
||||||
connect(elmt, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)),this, SLOT(updateLabel()));
|
|
||||||
connect(elmt -> diagram() -> project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
|
connect(elmt -> diagram() -> project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
|
||||||
connect(elmt -> diagram() -> project(), SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
|
connect(elmt -> diagram() -> project(), SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
|
||||||
connect(elmt -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties()));
|
connect(elmt -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties()));
|
||||||
@@ -106,6 +112,13 @@ QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_p
|
|||||||
void CrossRefItem::allElementsPositionText(QString &no_str, QString &nc_str, const bool &add_prefix) const {
|
void CrossRefItem::allElementsPositionText(QString &no_str, QString &nc_str, const bool &add_prefix) const {
|
||||||
QString *tmp_str;
|
QString *tmp_str;
|
||||||
foreach (Element *elmt, m_element->linkedElements()) {
|
foreach (Element *elmt, m_element->linkedElements()) {
|
||||||
|
//We continue if element is a power contact and xref propertie
|
||||||
|
//is set to don't show power contact
|
||||||
|
if (m_properties.displayHas() == XRefProperties::Cross &&
|
||||||
|
!m_properties.showPowerContact() &&
|
||||||
|
elmt -> kindInformations()["type"].toString() == "power")
|
||||||
|
continue;
|
||||||
|
|
||||||
QString state = elmt->kindInformations()["state"].toString();
|
QString state = elmt->kindInformations()["state"].toString();
|
||||||
|
|
||||||
//NO and NC are displayed in single place in the cross
|
//NO and NC are displayed in single place in the cross
|
||||||
@@ -184,7 +197,6 @@ void CrossRefItem::updateLabel() {
|
|||||||
qp.end();
|
qp.end();
|
||||||
|
|
||||||
autoPos();
|
autoPos();
|
||||||
checkMustShow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,18 +286,23 @@ void CrossRefItem::buildHeaderContact() {
|
|||||||
* The cross ref item is drawing according to the size of the cross bounding rect.
|
* The cross ref item is drawing according to the size of the cross bounding rect.
|
||||||
*/
|
*/
|
||||||
void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) {
|
void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) {
|
||||||
//this is the default size of cross ref item
|
|
||||||
QRectF default_bounding(0, 0, 40, header + cross_min_heigth);
|
|
||||||
|
|
||||||
//No need to calcul if nothing is linked
|
//No need to calcul if nothing is linked
|
||||||
if (!m_element->isFree()) {
|
if (!m_element->isFree()) {
|
||||||
|
|
||||||
QString no_str, nc_str;
|
QString no_str, nc_str;
|
||||||
allElementsPositionText(no_str, nc_str, true);
|
allElementsPositionText(no_str, nc_str, true);
|
||||||
|
|
||||||
//Adjust the size of default_bounding if needed.
|
//There is no string to display, we return now
|
||||||
//We calcule the size by using a single text
|
if (no_str.isEmpty() && nc_str.isEmpty()) return;
|
||||||
//because in the method fillCrossRef, the text is draw like this (aka single text)
|
|
||||||
|
//this is the default size of cross ref item
|
||||||
|
QRectF default_bounding(0, 0, 40, header + cross_min_heigth);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Adjust the size of default_bounding if needed.
|
||||||
|
* We calcule the size by using a single text
|
||||||
|
* because in the method fillCrossRef, the text is draw like this (aka single text)
|
||||||
|
*/
|
||||||
|
|
||||||
//Adjust according to the NO
|
//Adjust according to the NO
|
||||||
QRectF bounding = painter.boundingRect(QRectF (), Qt::AlignCenter, no_str);
|
QRectF bounding = painter.boundingRect(QRectF (), Qt::AlignCenter, no_str);
|
||||||
@@ -300,11 +317,11 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) {
|
|||||||
default_bounding.setHeight(bounding.height() + header); //adjust the heigth
|
default_bounding.setHeight(bounding.height() + header); //adjust the heigth
|
||||||
if (bounding.width() > default_bounding.width()/2)
|
if (bounding.width() > default_bounding.width()/2)
|
||||||
default_bounding.setWidth(bounding.width()*2); //adjust the width
|
default_bounding.setWidth(bounding.width()*2); //adjust the width
|
||||||
}
|
|
||||||
|
|
||||||
m_shape_path.addRect(default_bounding);
|
m_shape_path.addRect(default_bounding);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
m_bounding_rect = default_bounding;
|
m_bounding_rect = default_bounding;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,6 +333,9 @@ void CrossRefItem::drawHasCross(QPainter &painter) {
|
|||||||
//calcul the size of the cross
|
//calcul the size of the cross
|
||||||
setUpCrossBoundingRect(painter);
|
setUpCrossBoundingRect(painter);
|
||||||
|
|
||||||
|
//Bounding rect is empty that mean there's no contact to draw
|
||||||
|
if (boundingRect().isEmpty()) return;
|
||||||
|
|
||||||
//draw the cross
|
//draw the cross
|
||||||
QRectF br = boundingRect();
|
QRectF br = boundingRect();
|
||||||
painter.drawLine(br.width()/2, 0, br.width()/2, br.height()); //vertical line
|
painter.drawLine(br.width()/2, 0, br.width()/2, br.height()); //vertical line
|
||||||
@@ -338,6 +358,8 @@ void CrossRefItem::drawHasCross(QPainter &painter) {
|
|||||||
* @param painter painter to use
|
* @param painter painter to use
|
||||||
*/
|
*/
|
||||||
void CrossRefItem::drawHasContacts(QPainter &painter) {
|
void CrossRefItem::drawHasContacts(QPainter &painter) {
|
||||||
|
if (m_element -> isFree()) return;
|
||||||
|
|
||||||
m_drawed_contacts = 0;
|
m_drawed_contacts = 0;
|
||||||
|
|
||||||
//Draw each linked contact
|
//Draw each linked contact
|
||||||
@@ -494,8 +516,6 @@ void CrossRefItem::fillCrossRef(QPainter &painter) {
|
|||||||
|
|
||||||
rect_.moveTopLeft(QPointF (middle_cross, header));
|
rect_.moveTopLeft(QPointF (middle_cross, header));
|
||||||
painter.drawText(rect_, Qt::AlignTop | Qt::AlignRight, nc_str);
|
painter.drawText(rect_, Qt::AlignTop | Qt::AlignRight, nc_str);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -504,8 +524,8 @@ void CrossRefItem::fillCrossRef(QPainter &painter) {
|
|||||||
* @param painter painter to use for draw the text
|
* @param painter painter to use for draw the text
|
||||||
*/
|
*/
|
||||||
void CrossRefItem::AddExtraInfo(QPainter &painter) {
|
void CrossRefItem::AddExtraInfo(QPainter &painter) {
|
||||||
QString comment = m_element-> elementInformations()["comment"].toString();
|
QString comment = m_element -> elementInformations()["comment"].toString();
|
||||||
bool must_show = m_element-> elementInformations().keyMustShow("comment");
|
bool must_show = m_element -> elementInformations().keyMustShow("comment");
|
||||||
|
|
||||||
if (!comment.isEmpty() && must_show) {
|
if (!comment.isEmpty() && must_show) {
|
||||||
painter.save();
|
painter.save();
|
||||||
@@ -527,43 +547,6 @@ void CrossRefItem::AddExtraInfo(QPainter &painter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief CrossRefItem::checkMustShow
|
|
||||||
* Check the propertie of this Xref for know if we
|
|
||||||
* must to be show or not
|
|
||||||
*/
|
|
||||||
void CrossRefItem::checkMustShow() {
|
|
||||||
//We always show Xref when is displayed has contact
|
|
||||||
if (m_properties.displayHas() == XRefProperties::Contacts) {
|
|
||||||
this->show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if Xref is display has cross and we must to don't show power contact, check it
|
|
||||||
else if (m_properties.displayHas() == XRefProperties::Cross && !m_properties.showPowerContact()) {
|
|
||||||
bool power = false;
|
|
||||||
foreach (Element *elmt, m_element->linkedElements()) {
|
|
||||||
// contact checked isn't power, show this xref and return;
|
|
||||||
if (elmt->kindInformations()["type"].toString() != "power") {
|
|
||||||
this->show();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
power = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (power) {
|
|
||||||
this->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//By default, show this Xref
|
|
||||||
else {
|
|
||||||
this->show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief CrossRefItem::setTextParent
|
* @brief CrossRefItem::setTextParent
|
||||||
* Set the text field tagged "label" of m_element
|
* Set the text field tagged "label" of m_element
|
||||||
@@ -572,6 +555,6 @@ void CrossRefItem::checkMustShow() {
|
|||||||
void CrossRefItem::setTextParent() {
|
void CrossRefItem::setTextParent() {
|
||||||
ElementTextItem *eti = m_element->taggedText("label");
|
ElementTextItem *eti = m_element->taggedText("label");
|
||||||
if (eti) setParentItem(eti);
|
if (eti) setParentItem(eti);
|
||||||
else qDebug() << "CrossRefItem,no texte tagged 'label' found to set has parent";
|
else qDebug() << "CrossRefItem,no text tagged 'label' found to set has parent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ class CrossRefItem : public QGraphicsObject
|
|||||||
void drawContact (QPainter &painter, int flags, QString str = QString());
|
void drawContact (QPainter &painter, int flags, QString str = QString());
|
||||||
void fillCrossRef (QPainter &painter);
|
void fillCrossRef (QPainter &painter);
|
||||||
void AddExtraInfo (QPainter &painter);
|
void AddExtraInfo (QPainter &painter);
|
||||||
void checkMustShow ();
|
|
||||||
void setTextParent ();
|
void setTextParent ();
|
||||||
|
|
||||||
//Attributes
|
//Attributes
|
||||||
|
|||||||
@@ -91,8 +91,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 (aboutDeleteXref()) return;
|
|
||||||
cri_ -> updateLabel();
|
cri_ -> updateLabel();
|
||||||
|
aboutDeleteXref();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +128,7 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
|||||||
|
|
||||||
//Delete or update the xref
|
//Delete or update the xref
|
||||||
if (cri_) {
|
if (cri_) {
|
||||||
|
cri_ -> updateLabel();
|
||||||
aboutDeleteXref();
|
aboutDeleteXref();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -150,11 +151,7 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
|||||||
bool MasterElement::aboutDeleteXref() {
|
bool MasterElement::aboutDeleteXref() {
|
||||||
if(!cri_) return true;
|
if(!cri_) return true;
|
||||||
|
|
||||||
QString comment = elementInformations()["comment"].toString();
|
if (cri_ -> boundingRect().isNull()) {
|
||||||
bool must_show = elementInformations().keyMustShow("comment");
|
|
||||||
|
|
||||||
//Delete Xref item if there isn't reason to display it
|
|
||||||
if (linkedElements().isEmpty() && (comment.isEmpty() || !must_show)) {
|
|
||||||
delete cri_;
|
delete cri_;
|
||||||
cri_ = nullptr;
|
cri_ = nullptr;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user