2013-12-20 20:30:55 +00:00
|
|
|
/*
|
2014-01-29 18:37:45 +00:00
|
|
|
Copyright 2006-2014 The QElectroTech Team
|
2013-12-20 20:30:55 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "simpleelement.h"
|
2014-10-27 19:37:04 +00:00
|
|
|
#include "commentitem.h"
|
2014-10-20 21:23:12 +00:00
|
|
|
/**
|
|
|
|
* @brief SimpleElement::SimpleElement
|
|
|
|
* @param location
|
|
|
|
* @param qgi
|
|
|
|
* @param s
|
|
|
|
* @param state
|
|
|
|
*/
|
2013-12-20 20:30:55 +00:00
|
|
|
SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
2014-10-27 19:37:04 +00:00
|
|
|
CustomElement(location, qgi, s, state),
|
|
|
|
m_comment_item (nullptr)
|
2014-02-18 20:44:54 +00:00
|
|
|
{
|
|
|
|
link_type_ = Simple;
|
2014-10-20 21:23:12 +00:00
|
|
|
connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SimpleElement::~SimpleElement
|
|
|
|
*/
|
|
|
|
SimpleElement::~SimpleElement() {
|
|
|
|
disconnect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
|
2014-10-27 19:37:04 +00:00
|
|
|
if (m_comment_item) delete m_comment_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleElement::initLink(QETProject *project) {
|
|
|
|
CustomElement::initLink(project);
|
|
|
|
updateLabel();
|
2014-10-20 21:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SimpleElement::updateLabel
|
|
|
|
* update label of this element
|
|
|
|
*/
|
|
|
|
void SimpleElement::updateLabel() {
|
2014-10-27 19:37:04 +00:00
|
|
|
//Label of element
|
2014-10-20 21:23:12 +00:00
|
|
|
QString label = elementInformations()["label"].toString();
|
|
|
|
bool show = elementInformations().keyMustShow("label");
|
|
|
|
|
|
|
|
// setup the label
|
|
|
|
(label.isEmpty() || !show)?
|
|
|
|
setTaggedText("label", "_", false):
|
|
|
|
setTaggedText("label", label, true);
|
2014-10-27 19:37:04 +00:00
|
|
|
|
|
|
|
//Comment of element
|
|
|
|
QString comment = elementInformations()["comment"].toString();
|
|
|
|
bool must_show = elementInformations().keyMustShow("comment");
|
|
|
|
|
|
|
|
if (!(comment.isEmpty() || !must_show) && !m_comment_item) {
|
|
|
|
m_comment_item = new CommentItem(this);
|
|
|
|
}
|
|
|
|
else if ((comment.isEmpty() || !must_show) && m_comment_item) {
|
|
|
|
delete m_comment_item;
|
|
|
|
m_comment_item = nullptr;
|
|
|
|
}
|
2013-12-20 20:30:55 +00:00
|
|
|
}
|