2013-12-20 20:30:55 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 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 "reportelement.h"
|
2013-12-29 18:09:25 +00:00
|
|
|
#include "elementtextitem.h"
|
2013-12-29 18:37:34 +00:00
|
|
|
#include "diagramposition.h"
|
2014-01-01 16:28:19 +00:00
|
|
|
#include "qetproject.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
#include "diagram.h"
|
2015-09-10 08:48:33 +00:00
|
|
|
#include "terminal.h"
|
|
|
|
#include "conductor.h"
|
2013-12-20 20:30:55 +00:00
|
|
|
|
2014-12-14 13:06:21 +00:00
|
|
|
ReportElement::ReportElement(const ElementsLocation &location, QString link_type,QGraphicsItem *qgi, int *state) :
|
2014-12-18 10:51:08 +00:00
|
|
|
CustomElement(location, qgi, state),
|
2015-09-10 08:48:33 +00:00
|
|
|
m_text_field (nullptr),
|
|
|
|
m_watched_conductor(nullptr)
|
2014-12-18 10:51:08 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Get text tagged label. This is work for report
|
|
|
|
* create after the revision 3559.
|
|
|
|
* for report create before, we take the first text field
|
|
|
|
* because report haven't got a text field tagged label
|
|
|
|
*/
|
|
|
|
m_text_field = taggedText("label");
|
|
|
|
if (!m_text_field && !texts().isEmpty())
|
|
|
|
m_text_field = texts().first();
|
|
|
|
if (m_text_field)
|
|
|
|
m_text_field -> setNoEditable();
|
|
|
|
|
2014-01-01 19:21:10 +00:00
|
|
|
link_type == "next_report"? link_type_=NextReport : link_type_=PreviousReport;
|
2017-02-09 11:07:45 +00:00
|
|
|
link_type == "next_report"? m_inverse_report=PreviousReport : m_inverse_report=NextReport;
|
2015-09-10 08:48:33 +00:00
|
|
|
|
|
|
|
//We make these connections, to be always aware about the conductor properties
|
2015-09-11 20:11:01 +00:00
|
|
|
if (terminals().size())
|
|
|
|
{
|
|
|
|
connect (terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
|
|
|
|
connect (terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
|
|
|
|
}
|
2013-12-29 18:09:25 +00:00
|
|
|
}
|
2013-12-20 20:30:55 +00:00
|
|
|
|
2015-09-10 08:48:33 +00:00
|
|
|
/**
|
|
|
|
* @brief ReportElement::~ReportElement
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
ReportElement::~ReportElement()
|
|
|
|
{
|
2014-01-01 16:28:19 +00:00
|
|
|
unlinkAllElements();
|
2015-09-11 20:11:01 +00:00
|
|
|
if (terminals().size())
|
|
|
|
disconnect(terminals().first(), 0, 0, 0);
|
2015-09-10 08:48:33 +00:00
|
|
|
if (m_watched_conductor)
|
|
|
|
disconnect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
|
2014-01-01 16:28:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 22:47:31 +00:00
|
|
|
/**
|
|
|
|
* @brief ReportElement::linkToElement
|
|
|
|
* Link this element to the other element
|
|
|
|
* @param elmt
|
|
|
|
* element to be linked with this
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
void ReportElement::linkToElement(Element * elmt)
|
|
|
|
{
|
|
|
|
if (!diagram() && !elmt -> diagram())
|
|
|
|
{
|
|
|
|
qDebug() << "ReportElement : linkToElement : Unable to link this or element to link isn't in a diagram";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//ensure elmt isn't already linked
|
|
|
|
bool i = true;
|
2015-09-10 08:48:33 +00:00
|
|
|
if (!this -> isFree() && (connected_elements.first() == elmt))
|
|
|
|
i = false;
|
2013-12-29 22:47:31 +00:00
|
|
|
|
2014-12-14 13:06:21 +00:00
|
|
|
//ensure elmt is an inverse report of this element
|
2017-02-09 11:07:45 +00:00
|
|
|
if ((elmt->linkType() == m_inverse_report) && i)
|
2014-12-14 13:06:21 +00:00
|
|
|
{
|
2014-01-01 16:28:19 +00:00
|
|
|
unlinkAllElements();
|
2013-12-29 22:47:31 +00:00
|
|
|
connected_elements << elmt;
|
2017-02-11 11:42:52 +00:00
|
|
|
m_formula = diagram()->project()->defaultReportProperties();
|
|
|
|
setConnectionForFormula(m_formula);
|
2017-02-09 11:07:45 +00:00
|
|
|
connect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange);
|
2017-02-11 11:42:52 +00:00
|
|
|
|
2015-09-12 08:29:45 +00:00
|
|
|
if (elmt->terminals().size())
|
|
|
|
{
|
|
|
|
connect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
|
|
|
|
connect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
|
|
|
|
}
|
2017-02-11 11:42:52 +00:00
|
|
|
|
2015-09-10 08:48:33 +00:00
|
|
|
if (!m_watched_conductor && elmt->conductors().size())
|
|
|
|
conductorWasAdded(elmt->conductors().first());
|
|
|
|
else
|
|
|
|
updateLabel();
|
2014-12-14 13:06:21 +00:00
|
|
|
|
2017-02-11 11:42:52 +00:00
|
|
|
elmt->linkToElement(this);
|
2015-09-10 08:48:33 +00:00
|
|
|
|
2015-05-27 07:22:50 +00:00
|
|
|
emit linkedElementChanged();
|
2013-12-29 22:47:31 +00:00
|
|
|
}
|
2013-12-29 18:37:34 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 22:47:31 +00:00
|
|
|
/**
|
|
|
|
* @brief ReportElement::unLinkAllElements
|
|
|
|
* Unlink all of the element in the QList connected_elements
|
|
|
|
*/
|
2014-12-19 19:18:05 +00:00
|
|
|
void ReportElement::unlinkAllElements()
|
|
|
|
{
|
2017-02-11 11:42:52 +00:00
|
|
|
if (isFree())
|
|
|
|
return;
|
2015-09-10 08:48:33 +00:00
|
|
|
|
2017-02-11 11:42:52 +00:00
|
|
|
const QList <Element *> tmp_elmt = connected_elements;
|
2015-09-10 08:48:33 +00:00
|
|
|
|
2017-02-11 11:42:52 +00:00
|
|
|
for (Element *elmt : tmp_elmt)
|
2015-05-27 07:22:50 +00:00
|
|
|
{
|
2017-02-11 11:42:52 +00:00
|
|
|
removeConnectionForFormula(m_formula);
|
2017-02-09 11:07:45 +00:00
|
|
|
disconnect(diagram()->project(), &QETProject::reportPropertiesChanged, this, &ReportElement::reportPropertiesChange);
|
2017-02-11 11:42:52 +00:00
|
|
|
|
2015-09-12 08:29:45 +00:00
|
|
|
if (elmt->terminals().size())
|
|
|
|
{
|
|
|
|
disconnect(elmt->terminals().first(), &Terminal::conductorWasAdded, this, &ReportElement::conductorWasAdded);
|
|
|
|
disconnect(elmt->terminals().first(), &Terminal::conductorWasRemoved, this, &ReportElement::conductorWasRemoved);
|
|
|
|
}
|
2015-09-10 08:48:33 +00:00
|
|
|
connected_elements.removeAll(elmt);
|
|
|
|
//if elmt is the owner of m_watched_conductor, we remove it
|
|
|
|
if (elmt->conductors().contains(m_watched_conductor))
|
|
|
|
conductorWasRemoved(m_watched_conductor);
|
|
|
|
}
|
|
|
|
updateLabel();
|
2013-12-29 22:47:31 +00:00
|
|
|
|
2017-02-11 11:42:52 +00:00
|
|
|
for(Element *elmt : tmp_elmt)
|
2015-09-10 08:48:33 +00:00
|
|
|
{
|
|
|
|
elmt -> setHighlighted(false);
|
|
|
|
elmt -> unlinkAllElements();
|
2013-12-29 22:47:31 +00:00
|
|
|
}
|
2017-02-11 11:42:52 +00:00
|
|
|
|
2015-09-10 08:48:33 +00:00
|
|
|
emit linkedElementChanged();
|
2013-12-29 22:47:31 +00:00
|
|
|
}
|
2014-01-07 20:11:28 +00:00
|
|
|
/**
|
|
|
|
* @brief ReportElement::unlinkElement
|
|
|
|
*unlink the specified element.
|
|
|
|
*for reportelement, they must be only one linked element, so we call
|
|
|
|
*unlinkAllElements for clear the connected_elements list.
|
|
|
|
* @param elmt
|
|
|
|
*/
|
|
|
|
void ReportElement::unlinkElement(Element *elmt) {
|
|
|
|
Q_UNUSED (elmt);
|
|
|
|
unlinkAllElements();
|
|
|
|
}
|
2013-12-29 22:47:31 +00:00
|
|
|
|
2015-09-10 08:48:33 +00:00
|
|
|
/**
|
|
|
|
* @brief ReportElement::conductorWasAdded
|
|
|
|
* This method is called when a conduxtor is added to the potential
|
|
|
|
* @param conductor : added conductor
|
|
|
|
*/
|
|
|
|
void ReportElement::conductorWasAdded(Conductor *conductor)
|
|
|
|
{
|
|
|
|
if (m_watched_conductor) return;
|
|
|
|
|
|
|
|
m_watched_conductor = conductor;
|
|
|
|
connect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
|
|
|
|
updateLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ReportElement::conductorWasRemoved
|
|
|
|
* This method is called when a conductor is removed to the potential
|
|
|
|
* @param conductor : removed conductor
|
|
|
|
*/
|
|
|
|
void ReportElement::conductorWasRemoved(Conductor *conductor)
|
|
|
|
{
|
|
|
|
if (m_watched_conductor != conductor) return;
|
|
|
|
|
|
|
|
disconnect(m_watched_conductor, &Conductor::propertiesChange, this, &ReportElement::updateLabel);
|
|
|
|
m_watched_conductor = nullptr;
|
|
|
|
|
|
|
|
//Get another conductor to be always up to date about the properties of the potential.
|
|
|
|
|
|
|
|
//Get a conducteur docked to this report
|
|
|
|
if (conductors().size())
|
|
|
|
conductorWasAdded(conductors().first());
|
|
|
|
//Else we get a conductor of the linked report (if any)
|
|
|
|
else if (linkedElements().size() && linkedElements().first()->conductors().size())
|
|
|
|
conductorWasAdded(linkedElements().first()->conductors().first());
|
|
|
|
else
|
|
|
|
updateLabel();
|
|
|
|
}
|
|
|
|
|
2014-01-18 19:04:39 +00:00
|
|
|
/**
|
2017-02-11 11:42:52 +00:00
|
|
|
* @brief ReportElement::setFormula
|
|
|
|
* Set new Formula and call updatelabel
|
|
|
|
* @param formula : the new formula
|
2014-01-18 19:04:39 +00:00
|
|
|
*/
|
2017-02-11 11:42:52 +00:00
|
|
|
void ReportElement::setFormula(QString formula)
|
|
|
|
{
|
|
|
|
removeConnectionForFormula(m_formula);
|
|
|
|
m_formula = formula;
|
|
|
|
setConnectionForFormula(m_formula);
|
2014-01-18 19:04:39 +00:00
|
|
|
updateLabel();
|
|
|
|
}
|
|
|
|
|
2013-12-29 22:47:31 +00:00
|
|
|
/**
|
|
|
|
* @brief ReportElement::updateLabel
|
|
|
|
* Update the displayed label.
|
|
|
|
* ie the folio and position of the linked folio report
|
|
|
|
*/
|
2014-12-18 10:51:08 +00:00
|
|
|
void ReportElement::updateLabel()
|
|
|
|
{
|
|
|
|
if (!m_text_field) return;
|
2014-02-04 18:03:02 +00:00
|
|
|
|
2014-12-18 10:51:08 +00:00
|
|
|
if (!connected_elements.isEmpty())
|
|
|
|
{
|
2013-12-29 22:47:31 +00:00
|
|
|
Element *elmt = connected_elements.at(0);
|
2017-02-11 11:42:52 +00:00
|
|
|
QString label = m_formula;
|
2016-11-09 16:06:04 +00:00
|
|
|
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
2014-12-18 10:51:08 +00:00
|
|
|
m_text_field -> setPlainText(label);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_text_field -> setPlainText("/");
|
2015-09-10 08:48:33 +00:00
|
|
|
|
|
|
|
setTaggedText("function", (m_watched_conductor? m_watched_conductor->properties().m_function : ""));
|
|
|
|
setTaggedText("tension-protocol", (m_watched_conductor? m_watched_conductor->properties().m_tension_protocol : ""));
|
2013-12-29 22:47:31 +00:00
|
|
|
}
|
2017-02-09 11:07:45 +00:00
|
|
|
|
|
|
|
void ReportElement::reportPropertiesChange(const QString &old_str, const QString &new_str)
|
|
|
|
{
|
|
|
|
Q_UNUSED(old_str);
|
2017-02-11 11:42:52 +00:00
|
|
|
setFormula(new_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ReportElement::setConnectionForFormula
|
|
|
|
* Set up the required connection for the formula @str.
|
|
|
|
* @param str
|
|
|
|
*/
|
|
|
|
void ReportElement::setConnectionForFormula(const QString &str)
|
|
|
|
{
|
|
|
|
if (connected_elements.isEmpty() || str.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString string = str;
|
|
|
|
Element *other_elmt = connected_elements.first();
|
|
|
|
Diagram *other_diagram = other_elmt->diagram();
|
|
|
|
|
|
|
|
//Because the variable %F is a reference to another text which can contain variables,
|
|
|
|
//we must to replace %F by the real text, to check if the real text contain the variable %id
|
|
|
|
if (other_diagram && string.contains("%F"))
|
|
|
|
{
|
|
|
|
m_F_str = other_diagram->border_and_titleblock.folio();
|
|
|
|
string.replace("%F", m_F_str);
|
|
|
|
connect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &ReportElement::updateFormulaConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (other_diagram && (string.contains("%f") || string.contains("%id")))
|
|
|
|
connect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &ReportElement::updateLabel);
|
|
|
|
if (string.contains("%l"))
|
|
|
|
connect(other_elmt, &Element::yChanged, this, &ReportElement::updateLabel);
|
|
|
|
if (string.contains("%c"))
|
|
|
|
connect(other_elmt, &Element::xChanged, this, &ReportElement::updateLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ReportElement::removeConnectionForFormula
|
|
|
|
* Remove the existing connection made for the formula @str
|
|
|
|
* @param str
|
|
|
|
*/
|
|
|
|
void ReportElement::removeConnectionForFormula(const QString &str)
|
|
|
|
{
|
|
|
|
if (connected_elements.isEmpty() || str.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString string = str;
|
|
|
|
Element *other_element = connected_elements.first();
|
|
|
|
Diagram *other_diagram = other_element->diagram();
|
|
|
|
|
|
|
|
//Because the variable %F is a reference to another text which can contain variables,
|
|
|
|
//we must to replace %F by the real text, to check if the real text contain the variable %id
|
|
|
|
if (other_diagram && string.contains("%F"))
|
|
|
|
{
|
|
|
|
string.replace("%F", m_F_str);
|
|
|
|
disconnect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &ReportElement::updateFormulaConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (other_diagram && (string.contains("%f") || string.contains("%id")))
|
|
|
|
disconnect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &ReportElement::updateLabel);
|
|
|
|
if (string.contains("%l"))
|
|
|
|
disconnect(other_element, &Element::yChanged, this, &ReportElement::updateLabel);
|
|
|
|
if (string.contains("%c"))
|
|
|
|
disconnect(other_element, &Element::xChanged, this, &ReportElement::updateLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportElement::updateFormulaConnection()
|
|
|
|
{
|
|
|
|
removeConnectionForFormula(m_formula);
|
|
|
|
setConnectionForFormula(m_formula);
|
|
|
|
updateLabel();
|
2017-02-09 11:07:45 +00:00
|
|
|
}
|