2013-12-20 20:30:55 +00:00
|
|
|
/*
|
2016-05-13 17:40:36 +00:00
|
|
|
Copyright 2006-2016 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-11-18 23:00:06 +00:00
|
|
|
#include "elementtextitem.h"
|
2016-10-17 12:17:45 +00:00
|
|
|
#include "diagram.h"
|
2016-05-24 18:21:52 +00:00
|
|
|
|
2014-10-20 21:23:12 +00:00
|
|
|
/**
|
|
|
|
* @brief SimpleElement::SimpleElement
|
|
|
|
* @param location
|
|
|
|
* @param qgi
|
|
|
|
* @param s
|
|
|
|
* @param state
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
|
|
|
CustomElement(location, qgi, state),
|
2016-06-07 12:55:05 +00:00
|
|
|
m_comment_item (nullptr),
|
|
|
|
m_location_item (nullptr)
|
2014-02-18 20:44:54 +00:00
|
|
|
{
|
|
|
|
link_type_ = Simple;
|
2014-11-18 23:00:06 +00:00
|
|
|
connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
|
2016-05-24 18:21:52 +00:00
|
|
|
connect(this, SIGNAL(xChanged()),this, SLOT(changeElementInfo()));
|
|
|
|
connect(this, SIGNAL(yChanged()),this, SLOT(changeElementInfo()));
|
2016-07-05 20:14:14 +00:00
|
|
|
connect(this, SIGNAL(updateLabel()),this,SLOT(changeElementInfo()));
|
2014-10-20 21:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SimpleElement::~SimpleElement
|
|
|
|
*/
|
|
|
|
SimpleElement::~SimpleElement() {
|
2014-10-27 19:37:04 +00:00
|
|
|
if (m_comment_item) delete m_comment_item;
|
|
|
|
}
|
|
|
|
|
2014-11-18 23:00:06 +00:00
|
|
|
/**
|
|
|
|
* @brief SimpleElement::initLink
|
|
|
|
* @param project
|
|
|
|
* Call init Link from custom element and after
|
|
|
|
* call update label for setup it.
|
|
|
|
*/
|
2014-10-27 19:37:04 +00:00
|
|
|
void SimpleElement::initLink(QETProject *project) {
|
|
|
|
CustomElement::initLink(project);
|
2014-11-18 23:00:06 +00:00
|
|
|
updateLabel(DiagramContext(), elementInformations());
|
2014-10-20 21:23:12 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 12:17:45 +00:00
|
|
|
/**
|
|
|
|
* @brief SimpleElement::folioIdChange
|
|
|
|
* Use to update the label of this item when the foio id change
|
|
|
|
*/
|
2016-11-09 16:06:04 +00:00
|
|
|
void SimpleElement::folioIdChange()
|
|
|
|
{
|
2016-10-17 12:17:45 +00:00
|
|
|
DiagramContext dc =elementInformations();
|
2016-11-09 16:06:04 +00:00
|
|
|
setTaggedText("label", autonum::AssignVariables::formulaToLabel(dc["label"].toString(), m_autoNum_seq, diagram(), this));
|
2016-10-17 12:17:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:21:52 +00:00
|
|
|
/**
|
|
|
|
* @brief SimpleElement::changeElementInfo()
|
|
|
|
* Update label if it contains %c, %l, %f or %F variables
|
|
|
|
*/
|
|
|
|
void SimpleElement::changeElementInfo(){
|
|
|
|
QString temp_label = this->elementInformations()["label"].toString();
|
2016-07-10 01:33:49 +00:00
|
|
|
if (temp_label.contains("\%")) {
|
2016-05-24 18:21:52 +00:00
|
|
|
if (this->diagram()!=NULL)
|
|
|
|
this->updateLabel(this->elementInformations(),this->elementInformations());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 21:23:12 +00:00
|
|
|
/**
|
|
|
|
* @brief SimpleElement::updateLabel
|
|
|
|
* update label of this element
|
|
|
|
*/
|
2016-11-09 16:06:04 +00:00
|
|
|
void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
|
|
|
|
{
|
|
|
|
QString label = autonum::AssignVariables::formulaToLabel(new_info["label"].toString(), m_autoNum_seq, diagram(), this);
|
2016-05-24 18:21:52 +00:00
|
|
|
|
2016-10-17 12:17:45 +00:00
|
|
|
//Label of element
|
2016-05-24 18:21:52 +00:00
|
|
|
if (old_info["label"].toString() != label) {
|
2014-11-18 23:00:06 +00:00
|
|
|
if (new_info["label"].toString().isEmpty())
|
|
|
|
setTaggedText("label", "_", false);
|
2016-05-24 18:21:52 +00:00
|
|
|
else {
|
|
|
|
setTaggedText("label", label, true);
|
|
|
|
}
|
2016-10-17 12:17:45 +00:00
|
|
|
|
|
|
|
//If autonum formula have %id we connect the change of folio position, to keep up to date the label.
|
|
|
|
if (diagram() && diagram()->project()) {
|
|
|
|
if (old_info["label"].toString().contains("%id") && !new_info["label"].toString().contains("%id")) {
|
|
|
|
disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &SimpleElement::folioIdChange);
|
|
|
|
}
|
|
|
|
else if (new_info["label"].toString().contains("%id")) {
|
|
|
|
connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &SimpleElement::folioIdChange);
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 23:00:06 +00:00
|
|
|
}
|
2014-10-20 21:23:12 +00:00
|
|
|
|
2014-11-18 23:00:06 +00:00
|
|
|
if (ElementTextItem *eti = taggedText("label")) {
|
|
|
|
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
|
|
|
|
}
|
2014-10-27 19:37:04 +00:00
|
|
|
|
2016-06-07 12:55:05 +00:00
|
|
|
//Comment and Location of element
|
2014-11-18 23:00:06 +00:00
|
|
|
QString comment = new_info["comment"].toString();
|
|
|
|
bool must_show = new_info.keyMustShow("comment");
|
2016-06-07 12:55:05 +00:00
|
|
|
QString location = new_info["location"].toString();
|
|
|
|
bool must_show_location = new_info.keyMustShow("location");
|
2014-10-27 19:37:04 +00:00
|
|
|
|
2016-06-07 12:55:05 +00:00
|
|
|
if ((!(comment.isEmpty() || !must_show) && !m_comment_item)||(!(location.isEmpty() || !must_show_location) && !m_comment_item)) {
|
2014-10-27 19:37:04 +00:00
|
|
|
m_comment_item = new CommentItem(this);
|
|
|
|
}
|
2016-06-07 12:55:05 +00:00
|
|
|
else if (((comment.isEmpty() || !must_show) && m_comment_item) && ((location.isEmpty() || !must_show_location) && m_comment_item)) {
|
2014-10-27 19:37:04 +00:00
|
|
|
delete m_comment_item;
|
|
|
|
m_comment_item = nullptr;
|
|
|
|
}
|
2013-12-20 20:30:55 +00:00
|
|
|
}
|