mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
report element: label update when the linked folio report position change
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2682 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -51,12 +51,12 @@ class Element : public QetGraphicsItem {
|
|||||||
enum { Type = UserType + 1000 };
|
enum { Type = UserType + 1000 };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QList <Element *> connected_elements;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSize dimensions;
|
QSize dimensions;
|
||||||
QPoint hotspot_coord;
|
QPoint hotspot_coord;
|
||||||
QPixmap preview;
|
QPixmap preview;
|
||||||
QList <Element *> connected_elements;
|
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
@@ -82,6 +82,7 @@ class Element : public QetGraphicsItem {
|
|||||||
virtual int maxTerminalsCount() const = 0;
|
virtual int maxTerminalsCount() const = 0;
|
||||||
bool isFree () const;
|
bool isFree () const;
|
||||||
virtual void linkToElement(Element *) {}
|
virtual void linkToElement(Element *) {}
|
||||||
|
virtual void unLinkAllElements() {}
|
||||||
/**
|
/**
|
||||||
Draw this element
|
Draw this element
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ void QetGraphicsItem::setPos(const QPointF &p) {
|
|||||||
// arrondit l'ordonnee a 10 px pres
|
// arrondit l'ordonnee a 10 px pres
|
||||||
int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid;
|
int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid;
|
||||||
QGraphicsItem::setPos(p_x, p_y);
|
QGraphicsItem::setPos(p_x, p_y);
|
||||||
|
emit positionChange(pos());
|
||||||
} else QGraphicsItem::setPos(p);
|
} else QGraphicsItem::setPos(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class QetGraphicsItem : public QGraphicsObject {
|
|||||||
virtual void editProperty ()=0;
|
virtual void editProperty ()=0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void positionChange(QPointF);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,68 @@ ReportElement::ReportElement(const ElementsLocation &location, QGraphicsItem *qg
|
|||||||
texts().at(0)->setNoEditable();
|
texts().at(0)->setNoEditable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ReportElement::linkToElement
|
||||||
|
* Link this element to the other element
|
||||||
|
* @param elmt
|
||||||
|
* element to be linked with this
|
||||||
|
*/
|
||||||
void ReportElement::linkToElement(Element * elmt) {
|
void ReportElement::linkToElement(Element * elmt) {
|
||||||
texts().at(0)->setPlainText(QString ("%1-%2").arg(elmt->diagram()->folioIndex() + 1)
|
//ensure elmt isn't already linked
|
||||||
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()));
|
bool i=true;
|
||||||
|
if (!this->isFree()){
|
||||||
|
if (connected_elements.first() == elmt) i = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ensure elmt is a report
|
||||||
|
if (elmt->linkType() == REPORT && i) {
|
||||||
|
unLinkAllElements();
|
||||||
|
connected_elements << elmt;
|
||||||
|
connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel()));
|
||||||
|
updateLabel();
|
||||||
|
elmt->linkToElement(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ReportElement::unLinkAllElements
|
||||||
|
* Unlink all of the element in the QList connected_elements
|
||||||
|
*/
|
||||||
|
void ReportElement::unLinkAllElements(){
|
||||||
|
if (!isFree()){
|
||||||
|
QList <Element *> tmp_elmt = connected_elements;
|
||||||
|
|
||||||
|
foreach(Element *elmt, connected_elements) {
|
||||||
|
disconnect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel()));
|
||||||
|
}
|
||||||
|
connected_elements.clear();
|
||||||
|
updateLabel();
|
||||||
|
|
||||||
|
foreach(Element *elmt, tmp_elmt){
|
||||||
|
elmt->unLinkAllElements();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ReportElement::linkType
|
||||||
|
* @return the kind of link type
|
||||||
|
*/
|
||||||
int ReportElement::linkType() const {
|
int ReportElement::linkType() const {
|
||||||
return REPORT;
|
return REPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ReportElement::updateLabel
|
||||||
|
* Update the displayed label.
|
||||||
|
* ie the folio and position of the linked folio report
|
||||||
|
*/
|
||||||
|
void ReportElement::updateLabel() {
|
||||||
|
if (!connected_elements.isEmpty()){
|
||||||
|
Element *elmt = connected_elements.at(0);
|
||||||
|
texts().at(0)->setPlainText(QString ("%1-%2").arg(elmt->diagram()->folioIndex() + 1)
|
||||||
|
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()));
|
||||||
|
} else {
|
||||||
|
texts().at(0)->setPlainText("_");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,12 +32,15 @@ class ReportElement : public CustomElement {
|
|||||||
public :
|
public :
|
||||||
explicit ReportElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
explicit ReportElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
||||||
virtual void linkToElement(Element *);
|
virtual void linkToElement(Element *);
|
||||||
|
virtual void unLinkAllElements();
|
||||||
virtual int linkType() const;
|
virtual int linkType() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
|
void updateLabel();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REPORTELEMENT_H
|
#endif // REPORTELEMENT_H
|
||||||
|
|||||||
@@ -66,9 +66,5 @@ void FolioReportProperties::BuildRadioList() {
|
|||||||
* Apply the new properties for this folio report
|
* Apply the new properties for this folio report
|
||||||
*/
|
*/
|
||||||
void FolioReportProperties::Apply() {
|
void FolioReportProperties::Apply() {
|
||||||
if (element_to_link) {
|
if (element_to_link) element_to_link->linkToElement(element_);
|
||||||
element_to_link->linkToElement(element_);
|
|
||||||
element_->linkToElement(element_to_link);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user