mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
Master element : comment is displayed even if there isn't slave linked
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3414 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -78,6 +78,15 @@ void CommentItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
|||||||
m_picture.play(painter);
|
m_picture.play(painter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CommentItem::mouseDoubleClickEvent
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
void CommentItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
event -> accept();
|
||||||
|
m_element -> editProperty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief CommentItem::updateLabel
|
* @brief CommentItem::updateLabel
|
||||||
* update the content of this item
|
* update the content of this item
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class CommentItem : public QGraphicsObject
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Element *m_element;
|
Element *m_element;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "masterelement.h"
|
#include "masterelement.h"
|
||||||
#include "crossrefitem.h"
|
#include "crossrefitem.h"
|
||||||
|
#include "commentitem.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MasterElement::MasterElement
|
* @brief MasterElement::MasterElement
|
||||||
@@ -27,10 +28,11 @@
|
|||||||
* @param state int used to know if the creation of element have error
|
* @param state int used to know if the creation of element have error
|
||||||
*/
|
*/
|
||||||
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),
|
||||||
|
m_ci (nullptr)
|
||||||
{
|
{
|
||||||
link_type_ = Master;
|
link_type_ = Master;
|
||||||
cri_ = nullptr;
|
|
||||||
connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +42,7 @@ 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()));
|
disconnect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,10 +59,18 @@ void MasterElement::linkToElement(Element *elmt) {
|
|||||||
elmt->linkToElement(this);
|
elmt->linkToElement(this);
|
||||||
|
|
||||||
if (!cri_) cri_ = new CrossRefItem(this); //create cross ref item if not yet
|
if (!cri_) cri_ = new CrossRefItem(this); //create cross ref item if not yet
|
||||||
connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
|
||||||
connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
||||||
cri_->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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,6 +104,7 @@ void MasterElement::unlinkElement(Element *elmt) {
|
|||||||
if (linkedElements().isEmpty()) {
|
if (linkedElements().isEmpty()) {
|
||||||
delete cri_;
|
delete cri_;
|
||||||
cri_ = nullptr;
|
cri_ = nullptr;
|
||||||
|
updateLabel();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cri_->updateLabel();
|
cri_->updateLabel();
|
||||||
@@ -100,9 +112,24 @@ void MasterElement::unlinkElement(Element *elmt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterElement::initLink
|
||||||
|
* Initialise the links between this element and other element.
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MasterElement::updateLabel
|
* @brief MasterElement::updateLabel
|
||||||
* update label of this element
|
* update label of this element
|
||||||
|
* and the comment item if he's displayed.
|
||||||
*/
|
*/
|
||||||
void MasterElement::updateLabel() {
|
void MasterElement::updateLabel() {
|
||||||
QString label = elementInformations()["label"].toString();
|
QString label = elementInformations()["label"].toString();
|
||||||
@@ -112,4 +139,20 @@ void MasterElement::updateLabel() {
|
|||||||
(label.isEmpty() || !show)?
|
(label.isEmpty() || !show)?
|
||||||
setTaggedText("label", "_", false):
|
setTaggedText("label", "_", false):
|
||||||
setTaggedText("label", label, true);
|
setTaggedText("label", label, true);
|
||||||
|
|
||||||
|
if (cri_) return;
|
||||||
|
|
||||||
|
//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
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,25 +21,35 @@
|
|||||||
#include "customelement.h"
|
#include "customelement.h"
|
||||||
|
|
||||||
class CrossRefItem;
|
class CrossRefItem;
|
||||||
|
class CommentItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The MasterElement class
|
||||||
|
* This class is a custom element, with extended behavior
|
||||||
|
* to be a master element. Master element can be linked with slave element
|
||||||
|
* and display a cross ref item for know with what other element he is linked
|
||||||
|
*/
|
||||||
class MasterElement : public CustomElement
|
class MasterElement : public CustomElement
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MasterElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
explicit MasterElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
||||||
~MasterElement();
|
~MasterElement();
|
||||||
virtual void linkToElement(Element *elmt);
|
|
||||||
virtual void unlinkAllElements();
|
virtual void linkToElement (Element *elmt);
|
||||||
virtual void unlinkElement(Element *elmt);
|
virtual void unlinkAllElements ();
|
||||||
|
virtual void unlinkElement (Element *elmt);
|
||||||
|
virtual void initLink (QETProject *project);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateLabel();
|
void updateLabel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CrossRefItem *cri_;
|
CrossRefItem *cri_;
|
||||||
|
CommentItem *m_ci;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MASTERELEMENT_H
|
#endif // MASTERELEMENT_H
|
||||||
|
|||||||
@@ -70,6 +70,20 @@ bool ElementInfoPartWidget::mustShow() const {
|
|||||||
return (ui->checkBox->isChecked());
|
return (ui->checkBox->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementInfoPartWidget::setShow(bool s) {
|
/**
|
||||||
|
* @brief ElementInfoPartWidget::setShow
|
||||||
|
* Check or not the ckeck box
|
||||||
|
* @param s true-> checked
|
||||||
|
*/
|
||||||
|
void ElementInfoPartWidget::setShow(const bool &s) {
|
||||||
ui->checkBox->setChecked(s);
|
ui->checkBox->setChecked(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementInfoPartWidget::setHideShow
|
||||||
|
* Hide or not the check box
|
||||||
|
* @param hide true -> hidden
|
||||||
|
*/
|
||||||
|
void ElementInfoPartWidget::setHideShow(const bool &hide) {
|
||||||
|
ui -> checkBox -> setHidden(hide);
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,20 +27,22 @@ namespace Ui {
|
|||||||
class ElementInfoPartWidget : public QWidget {
|
class ElementInfoPartWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
//METHODS
|
//METHODS
|
||||||
public:
|
public:
|
||||||
explicit ElementInfoPartWidget(QString key, QString translated_key, QWidget *parent = 0);
|
explicit ElementInfoPartWidget(QString key, QString translated_key, QWidget *parent = 0);
|
||||||
~ElementInfoPartWidget();
|
~ElementInfoPartWidget();
|
||||||
QString key() const {return key_;}
|
|
||||||
void setText(const QString &);
|
|
||||||
QString text() const;
|
|
||||||
bool mustShow() const;
|
|
||||||
void setShow(bool);
|
|
||||||
|
|
||||||
//ATTRIBUTES
|
QString key () const {return key_;}
|
||||||
private:
|
void setText (const QString &);
|
||||||
Ui::ElementInfoPartWidget *ui;
|
QString text () const;
|
||||||
QString key_;
|
bool mustShow () const;
|
||||||
|
void setShow (const bool &);
|
||||||
|
void setHideShow (const bool &);
|
||||||
|
|
||||||
|
//ATTRIBUTES
|
||||||
|
private:
|
||||||
|
Ui::ElementInfoPartWidget *ui;
|
||||||
|
QString key_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELEMENTINFOPARTWIDGET_H
|
#endif // ELEMENTINFOPARTWIDGET_H
|
||||||
|
|||||||
@@ -81,12 +81,17 @@ void ElementInfoWidget::buildInterface() {
|
|||||||
*/
|
*/
|
||||||
void ElementInfoWidget::fillInfo() {
|
void ElementInfoWidget::fillInfo() {
|
||||||
foreach (ElementInfoPartWidget *eipw, eipw_list) {
|
foreach (ElementInfoPartWidget *eipw, eipw_list) {
|
||||||
eipw->setText(elmt_info[eipw->key()].toString());
|
|
||||||
eipw->setShow(elmt_info.keyMustShow(eipw->key()));
|
eipw -> setText (elmt_info[eipw->key()].toString());
|
||||||
//check "show" if this eipw is label and if elmt_info haven't got value for label.
|
eipw -> setShow (elmt_info.keyMustShow(eipw->key()));
|
||||||
if (eipw->key() == "label" && (elmt_info["label"].toString().isEmpty()))
|
|
||||||
eipw->setShow(true);
|
//If the current eipw is for label or comment and the text is empty
|
||||||
else if (eipw->key() == "comment" && (elmt_info["comment"].toString().isEmpty()))
|
//we force the checkbox to ckecked
|
||||||
eipw->setShow(true);
|
if (eipw -> key() == "label" || eipw -> key() == "comment") {
|
||||||
|
if (elmt_info[eipw->key()].toString().isEmpty())
|
||||||
|
eipw->setShow(true);
|
||||||
|
}
|
||||||
|
else //< for other eipw we hide the checkbox
|
||||||
|
eipw->setHideShow(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user