mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Element : variable assignement of label is now managed by an external class instead of the element itself
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4772 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
135
sources/autoNum/assignvariables.cpp
Normal file
135
sources/autoNum/assignvariables.cpp
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2016 The QElectroTech Team
|
||||||
|
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 "assignvariables.h"
|
||||||
|
#include "diagram.h"
|
||||||
|
#include "element.h"
|
||||||
|
#include "diagramposition.h"
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
namespace autonum
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief AssignVariables::formulaToLabel
|
||||||
|
* Return the @formula with variable assigned (ready to be displayed)
|
||||||
|
* @param formula - the formula to work
|
||||||
|
* @param seqStruct - struct where is stocked int values (struct is passed as a reference and modified by this static method)
|
||||||
|
* @param diagram - the diagram where occure the formula.
|
||||||
|
* @param elmt - parent element (if any) of the formula
|
||||||
|
* @return the string with variable assigned.
|
||||||
|
*/
|
||||||
|
QString AssignVariables::formulaToLabel(QString formula, sequenceStruct &seqStruct, Diagram *diagram, Element *elmt)
|
||||||
|
{
|
||||||
|
AssignVariables av(formula, seqStruct, diagram, elmt);
|
||||||
|
seqStruct = av.m_seq_struct;
|
||||||
|
return av.m_assigned_label;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssignVariables::AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, Element *elmt):
|
||||||
|
m_arg_formula(formula),
|
||||||
|
m_assigned_label(formula),
|
||||||
|
m_diagram(diagram),
|
||||||
|
m_seq_struct(seqStruct),
|
||||||
|
m_element(elmt)
|
||||||
|
{
|
||||||
|
if (m_diagram)
|
||||||
|
{
|
||||||
|
m_assigned_label.replace("%f", QString::number(m_diagram->folioIndex()+1));
|
||||||
|
m_assigned_label.replace("%id", QString::number(m_diagram->folioIndex()+1));
|
||||||
|
m_assigned_label.replace("%total", QString::number(m_diagram->border_and_titleblock.folioTotal()));
|
||||||
|
m_assigned_label.replace("%F", m_diagram -> border_and_titleblock.folio());
|
||||||
|
m_assigned_label.replace("%M", m_diagram -> border_and_titleblock.machine());
|
||||||
|
m_assigned_label.replace("%LM", m_diagram -> border_and_titleblock.locmach());
|
||||||
|
|
||||||
|
|
||||||
|
if (m_element)
|
||||||
|
{
|
||||||
|
m_assigned_label.replace("%c", QString::number(m_diagram->convertPosition(m_element->scenePos()).number()));
|
||||||
|
m_assigned_label.replace("%l", m_diagram->convertPosition(m_element->scenePos()).letter());
|
||||||
|
m_assigned_label.replace("%prefix", m_element->getPrefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
assignTitleBlockVar();
|
||||||
|
assignProjectVar();
|
||||||
|
assignSequence();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignVariables::assignTitleBlockVar()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_diagram->border_and_titleblock.additionalFields().count(); i++)
|
||||||
|
{
|
||||||
|
QString folio_variable = m_diagram->border_and_titleblock.additionalFields().keys().at(i);
|
||||||
|
QVariant folio_value = m_diagram->border_and_titleblock.additionalFields().operator [](folio_variable);
|
||||||
|
|
||||||
|
if (m_assigned_label.contains(folio_variable)) {
|
||||||
|
m_assigned_label.replace("%{" + folio_variable + "}", folio_value.toString());
|
||||||
|
m_assigned_label.replace("%" + folio_variable , folio_value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignVariables::assignProjectVar()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_diagram->project()->projectProperties().count(); i++)
|
||||||
|
{
|
||||||
|
QString folio_variable = m_diagram->project()->projectProperties().keys().at(i);
|
||||||
|
QVariant folio_value = m_diagram->project()->projectProperties().operator [](folio_variable);
|
||||||
|
|
||||||
|
if (m_assigned_label.contains(folio_variable)) {
|
||||||
|
m_assigned_label.replace("%{" + folio_variable + "}", folio_value.toString());
|
||||||
|
m_assigned_label.replace("%" + folio_variable , folio_value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignVariables::assignSequence()
|
||||||
|
{
|
||||||
|
int max = qMax(
|
||||||
|
qMax(
|
||||||
|
qMax(m_seq_struct.unit_folio.size(),
|
||||||
|
m_seq_struct.ten_folio.size()),
|
||||||
|
qMax(m_seq_struct.hundred_folio.size(),
|
||||||
|
m_seq_struct.unit.size())),
|
||||||
|
qMax(m_seq_struct.hundred.size(),
|
||||||
|
m_seq_struct.ten.size())
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int i=1; i<=max ; i++)
|
||||||
|
{
|
||||||
|
if (m_assigned_label.contains("%sequ_" + QString::number(i)) && !m_seq_struct.unit.isEmpty()) {
|
||||||
|
m_assigned_label.replace("%sequ_" + QString::number(i),m_seq_struct.unit.at(i-1));
|
||||||
|
}
|
||||||
|
if (m_assigned_label.contains("%seqt_" + QString::number(i)) && !m_seq_struct.ten.isEmpty()) {
|
||||||
|
m_assigned_label.replace("%seqt_" + QString::number(i),m_seq_struct.ten.at(i-1));
|
||||||
|
}
|
||||||
|
if (m_assigned_label.contains("%seqh_" + QString::number(i)) && !m_seq_struct.hundred.isEmpty()) {
|
||||||
|
m_assigned_label.replace("%seqh_" + QString::number(i),m_seq_struct.hundred.at(i-1));
|
||||||
|
}
|
||||||
|
if (m_assigned_label.contains("%sequf_" + QString::number(i)) && !m_seq_struct.unit_folio.isEmpty()) {
|
||||||
|
m_assigned_label.replace("%sequf_" + QString::number(i),m_seq_struct.unit_folio.at(i-1));
|
||||||
|
}
|
||||||
|
if (m_assigned_label.contains("%seqtf_" + QString::number(i)) && !m_seq_struct.ten_folio.isEmpty()) {
|
||||||
|
m_assigned_label.replace("%seqtf_" + QString::number(i),m_seq_struct.ten_folio.at(i-1));
|
||||||
|
}
|
||||||
|
if (m_assigned_label.contains("%seqhf_" + QString::number(i)) && !m_seq_struct.hundred_folio.isEmpty()) {
|
||||||
|
m_assigned_label.replace("%seqhf_" + QString::number(i),m_seq_struct.hundred_folio.at(i-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
66
sources/autoNum/assignvariables.h
Normal file
66
sources/autoNum/assignvariables.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2016 The QElectroTech Team
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
#ifndef ASSIGNVARIABLES_H
|
||||||
|
#define ASSIGNVARIABLES_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class Diagram;
|
||||||
|
class Element;
|
||||||
|
|
||||||
|
namespace autonum
|
||||||
|
{
|
||||||
|
struct sequenceStruct {
|
||||||
|
QStringList unit;
|
||||||
|
QStringList unit_folio;
|
||||||
|
QStringList ten;
|
||||||
|
QStringList ten_folio;
|
||||||
|
QStringList hundred;
|
||||||
|
QStringList hundred_folio;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The AssignVariables class
|
||||||
|
* This class assign variable of a formula string.
|
||||||
|
* Return the final string used to be displayed from a formula string.
|
||||||
|
*/
|
||||||
|
class AssignVariables
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString formulaToLabel (QString formula, sequenceStruct &seqStruct, Diagram *diagram, Element *elmt = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, Element *elmt = nullptr);
|
||||||
|
void assignTitleBlockVar();
|
||||||
|
void assignProjectVar();
|
||||||
|
void assignSequence();
|
||||||
|
|
||||||
|
Diagram *m_diagram = nullptr;
|
||||||
|
QString m_arg_formula;
|
||||||
|
QString m_assigned_label;
|
||||||
|
sequenceStruct m_seq_struct;
|
||||||
|
Element *m_element = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ASSIGNVARIABLES_H
|
||||||
@@ -26,7 +26,23 @@
|
|||||||
/**
|
/**
|
||||||
This class represents a diagram context, i.e. the data (a list of key/value
|
This class represents a diagram context, i.e. the data (a list of key/value
|
||||||
pairs) of a diagram at a given time. It is notably used by titleblock templates
|
pairs) of a diagram at a given time. It is notably used by titleblock templates
|
||||||
to fetch the informations they need to do their rendering.
|
to fetch the informations they need to do their rendering, or element for retrieve information about itself
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key for element :
|
||||||
|
* label -> label or identification of element
|
||||||
|
* designation -> exhaustive comment used to explain what the element does.
|
||||||
|
* comment -> a little comment wich can be displayed in the folio
|
||||||
|
* manufacturer -> the manufacturer of the element
|
||||||
|
* manufacturer-reference -> the manufacturer reference of the element
|
||||||
|
* auxiliary1 -> auxiliary 1 of element
|
||||||
|
* auxiliary2 -> auxiliary 2 of element
|
||||||
|
* machine-manufacturer-reference -> reference of the manufacturer machine
|
||||||
|
* function -> the function of element
|
||||||
|
* location -> the location of the element
|
||||||
|
* frozenLabel -> label locked at a given time
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class DiagramContext {
|
class DiagramContext {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "nomenclature.h"
|
#include "nomenclature.h"
|
||||||
#include "elementprovider.h"
|
#include "elementprovider.h"
|
||||||
|
#include "assignvariables.h"
|
||||||
#define PR(x) qDebug() << #x " = " << x;
|
#define PR(x) qDebug() << #x " = " << x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,15 +143,16 @@ QString nomenclature::getElementInfo(Element *elmt) {
|
|||||||
info += diagram -> border_and_titleblock.folio() + ";";
|
info += diagram -> border_and_titleblock.folio() + ";";
|
||||||
info += elmt -> name() + ";";
|
info += elmt -> name() + ";";
|
||||||
info += elmt-> diagram()-> convertPosition(elmt -> scenePos()).toString() + ";";
|
info += elmt-> diagram()-> convertPosition(elmt -> scenePos()).toString() + ";";
|
||||||
info += elmt->assignVariables(elmt_info["label"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["designation"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["designation"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["comment"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["manufacturer"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["manufacturer-reference"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["auxiliary1"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary1"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["auxiliary2"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary2"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["machine-manufacturer-reference"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["machine-manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["location"].toString(), elmt) + ";";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
||||||
info += elmt->assignVariables(elmt_info["function"].toString(), elmt) + "\n";
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["function"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + "\n";
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,9 +151,9 @@ void CommentItem::updateLabel()
|
|||||||
* Draw Info to item text.
|
* Draw Info to item text.
|
||||||
* (draw this item in a QPicture)
|
* (draw this item in a QPicture)
|
||||||
*/
|
*/
|
||||||
void CommentItem::addInfo(QPainter &painter, QString type){
|
void CommentItem::addInfo(QPainter &painter, QString type)
|
||||||
|
{
|
||||||
QString text = m_element -> assignVariables(m_element -> elementInformations()[type].toString(), m_element);
|
QString text = autonum::AssignVariables::formulaToLabel(m_element -> elementInformations()[type].toString(), m_element->rSequenceStruct(), m_element->diagram(), m_element);
|
||||||
bool must_show = m_element -> elementInformations().keyMustShow(type);
|
bool must_show = m_element -> elementInformations().keyMustShow(type);
|
||||||
|
|
||||||
if (!text.isEmpty() && must_show)
|
if (!text.isEmpty() && must_show)
|
||||||
|
|||||||
@@ -539,7 +539,7 @@ void CrossRefItem::fillCrossRef(QPainter &painter) {
|
|||||||
*/
|
*/
|
||||||
void CrossRefItem::AddExtraInfo(QPainter &painter, QString type)
|
void CrossRefItem::AddExtraInfo(QPainter &painter, QString type)
|
||||||
{
|
{
|
||||||
QString text = m_element -> assignVariables(m_element -> elementInformations()[type].toString(), m_element);
|
QString text = autonum::AssignVariables::formulaToLabel(m_element -> elementInformations()[type].toString(), m_element->rSequenceStruct(), m_element->diagram(), m_element);
|
||||||
bool must_show = m_element -> elementInformations().keyMustShow(type);
|
bool must_show = m_element -> elementInformations().keyMustShow(type);
|
||||||
|
|
||||||
if (!text.isEmpty() && must_show)
|
if (!text.isEmpty() && must_show)
|
||||||
|
|||||||
@@ -430,12 +430,12 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
m_prefix = e.attribute("prefix");
|
m_prefix = e.attribute("prefix");
|
||||||
|
|
||||||
//Load Sequential Values
|
//Load Sequential Values
|
||||||
loadSequential(&e,"sequ_",&seq_unit);
|
loadSequential(&e,"sequ_",&m_autoNum_seq.unit);
|
||||||
loadSequential(&e,"sequf_",&seq_unitfolio);
|
loadSequential(&e,"sequf_",&m_autoNum_seq.unit_folio);
|
||||||
loadSequential(&e,"seqt_",&seq_ten);
|
loadSequential(&e,"seqt_",&m_autoNum_seq.ten);
|
||||||
loadSequential(&e,"seqtf_",&seq_tenfolio);
|
loadSequential(&e,"seqtf_",&m_autoNum_seq.ten_folio);
|
||||||
loadSequential(&e,"seqh_",&seq_hundred);
|
loadSequential(&e,"seqh_",&m_autoNum_seq.hundred);
|
||||||
loadSequential(&e,"seqhf_",&seq_hundredfolio);
|
loadSequential(&e,"seqhf_",&m_autoNum_seq.hundred_folio);
|
||||||
|
|
||||||
//load informations
|
//load informations
|
||||||
m_element_informations.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
|
m_element_informations.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
|
||||||
@@ -492,33 +492,33 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
|
|
||||||
// Save Element sequential values to Xml
|
// Save Element sequential values to Xml
|
||||||
// Save Unit Sequential Values
|
// Save Unit Sequential Values
|
||||||
for (int i = 0; i < seq_unit.size(); i++) {
|
for (int i = 0; i < m_autoNum_seq.unit.size(); i++) {
|
||||||
element.setAttribute("sequ_" + QString::number(i+1),seq_unit.at(i));
|
element.setAttribute("sequ_" + QString::number(i+1),m_autoNum_seq.unit.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save UnitFolio Sequential Values
|
// Save UnitFolio Sequential Values
|
||||||
for (int i = 0; i < seq_unitfolio.size(); i++) {
|
for (int i = 0; i < m_autoNum_seq.unit_folio.size(); i++) {
|
||||||
element.setAttribute("sequf_" + QString::number(i+1),seq_unitfolio.at(i));
|
element.setAttribute("sequf_" + QString::number(i+1),m_autoNum_seq.unit_folio.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save Ten Sequential Values
|
// Save Ten Sequential Values
|
||||||
for (int i = 0; i < seq_ten.size(); i++) {
|
for (int i = 0; i < m_autoNum_seq.ten.size(); i++) {
|
||||||
element.setAttribute("seqt_" + QString::number(i+1),seq_ten.at(i));
|
element.setAttribute("seqt_" + QString::number(i+1),m_autoNum_seq.ten.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save TenFolio Sequential Values
|
// Save TenFolio Sequential Values
|
||||||
for (int i = 0; i < seq_tenfolio.size(); i++) {
|
for (int i = 0; i < m_autoNum_seq.ten_folio.size(); i++) {
|
||||||
element.setAttribute("seqtf_" + QString::number(i+1),seq_tenfolio.at(i));
|
element.setAttribute("seqtf_" + QString::number(i+1),m_autoNum_seq.ten_folio.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save Hundred Sequential Values
|
// Save Hundred Sequential Values
|
||||||
for (int i = 0; i < seq_hundred.size(); i++) {
|
for (int i = 0; i < m_autoNum_seq.hundred.size(); i++) {
|
||||||
element.setAttribute("seqh_" + QString::number(i+1),seq_hundred.at(i));
|
element.setAttribute("seqh_" + QString::number(i+1),m_autoNum_seq.hundred.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save Hundred Sequential Values
|
// Save Hundred Sequential Values
|
||||||
for (int i = 0; i < seq_hundredfolio.size(); i++) {
|
for (int i = 0; i < m_autoNum_seq.hundred_folio.size(); i++) {
|
||||||
element.setAttribute("seqhf_" + QString::number(i+1),seq_hundredfolio.at(i));
|
element.setAttribute("seqhf_" + QString::number(i+1),m_autoNum_seq.hundred_folio.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// position, selection et orientation
|
// position, selection et orientation
|
||||||
@@ -719,52 +719,6 @@ void Element::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Element::assignVariables()
|
|
||||||
* Assign variables values
|
|
||||||
* @param label, string to be changed
|
|
||||||
* @param elmt, element to extract variables values
|
|
||||||
*/
|
|
||||||
QString Element::assignVariables(QString label, Element *elmt){
|
|
||||||
|
|
||||||
//Titleblock Variables
|
|
||||||
for (int i = 0; i < elmt->diagram()->border_and_titleblock.additionalFields().count(); i++)
|
|
||||||
{
|
|
||||||
QString folio_variable = elmt->diagram()->border_and_titleblock.additionalFields().keys().at(i);
|
|
||||||
QVariant folio_value = elmt->diagram()->border_and_titleblock.additionalFields().operator [](folio_variable);
|
|
||||||
|
|
||||||
if (label.contains(folio_variable)) {
|
|
||||||
label.replace("%{" + folio_variable + "}", folio_value.toString());
|
|
||||||
label.replace("%" + folio_variable , folio_value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Project Variables
|
|
||||||
for (int i = 0; i < elmt->diagram()->project()->projectProperties().count(); i++)
|
|
||||||
{
|
|
||||||
QString folio_variable = elmt->diagram()->project()->projectProperties().keys().at(i);
|
|
||||||
QVariant folio_value = elmt->diagram()->project()->projectProperties().operator [](folio_variable);
|
|
||||||
|
|
||||||
if (label.contains(folio_variable)) {
|
|
||||||
label.replace("%{" + folio_variable + "}", folio_value.toString());
|
|
||||||
label.replace("%" + folio_variable , folio_value.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Default Variables
|
|
||||||
label.replace("%f", QString::number(elmt->diagram()->folioIndex()+1));
|
|
||||||
label.replace("%F", elmt->diagram() -> border_and_titleblock.folio());
|
|
||||||
label.replace("%M", elmt->diagram() -> border_and_titleblock.machine());
|
|
||||||
label.replace("%LM", elmt->diagram() -> border_and_titleblock.locmach());
|
|
||||||
label.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number()));
|
|
||||||
label.replace("%l", elmt->diagram() -> convertPosition(elmt -> scenePos()).letter());
|
|
||||||
label.replace("%id", QString::number(elmt->diagram()->folioIndex()+1));
|
|
||||||
label.replace("%total", QString::number(elmt->diagram()->border_and_titleblock.folioTotal()));
|
|
||||||
label.replace("%prefix", elmt->getPrefix());
|
|
||||||
label = assignSeq(label, elmt);
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Element::setSequential
|
* @brief Element::setSequential
|
||||||
* Set sequential values to element
|
* Set sequential values to element
|
||||||
@@ -778,22 +732,22 @@ void Element::setSequential() {
|
|||||||
NumerotationContextCommands ncc (nc);
|
NumerotationContextCommands ncc (nc);
|
||||||
if (!nc.isEmpty()) {
|
if (!nc.isEmpty()) {
|
||||||
if (label.contains("%sequ_"))
|
if (label.contains("%sequ_"))
|
||||||
setSequentialToList(&seq_unit,&nc,"unit");
|
setSequentialToList(&m_autoNum_seq.unit,&nc,"unit");
|
||||||
if (label.contains("%sequf_")) {
|
if (label.contains("%sequf_")) {
|
||||||
setSequentialToList(&seq_unitfolio,&nc,"unitfolio");
|
setSequentialToList(&m_autoNum_seq.unit_folio,&nc,"unitfolio");
|
||||||
setFolioSequentialToHash(&seq_unitfolio,&diagram()->m_elmt_unitfolio_max,element_currentAutoNum);
|
setFolioSequentialToHash(&m_autoNum_seq.unit_folio,&diagram()->m_elmt_unitfolio_max,element_currentAutoNum);
|
||||||
}
|
}
|
||||||
if (label.contains("%seqt_"))
|
if (label.contains("%seqt_"))
|
||||||
setSequentialToList(&seq_ten,&nc,"ten");
|
setSequentialToList(&m_autoNum_seq.ten,&nc,"ten");
|
||||||
if (label.contains("%seqtf_")) {
|
if (label.contains("%seqtf_")) {
|
||||||
setSequentialToList(&seq_tenfolio,&nc,"tenfolio");
|
setSequentialToList(&m_autoNum_seq.ten_folio,&nc,"tenfolio");
|
||||||
setFolioSequentialToHash(&seq_tenfolio,&diagram()->m_elmt_tenfolio_max,element_currentAutoNum);
|
setFolioSequentialToHash(&m_autoNum_seq.ten_folio,&diagram()->m_elmt_tenfolio_max,element_currentAutoNum);
|
||||||
}
|
}
|
||||||
if (label.contains("%seqh_"))
|
if (label.contains("%seqh_"))
|
||||||
setSequentialToList(&seq_hundred,&nc,"hundred");
|
setSequentialToList(&m_autoNum_seq.hundred,&nc,"hundred");
|
||||||
if (label.contains("%seqhf_")) {
|
if (label.contains("%seqhf_")) {
|
||||||
setSequentialToList(&seq_hundredfolio,&nc,"hundredfolio");
|
setSequentialToList(&m_autoNum_seq.hundred_folio,&nc,"hundredfolio");
|
||||||
setFolioSequentialToHash(&seq_hundredfolio,&diagram()->m_elmt_hundredfolio_max,element_currentAutoNum);
|
setFolioSequentialToHash(&m_autoNum_seq.hundred_folio,&diagram()->m_elmt_hundredfolio_max,element_currentAutoNum);
|
||||||
}
|
}
|
||||||
this->diagram()->project()->addElementAutoNum(element_currentAutoNum,ncc.next());
|
this->diagram()->project()->addElementAutoNum(element_currentAutoNum,ncc.next());
|
||||||
}
|
}
|
||||||
@@ -848,38 +802,6 @@ void Element::setFolioSequentialToHash(QStringList* list, QHash<QString, QString
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Element::assignSeq
|
|
||||||
* Replace sequential values to element label
|
|
||||||
* @param label to be replaced
|
|
||||||
* @return replaced label
|
|
||||||
*/
|
|
||||||
QString Element::assignSeq(QString label, Element* elmt) {
|
|
||||||
for (int i = 1; i <= qMax(qMax(qMax(elmt->seq_unitfolio.size(), elmt->seq_tenfolio.size()),qMax(elmt->seq_hundredfolio.size(),elmt->seq_unit.size())),qMax(elmt->seq_hundred.size(),elmt->seq_ten.size())); i++) {
|
|
||||||
// "&& !seq.isEmpty()" introduced in the methods below to avoid crash when copying and paste elements
|
|
||||||
// that contain folio sequential in their labels. Needs further debugging.
|
|
||||||
if (label.contains("%sequ_" + QString::number(i)) && !elmt->seq_unit.isEmpty()) {
|
|
||||||
label.replace("%sequ_" + QString::number(i),elmt->seq_unit.at(i-1));
|
|
||||||
}
|
|
||||||
if (label.contains("%seqt_" + QString::number(i)) && !elmt->seq_ten.isEmpty()) {
|
|
||||||
label.replace("%seqt_" + QString::number(i),elmt->seq_ten.at(i-1));
|
|
||||||
}
|
|
||||||
if (label.contains("%seqh_" + QString::number(i)) && !elmt->seq_hundred.isEmpty()) {
|
|
||||||
label.replace("%seqh_" + QString::number(i),elmt->seq_hundred.at(i-1));
|
|
||||||
}
|
|
||||||
if (label.contains("%sequf_" + QString::number(i)) && !elmt->seq_unitfolio.isEmpty()) {
|
|
||||||
label.replace("%sequf_" + QString::number(i),elmt->seq_unitfolio.at(i-1));
|
|
||||||
}
|
|
||||||
if (label.contains("%seqtf_" + QString::number(i)) && !elmt->seq_tenfolio.isEmpty()) {
|
|
||||||
label.replace("%seqtf_" + QString::number(i),elmt->seq_tenfolio.at(i-1));
|
|
||||||
}
|
|
||||||
if (label.contains("%seqhf_" + QString::number(i)) && !elmt->seq_hundredfolio.isEmpty()) {
|
|
||||||
label.replace("%seqhf_" + QString::number(i),elmt->seq_hundredfolio.at(i-1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementTextItem::setTaggedText
|
* @brief ElementTextItem::setTaggedText
|
||||||
* Set text @newstr to the text tagged with @tagg.
|
* Set text @newstr to the text tagged with @tagg.
|
||||||
@@ -917,11 +839,14 @@ void Element::setPrefix(QString prefix) {
|
|||||||
* @brief Element::freezeLabel
|
* @brief Element::freezeLabel
|
||||||
* Freeze this element label
|
* Freeze this element label
|
||||||
*/
|
*/
|
||||||
void Element::freezeLabel() {
|
void Element::freezeLabel()
|
||||||
|
{
|
||||||
DiagramContext &dc = this->rElementInformations();
|
DiagramContext &dc = this->rElementInformations();
|
||||||
QString freezelabel = dc["label"].toString();
|
QString freezelabel = dc["label"].toString();
|
||||||
QString label = assignVariables(freezelabel,this);
|
QString label = autonum::AssignVariables::formulaToLabel(freezelabel, m_autoNum_seq, diagram(),this );
|
||||||
if (!(label == freezelabel)) {
|
|
||||||
|
if (!(label == freezelabel))
|
||||||
|
{
|
||||||
dc.addValue("frozenlabel", freezelabel);
|
dc.addValue("frozenlabel", freezelabel);
|
||||||
dc.addValue("label",label);
|
dc.addValue("label",label);
|
||||||
this->setTaggedText("label", label);
|
this->setTaggedText("label", label);
|
||||||
@@ -933,14 +858,14 @@ void Element::freezeLabel() {
|
|||||||
* @brief Element::unfreezeLabel
|
* @brief Element::unfreezeLabel
|
||||||
* Unfreeze this element label
|
* Unfreeze this element label
|
||||||
*/
|
*/
|
||||||
void Element::unfreezeLabel() {
|
void Element::unfreezeLabel()
|
||||||
|
{
|
||||||
DiagramContext &dc = this->rElementInformations();
|
DiagramContext &dc = this->rElementInformations();
|
||||||
QString label = dc["label"].toString();
|
|
||||||
QString frozenlabel = dc["frozenlabel"].toString();
|
QString frozenlabel = dc["frozenlabel"].toString();
|
||||||
if (frozenlabel == "") return;
|
if (frozenlabel == "") return;
|
||||||
dc.addValue("frozenlabel", "");
|
dc.addValue("frozenlabel", "");
|
||||||
dc.addValue("label",frozenlabel);
|
dc.addValue("label",frozenlabel);
|
||||||
frozenlabel = assignVariables(frozenlabel,this);
|
frozenlabel = autonum::AssignVariables::formulaToLabel(frozenlabel, m_autoNum_seq, diagram(),this );
|
||||||
this->setTaggedText("label", frozenlabel);
|
this->setTaggedText("label", frozenlabel);
|
||||||
this->setElementInformations(dc);
|
this->setElementInformations(dc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
#include "qetgraphicsitem.h"
|
#include "qetgraphicsitem.h"
|
||||||
#include "diagramcontext.h"
|
#include "diagramcontext.h"
|
||||||
|
#include "assignvariables.h"
|
||||||
|
|
||||||
class ElementTextItem;
|
class ElementTextItem;
|
||||||
class QETProject;
|
class QETProject;
|
||||||
@@ -134,8 +135,10 @@ class Element : public QetGraphicsItem {
|
|||||||
DiagramContext kindInformations () const {return kind_informations_;} //@kind_information_ is used to store more information
|
DiagramContext kindInformations () const {return kind_informations_;} //@kind_information_ is used to store more information
|
||||||
//about the herited class like contactelement for know
|
//about the herited class like contactelement for know
|
||||||
// kind of contact (simple tempo) or number of contact show by the element.
|
// kind of contact (simple tempo) or number of contact show by the element.
|
||||||
QString assignVariables (QString, Element *);
|
|
||||||
QString assignSeq (QString, Element*);
|
autonum::sequenceStruct sequenceStruct () const {return m_autoNum_seq;}
|
||||||
|
autonum::sequenceStruct& rSequenceStruct() {return m_autoNum_seq;}
|
||||||
|
|
||||||
void setSequential ();
|
void setSequential ();
|
||||||
void setSequentialToList(QStringList*, NumerotationContext*, QString);
|
void setSequentialToList(QStringList*, NumerotationContext*, QString);
|
||||||
void setFolioSequentialToHash(QStringList*, QHash<QString, QStringList>*, QString);
|
void setFolioSequentialToHash(QStringList*, QHash<QString, QStringList>*, QString);
|
||||||
@@ -148,6 +151,7 @@ class Element : public QetGraphicsItem {
|
|||||||
//ATTRIBUTES
|
//ATTRIBUTES
|
||||||
protected:
|
protected:
|
||||||
DiagramContext m_element_informations, kind_informations_;
|
DiagramContext m_element_informations, kind_informations_;
|
||||||
|
autonum::sequenceStruct m_autoNum_seq;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Draw this element
|
Draw this element
|
||||||
@@ -188,14 +192,6 @@ class Element : public QetGraphicsItem {
|
|||||||
// orientation-related methods
|
// orientation-related methods
|
||||||
int orientation() const;
|
int orientation() const;
|
||||||
|
|
||||||
// Lists containing Sequentials
|
|
||||||
QStringList seq_unit;
|
|
||||||
QStringList seq_unitfolio;
|
|
||||||
QStringList seq_ten;
|
|
||||||
QStringList seq_tenfolio;
|
|
||||||
QStringList seq_hundred;
|
|
||||||
QStringList seq_hundredfolio;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void MasterElement::initLink(QETProject *project) {
|
|||||||
*/
|
*/
|
||||||
void MasterElement::folioIdChange() {
|
void MasterElement::folioIdChange() {
|
||||||
DiagramContext dc =elementInformations();
|
DiagramContext dc =elementInformations();
|
||||||
setTaggedText("label", assignVariables(dc["label"].toString(), this), true);
|
setTaggedText("label", autonum::AssignVariables::formulaToLabel(dc["label"].toString(), m_autoNum_seq, diagram(), this), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,8 +151,7 @@ void MasterElement::changeElementInfo(){
|
|||||||
*/
|
*/
|
||||||
void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
|
void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
|
||||||
QString newstr = new_info["label"].toString();
|
QString newstr = new_info["label"].toString();
|
||||||
Element *elmt = this;
|
newstr = autonum::AssignVariables::formulaToLabel(newstr, m_autoNum_seq, diagram(), this);
|
||||||
newstr = assignVariables(newstr, elmt);
|
|
||||||
|
|
||||||
//Label of element
|
//Label of element
|
||||||
if (old_info["label"].toString() != newstr) {
|
if (old_info["label"].toString() != newstr) {
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ void ReportElement::updateLabel()
|
|||||||
{
|
{
|
||||||
Element *elmt = connected_elements.at(0);
|
Element *elmt = connected_elements.at(0);
|
||||||
QString label = label_;
|
QString label = label_;
|
||||||
label = assignVariables(label,elmt);
|
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
||||||
m_text_field -> setPlainText(label);
|
m_text_field -> setPlainText(label);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -61,9 +61,10 @@ void SimpleElement::initLink(QETProject *project) {
|
|||||||
* @brief SimpleElement::folioIdChange
|
* @brief SimpleElement::folioIdChange
|
||||||
* Use to update the label of this item when the foio id change
|
* Use to update the label of this item when the foio id change
|
||||||
*/
|
*/
|
||||||
void SimpleElement::folioIdChange() {
|
void SimpleElement::folioIdChange()
|
||||||
|
{
|
||||||
DiagramContext dc =elementInformations();
|
DiagramContext dc =elementInformations();
|
||||||
setTaggedText("label", assignVariables(dc["label"].toString(), this), true);
|
setTaggedText("label", autonum::AssignVariables::formulaToLabel(dc["label"].toString(), m_autoNum_seq, diagram(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,10 +83,9 @@ void SimpleElement::changeElementInfo(){
|
|||||||
* @brief SimpleElement::updateLabel
|
* @brief SimpleElement::updateLabel
|
||||||
* update label of this element
|
* update label of this element
|
||||||
*/
|
*/
|
||||||
void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
|
void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
|
||||||
QString label = new_info["label"].toString();
|
{
|
||||||
Element *elmt = this;
|
QString label = autonum::AssignVariables::formulaToLabel(new_info["label"].toString(), m_autoNum_seq, diagram(), this);
|
||||||
label = assignVariables(label,elmt);
|
|
||||||
|
|
||||||
//Label of element
|
//Label of element
|
||||||
if (old_info["label"].toString() != label) {
|
if (old_info["label"].toString() != label) {
|
||||||
|
|||||||
@@ -134,16 +134,17 @@ void SlaveElement::updateLabel()
|
|||||||
bool no_editable = false;
|
bool no_editable = false;
|
||||||
|
|
||||||
//must be linked to set the label of master
|
//must be linked to set the label of master
|
||||||
if (linkedElements().count()) {
|
if (linkedElements().count())
|
||||||
|
{
|
||||||
no_editable = true;
|
no_editable = true;
|
||||||
Element *elmt = linkedElements().first();
|
Element *elmt = linkedElements().first();
|
||||||
label = elmt -> elementInformations()["label"].toString();
|
label = elmt -> elementInformations()["label"].toString();
|
||||||
XRefProperties xrp = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
|
XRefProperties xrp = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
|
||||||
Xreflabel = xrp.slaveLabel();
|
Xreflabel = xrp.slaveLabel();
|
||||||
Xreflabel = assignVariables(Xreflabel, elmt);
|
Xreflabel = autonum::AssignVariables::formulaToLabel(Xreflabel, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
||||||
label = assignVariables(label, elmt);
|
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
||||||
}
|
}
|
||||||
else label = assignVariables(label, this);
|
else label = autonum::AssignVariables::formulaToLabel(label, m_autoNum_seq, diagram(), this);
|
||||||
|
|
||||||
// set the new label
|
// set the new label
|
||||||
ElementTextItem *eti = setTaggedText("label", label, no_editable);
|
ElementTextItem *eti = setTaggedText("label", label, no_editable);
|
||||||
|
|||||||
@@ -68,10 +68,9 @@ void TerminalElement::changeElementInfo(){
|
|||||||
* @brief SimpleElement::updateLabel
|
* @brief SimpleElement::updateLabel
|
||||||
* update label of this element
|
* update label of this element
|
||||||
*/
|
*/
|
||||||
void TerminalElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
|
void TerminalElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
|
||||||
QString label = new_info["label"].toString();
|
{
|
||||||
Element *elmt = this;
|
QString label = autonum::AssignVariables::formulaToLabel(new_info["label"].toString(), m_autoNum_seq, diagram(), this);
|
||||||
label = assignVariables(label,elmt);
|
|
||||||
|
|
||||||
//Label of element
|
//Label of element
|
||||||
if (old_info["label"].toString() != label) {
|
if (old_info["label"].toString() != label) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
|
#include "assignvariables.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementSelectorWidget::ElementSelectorWidget
|
* @brief ElementSelectorWidget::ElementSelectorWidget
|
||||||
@@ -134,13 +135,13 @@ void ElementSelectorWidget::buildInterface() {
|
|||||||
DiagramContext dc = elmt -> elementInformations();
|
DiagramContext dc = elmt -> elementInformations();
|
||||||
|
|
||||||
if (!dc["label"].toString().isEmpty())
|
if (!dc["label"].toString().isEmpty())
|
||||||
button_text = elmt->assignVariables(dc["label"].toString(), elmt) + " ";
|
button_text = autonum::AssignVariables::formulaToLabel(dc["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + " ";
|
||||||
|
|
||||||
if (!dc["comment"].toString().isEmpty())
|
if (!dc["comment"].toString().isEmpty())
|
||||||
button_text += elmt->assignVariables(dc["comment"].toString(), elmt);
|
button_text = autonum::AssignVariables::formulaToLabel(dc["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
||||||
|
|
||||||
if (!dc["location"].toString().isEmpty())
|
if (!dc["location"].toString().isEmpty())
|
||||||
button_text += elmt->assignVariables(dc["location"].toString(), elmt);
|
button_text = autonum::AssignVariables::formulaToLabel(dc["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
||||||
|
|
||||||
if (!button_text.isEmpty())
|
if (!button_text.isEmpty())
|
||||||
button_text += "\n";
|
button_text += "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user