mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
rap code for better readability
This commit is contained in:
@@ -38,17 +38,23 @@ class ElementXmlRetroCompatibility
|
|||||||
{
|
{
|
||||||
friend class Element;
|
friend class Element;
|
||||||
|
|
||||||
static void loadSequential(const QDomElement &dom_element, const QString& seq, QStringList* list)
|
static void loadSequential(const QDomElement &dom_element,
|
||||||
|
const QString& seq,
|
||||||
|
QStringList* list)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (!dom_element.attribute(seq + QString::number(i+1)).isEmpty())
|
while (!dom_element.attribute(seq +
|
||||||
|
QString::number(i+1)).isEmpty())
|
||||||
{
|
{
|
||||||
list->append(dom_element.attribute(seq + QString::number(i+1)));
|
list->append(dom_element.attribute(
|
||||||
|
seq +
|
||||||
|
QString::number(i+1)));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadSequential(const QDomElement &dom_element, Element *element)
|
static void loadSequential(const QDomElement &dom_element,
|
||||||
|
Element *element)
|
||||||
{
|
{
|
||||||
autonum::sequentialNumbers sn;
|
autonum::sequentialNumbers sn;
|
||||||
|
|
||||||
@@ -69,7 +75,10 @@ class ElementXmlRetroCompatibility
|
|||||||
* @param parent, parent graphics item
|
* @param parent, parent graphics item
|
||||||
* @param state, state of the instanciation
|
* @param state, state of the instanciation
|
||||||
*/
|
*/
|
||||||
Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *state, kind link_type) :
|
Element::Element(const ElementsLocation &location,
|
||||||
|
QGraphicsItem *parent,
|
||||||
|
int *state,
|
||||||
|
kind link_type) :
|
||||||
QetGraphicsItem(parent),
|
QetGraphicsItem(parent),
|
||||||
m_link_type (link_type),
|
m_link_type (link_type),
|
||||||
m_location (location)
|
m_location (location)
|
||||||
@@ -97,7 +106,8 @@ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *s
|
|||||||
setPrefix(autonum::elementPrefixForLocation(location));
|
setPrefix(autonum::elementPrefixForLocation(location));
|
||||||
m_uuid = QUuid::createUuid();
|
m_uuid = QUuid::createUuid();
|
||||||
setZValue(10);
|
setZValue(10);
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable
|
||||||
|
| QGraphicsItem::ItemIsSelectable);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
|
||||||
connect(this, &Element::rotationChanged, [this]() {
|
connect(this, &Element::rotationChanged, [this]() {
|
||||||
@@ -149,7 +159,10 @@ void Element::editProperty()
|
|||||||
{
|
{
|
||||||
ElementPropertiesWidget *epw = new ElementPropertiesWidget(this);
|
ElementPropertiesWidget *epw = new ElementPropertiesWidget(this);
|
||||||
PropertiesEditorDialog dialog(epw, QApplication::activeWindow());
|
PropertiesEditorDialog dialog(epw, QApplication::activeWindow());
|
||||||
connect(epw, &ElementPropertiesWidget::findEditClicked, &dialog, &QDialog::reject);
|
connect(epw,
|
||||||
|
&ElementPropertiesWidget::findEditClicked,
|
||||||
|
&dialog,
|
||||||
|
&QDialog::reject);
|
||||||
//Must be windowModal, else when user do a drag and drop
|
//Must be windowModal, else when user do a drag and drop
|
||||||
//with the "text" tab of ElementPropertiesWidget, the ui freeze, until user press escape key
|
//with the "text" tab of ElementPropertiesWidget, the ui freeze, until user press escape key
|
||||||
dialog.setWindowModality(Qt::WindowModal);
|
dialog.setWindowModality(Qt::WindowModal);
|
||||||
@@ -182,7 +195,9 @@ void Element::displayHelpLine(bool b)
|
|||||||
* @param options
|
* @param options
|
||||||
* @param widget
|
* @param widget
|
||||||
*/
|
*/
|
||||||
void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *)
|
void Element::paint(QPainter *painter,
|
||||||
|
const QStyleOptionGraphicsItem *options,
|
||||||
|
QWidget *)
|
||||||
{
|
{
|
||||||
if (m_must_highlight) {
|
if (m_must_highlight) {
|
||||||
drawHighlight(painter, options);
|
drawHighlight(painter, options);
|
||||||
@@ -204,7 +219,8 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
|
|||||||
@return Le rectangle delimitant le contour de l'element
|
@return Le rectangle delimitant le contour de l'element
|
||||||
*/
|
*/
|
||||||
QRectF Element::boundingRect() const {
|
QRectF Element::boundingRect() const {
|
||||||
return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()), dimensions));
|
return(QRectF(QPointF(-hotspot_coord.x(), -hotspot_coord.y()),
|
||||||
|
dimensions));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,7 +287,8 @@ QPixmap Element::pixmap() {
|
|||||||
@param painter Le QPainter a utiliser pour dessiner les axes
|
@param painter Le QPainter a utiliser pour dessiner les axes
|
||||||
@param options Les options de style a prendre en compte
|
@param options Les options de style a prendre en compte
|
||||||
*/
|
*/
|
||||||
void Element::drawAxes(QPainter *painter, const QStyleOptionGraphicsItem *options) {
|
void Element::drawAxes(QPainter *painter,
|
||||||
|
const QStyleOptionGraphicsItem *options) {
|
||||||
Q_UNUSED(options);
|
Q_UNUSED(options);
|
||||||
painter -> setPen(Qt::blue);
|
painter -> setPen(Qt::blue);
|
||||||
painter -> drawLine(0, 0, 10, 0);
|
painter -> drawLine(0, 0, 10, 0);
|
||||||
@@ -290,7 +307,8 @@ void Element::drawAxes(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
@param painter Le QPainter a utiliser pour dessiner les bornes.
|
@param painter Le QPainter a utiliser pour dessiner les bornes.
|
||||||
@param options Les options de style a prendre en compte
|
@param options Les options de style a prendre en compte
|
||||||
*/
|
*/
|
||||||
void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *options) {
|
void Element::drawSelection(QPainter *painter,
|
||||||
|
const QStyleOptionGraphicsItem *options) {
|
||||||
Q_UNUSED(options);
|
Q_UNUSED(options);
|
||||||
painter -> save();
|
painter -> save();
|
||||||
// Annulation des renderhints
|
// Annulation des renderhints
|
||||||
@@ -304,7 +322,9 @@ void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||||||
t.setCosmetic(true);
|
t.setCosmetic(true);
|
||||||
painter -> setPen(t);
|
painter -> setPen(t);
|
||||||
// Le dessin se fait a partir du rectangle delimitant
|
// Le dessin se fait a partir du rectangle delimitant
|
||||||
painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
|
painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1),
|
||||||
|
10,
|
||||||
|
10);
|
||||||
painter -> restore();
|
painter -> restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,11 +333,13 @@ void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||||||
@param painter Le QPainter a utiliser pour dessiner les bornes.
|
@param painter Le QPainter a utiliser pour dessiner les bornes.
|
||||||
@param options Les options de style a prendre en compte
|
@param options Les options de style a prendre en compte
|
||||||
*/
|
*/
|
||||||
void Element::drawHighlight(QPainter *painter, const QStyleOptionGraphicsItem *options) {
|
void Element::drawHighlight(QPainter *painter,
|
||||||
|
const QStyleOptionGraphicsItem *options) {
|
||||||
Q_UNUSED(options);
|
Q_UNUSED(options);
|
||||||
painter -> save();
|
painter -> save();
|
||||||
|
|
||||||
qreal gradient_radius = qMin(boundingRect().width(), boundingRect().height()) / 2.0;
|
qreal gradient_radius = qMin(boundingRect().width(),
|
||||||
|
boundingRect().height()) / 2.0;
|
||||||
QRadialGradient gradient(
|
QRadialGradient gradient(
|
||||||
boundingRect().center(),
|
boundingRect().center(),
|
||||||
gradient_radius,
|
gradient_radius,
|
||||||
@@ -330,7 +352,9 @@ void Element::drawHighlight(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||||||
painter -> setPen(Qt::NoPen);
|
painter -> setPen(Qt::NoPen);
|
||||||
painter -> setBrush(brush);
|
painter -> setBrush(brush);
|
||||||
// Le dessin se fait a partir du rectangle delimitant
|
// Le dessin se fait a partir du rectangle delimitant
|
||||||
painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1), 10, 10);
|
painter -> drawRoundedRect(boundingRect().adjusted(1, 1, -1, -1),
|
||||||
|
10,
|
||||||
|
10);
|
||||||
painter -> restore();
|
painter -> restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +376,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
|
|||||||
{
|
{
|
||||||
m_state = QET::GIBuildingFromXml;
|
m_state = QET::GIBuildingFromXml;
|
||||||
|
|
||||||
if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element")
|
if (xml_def_elmt.tagName() != "definition"
|
||||||
|
|| xml_def_elmt.attribute("type") != "element")
|
||||||
{
|
{
|
||||||
if (state) *state = 4;
|
if (state) *state = 4;
|
||||||
m_state = QET::GIOK;
|
m_state = QET::GIOK;
|
||||||
@@ -363,7 +388,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
|
|||||||
if (xml_def_elmt.hasAttribute("version"))
|
if (xml_def_elmt.hasAttribute("version"))
|
||||||
{
|
{
|
||||||
bool conv_ok;
|
bool conv_ok;
|
||||||
qreal element_version = xml_def_elmt.attribute("version").toDouble(&conv_ok);
|
qreal element_version = xml_def_elmt.attribute(
|
||||||
|
"version").toDouble(&conv_ok);
|
||||||
if (conv_ok && QET::version.toDouble() < element_version)
|
if (conv_ok && QET::version.toDouble() < element_version)
|
||||||
{
|
{
|
||||||
std::cerr << qPrintable(
|
std::cerr << qPrintable(
|
||||||
@@ -402,13 +428,19 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
|
|||||||
setToolTip(name());
|
setToolTip(name());
|
||||||
|
|
||||||
//load kind informations
|
//load kind informations
|
||||||
m_kind_informations.fromXml(xml_def_elmt.firstChildElement("kindInformations"), "kindInformation");
|
m_kind_informations.fromXml(
|
||||||
|
xml_def_elmt.firstChildElement("kindInformations"),
|
||||||
|
"kindInformation");
|
||||||
//load element information
|
//load element information
|
||||||
m_element_informations.fromXml(xml_def_elmt.firstChildElement("elementInformations"), "elementInformation");
|
m_element_informations.fromXml(
|
||||||
|
xml_def_elmt.firstChildElement("elementInformations"),
|
||||||
|
"elementInformation");
|
||||||
|
|
||||||
//scroll of the Children of the Definition: Parts of the Drawing
|
//scroll of the Children of the Definition: Parts of the Drawing
|
||||||
int parsed_elements_count = 0;
|
int parsed_elements_count = 0;
|
||||||
for (QDomNode node = xml_def_elmt.firstChild() ; !node.isNull() ; node = node.nextSibling())
|
for (QDomNode node = xml_def_elmt.firstChild() ;
|
||||||
|
!node.isNull() ;
|
||||||
|
node = node.nextSibling())
|
||||||
{
|
{
|
||||||
QDomElement elmts = node.toElement();
|
QDomElement elmts = node.toElement();
|
||||||
if (elmts.isNull())
|
if (elmts.isNull())
|
||||||
@@ -420,20 +452,26 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
|
|||||||
//If not, we set the tagg "label" to the first "input.
|
//If not, we set the tagg "label" to the first "input.
|
||||||
QList <QDomElement> input_field;
|
QList <QDomElement> input_field;
|
||||||
bool have_label = false;
|
bool have_label = false;
|
||||||
for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input"))
|
for (QDomElement input_node = node.firstChildElement("input") ;
|
||||||
|
!input_node.isNull() ;
|
||||||
|
input_node = input_node.nextSiblingElement("input"))
|
||||||
{
|
{
|
||||||
if (!input_node.isNull())
|
if (!input_node.isNull())
|
||||||
{
|
{
|
||||||
input_field << input_node;
|
input_field << input_node;
|
||||||
if (input_node.attribute("tagg", "none") == "label")
|
if (input_node.attribute("tagg", "none")
|
||||||
|
== "label")
|
||||||
have_label = true;
|
have_label = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!have_label && !input_field.isEmpty())
|
if(!have_label && !input_field.isEmpty())
|
||||||
input_field.first().setAttribute("tagg", "label");
|
input_field.first().setAttribute("tagg",
|
||||||
|
"label");
|
||||||
|
|
||||||
//Parse the definition
|
//Parse the definition
|
||||||
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling())
|
for (QDomNode n = node.firstChild() ;
|
||||||
|
!n.isNull() ;
|
||||||
|
n = n.nextSibling())
|
||||||
{
|
{
|
||||||
QDomElement qde = n.toElement();
|
QDomElement qde = n.toElement();
|
||||||
if (qde.isNull())
|
if (qde.isNull())
|
||||||
@@ -454,7 +492,9 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ElementPictureFactory *epf = ElementPictureFactory::instance();
|
ElementPictureFactory *epf = ElementPictureFactory::instance();
|
||||||
epf->getPictures(m_location, const_cast<QPicture&>(m_picture), const_cast<QPicture&>(m_low_zoom_picture));
|
epf->getPictures(m_location,
|
||||||
|
const_cast<QPicture&>(m_picture),
|
||||||
|
const_cast<QPicture&>(m_low_zoom_picture));
|
||||||
|
|
||||||
if(!m_picture.isNull())
|
if(!m_picture.isNull())
|
||||||
++ parsed_elements_count;
|
++ parsed_elements_count;
|
||||||
@@ -512,9 +552,11 @@ bool Element::parseInput(const QDomElement &dom_element)
|
|||||||
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
||||||
deti->setText(dom_element.attribute("text", "_"));
|
deti->setText(dom_element.attribute("text", "_"));
|
||||||
QFont font = deti->font();
|
QFont font = deti->font();
|
||||||
font.setPointSize(dom_element.attribute("size", QString::number(9)).toInt());
|
font.setPointSize(dom_element.attribute("size",
|
||||||
|
QString::number(9)).toInt());
|
||||||
deti->setFont(font);
|
deti->setFont(font);
|
||||||
deti->setRotation(dom_element.attribute("rotation", QString::number(0)).toDouble());
|
deti->setRotation(dom_element.attribute("rotation",
|
||||||
|
QString::number(0)).toDouble());
|
||||||
|
|
||||||
if(dom_element.attribute("tagg", "none") != "none")
|
if(dom_element.attribute("tagg", "none") != "none")
|
||||||
{
|
{
|
||||||
@@ -527,12 +569,17 @@ bool Element::parseInput(const QDomElement &dom_element)
|
|||||||
//We need to use a QTransform to find the pos of this text from the saved pos of text item
|
//We need to use a QTransform to find the pos of this text from the saved pos of text item
|
||||||
QTransform transform;
|
QTransform transform;
|
||||||
//First make the rotation
|
//First make the rotation
|
||||||
transform.rotate(dom_element.attribute("rotation", "0").toDouble());
|
transform.rotate(dom_element.attribute("rotation",
|
||||||
QPointF pos = transform.map(QPointF(0, -deti->boundingRect().height()/2));
|
"0").toDouble());
|
||||||
|
QPointF pos = transform.map(
|
||||||
|
QPointF(0,
|
||||||
|
-deti->boundingRect().height()/2));
|
||||||
transform.reset();
|
transform.reset();
|
||||||
//Second translate to the pos
|
//Second translate to the pos
|
||||||
QPointF p(dom_element.attribute("x", QString::number(0)).toDouble(),
|
QPointF p(dom_element.attribute("x",
|
||||||
dom_element.attribute("y", QString::number(0)).toDouble());
|
QString::number(0)).toDouble(),
|
||||||
|
dom_element.attribute("y",
|
||||||
|
QString::number(0)).toDouble());
|
||||||
transform.translate(p.x(), p.y());
|
transform.translate(p.x(), p.y());
|
||||||
deti->setPos(transform.map(pos));
|
deti->setPos(transform.map(pos));
|
||||||
m_converted_text_from_xml_description.insert(deti, p);
|
m_converted_text_from_xml_description.insert(deti, p);
|
||||||
@@ -546,7 +593,8 @@ bool Element::parseInput(const QDomElement &dom_element)
|
|||||||
* @param dom_element
|
* @param dom_element
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element)
|
DynamicElementTextItem *Element::parseDynamicText(
|
||||||
|
const QDomElement &dom_element)
|
||||||
{
|
{
|
||||||
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
||||||
//Because the xml description of a .elmt file is the same as how a dynamic text field is save to xml in a .qet file
|
//Because the xml description of a .elmt file is the same as how a dynamic text field is save to xml in a .qet file
|
||||||
@@ -580,7 +628,10 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element)
|
|||||||
m_terminals << new_terminal;
|
m_terminals << new_terminal;
|
||||||
|
|
||||||
//Sort from top to bottom and left to rigth
|
//Sort from top to bottom and left to rigth
|
||||||
std::sort(m_terminals.begin(), m_terminals.end(), [](Terminal *a, Terminal *b)
|
std::sort(m_terminals.begin(),
|
||||||
|
m_terminals.end(),
|
||||||
|
[](Terminal *a,
|
||||||
|
Terminal *b)
|
||||||
{
|
{
|
||||||
if(a->dockConductor().y() == b->dockConductor().y())
|
if(a->dockConductor().y() == b->dockConductor().y())
|
||||||
return (a->dockConductor().x() < b->dockConductor().x());
|
return (a->dockConductor().x() < b->dockConductor().x());
|
||||||
@@ -629,7 +680,10 @@ bool Element::valideXml(QDomElement &e) {
|
|||||||
* @param handle_inputs_rotation : apply the rotation of this element to his child text
|
* @param handle_inputs_rotation : apply the rotation of this element to his child text
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool handle_inputs_rotation)
|
bool Element::fromXml(QDomElement &e,
|
||||||
|
QHash<int,
|
||||||
|
Terminal *> &table_id_adr,
|
||||||
|
bool handle_inputs_rotation)
|
||||||
{
|
{
|
||||||
m_state = QET::GILoadingFromXml;
|
m_state = QET::GILoadingFromXml;
|
||||||
/*
|
/*
|
||||||
@@ -637,7 +691,8 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
ce recensement servira lors de la mise en place des fils
|
ce recensement servira lors de la mise en place des fils
|
||||||
*/
|
*/
|
||||||
QList<QDomElement> liste_terminals;
|
QList<QDomElement> liste_terminals;
|
||||||
foreach(QDomElement qde, QET::findInDomElement(e, "terminals", "terminal")) {
|
foreach(QDomElement qde,
|
||||||
|
QET::findInDomElement(e, "terminals", "terminal")) {
|
||||||
if (Terminal::valideXml(qde)) liste_terminals << qde;
|
if (Terminal::valideXml(qde)) liste_terminals << qde;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +703,10 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
bool terminal_trouvee = false;
|
bool terminal_trouvee = false;
|
||||||
foreach(QDomElement qde, liste_terminals) {
|
foreach(QDomElement qde, liste_terminals) {
|
||||||
if (p -> fromXml(qde)) {
|
if (p -> fromXml(qde)) {
|
||||||
priv_id_adr.insert(qde.attribute("id").toInt(), p);
|
priv_id_adr.insert(
|
||||||
|
qde.attribute(
|
||||||
|
"id").toInt(),
|
||||||
|
p);
|
||||||
terminal_trouvee = true;
|
terminal_trouvee = true;
|
||||||
// We used to break here, because we did not expect
|
// We used to break here, because we did not expect
|
||||||
// several terminals to share the same position.
|
// several terminals to share the same position.
|
||||||
@@ -678,13 +736,17 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
}
|
}
|
||||||
// copie des associations id / adr
|
// copie des associations id / adr
|
||||||
foreach(int id_trouve, priv_id_adr.keys()) {
|
foreach(int id_trouve, priv_id_adr.keys()) {
|
||||||
table_id_adr.insert(id_trouve, priv_id_adr.value(id_trouve));
|
table_id_adr.insert(id_trouve,
|
||||||
|
priv_id_adr.value(id_trouve));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//load uuid of connected elements
|
//load uuid of connected elements
|
||||||
QList <QDomElement> uuid_list = QET::findInDomElement(e, "links_uuids", "link_uuid");
|
QList <QDomElement> uuid_list = QET::findInDomElement(e,
|
||||||
foreach (QDomElement qdo, uuid_list) tmp_uuids_link << qdo.attribute("uuid");
|
"links_uuids",
|
||||||
|
"link_uuid");
|
||||||
|
foreach (QDomElement qdo, uuid_list)
|
||||||
|
tmp_uuids_link << qdo.attribute("uuid");
|
||||||
|
|
||||||
//uuid of this element
|
//uuid of this element
|
||||||
m_uuid= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
|
m_uuid= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
|
||||||
@@ -696,16 +758,23 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
m_freeze_label = fl == "false"? false : true;
|
m_freeze_label = fl == "false"? false : true;
|
||||||
|
|
||||||
//Load Sequential Values
|
//Load Sequential Values
|
||||||
if (e.hasAttribute("sequ_1") || e.hasAttribute("sequf_1") || e.hasAttribute("seqt_1") || e.hasAttribute("seqtf_1") || e.hasAttribute("seqh_1") || e.hasAttribute("sequf_1"))
|
if (e.hasAttribute("sequ_1")
|
||||||
|
|| e.hasAttribute("sequf_1")
|
||||||
|
|| e.hasAttribute("seqt_1")
|
||||||
|
|| e.hasAttribute("seqtf_1")
|
||||||
|
|| e.hasAttribute("seqh_1")
|
||||||
|
|| e.hasAttribute("sequf_1"))
|
||||||
ElementXmlRetroCompatibility::loadSequential(e, this);
|
ElementXmlRetroCompatibility::loadSequential(e, this);
|
||||||
else
|
else
|
||||||
m_autoNum_seq.fromXml(e.firstChildElement("sequentialNumbers"));
|
m_autoNum_seq.fromXml(e.firstChildElement("sequentialNumbers"));
|
||||||
|
|
||||||
//Position and selection.
|
//Position and selection.
|
||||||
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
|
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
|
||||||
QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
QGraphicsObject::setPos(e.attribute("x").toDouble(),
|
||||||
|
e.attribute("y").toDouble());
|
||||||
setZValue(e.attribute("z", QString::number(this->zValue())).toDouble());
|
setZValue(e.attribute("z", QString::number(this->zValue())).toDouble());
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable
|
||||||
|
| QGraphicsItem::ItemIsSelectable);
|
||||||
|
|
||||||
// orientation
|
// orientation
|
||||||
bool conv_ok;
|
bool conv_ok;
|
||||||
@@ -726,7 +795,10 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
//************************//
|
//************************//
|
||||||
//***Dynamic texts item***//
|
//***Dynamic texts item***//
|
||||||
//************************//
|
//************************//
|
||||||
for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName()))
|
for (const QDomElement& qde : QET::findInDomElement(
|
||||||
|
e,
|
||||||
|
"dynamic_texts",
|
||||||
|
DynamicElementTextItem::xmlTagName()))
|
||||||
{
|
{
|
||||||
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
|
||||||
addDynamicTextItem(deti);
|
addDynamicTextItem(deti);
|
||||||
@@ -740,7 +812,8 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
|
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
|
||||||
|
|
||||||
//First case, we check for the text item converted to dynamic text item
|
//First case, we check for the text item converted to dynamic text item
|
||||||
const QList <DynamicElementTextItem *> conv_deti_list = m_converted_text_from_xml_description.keys();
|
const QList <DynamicElementTextItem *> conv_deti_list =
|
||||||
|
m_converted_text_from_xml_description.keys();
|
||||||
QList <DynamicElementTextItem *> successfully_converted;
|
QList <DynamicElementTextItem *> successfully_converted;
|
||||||
const QList <QDomElement> dom_inputs = inputs;
|
const QList <QDomElement> dom_inputs = inputs;
|
||||||
|
|
||||||
@@ -751,13 +824,18 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
//we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored.
|
//we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored.
|
||||||
//The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element
|
//The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element
|
||||||
//that mean this is the good text
|
//that mean this is the good text
|
||||||
if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), m_converted_text_from_xml_description.value(deti).x()) &&
|
if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()),
|
||||||
qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), m_converted_text_from_xml_description.value(deti).y()))
|
m_converted_text_from_xml_description.value(deti).x()) &&
|
||||||
|
qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()),
|
||||||
|
m_converted_text_from_xml_description.value(deti).y()))
|
||||||
{
|
{
|
||||||
//Once again this 'if', is only for retrocompatibility with old old old project
|
//Once again this 'if', is only for retrocompatibility with old old old project
|
||||||
//when element text with tagg "label" is not null, but the element information "label" is.
|
//when element text with tagg "label" is not null, but the element information "label" is.
|
||||||
if((deti->textFrom() == DynamicElementTextItem::ElementInfo) && (deti->infoName() == "label"))
|
if((deti->textFrom() == DynamicElementTextItem::ElementInfo)
|
||||||
m_element_informations.addValue("label", dom_input.attribute("text"));
|
&& (deti->infoName() == "label"))
|
||||||
|
m_element_informations.addValue(
|
||||||
|
"label",
|
||||||
|
dom_input.attribute("text"));
|
||||||
|
|
||||||
deti->setText(dom_input.attribute("text"));
|
deti->setText(dom_input.attribute("text"));
|
||||||
|
|
||||||
@@ -782,7 +860,9 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
QTransform transform;
|
QTransform transform;
|
||||||
//First make the rotation
|
//First make the rotation
|
||||||
transform.rotate(rotation);
|
transform.rotate(rotation);
|
||||||
QPointF pos = transform.map(QPointF(0, -deti->boundingRect().height()/2));
|
QPointF pos = transform.map(
|
||||||
|
QPointF(0,
|
||||||
|
-deti->boundingRect().height()/2));
|
||||||
transform.reset();
|
transform.reset();
|
||||||
//Second translate to the pos
|
//Second translate to the pos
|
||||||
transform.translate(xml_pos.x(), xml_pos.y());
|
transform.translate(xml_pos.x(), xml_pos.y());
|
||||||
@@ -811,15 +891,20 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
delete deti;
|
delete deti;
|
||||||
m_converted_text_from_xml_description.clear();
|
m_converted_text_from_xml_description.clear();
|
||||||
|
|
||||||
for (QDomElement qde : QET::findInDomElement(e, "texts_groups", ElementTextItemGroup::xmlTaggName()))
|
for (QDomElement qde : QET::findInDomElement(
|
||||||
|
e,
|
||||||
|
"texts_groups",
|
||||||
|
ElementTextItemGroup::xmlTaggName()))
|
||||||
{
|
{
|
||||||
ElementTextItemGroup *group = addTextGroup("loaded_from_xml_group");
|
ElementTextItemGroup *group =
|
||||||
|
addTextGroup("loaded_from_xml_group");
|
||||||
group->fromXml(qde);
|
group->fromXml(qde);
|
||||||
}
|
}
|
||||||
|
|
||||||
//load informations
|
//load informations
|
||||||
DiagramContext dc;
|
DiagramContext dc;
|
||||||
dc.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
|
dc.fromXml(e.firstChildElement("elementInformations"),
|
||||||
|
"elementInformation");
|
||||||
/**
|
/**
|
||||||
* Since the commit 4791, the value used as "label" and "formula" is stored in differents keys (instead of the same key, "label" in previous version),
|
* Since the commit 4791, the value used as "label" and "formula" is stored in differents keys (instead of the same key, "label" in previous version),
|
||||||
* so, if "label" contain "%" (Use variable value), and "formula" does not exist,
|
* so, if "label" contain "%" (Use variable value), and "formula" does not exist,
|
||||||
@@ -827,7 +912,8 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
* @TODO remove this code at version 0.7 or more (probably useless).
|
* @TODO remove this code at version 0.7 or more (probably useless).
|
||||||
*/
|
*/
|
||||||
#pragma message("@TODO remove this code for qet 0.7 or later")
|
#pragma message("@TODO remove this code for qet 0.7 or later")
|
||||||
if (dc["label"].toString().contains("%") && dc["formula"].toString().isNull())
|
if (dc["label"].toString().contains("%")
|
||||||
|
&& dc["formula"].toString().isNull())
|
||||||
{
|
{
|
||||||
dc.addValue("formula", dc["label"]);
|
dc.addValue("formula", dc["label"]);
|
||||||
}
|
}
|
||||||
@@ -856,31 +942,40 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
{
|
{
|
||||||
//#2 the element information must have label not empty and visible
|
//#2 the element information must have label not empty and visible
|
||||||
//and a least comment or location not empty and visible
|
//and a least comment or location not empty and visible
|
||||||
QString label = m_element_informations.value("label").toString();
|
QString label = m_element_informations.value(
|
||||||
QString comment = m_element_informations.value("comment").toString();
|
"label").toString();
|
||||||
QString location = m_element_informations.value("location").toString();
|
QString comment = m_element_informations.value(
|
||||||
|
"comment").toString();
|
||||||
|
QString location = m_element_informations.value(
|
||||||
|
"location").toString();
|
||||||
bool la = m_element_informations.keyMustShow("label");
|
bool la = m_element_informations.keyMustShow("label");
|
||||||
bool c = m_element_informations.keyMustShow("comment");
|
bool c = m_element_informations.keyMustShow("comment");
|
||||||
bool lo = m_element_informations.keyMustShow("location");
|
bool lo = m_element_informations.keyMustShow("location");
|
||||||
|
|
||||||
if((m_link_type != Master) ||
|
if((m_link_type != Master) ||
|
||||||
((m_link_type == Master) &&
|
((m_link_type == Master) &&
|
||||||
(diagram()->project()->defaultXRefProperties(m_kind_informations["type"].toString()).snapTo() == XRefProperties::Label))
|
(diagram()->project()->defaultXRefProperties(
|
||||||
|
m_kind_informations["type"].toString()).snapTo()
|
||||||
|
== XRefProperties::Label))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if(!label.isEmpty() && la &&
|
if(!label.isEmpty() && la &&
|
||||||
((!comment.isEmpty() && c) || (!location.isEmpty() && lo)))
|
((!comment.isEmpty() && c)
|
||||||
|
|| (!location.isEmpty() && lo)))
|
||||||
{
|
{
|
||||||
//#2 in the converted list one text must have text from = element info and info name = label
|
//#2 in the converted list one text must have text from = element info and info name = label
|
||||||
for(DynamicElementTextItem *deti : successfully_converted)
|
for(DynamicElementTextItem *deti
|
||||||
|
: successfully_converted)
|
||||||
{
|
{
|
||||||
if(deti->textFrom() == DynamicElementTextItem::ElementInfo && deti->infoName() == "label")
|
if(deti->textFrom()== DynamicElementTextItem::ElementInfo
|
||||||
|
&& deti->infoName() == "label")
|
||||||
{
|
{
|
||||||
qreal rotation = deti->rotation();
|
qreal rotation = deti->rotation();
|
||||||
|
|
||||||
//Create the comment item
|
//Create the comment item
|
||||||
DynamicElementTextItem *comment_text = nullptr;
|
DynamicElementTextItem *comment_text = nullptr;
|
||||||
if (m_link_type !=PreviousReport || m_link_type !=NextReport)
|
if (m_link_type !=PreviousReport
|
||||||
|
|| m_link_type !=NextReport)
|
||||||
{
|
{
|
||||||
m_state = QET::GIOK;
|
m_state = QET::GIOK;
|
||||||
return(true);
|
return(true);
|
||||||
@@ -921,18 +1016,22 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPointF pos = deti->pos();
|
QPointF pos = deti->pos();
|
||||||
if (m_link_type !=PreviousReport || m_link_type !=NextReport)
|
if (m_link_type !=PreviousReport
|
||||||
|
|| m_link_type !=NextReport)
|
||||||
{
|
{
|
||||||
m_state = QET::GIOK;
|
m_state = QET::GIOK;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
//Create the group
|
//Create the group
|
||||||
ElementTextItemGroup *group = addTextGroup(tr("Label + commentaire"));
|
ElementTextItemGroup *group =
|
||||||
|
addTextGroup(tr("Label + commentaire"));
|
||||||
addTextToGroup(deti, group);
|
addTextToGroup(deti, group);
|
||||||
if(comment_text)
|
if(comment_text)
|
||||||
addTextToGroup(comment_text, group);
|
addTextToGroup(comment_text,
|
||||||
|
group);
|
||||||
if(location_text)
|
if(location_text)
|
||||||
addTextToGroup(location_text, group);
|
addTextToGroup(location_text,
|
||||||
|
group);
|
||||||
group->setAlignment(Qt::AlignVCenter);
|
group->setAlignment(Qt::AlignVCenter);
|
||||||
group->setVerticalAdjustment(-4);
|
group->setVerticalAdjustment(-4);
|
||||||
group->setRotation(rotation);
|
group->setRotation(rotation);
|
||||||
@@ -955,7 +1054,9 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
if(!comment.isEmpty() && c)
|
if(!comment.isEmpty() && c)
|
||||||
{
|
{
|
||||||
comment_text = new DynamicElementTextItem(this);
|
comment_text = new DynamicElementTextItem(this);
|
||||||
comment_text->setTextFrom(DynamicElementTextItem::ElementInfo);
|
comment_text
|
||||||
|
->setTextFrom(
|
||||||
|
DynamicElementTextItem::ElementInfo);
|
||||||
comment_text->setInfoName("comment");
|
comment_text->setInfoName("comment");
|
||||||
QFont font = comment_text->font();
|
QFont font = comment_text->font();
|
||||||
font.setPointSize(6);
|
font.setPointSize(6);
|
||||||
@@ -969,19 +1070,24 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
if(!location.isEmpty() && lo)
|
if(!location.isEmpty() && lo)
|
||||||
{
|
{
|
||||||
location_text = new DynamicElementTextItem(this);
|
location_text = new DynamicElementTextItem(this);
|
||||||
location_text->setTextFrom(DynamicElementTextItem::ElementInfo);
|
location_text
|
||||||
|
->setTextFrom(
|
||||||
|
DynamicElementTextItem::ElementInfo);
|
||||||
location_text->setInfoName("location");
|
location_text->setInfoName("location");
|
||||||
QFont font = location_text->font();
|
QFont font = location_text->font();
|
||||||
font.setPointSize(6);
|
font.setPointSize(6);
|
||||||
location_text->setFont(font);
|
location_text->setFont(font);
|
||||||
location_text->setTextWidth(80);
|
location_text->setTextWidth(80);
|
||||||
if(comment_text)
|
if(comment_text)
|
||||||
location_text->setPos(comment_text->x(), comment_text->y()+10); //+10 is arbitrary, location_text must be below the comment
|
location_text->setPos(
|
||||||
|
comment_text->x(),
|
||||||
|
comment_text->y()+10); //+10 is arbitrary, location_text must be below the comment
|
||||||
addDynamicTextItem(location_text);
|
addDynamicTextItem(location_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create the group
|
//Create the group
|
||||||
ElementTextItemGroup *group = addTextGroup(tr("Label + commentaire"));
|
ElementTextItemGroup *group =
|
||||||
|
addTextGroup(tr("Label + commentaire"));
|
||||||
if(comment_text)
|
if(comment_text)
|
||||||
addTextToGroup(comment_text, group);
|
addTextToGroup(comment_text, group);
|
||||||
if(location_text)
|
if(location_text)
|
||||||
@@ -992,7 +1098,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_state = QET::GIOK;
|
m_state = QET::GIOK;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,7 +1118,9 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
\~ @return The XML element representing this electrical element
|
\~ @return The XML element representing this electrical element
|
||||||
\~French L'element XML representant cet element electrique
|
\~French L'element XML representant cet element electrique
|
||||||
*/
|
*/
|
||||||
QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table_adr_id) const
|
QDomElement Element::toXml(QDomDocument &document,
|
||||||
|
QHash<Terminal *,
|
||||||
|
int> &table_adr_id) const
|
||||||
{
|
{
|
||||||
QDomElement element = document.createElement("element");
|
QDomElement element = document.createElement("element");
|
||||||
|
|
||||||
@@ -1059,7 +1167,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
foreach(Terminal *t, terminals()) {
|
foreach(Terminal *t, terminals()) {
|
||||||
// alors on enregistre la borne
|
// alors on enregistre la borne
|
||||||
QDomElement terminal = t -> toXml(document);
|
QDomElement terminal = t -> toXml(document);
|
||||||
terminal.setAttribute("id", id_terminal); // for backward compatibility
|
terminal.setAttribute("id", id_terminal); // for backward compatibility
|
||||||
table_adr_id.insert(t, id_terminal ++);
|
table_adr_id.insert(t, id_terminal ++);
|
||||||
xml_terminals.appendChild(terminal);
|
xml_terminals.appendChild(terminal);
|
||||||
}
|
}
|
||||||
@@ -1074,7 +1182,8 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
if (! isFree()) {
|
if (! isFree()) {
|
||||||
QDomElement links_uuids = document.createElement("links_uuids");
|
QDomElement links_uuids = document.createElement("links_uuids");
|
||||||
foreach (Element *elmt, connected_elements) {
|
foreach (Element *elmt, connected_elements) {
|
||||||
QDomElement link_uuid = document.createElement("link_uuid");
|
QDomElement link_uuid =
|
||||||
|
document.createElement("link_uuid");
|
||||||
link_uuid.setAttribute("uuid", elmt->uuid().toString());
|
link_uuid.setAttribute("uuid", elmt->uuid().toString());
|
||||||
links_uuids.appendChild(link_uuid);
|
links_uuids.appendChild(link_uuid);
|
||||||
}
|
}
|
||||||
@@ -1083,14 +1192,15 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
|
|
||||||
//save information of this element
|
//save information of this element
|
||||||
if (! m_element_informations.keys().isEmpty()) {
|
if (! m_element_informations.keys().isEmpty()) {
|
||||||
QDomElement infos = document.createElement("elementInformations");
|
QDomElement infos =
|
||||||
|
document.createElement("elementInformations");
|
||||||
m_element_informations.toXml(infos, "elementInformation");
|
m_element_informations.toXml(infos, "elementInformation");
|
||||||
element.appendChild(infos);
|
element.appendChild(infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dynamic texts
|
//Dynamic texts
|
||||||
QDomElement dyn_text = document.createElement("dynamic_texts");
|
QDomElement dyn_text = document.createElement("dynamic_texts");
|
||||||
for (DynamicElementTextItem *deti : m_dynamic_text_list)
|
for (DynamicElementTextItem *deti : m_dynamic_text_list)
|
||||||
dyn_text.appendChild(deti->toXml(document));
|
dyn_text.appendChild(deti->toXml(document));
|
||||||
|
|
||||||
QDomElement texts_group = document.createElement("texts_groups");
|
QDomElement texts_group = document.createElement("texts_groups");
|
||||||
@@ -1131,7 +1241,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
//Append the texts group to element
|
//Append the texts group to element
|
||||||
element.appendChild(texts_group);
|
element.appendChild(texts_group);
|
||||||
|
|
||||||
return(element);
|
return(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1142,18 +1252,18 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
*/
|
*/
|
||||||
void Element::addDynamicTextItem(DynamicElementTextItem *deti)
|
void Element::addDynamicTextItem(DynamicElementTextItem *deti)
|
||||||
{
|
{
|
||||||
if (deti && !m_dynamic_text_list.contains(deti))
|
if (deti && !m_dynamic_text_list.contains(deti))
|
||||||
{
|
{
|
||||||
m_dynamic_text_list.append(deti);
|
m_dynamic_text_list.append(deti);
|
||||||
deti->setParentItem(this);
|
deti->setParentItem(this);
|
||||||
emit textAdded(deti);
|
emit textAdded(deti);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DynamicElementTextItem *text = new DynamicElementTextItem(this);
|
DynamicElementTextItem *text = new DynamicElementTextItem(this);
|
||||||
m_dynamic_text_list.append(text);
|
m_dynamic_text_list.append(text);
|
||||||
emit textAdded(text);
|
emit textAdded(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1164,9 +1274,9 @@ void Element::addDynamicTextItem(DynamicElementTextItem *deti)
|
|||||||
*/
|
*/
|
||||||
void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
void Element::removeDynamicTextItem(DynamicElementTextItem *deti)
|
||||||
{
|
{
|
||||||
if (m_dynamic_text_list.contains(deti))
|
if (m_dynamic_text_list.contains(deti))
|
||||||
{
|
{
|
||||||
m_dynamic_text_list.removeOne(deti);
|
m_dynamic_text_list.removeOne(deti);
|
||||||
deti->setParentItem(nullptr);
|
deti->setParentItem(nullptr);
|
||||||
emit textRemoved(deti);
|
emit textRemoved(deti);
|
||||||
return;
|
return;
|
||||||
@@ -1207,7 +1317,8 @@ ElementTextItemGroup *Element::addTextGroup(const QString &name)
|
|||||||
{
|
{
|
||||||
if(m_texts_group.isEmpty())
|
if(m_texts_group.isEmpty())
|
||||||
{
|
{
|
||||||
ElementTextItemGroup *group = new ElementTextItemGroup(name, this);
|
ElementTextItemGroup *group = new ElementTextItemGroup(name,
|
||||||
|
this);
|
||||||
m_texts_group << group;
|
m_texts_group << group;
|
||||||
emit textsGroupAdded(group);
|
emit textsGroupAdded(group);
|
||||||
return group;
|
return group;
|
||||||
@@ -1262,7 +1373,8 @@ void Element::removeTextGroup(ElementTextItemGroup *group)
|
|||||||
{
|
{
|
||||||
if(qgi->type() == DynamicElementTextItem::Type)
|
if(qgi->type() == DynamicElementTextItem::Type)
|
||||||
{
|
{
|
||||||
DynamicElementTextItem *deti = static_cast<DynamicElementTextItem *>(qgi);
|
DynamicElementTextItem *deti =
|
||||||
|
static_cast<DynamicElementTextItem *>(qgi);
|
||||||
removeTextFromGroup(deti, group);
|
removeTextFromGroup(deti, group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1304,7 +1416,8 @@ QList<ElementTextItemGroup *> Element::textGroups() const
|
|||||||
* The text must be a text of this element.
|
* The text must be a text of this element.
|
||||||
* @return : true if the text was succesfully added to the group.
|
* @return : true if the text was succesfully added to the group.
|
||||||
*/
|
*/
|
||||||
bool Element::addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
|
bool Element::addTextToGroup(DynamicElementTextItem *text,
|
||||||
|
ElementTextItemGroup *group)
|
||||||
{
|
{
|
||||||
if(!m_dynamic_text_list.contains(text))
|
if(!m_dynamic_text_list.contains(text))
|
||||||
return false;
|
return false;
|
||||||
@@ -1325,7 +1438,8 @@ bool Element::addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup
|
|||||||
* Remove the text @text from the group @group, en reparent @text to this element
|
* Remove the text @text from the group @group, en reparent @text to this element
|
||||||
* @return true if text was succesfully removed
|
* @return true if text was succesfully removed
|
||||||
*/
|
*/
|
||||||
bool Element::removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group)
|
bool Element::removeTextFromGroup(DynamicElementTextItem *text,
|
||||||
|
ElementTextItemGroup *group)
|
||||||
{
|
{
|
||||||
if(!m_texts_group.contains(group))
|
if(!m_texts_group.contains(group))
|
||||||
return false;
|
return false;
|
||||||
@@ -1357,7 +1471,8 @@ QList <QPair <Terminal *, Terminal *> > Element::AlignedFreeTerminals() const
|
|||||||
{
|
{
|
||||||
if (terminal->conductors().isEmpty())
|
if (terminal->conductors().isEmpty())
|
||||||
{
|
{
|
||||||
Terminal *other_terminal = terminal -> alignedWithTerminal();
|
Terminal *other_terminal =
|
||||||
|
terminal -> alignedWithTerminal();
|
||||||
if (other_terminal)
|
if (other_terminal)
|
||||||
list << qMakePair(terminal, other_terminal);
|
list << qMakePair(terminal, other_terminal);
|
||||||
}
|
}
|
||||||
@@ -1436,10 +1551,16 @@ void Element::setElementInformations(DiagramContext dc)
|
|||||||
bool comparPos(const Element *elmt1, const Element *elmt2) {
|
bool comparPos(const Element *elmt1, const Element *elmt2) {
|
||||||
//Compare folio first
|
//Compare folio first
|
||||||
if (elmt1->diagram()->folioIndex() != elmt2->diagram()->folioIndex())
|
if (elmt1->diagram()->folioIndex() != elmt2->diagram()->folioIndex())
|
||||||
return elmt1->diagram()->folioIndex() < elmt2->diagram()->folioIndex();
|
return elmt1->diagram()->folioIndex()
|
||||||
|
<
|
||||||
|
elmt2->diagram()->folioIndex();
|
||||||
//Compare the row(in letter pos) in second
|
//Compare the row(in letter pos) in second
|
||||||
QString a = elmt1->diagram()->convertPosition(elmt1->scenePos()).letter();
|
QString a = elmt1
|
||||||
QString b = elmt2->diagram()->convertPosition(elmt2->scenePos()).letter();
|
->diagram()
|
||||||
|
->convertPosition(elmt1->scenePos()).letter();
|
||||||
|
QString b = elmt2
|
||||||
|
->diagram()
|
||||||
|
->convertPosition(elmt2->scenePos()).letter();
|
||||||
if (a != b)
|
if (a != b)
|
||||||
return a<b;
|
return a<b;
|
||||||
//In last compare the line, if line is egal, return sorted by row in real pos
|
//In last compare the line, if line is egal, return sorted by row in real pos
|
||||||
@@ -1522,17 +1643,28 @@ void Element::setUpFormula(bool code_letter)
|
|||||||
|
|
||||||
if (diagram())
|
if (diagram())
|
||||||
{
|
{
|
||||||
QString formula = diagram()->project()->elementAutoNumCurrentFormula();
|
QString formula = diagram()
|
||||||
|
->project()
|
||||||
|
->elementAutoNumCurrentFormula();
|
||||||
|
|
||||||
m_element_informations.addValue("formula", formula);
|
m_element_informations.addValue("formula", formula);
|
||||||
|
|
||||||
QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
|
QString element_currentAutoNum = diagram()
|
||||||
NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
|
->project()
|
||||||
|
->elementCurrentAutoNum();
|
||||||
|
NumerotationContext nc = diagram()
|
||||||
|
->project()
|
||||||
|
->elementAutoNum(element_currentAutoNum);
|
||||||
NumerotationContextCommands ncc (nc);
|
NumerotationContextCommands ncc (nc);
|
||||||
|
|
||||||
m_autoNum_seq.clear();
|
m_autoNum_seq.clear();
|
||||||
autonum::setSequential(formula, m_autoNum_seq, nc, diagram(), element_currentAutoNum);
|
autonum::setSequential(formula,
|
||||||
diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
|
m_autoNum_seq,
|
||||||
|
nc,
|
||||||
|
diagram(),
|
||||||
|
element_currentAutoNum);
|
||||||
|
diagram()->project()->addElementAutoNum(element_currentAutoNum,
|
||||||
|
ncc.next());
|
||||||
|
|
||||||
if(!m_freeze_label && !formula.isEmpty())
|
if(!m_freeze_label && !formula.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -1573,10 +1705,11 @@ void Element::freezeLabel(bool freeze)
|
|||||||
* Freeze this label if needed
|
* Freeze this label if needed
|
||||||
*/
|
*/
|
||||||
void Element::freezeNewAddedElement() {
|
void Element::freezeNewAddedElement() {
|
||||||
if (this->diagram()->freezeNewElements() || this->diagram()->project()->isFreezeNewElements()) {
|
if (this->diagram()->freezeNewElements()
|
||||||
|
|| this->diagram()->project()->isFreezeNewElements()) {
|
||||||
freezeLabel(true);
|
freezeLabel(true);
|
||||||
}
|
}
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1587,11 +1720,16 @@ void Element::freezeNewAddedElement() {
|
|||||||
*/
|
*/
|
||||||
QString Element::actualLabel()
|
QString Element::actualLabel()
|
||||||
{
|
{
|
||||||
if (m_element_informations.value("formula").toString().isEmpty()) {
|
if (m_element_informations.value("formula").toString().isEmpty()) {
|
||||||
return m_element_informations.value("label").toString();
|
return m_element_informations.value("label").toString();
|
||||||
} else {
|
} else {
|
||||||
return autonum::AssignVariables::formulaToLabel(m_element_informations.value("formula").toString(), m_autoNum_seq, diagram(), this);
|
return autonum::AssignVariables::formulaToLabel(
|
||||||
}
|
m_element_informations.value(
|
||||||
|
"formula").toString(),
|
||||||
|
m_autoNum_seq,
|
||||||
|
diagram(),
|
||||||
|
this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -48,14 +48,17 @@ class Element : public QetGraphicsItem
|
|||||||
* Used to know the kind of this element (master, slave, report ect...)
|
* Used to know the kind of this element (master, slave, report ect...)
|
||||||
*/
|
*/
|
||||||
enum kind {Simple = 1,
|
enum kind {Simple = 1,
|
||||||
NextReport = 2,
|
NextReport = 2,
|
||||||
PreviousReport = 4,
|
PreviousReport = 4,
|
||||||
AllReport = 6,
|
AllReport = 6,
|
||||||
Master = 8,
|
Master = 8,
|
||||||
Slave = 16,
|
Slave = 16,
|
||||||
Terminale = 32};
|
Terminale = 32};
|
||||||
|
|
||||||
Element(const ElementsLocation &location, QGraphicsItem * = nullptr, int *state = nullptr, Element::kind link_type = Element::Simple);
|
Element(const ElementsLocation &location,
|
||||||
|
QGraphicsItem * = nullptr,
|
||||||
|
int *state = nullptr,
|
||||||
|
Element::kind link_type = Element::Simple);
|
||||||
~Element() override;
|
~Element() override;
|
||||||
private:
|
private:
|
||||||
Element(const Element &);
|
Element(const Element &);
|
||||||
@@ -71,36 +74,43 @@ class Element : public QetGraphicsItem
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void linkedElementChanged(); //This signal is emited when the linked elements with this element change
|
void linkedElementChanged(); //This signal is emited when the linked elements with this element change
|
||||||
void elementInfoChange(DiagramContext old_info, DiagramContext new_info);
|
void elementInfoChange(DiagramContext old_info,
|
||||||
|
DiagramContext new_info);
|
||||||
void textAdded(DynamicElementTextItem *deti);
|
void textAdded(DynamicElementTextItem *deti);
|
||||||
void textRemoved(DynamicElementTextItem *deti);
|
void textRemoved(DynamicElementTextItem *deti);
|
||||||
void textsGroupAdded(ElementTextItemGroup *group);
|
void textsGroupAdded(ElementTextItemGroup *group);
|
||||||
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group);
|
void textsGroupAboutToBeRemoved(ElementTextItemGroup *group);
|
||||||
void textAddedToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group);
|
void textAddedToGroup(DynamicElementTextItem *text,
|
||||||
void textRemovedFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group);
|
ElementTextItemGroup *group);
|
||||||
|
void textRemovedFromGroup(DynamicElementTextItem *text,
|
||||||
|
ElementTextItemGroup *group);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<Terminal *> terminals() const;
|
QList<Terminal *> terminals() const;
|
||||||
QList<Conductor *> conductors() const;
|
QList<Conductor *> conductors() const;
|
||||||
QList <QPair <Terminal *, Terminal *> > AlignedFreeTerminals () const;
|
QList<QPair<Terminal *,Terminal *>> AlignedFreeTerminals() const;
|
||||||
|
|
||||||
//METHODS related to information
|
//METHODS related to information
|
||||||
DiagramContext elementInformations ()const {return m_element_informations;}
|
DiagramContext elementInformations()const
|
||||||
virtual void setElementInformations (DiagramContext dc);
|
{return m_element_informations;}
|
||||||
DiagramContext kindInformations () const {return m_kind_informations;} //@kind_information_ is used to store more information
|
virtual void setElementInformations(DiagramContext dc);
|
||||||
|
DiagramContext kindInformations() const
|
||||||
|
{return m_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.
|
||||||
|
|
||||||
autonum::sequentialNumbers sequenceStruct () const {return m_autoNum_seq;}
|
autonum::sequentialNumbers sequenceStruct() const
|
||||||
autonum::sequentialNumbers& rSequenceStruct() {return m_autoNum_seq;}
|
{return m_autoNum_seq;}
|
||||||
|
autonum::sequentialNumbers& rSequenceStruct()
|
||||||
|
{return m_autoNum_seq;}
|
||||||
void setUpFormula(bool code_letter = true);
|
void setUpFormula(bool code_letter = true);
|
||||||
void setPrefix(QString);
|
void setPrefix(QString);
|
||||||
QString getPrefix() const;
|
QString getPrefix() const;
|
||||||
void freezeLabel(bool freeze);
|
void freezeLabel(bool freeze);
|
||||||
bool isFreezeLabel() const {return m_freeze_label;}
|
bool isFreezeLabel() const {return m_freeze_label;}
|
||||||
void freezeNewAddedElement();
|
void freezeNewAddedElement();
|
||||||
QString actualLabel();
|
QString actualLabel();
|
||||||
|
|
||||||
QString name() const override;
|
QString name() const override;
|
||||||
ElementsLocation location() const;
|
ElementsLocation location() const;
|
||||||
@@ -108,36 +118,43 @@ class Element : public QetGraphicsItem
|
|||||||
void displayHelpLine(bool b = true);
|
void displayHelpLine(bool b = true);
|
||||||
QSize size() const;
|
QSize size() const;
|
||||||
QPixmap pixmap();
|
QPixmap pixmap();
|
||||||
QPoint setHotspot(QPoint);
|
QPoint setHotspot(QPoint);
|
||||||
QPoint hotspot() const;
|
QPoint hotspot() const;
|
||||||
void editProperty() override;
|
void editProperty() override;
|
||||||
static bool valideXml(QDomElement &);
|
static bool valideXml(QDomElement &);
|
||||||
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
|
virtual bool fromXml(QDomElement &,
|
||||||
virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
|
QHash<int,
|
||||||
QUuid uuid() const;
|
Terminal *> &,
|
||||||
int orientation() const;
|
bool = false);
|
||||||
|
virtual QDomElement toXml(QDomDocument &,
|
||||||
|
QHash<Terminal *,
|
||||||
|
int> &) const;
|
||||||
|
QUuid uuid() const;
|
||||||
|
int orientation() const;
|
||||||
|
|
||||||
//METHODS related to texts
|
//METHODS related to texts
|
||||||
void addDynamicTextItem(DynamicElementTextItem *deti = nullptr);
|
void addDynamicTextItem(DynamicElementTextItem *deti = nullptr);
|
||||||
void removeDynamicTextItem(DynamicElementTextItem *deti);
|
void removeDynamicTextItem(DynamicElementTextItem *deti);
|
||||||
QList<DynamicElementTextItem *> dynamicTextItems() const;
|
QList<DynamicElementTextItem *> dynamicTextItems() const;
|
||||||
ElementTextItemGroup *addTextGroup(const QString &name);
|
ElementTextItemGroup *addTextGroup(const QString &name);
|
||||||
void addTextGroup(ElementTextItemGroup *group);
|
void addTextGroup(ElementTextItemGroup *group);
|
||||||
void removeTextGroup(ElementTextItemGroup *group);
|
void removeTextGroup(ElementTextItemGroup *group);
|
||||||
ElementTextItemGroup *textGroup(const QString &name) const;
|
ElementTextItemGroup *textGroup(const QString &name) const;
|
||||||
QList<ElementTextItemGroup *> textGroups() const;
|
QList<ElementTextItemGroup *> textGroups() const;
|
||||||
bool addTextToGroup(DynamicElementTextItem *text, ElementTextItemGroup *group);
|
bool addTextToGroup(DynamicElementTextItem *text,
|
||||||
bool removeTextFromGroup(DynamicElementTextItem *text, ElementTextItemGroup *group);
|
ElementTextItemGroup *group);
|
||||||
|
bool removeTextFromGroup(DynamicElementTextItem *text,
|
||||||
|
ElementTextItemGroup *group);
|
||||||
|
|
||||||
//METHODS related to linked element
|
//METHODS related to linked element
|
||||||
bool isFree () const;
|
bool isFree() const;
|
||||||
virtual void linkToElement (Element *) {}
|
virtual void linkToElement(Element *) {}
|
||||||
virtual void unlinkAllElements () {}
|
virtual void unlinkAllElements() {}
|
||||||
virtual void unlinkElement (Element *) {}
|
virtual void unlinkElement(Element *) {}
|
||||||
virtual void initLink (QETProject *);
|
virtual void initLink(QETProject *);
|
||||||
QList<Element *> linkedElements ();
|
QList<Element *> linkedElements ();
|
||||||
virtual kind linkType() const {return m_link_type;} // @return the linkable type
|
virtual kind linkType() const {return m_link_type;} // @return the linkable type
|
||||||
QString linkTypeToString() const;
|
QString linkTypeToString() const;
|
||||||
void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
|
void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this element
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -145,29 +162,36 @@ class Element : public QetGraphicsItem
|
|||||||
void setSize(int, int);
|
void setSize(int, int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
|
void drawSelection(QPainter *,
|
||||||
void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
|
const QStyleOptionGraphicsItem *);
|
||||||
|
void drawHighlight(QPainter *,
|
||||||
|
const QStyleOptionGraphicsItem *);
|
||||||
bool buildFromXml(const QDomElement &, int * = nullptr);
|
bool buildFromXml(const QDomElement &, int * = nullptr);
|
||||||
bool parseElement(const QDomElement &dom);
|
bool parseElement(const QDomElement &dom);
|
||||||
bool parseInput(const QDomElement &dom_element);
|
bool parseInput(const QDomElement &dom_element);
|
||||||
DynamicElementTextItem *parseDynamicText(const QDomElement &dom_element);
|
DynamicElementTextItem *parseDynamicText(
|
||||||
|
const QDomElement &dom_element);
|
||||||
Terminal *parseTerminal(const QDomElement &dom_element);
|
Terminal *parseTerminal(const QDomElement &dom_element);
|
||||||
|
|
||||||
//Reimplemented from QGraphicsItem
|
//Reimplemented from QGraphicsItem
|
||||||
public:
|
public:
|
||||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
void paint(QPainter *,
|
||||||
|
const QStyleOptionGraphicsItem *,
|
||||||
|
QWidget *) override;
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent ( QGraphicsSceneMouseEvent *event ) override;
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseReleaseEvent ( QGraphicsSceneMouseEvent *event ) override;
|
void mouseReleaseEvent(
|
||||||
void hoverEnterEvent ( QGraphicsSceneHoverEvent * ) override;
|
QGraphicsSceneMouseEvent *event) override;
|
||||||
void hoverLeaveEvent ( QGraphicsSceneHoverEvent * ) override;
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// @m_converted_text_from_description, when a element is created from his description, the old element text item (tagged as 'input' in the xml)
|
// @m_converted_text_from_description, when a element is created from his description, the old element text item (tagged as 'input' in the xml)
|
||||||
// are converted to dynamic text field, the QPointF is the original position of the text item, because the origin transformation point of text item
|
// are converted to dynamic text field, the QPointF is the original position of the text item, because the origin transformation point of text item
|
||||||
// and dynamic text item are not the same, so we must to keep a track of this value, to be use in the function element::fromXml
|
// and dynamic text item are not the same, so we must to keep a track of this value, to be use in the function element::fromXml
|
||||||
QHash <DynamicElementTextItem *, QPointF> m_converted_text_from_xml_description;
|
QHash <DynamicElementTextItem *, QPointF>
|
||||||
|
m_converted_text_from_xml_description;
|
||||||
|
|
||||||
//ATTRIBUTES related to linked element
|
//ATTRIBUTES related to linked element
|
||||||
QList <Element *> connected_elements;
|
QList <Element *> connected_elements;
|
||||||
@@ -193,7 +217,7 @@ class Element : public QetGraphicsItem
|
|||||||
QPoint hotspot_coord;
|
QPoint hotspot_coord;
|
||||||
bool m_mouse_over = false;
|
bool m_mouse_over = false;
|
||||||
QString m_prefix;
|
QString m_prefix;
|
||||||
QList <DynamicElementTextItem *> m_dynamic_text_list;
|
QList <DynamicElementTextItem *> m_dynamic_text_list;
|
||||||
QList <ElementTextItemGroup *> m_texts_group;
|
QList <ElementTextItemGroup *> m_texts_group;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -229,7 +253,9 @@ inline QUuid Element::uuid() const {
|
|||||||
* @return the list of linked elements, the list is sorted by position
|
* @return the list of linked elements, the list is sorted by position
|
||||||
*/
|
*/
|
||||||
inline QList <Element *> Element::linkedElements() {
|
inline QList <Element *> Element::linkedElements() {
|
||||||
std::sort(connected_elements.begin(), connected_elements.end(), comparPos);
|
std::sort(connected_elements.begin(),
|
||||||
|
connected_elements.end(),
|
||||||
|
comparPos);
|
||||||
return connected_elements;
|
return connected_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user