mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10: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
|
||||
* 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
|
||||
*/
|
||||
CrossRefItem::CrossRefItem(Element *elmt) :
|
||||
QGraphicsObject(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());
|
||||
|
||||
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(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
|
||||
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 {
|
||||
QString *tmp_str;
|
||||
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();
|
||||
|
||||
//NO and NC are displayed in single place in the cross
|
||||
@@ -184,7 +197,6 @@ void CrossRefItem::updateLabel() {
|
||||
qp.end();
|
||||
|
||||
autoPos();
|
||||
checkMustShow();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,18 +286,23 @@ void CrossRefItem::buildHeaderContact() {
|
||||
* The cross ref item is drawing according to the size of the cross bounding rect.
|
||||
*/
|
||||
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
|
||||
if (!m_element->isFree()) {
|
||||
|
||||
QString no_str, nc_str;
|
||||
allElementsPositionText(no_str, nc_str, true);
|
||||
|
||||
//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)
|
||||
//There is no string to display, we return now
|
||||
if (no_str.isEmpty() && nc_str.isEmpty()) return;
|
||||
|
||||
//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
|
||||
QRectF bounding = painter.boundingRect(QRectF (), Qt::AlignCenter, no_str);
|
||||
@@ -300,12 +317,12 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) {
|
||||
default_bounding.setHeight(bounding.height() + header); //adjust the heigth
|
||||
if (bounding.width() > default_bounding.width()/2)
|
||||
default_bounding.setWidth(bounding.width()*2); //adjust the width
|
||||
}
|
||||
|
||||
m_shape_path.addRect(default_bounding);
|
||||
prepareGeometryChange();
|
||||
m_bounding_rect = default_bounding;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CrossRefItem::drawHasCross
|
||||
@@ -316,6 +333,9 @@ void CrossRefItem::drawHasCross(QPainter &painter) {
|
||||
//calcul the size of the cross
|
||||
setUpCrossBoundingRect(painter);
|
||||
|
||||
//Bounding rect is empty that mean there's no contact to draw
|
||||
if (boundingRect().isEmpty()) return;
|
||||
|
||||
//draw the cross
|
||||
QRectF br = boundingRect();
|
||||
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
|
||||
*/
|
||||
void CrossRefItem::drawHasContacts(QPainter &painter) {
|
||||
if (m_element -> isFree()) return;
|
||||
|
||||
m_drawed_contacts = 0;
|
||||
|
||||
//Draw each linked contact
|
||||
@@ -494,8 +516,6 @@ void CrossRefItem::fillCrossRef(QPainter &painter) {
|
||||
|
||||
rect_.moveTopLeft(QPointF (middle_cross, header));
|
||||
painter.drawText(rect_, Qt::AlignTop | Qt::AlignRight, nc_str);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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
|
||||
* Set the text field tagged "label" of m_element
|
||||
@@ -572,6 +555,6 @@ void CrossRefItem::checkMustShow() {
|
||||
void CrossRefItem::setTextParent() {
|
||||
ElementTextItem *eti = m_element->taggedText("label");
|
||||
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 fillCrossRef (QPainter &painter);
|
||||
void AddExtraInfo (QPainter &painter);
|
||||
void checkMustShow ();
|
||||
void setTextParent ();
|
||||
|
||||
//Attributes
|
||||
|
||||
@@ -91,8 +91,8 @@ void MasterElement::unlinkElement(Element *elmt) {
|
||||
disconnect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
||||
disconnect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
||||
|
||||
if (aboutDeleteXref()) return;
|
||||
cri_ -> updateLabel();
|
||||
aboutDeleteXref();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
||||
|
||||
//Delete or update the xref
|
||||
if (cri_) {
|
||||
cri_ -> updateLabel();
|
||||
aboutDeleteXref();
|
||||
}
|
||||
else {
|
||||
@@ -150,11 +151,7 @@ void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info
|
||||
bool MasterElement::aboutDeleteXref() {
|
||||
if(!cri_) return true;
|
||||
|
||||
QString comment = elementInformations()["comment"].toString();
|
||||
bool must_show = elementInformations().keyMustShow("comment");
|
||||
|
||||
//Delete Xref item if there isn't reason to display it
|
||||
if (linkedElements().isEmpty() && (comment.isEmpty() || !must_show)) {
|
||||
if (cri_ -> boundingRect().isNull()) {
|
||||
delete cri_;
|
||||
cri_ = nullptr;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user