mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Dynamic element text item :
when text is owned by a folio report, the only information available to the text is : the label (formula used for the Xref between linked report), the function of the potential and tension/protocol of the potential. Unlike other elements there is no more information, because a report is not a real element. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5039 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -315,6 +315,7 @@ QString QETApp::elementTranslatedInfoKey(const QString &info)
|
|||||||
else if (info == "machine-manufacturer-reference") return tr("Référence fabricant machine");
|
else if (info == "machine-manufacturer-reference") return tr("Référence fabricant machine");
|
||||||
else if (info == "location") return tr("Localisation");
|
else if (info == "location") return tr("Localisation");
|
||||||
else if (info == "function") return tr("Fonction");
|
else if (info == "function") return tr("Fonction");
|
||||||
|
else if (info == "tension-protocol") return tr("Tension / Protocole");
|
||||||
return (info);
|
return (info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,6 +338,7 @@ QString QETApp::elementInfoToVar(const QString &info)
|
|||||||
else if (info == "machine-manufacturer-reference") return QString("%{machine-manufacturer-reference}");
|
else if (info == "machine-manufacturer-reference") return QString("%{machine-manufacturer-reference}");
|
||||||
else if (info == "location") return QString("%{location}");
|
else if (info == "location") return QString("%{location}");
|
||||||
else if (info == "function") return QString("%{function}");
|
else if (info == "function") return QString("%{function}");
|
||||||
|
else if (info == "tension-protocol") return QString("%{tension-protocol}");
|
||||||
|
|
||||||
return (QString ("%{void}"));
|
return (QString ("%{void}"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
#include "terminal.h"
|
||||||
|
#include "conductor.h"
|
||||||
|
|
||||||
#include <QDomDocument>
|
#include <QDomDocument>
|
||||||
#include <QDomElement>
|
#include <QDomElement>
|
||||||
@@ -58,6 +60,27 @@ DynamicElementTextItem::DynamicElementTextItem(Element *parent_element) :
|
|||||||
if(!parent_element->linkedElements().isEmpty())
|
if(!parent_element->linkedElements().isEmpty())
|
||||||
masterChanged();
|
masterChanged();
|
||||||
}
|
}
|
||||||
|
if(parent_element->linkType() & Element::AllReport)
|
||||||
|
{
|
||||||
|
//Get the report formula, and add connection to keep up to date the formula.
|
||||||
|
if (parent_element->diagram() && parent_element->diagram()->project())
|
||||||
|
{
|
||||||
|
m_report_formula = parent_element->diagram()->project()->defaultReportProperties();
|
||||||
|
m_report_formula_con = connect(parent_element->diagram()->project(), &QETProject::reportPropertiesChanged, this, &DynamicElementTextItem::reportFormulaChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add connection to keep up to date the status of the element linked to the parent folio report of this text.
|
||||||
|
connect(parent_element, &Element::linkedElementChanged, this, &DynamicElementTextItem::reportChanged);
|
||||||
|
//The parent is already linked, we call reportChanged for init the connection
|
||||||
|
if(!parent_element->linkedElements().isEmpty())
|
||||||
|
reportChanged();
|
||||||
|
|
||||||
|
//Add connection to keep up date the conductors added or removed to the parent folio report element
|
||||||
|
connect(parent_element->terminals().first(), &Terminal::conductorWasAdded, this, &DynamicElementTextItem::conductorWasAdded);
|
||||||
|
connect(parent_element->terminals().first(), &Terminal::conductorWasRemoved, this, &DynamicElementTextItem::conductorWasRemoved);
|
||||||
|
//Get a conductor in the potential
|
||||||
|
setPotentialConductor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicElementTextItem::~DynamicElementTextItem()
|
DynamicElementTextItem::~DynamicElementTextItem()
|
||||||
@@ -144,7 +167,8 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
|
|||||||
if(m_text_from == ElementInfo || m_text_from == CompositeText)
|
if(m_text_from == ElementInfo || m_text_from == CompositeText)
|
||||||
{
|
{
|
||||||
setNoEditable(true);
|
setNoEditable(true);
|
||||||
if (elementUseForInfo())
|
//We don't made the connection below if the parent element is a report, because report haven't got info.
|
||||||
|
if (!(parentElement()->linkType() & Element::AllReport) && elementUseForInfo())
|
||||||
connect(elementUseForInfo(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged);
|
connect(elementUseForInfo(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -315,36 +339,102 @@ void DynamicElementTextItem::setText(const QString &text)
|
|||||||
*/
|
*/
|
||||||
void DynamicElementTextItem::setInfoName(const QString &info_name)
|
void DynamicElementTextItem::setInfoName(const QString &info_name)
|
||||||
{
|
{
|
||||||
|
QString old_info_name = m_info_name;
|
||||||
m_info_name = info_name;
|
m_info_name = info_name;
|
||||||
|
|
||||||
if(elementUseForInfo()) {
|
if (m_parent_element && (m_parent_element.data()->linkType() & Element::AllReport)) //special treatment for report
|
||||||
|
{
|
||||||
|
if(old_info_name != info_name)
|
||||||
|
{
|
||||||
|
if(old_info_name == "label") {
|
||||||
|
removeConnectionForReportFormula(m_report_formula);
|
||||||
|
}
|
||||||
|
if(info_name == "label")
|
||||||
|
{
|
||||||
|
setConnectionForReportFormula(m_report_formula);
|
||||||
|
updateReportText();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
conductorPropertiesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(elementUseForInfo()) {
|
||||||
setPlainText(elementUseForInfo()->elementInformations().value(info_name).toString());
|
setPlainText(elementUseForInfo()->elementInformations().value(info_name).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
emit infoNameChanged(info_name);
|
emit infoNameChanged(info_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::infoName
|
||||||
|
* @return the info name of this text
|
||||||
|
*/
|
||||||
QString DynamicElementTextItem::infoName() const {
|
QString DynamicElementTextItem::infoName() const {
|
||||||
return m_info_name;
|
return m_info_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::setCompositeText
|
||||||
|
* Set the composite text of this text item to @text
|
||||||
|
* @param text
|
||||||
|
*/
|
||||||
void DynamicElementTextItem::setCompositeText(const QString &text)
|
void DynamicElementTextItem::setCompositeText(const QString &text)
|
||||||
{
|
{
|
||||||
|
QString old_composite_text = m_composite_text;
|
||||||
m_composite_text = text;
|
m_composite_text = text;
|
||||||
|
|
||||||
|
if (m_parent_element && (m_parent_element.data()->linkType() & Element::AllReport)) //special treatment for report
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* May be in some case the old and new composite text have both the var %{label},
|
||||||
|
* and so we don't have to remove connection and after set conection,
|
||||||
|
* but for that we must to do several check and because I'm lazy,
|
||||||
|
* in every case I remove connection and set it after ;)
|
||||||
|
*/
|
||||||
|
if(old_composite_text.contains("%{label}"))
|
||||||
|
removeConnectionForReportFormula(m_report_formula);
|
||||||
|
if(m_composite_text.contains("%{label}"))
|
||||||
|
setConnectionForReportFormula(m_report_formula);
|
||||||
|
|
||||||
|
updateReportText();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
DiagramContext dc;
|
DiagramContext dc;
|
||||||
if(elementUseForInfo())
|
if(elementUseForInfo())
|
||||||
dc = elementUseForInfo()->elementInformations();
|
dc = elementUseForInfo()->elementInformations();
|
||||||
setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, dc));
|
setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, dc));
|
||||||
|
}
|
||||||
|
|
||||||
emit compositeTextChanged(m_composite_text);
|
emit compositeTextChanged(m_composite_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::compositeText
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
QString DynamicElementTextItem::compositeText() const
|
QString DynamicElementTextItem::compositeText() const
|
||||||
{
|
{
|
||||||
return m_composite_text;
|
return m_composite_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::mousePressEvent
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
//The text become selected, we set the real color, otherwise the editor will display the color of text as blue,
|
||||||
|
//but this is not the color set by the user.
|
||||||
|
if(m_user_color.isValid())
|
||||||
|
{
|
||||||
|
setDefaultTextColor(m_user_color);
|
||||||
|
m_user_color = QColor(); //m_user_color is now invalid
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagramTextItem::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DynamicElementTextItem::mouseMoveEvent
|
* @brief DynamicElementTextItem::mouseMoveEvent
|
||||||
* @param event
|
* @param event
|
||||||
@@ -408,29 +498,98 @@ void DynamicElementTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *eve
|
|||||||
{
|
{
|
||||||
DiagramTextItem::mouseDoubleClickEvent(event);
|
DiagramTextItem::mouseDoubleClickEvent(event);
|
||||||
|
|
||||||
if(m_parent_element && m_parent_element.data()->linkType() == Element::Slave && m_master_element)
|
if(!parentElement())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Element *zoomed_element = nullptr;
|
||||||
|
|
||||||
|
if(parentElement()->linkType() == Element::Slave && m_master_element)
|
||||||
{
|
{
|
||||||
if ((m_text_from == ElementInfo && m_info_name == "label") ||
|
if ((m_text_from == ElementInfo && m_info_name == "label") ||
|
||||||
(m_text_from == CompositeText && m_composite_text.contains("%{label}")))
|
(m_text_from == CompositeText && m_composite_text.contains("%{label}")))
|
||||||
|
zoomed_element = m_master_element.data();
|
||||||
|
}
|
||||||
|
if((parentElement()->linkType() & Element::AllReport) && m_other_report)
|
||||||
|
{
|
||||||
|
if((m_text_from == ElementInfo && m_info_name == "label") ||
|
||||||
|
(m_text_from == CompositeText && m_composite_text.contains("%{label}")))
|
||||||
|
zoomed_element = m_other_report.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(zoomed_element)
|
||||||
{
|
{
|
||||||
//Unselect and ungrab mouse to prevent unwanted
|
//Unselect and ungrab mouse to prevent unwanted
|
||||||
//move when linked element is in the same scene of this.
|
//move when linked element is in the same scene of this.
|
||||||
setSelected(false);
|
setSelected(false);
|
||||||
ungrabMouse();
|
ungrabMouse();
|
||||||
|
|
||||||
if(scene() != m_master_element.data()->scene())
|
if(scene() != zoomed_element->scene())
|
||||||
m_master_element.data()->diagram()->showMe();
|
zoomed_element->diagram()->showMe();
|
||||||
m_master_element.data()->setSelected(true);
|
zoomed_element->setSelected(true);
|
||||||
|
|
||||||
//Zoom to the master element
|
//Zoom to the element
|
||||||
for(QGraphicsView *view : m_master_element.data()->scene()->views())
|
for(QGraphicsView *view : zoomed_element->scene()->views())
|
||||||
{
|
{
|
||||||
QRectF fit = m_master_element.data()->sceneBoundingRect();
|
QRectF fit = zoomed_element->sceneBoundingRect();
|
||||||
fit.adjust(-200, -200, 200, 200);
|
fit.adjust(-200, -200, 200, 200);
|
||||||
view->fitInView(fit, Qt::KeepAspectRatioByExpanding);
|
view->fitInView(fit, Qt::KeepAspectRatioByExpanding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::hoverEnterEvent
|
||||||
|
* If the parent element of this text is a folio report or a slave element, the element is linked
|
||||||
|
* and the text display the variable "label" we set the text blue for signal the user that the text act like
|
||||||
|
* a link when we double click on.
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
DiagramTextItem::hoverEnterEvent(event);
|
||||||
|
|
||||||
|
//If the text is selected we set the real color, otherwise the editor will display the color of text as blue,
|
||||||
|
//but this is not the color set by the user.
|
||||||
|
if(isSelected())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Element::kind type = parentElement()->linkType();
|
||||||
|
bool blue = false;
|
||||||
|
|
||||||
|
if ((type & Element::AllReport) && m_other_report)
|
||||||
|
{
|
||||||
|
if( (m_text_from == ElementInfo && m_info_name == "label") ||
|
||||||
|
(m_text_from == CompositeText && m_composite_text.contains("%{label}")) )
|
||||||
|
blue = true;
|
||||||
|
}
|
||||||
|
else if (type == Element::Slave && m_master_element)
|
||||||
|
{
|
||||||
|
if( (m_text_from == ElementInfo && m_info_name == "label") ||
|
||||||
|
(m_text_from == CompositeText && m_composite_text.contains("%{label}")) )
|
||||||
|
blue = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(blue)
|
||||||
|
{
|
||||||
|
m_user_color = color();
|
||||||
|
setDefaultTextColor(Qt::blue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::hoverLeaveEvent
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
|
{
|
||||||
|
DiagramTextItem::hoverLeaveEvent(event);
|
||||||
|
|
||||||
|
if(m_user_color.isValid())
|
||||||
|
{
|
||||||
|
setDefaultTextColor(m_user_color);
|
||||||
|
m_user_color = QColor(); //m_user_color is now invalid
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicElementTextItem::elementInfoChanged()
|
void DynamicElementTextItem::elementInfoChanged()
|
||||||
@@ -451,6 +610,11 @@ void DynamicElementTextItem::elementInfoChanged()
|
|||||||
setPlainText(final_text);
|
setPlainText(final_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::masterChanged
|
||||||
|
* This function is only use when the parent element is a slave.
|
||||||
|
* Call when the master element linked to the parent slave element of this text change
|
||||||
|
*/
|
||||||
void DynamicElementTextItem::masterChanged()
|
void DynamicElementTextItem::masterChanged()
|
||||||
{
|
{
|
||||||
//First we remove the old connection
|
//First we remove the old connection
|
||||||
@@ -468,3 +632,265 @@ void DynamicElementTextItem::masterChanged()
|
|||||||
elementInfoChanged();
|
elementInfoChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::reportChanged
|
||||||
|
* This function is only use when parent element of this text is a folio report
|
||||||
|
* The linked report of the parent element was changed
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::reportChanged()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* When the dynamic text are added by a drag & drop from the element panel,
|
||||||
|
* the connection below are made in the constructor.
|
||||||
|
* If the text are added at load of a .qet file, the text is not yet added to a diagram then the connection is not made.
|
||||||
|
* We make it now, because when the linked report changed, that mean this text is in a diagram
|
||||||
|
*/
|
||||||
|
if(!m_report_formula_con)
|
||||||
|
{
|
||||||
|
//Get the report formula, and add connection to keep up to date the formula.
|
||||||
|
if (parentElement()->diagram() && parentElement()->diagram()->project())
|
||||||
|
{
|
||||||
|
m_report_formula = parentElement()->diagram()->project()->defaultReportProperties();
|
||||||
|
m_report_formula_con = connect(parentElement()->diagram()->project(), &QETProject::reportPropertiesChanged, this, &DynamicElementTextItem::reportFormulaChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool text_have_label = false;
|
||||||
|
|
||||||
|
if((textFrom() == ElementInfo && m_info_name == "label") ||
|
||||||
|
(textFrom() == CompositeText && m_composite_text.contains("%{label}")))
|
||||||
|
text_have_label = true;
|
||||||
|
|
||||||
|
if(text_have_label)
|
||||||
|
removeConnectionForReportFormula(m_report_formula);
|
||||||
|
|
||||||
|
m_other_report.clear();
|
||||||
|
if(!m_parent_element.data()->linkedElements().isEmpty())
|
||||||
|
m_other_report = m_parent_element.data()->linkedElements().first();
|
||||||
|
|
||||||
|
//Because linked report was changed, we ensure there is a conductor watched
|
||||||
|
setPotentialConductor();
|
||||||
|
|
||||||
|
if(text_have_label)
|
||||||
|
{
|
||||||
|
setConnectionForReportFormula(m_report_formula);
|
||||||
|
updateReportText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::reportFormulaChanged
|
||||||
|
* The report formula use in the project was changed
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::reportFormulaChanged()
|
||||||
|
{
|
||||||
|
m_report_formula = parentElement()->diagram()->project()->defaultReportProperties();
|
||||||
|
|
||||||
|
if(m_text_from == ElementInfo && m_info_name == "label")
|
||||||
|
updateReportText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicElementTextItem::setConnectionForReportFormula(const QString &formula)
|
||||||
|
{
|
||||||
|
if(m_other_report.isNull() || formula.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Element *other_elmt = m_other_report.data();
|
||||||
|
QString string = formula;
|
||||||
|
Diagram *other_diagram = m_other_report.data()->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", other_diagram->border_and_titleblock.folio());
|
||||||
|
connect(&other_diagram->border_and_titleblock, &BorderTitleBlock::titleBlockFolioChanged, this, &DynamicElementTextItem::updateReportFormulaConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other_diagram && (string.contains("%f") || string.contains("%id")))
|
||||||
|
connect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &DynamicElementTextItem::updateReportText);
|
||||||
|
if (string.contains("%l"))
|
||||||
|
connect(other_elmt, &Element::yChanged, this, &DynamicElementTextItem::updateReportText);
|
||||||
|
if (string.contains("%c"))
|
||||||
|
connect(other_elmt, &Element::xChanged, this, &DynamicElementTextItem::updateReportText);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicElementTextItem::removeConnectionForReportFormula(const QString &formula)
|
||||||
|
{
|
||||||
|
if(m_other_report.isNull() || formula.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Element *other_element = m_other_report.data();
|
||||||
|
QString string = formula;
|
||||||
|
Diagram *other_diagram = m_other_report.data()->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, &DynamicElementTextItem::updateReportFormulaConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other_diagram && (string.contains("%f") || string.contains("%id")))
|
||||||
|
disconnect(other_diagram->project(), &QETProject::projectDiagramsOrderChanged, this, &DynamicElementTextItem::updateReportText);
|
||||||
|
if (string.contains("%l"))
|
||||||
|
disconnect(other_element, &Element::yChanged, this, &DynamicElementTextItem::updateReportText);
|
||||||
|
if (string.contains("%c"))
|
||||||
|
disconnect(other_element, &Element::xChanged, this, &DynamicElementTextItem::updateReportText);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicElementTextItem::updateReportFormulaConnection()
|
||||||
|
{
|
||||||
|
removeConnectionForReportFormula(m_report_formula);
|
||||||
|
setConnectionForReportFormula(m_report_formula);
|
||||||
|
updateReportText();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::updateReportText
|
||||||
|
* This function is only use when this text is owned by a report, and this text have for info the Label.
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::updateReportText()
|
||||||
|
{
|
||||||
|
if (m_text_from == ElementInfo && m_info_name == "label" && m_other_report)
|
||||||
|
{
|
||||||
|
Element *elmt = m_other_report.data();
|
||||||
|
QString label = m_report_formula;
|
||||||
|
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
||||||
|
setPlainText(label);
|
||||||
|
}
|
||||||
|
else if (m_text_from == CompositeText) {
|
||||||
|
setPlainText(reportReplacedCompositeText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::conductorWasAdded
|
||||||
|
* Function only use when parent element is a folio report
|
||||||
|
* @param conductor
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::conductorWasAdded(Conductor *conductor)
|
||||||
|
{
|
||||||
|
Q_UNUSED(conductor)
|
||||||
|
setPotentialConductor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::conductorWasRemoved
|
||||||
|
* Function only use when parent element is a folio report
|
||||||
|
* @param conductor
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::conductorWasRemoved(Conductor *conductor)
|
||||||
|
{
|
||||||
|
if(m_watched_conductor.data() == conductor)
|
||||||
|
{
|
||||||
|
disconnect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
|
||||||
|
m_watched_conductor.clear();
|
||||||
|
setPotentialConductor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::setPotentialConductor
|
||||||
|
* This function is only used when the parent element of this text is a report element
|
||||||
|
* Get a conductor in the potential of the parent report
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::setPotentialConductor()
|
||||||
|
{
|
||||||
|
if(parentElement() && (parentElement()->linkType() & Element::AllReport))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* #First case, if m_watched_conductor is a conductor of the parent report, everything is ok
|
||||||
|
* #Second case, if the conductors list of parent report element is not empty,
|
||||||
|
* we set one of these conductor as m_watched_conductor, even if m_watched_conductor is already set,
|
||||||
|
* because that mean the conductor is a conductor of the linked report, and we prefer to set a conductor
|
||||||
|
* owned by the parent report element of this text.
|
||||||
|
* #third case, if m_watched_conductor is null, we set a conductor of the linked report, if any.
|
||||||
|
*/
|
||||||
|
QList<Conductor *> c_list = parentElement()->terminals().first()->conductors();
|
||||||
|
|
||||||
|
if(!c_list.isEmpty() && c_list.contains(m_watched_conductor.data()))
|
||||||
|
return;
|
||||||
|
else if(!c_list.isEmpty())
|
||||||
|
{
|
||||||
|
if(!m_watched_conductor.isNull())
|
||||||
|
disconnect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
|
||||||
|
|
||||||
|
m_watched_conductor = c_list.first();
|
||||||
|
connect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
|
||||||
|
}
|
||||||
|
else if(m_watched_conductor.isNull() && m_other_report)
|
||||||
|
{
|
||||||
|
if (!m_other_report.data()->terminals().first()->conductors().isEmpty())
|
||||||
|
{
|
||||||
|
m_watched_conductor = m_other_report.data()->terminals().first()->conductors().first();
|
||||||
|
connect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //This text haven't got a parent element, then ther isn't a conductor in the potential
|
||||||
|
{
|
||||||
|
if(!m_watched_conductor.isNull())
|
||||||
|
disconnect(m_watched_conductor.data(), &Conductor::propertiesChange, this, &DynamicElementTextItem::conductorPropertiesChanged);
|
||||||
|
|
||||||
|
m_watched_conductor.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::conductorPropertiesChanged
|
||||||
|
* This function is only used when the parent element of this text is a report element
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItem::conductorPropertiesChanged()
|
||||||
|
{
|
||||||
|
if(m_parent_element && (m_parent_element.data()->linkType() & Element::AllReport))
|
||||||
|
{
|
||||||
|
if(m_text_from == ElementInfo)
|
||||||
|
{
|
||||||
|
if(m_info_name == "function")
|
||||||
|
setPlainText(m_watched_conductor? m_watched_conductor.data()->properties().m_function : "");
|
||||||
|
else if (m_info_name == "tension-protocol")
|
||||||
|
setPlainText(m_watched_conductor? m_watched_conductor.data()->properties().m_tension_protocol : "");
|
||||||
|
}
|
||||||
|
else if (m_text_from == CompositeText) {
|
||||||
|
setPlainText(reportReplacedCompositeText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItem::reportReplacedCompositeText
|
||||||
|
* This function is only used when the parent element of this text is a report element
|
||||||
|
* @return the composite text with the variable replaced by the real value.
|
||||||
|
* If the parent element of this text is not a folio report, return a default QString.
|
||||||
|
*/
|
||||||
|
QString DynamicElementTextItem::reportReplacedCompositeText() const
|
||||||
|
{
|
||||||
|
QString string;
|
||||||
|
|
||||||
|
if(m_parent_element.data()->linkType() & Element::AllReport)
|
||||||
|
{
|
||||||
|
string = m_composite_text;
|
||||||
|
|
||||||
|
if (string.contains("%{label}") && m_other_report)
|
||||||
|
{
|
||||||
|
Element *elmt = m_other_report.data();
|
||||||
|
QString label = m_report_formula;
|
||||||
|
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
||||||
|
string.replace("%{label}", label);
|
||||||
|
}
|
||||||
|
if (m_watched_conductor)
|
||||||
|
{
|
||||||
|
if(string.contains("%{function}"))
|
||||||
|
string.replace("%{function}", m_watched_conductor.data()->properties().m_function);
|
||||||
|
if(string.contains("%{tension-protocol}"))
|
||||||
|
string.replace("%{tension-protocol}", m_watched_conductor.data()->properties().m_tension_protocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
class Element;
|
class Element;
|
||||||
|
class Conductor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The DynamicElementTextItem class
|
* @brief The DynamicElementTextItem class
|
||||||
@@ -32,6 +33,9 @@ class Element;
|
|||||||
*/
|
*/
|
||||||
class DynamicElementTextItem : public DiagramTextItem
|
class DynamicElementTextItem : public DiagramTextItem
|
||||||
{
|
{
|
||||||
|
friend class DynamicTextItemDelegate;
|
||||||
|
friend class CompositeTextEditDialog;
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QString tagg READ tagg WRITE setTagg NOTIFY taggChanged)
|
Q_PROPERTY(QString tagg READ tagg WRITE setTagg NOTIFY taggChanged)
|
||||||
@@ -83,23 +87,43 @@ class DynamicElementTextItem : public DiagramTextItem
|
|||||||
QString compositeText() const;
|
QString compositeText() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void elementInfoChanged();
|
void elementInfoChanged();
|
||||||
void masterChanged();
|
void masterChanged();
|
||||||
|
void reportChanged();
|
||||||
|
void reportFormulaChanged();
|
||||||
|
void setConnectionForReportFormula(const QString &formula);
|
||||||
|
void removeConnectionForReportFormula(const QString &formula);
|
||||||
|
void updateReportFormulaConnection();
|
||||||
|
void updateReportText();
|
||||||
|
void conductorWasAdded(Conductor *conductor);
|
||||||
|
void conductorWasRemoved(Conductor *conductor);
|
||||||
|
void setPotentialConductor();
|
||||||
|
void conductorPropertiesChanged();
|
||||||
|
QString reportReplacedCompositeText() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer <Element> m_parent_element,
|
QPointer <Element> m_parent_element,
|
||||||
m_master_element;
|
m_master_element,
|
||||||
|
m_other_report;
|
||||||
|
QPointer <Conductor> m_watched_conductor;
|
||||||
QString m_tagg,
|
QString m_tagg,
|
||||||
m_text,
|
m_text,
|
||||||
m_info_name,
|
m_info_name,
|
||||||
m_composite_text;
|
m_composite_text,
|
||||||
|
m_report_formula,
|
||||||
|
m_F_str;
|
||||||
DynamicElementTextItem::TextFrom m_text_from = UserText;
|
DynamicElementTextItem::TextFrom m_text_from = UserText;
|
||||||
QUuid m_uuid;
|
QUuid m_uuid;
|
||||||
|
QMetaObject::Connection m_report_formula_con;
|
||||||
|
QColor m_user_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DYNAMICELEMENTTEXTITEM_H
|
#endif // DYNAMICELEMENTTEXTITEM_H
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "dynamicelementtextitem.h"
|
#include "dynamicelementtextitem.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
|
#include "conductor.h"
|
||||||
|
|
||||||
CompositeTextEditDialog::CompositeTextEditDialog(DynamicElementTextItem *text, QWidget *parent) :
|
CompositeTextEditDialog::CompositeTextEditDialog(DynamicElementTextItem *text, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@@ -37,6 +38,21 @@ QString CompositeTextEditDialog::plainText() const {
|
|||||||
void CompositeTextEditDialog::setUpComboBox()
|
void CompositeTextEditDialog::setUpComboBox()
|
||||||
{
|
{
|
||||||
QStringList qstrl;
|
QStringList qstrl;
|
||||||
|
if(m_text->parentElement()->linkType() & Element::AllReport) //Special treatment for text owned by a folio report
|
||||||
|
{
|
||||||
|
qstrl << "label";
|
||||||
|
|
||||||
|
if(!m_text->m_watched_conductor.isNull())
|
||||||
|
{
|
||||||
|
Conductor *cond = m_text->m_watched_conductor.data();
|
||||||
|
if (!cond->properties().m_function.isEmpty())
|
||||||
|
qstrl << "function";
|
||||||
|
if(!cond->properties().m_tension_protocol.isEmpty())
|
||||||
|
qstrl << "tension-protocol";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Element *elmt = m_text->elementUseForInfo();
|
Element *elmt = m_text->elementUseForInfo();
|
||||||
if(!elmt)
|
if(!elmt)
|
||||||
return;
|
return;
|
||||||
@@ -50,6 +66,7 @@ void CompositeTextEditDialog::setUpComboBox()
|
|||||||
if(dc.contains(info))
|
if(dc.contains(info))
|
||||||
qstrl << info;
|
qstrl << info;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//We use a QMap because the keys of the map are sorted, then no matter the curent local,
|
//We use a QMap because the keys of the map are sorted, then no matter the curent local,
|
||||||
//the value of the combo box are always alphabetically sorted
|
//the value of the combo box are always alphabetically sorted
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "compositetexteditdialog.h"
|
#include "compositetexteditdialog.h"
|
||||||
|
#include "terminal.h"
|
||||||
|
#include "conductor.h"
|
||||||
|
|
||||||
DynamicElementTextModel::DynamicElementTextModel(QObject *parent) :
|
DynamicElementTextModel::DynamicElementTextModel(QObject *parent) :
|
||||||
QStandardItemModel(parent)
|
QStandardItemModel(parent)
|
||||||
@@ -628,6 +630,24 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *
|
|||||||
QStringList DynamicTextItemDelegate::availableInfo(DynamicElementTextItem *deti) const
|
QStringList DynamicTextItemDelegate::availableInfo(DynamicElementTextItem *deti) const
|
||||||
{
|
{
|
||||||
QStringList qstrl;
|
QStringList qstrl;
|
||||||
|
|
||||||
|
if(deti->parentElement()->linkType() & Element::AllReport) //Special treatment for text owned by a folio report
|
||||||
|
{
|
||||||
|
qstrl << "label";
|
||||||
|
|
||||||
|
if(!deti->m_watched_conductor.isNull())
|
||||||
|
{
|
||||||
|
Conductor *cond = deti->m_watched_conductor.data();
|
||||||
|
if (!cond->properties().m_function.isEmpty())
|
||||||
|
qstrl << "function";
|
||||||
|
if(!cond->properties().m_tension_protocol.isEmpty())
|
||||||
|
qstrl << "tension-protocol";
|
||||||
|
}
|
||||||
|
|
||||||
|
return qstrl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Element *elmt = deti->elementUseForInfo();
|
Element *elmt = deti->elementUseForInfo();
|
||||||
if(!elmt)
|
if(!elmt)
|
||||||
return qstrl;
|
return qstrl;
|
||||||
@@ -642,6 +662,6 @@ QStringList DynamicTextItemDelegate::availableInfo(DynamicElementTextItem *deti)
|
|||||||
if(dc.contains(info))
|
if(dc.contains(info))
|
||||||
qstrl << info;
|
qstrl << info;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return qstrl;
|
return qstrl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user