Merge commit '77710e1cc5e597d06196d2ee163198176032987a'

Conflicts:
	sources/conductorproperties.cpp
	sources/qetgraphicsitem/element.cpp
	sources/qetgraphicsitem/qetshapeitem.cpp
This commit is contained in:
Martin Marmsoler
2021-02-27 07:49:24 +01:00
17 changed files with 47 additions and 364 deletions

View File

@@ -626,7 +626,7 @@ bool Element::parseInput(const QDomElement &dom_element)
QString::number(0)).toDouble());
transform.translate(p.x(), p.y());
deti->setPos(transform.map(pos));
m_converted_text_from_xml_description.insert(deti, p);
m_dynamic_text_list.append(deti);
return true;
}
}
@@ -863,99 +863,6 @@ bool Element::fromXml(
deti->fromXml(qde);
}
//************************//
//***Element texts item***//
//************************//
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input"); // inputs in diagram section
//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();
QList <DynamicElementTextItem *> successfully_converted;
const QList <QDomElement> dom_inputs = inputs;
for (DynamicElementTextItem *deti : conv_deti_list)
{
for(const QDomElement& dom_input : dom_inputs)
{
//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
//that mean this is the good text
if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()),
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
//when element text with tagg "label" is not null, but the element information "label" is.
if((deti->textFrom() == DynamicElementTextItem::ElementInfo)
&& (deti->infoName() == "label"))
m_data.m_informations.addValue(
"label",
dom_input.attribute("text"));
deti->setText(dom_input.attribute("text"));
qreal rotation = deti->rotation();
QPointF xml_pos = m_converted_text_from_xml_description.value(deti);
if (dom_input.attribute("userrotation").toDouble())
rotation = dom_input.attribute("userrotation").toDouble();
if (dom_input.hasAttribute("userx"))
xml_pos.setX(dom_input.attribute("userx").toDouble());
if(dom_input.hasAttribute("usery"))
xml_pos.setY(dom_input.attribute("usery", "0").toDouble());
//the origin transformation point of PartDynamicTextField
//is the top left corner, no matter the font size
//The origin transformation point of PartTextField
//is the middle of left edge, and so by definition,
//change with the size of the font
//We need to use a QTransform to find the pos of
//this text from the saved pos of text item
deti->setPos(xml_pos);
deti->setRotation(rotation);
QTransform transform;
//First make the rotation
transform.rotate(rotation);
QPointF pos = transform.map(
QPointF(0,
-deti->boundingRect().height()/2));
transform.reset();
//Second translate to the pos
transform.translate(xml_pos.x(), xml_pos.y());
deti->setPos(transform.map(pos));
//dom_input and deti matched we remove
//the dom_input from inputs list,
//to avoid unnecessary checking made below
//we also move deti from the
//m_converted_text_from_xml_description to m_dynamic_text_list
inputs.removeAll(dom_input);
m_dynamic_text_list.append(deti);
m_converted_text_from_xml_description.remove(deti);
successfully_converted << deti;
}
}
}
//###Firts case : if this is the first time the user open the project since text item are converted to dynamic text,
//in the previous opening of the project, every texts field present in the element description was created.
//At save time, the values of each of them was save in the 'input' dom element.
//The loop upper is made for the first case, to import the values in 'input' to the new converted dynamic texts field.
//###Second case : this is not the first time the user open the project since text item are converted to dynamic text.
//That mean, in a previous opening of the project, the text item was already converted and save as a dynamic text field.
//So there isn't 'input' dom element in the project, and every dynamic text item present in m_converted_text_from_xml_description
//need to be deleted (because already exist in m_dynamic_text_list, from a previous save)
for (DynamicElementTextItem *deti : m_converted_text_from_xml_description.keys())
delete deti;
m_converted_text_from_xml_description.clear();
for (QDomElement qde : QET::findInDomElement(
e,
"texts_groups",
@@ -970,27 +877,6 @@ bool Element::fromXml(
DiagramContext dc;
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), so, if "label" contain "%"
* (Use variable value), and "formula" does not exist,
* this mean the label was made before commit 4791 (0.51 dev).
* So we swap the value stored in "label" to "formula" as expected.
* @TODO remove this code at version 0.7 or more (probably useless).
*/
#if TODO_LIST
#pragma message("@TODO remove this code for qet 0.7 or later")
#endif
if (dc["label"].toString().contains("%")
&& dc["formula"].toString().isNull())
{
dc.addValue("formula", dc["label"]);
}
//retrocompatibility with older version
if(dc.value("label").toString().isEmpty() &&
!m_data.m_informations.value("label").toString().isEmpty())
dc.addValue("label", m_data.m_informations.value("label"));
//We must to block the update of the alignment when load the information
//otherwise the pos of the text will not be the same as it was at save time.
@@ -1000,181 +886,6 @@ bool Element::fromXml(
for(DynamicElementTextItem *deti : m_dynamic_text_list)
deti->m_block_alignment = false;
/* During the devel of the version 0.7,
* the "old text" was replaced by the dynamic element text item.
* When open a project made befor the 0.7,
* we must to reproduce the same visual when
* the label are not empty and visible,
* and comment are not empty
* and visible and/or location are not empty and visible.
* we create a text group with inside the needed texts,
* label and comment and/or location.
*/
//#1 There must be old text converted to dynamic text
if(!successfully_converted.isEmpty())
{
//#2 the element information must have label not empty and visible
//and a least comment or location not empty and visible
QString label = m_data.m_informations.value(
"label").toString();
QString comment = m_data.m_informations.value(
"comment").toString();
QString location = m_data.m_informations.value(
"location").toString();
bool la = m_data.m_informations.keyMustShow("label");
bool c = m_data.m_informations.keyMustShow("comment");
bool lo = m_data.m_informations.keyMustShow("location");
if((m_link_type != Master) ||
((m_link_type == Master) &&
(diagram()->project()->defaultXRefProperties(
m_kind_informations["type"].toString()).snapTo()
== XRefProperties::Label))
)
{
if(!label.isEmpty() && la &&
((!comment.isEmpty() && c)
|| (!location.isEmpty() && lo)))
{
//#2 in the converted list one text must have text from = element info and info name = label
for(DynamicElementTextItem *deti
: successfully_converted)
{
if(deti->textFrom()== DynamicElementTextItem::ElementInfo
&& deti->infoName() == "label")
{
qDebug() << "see 'Mod overlapping comparisons' in git";
qreal rotation = deti->rotation();
//Create the comment item
DynamicElementTextItem *comment_text = nullptr;
if (m_link_type != PreviousReport
&& m_link_type != NextReport)
{
m_state = QET::GIOK;
return(true);
}
if(!comment.isEmpty() && c)
{
comment_text = new DynamicElementTextItem(this);
comment_text->setTextFrom(DynamicElementTextItem::ElementInfo);
comment_text->setInfoName("comment");
QFont font = comment_text->font();
font.setPointSize(6);
comment_text->setFont(font);
comment_text->setFrame(true);
if(comment_text->toPlainText().count() > 17)
comment_text->setTextWidth(80);
comment_text->setPos(deti->x(), deti->y()+10); //+10 is arbitrary, comment_text must be below deti
addDynamicTextItem(comment_text);
}
//create the location item
DynamicElementTextItem *location_text = nullptr;
if (m_link_type != PreviousReport
&& m_link_type != NextReport)
{
m_state = QET::GIOK;
return(true);
}
if(!location.isEmpty() && lo)
{
location_text = new DynamicElementTextItem(this);
location_text->setTextFrom(DynamicElementTextItem::ElementInfo);
location_text->setInfoName("location");
QFont font = location_text->font();
font.setPointSize(6);
location_text->setFont(font);
if(location_text->toPlainText().count() > 17)
location_text->setTextWidth(80);
location_text->setPos(deti->x(), deti->y()+20); //+20 is arbitrary, location_text must be below deti and comment
addDynamicTextItem(location_text);
}
QPointF pos = deti->pos();
if (m_link_type != PreviousReport
&& m_link_type != NextReport)
{
m_state = QET::GIOK;
return(true);
}
//Create the group
ElementTextItemGroup *group =
addTextGroup(tr("Label + commentaire"));
addTextToGroup(deti, group);
if(comment_text)
addTextToGroup(comment_text,
group);
if(location_text)
addTextToGroup(location_text,
group);
group->setAlignment(Qt::AlignVCenter);
group->setVerticalAdjustment(-4);
group->setRotation(rotation);
//Change the position of the group,
//so that the text "label" stay in the same
//position in scene coordinate
group->setPos(pos - deti->pos());
break;
}
}
}
}
else
{
//This element is supposed to be a master and Xref property snap to bottom
if((!comment.isEmpty() && c) || (!location.isEmpty() && lo))
{
//Create the comment item
DynamicElementTextItem *comment_text = nullptr;
if(!comment.isEmpty() && c)
{
comment_text = new DynamicElementTextItem(this);
comment_text
->setTextFrom(
DynamicElementTextItem::ElementInfo);
comment_text->setInfoName("comment");
QFont font = comment_text->font();
font.setPointSize(6);
comment_text->setFont(font);
comment_text->setFrame(true);
comment_text->setTextWidth(80);
addDynamicTextItem(comment_text);
}
//create the location item
DynamicElementTextItem *location_text = nullptr;
if(!location.isEmpty() && lo)
{
location_text = new DynamicElementTextItem(this);
location_text
->setTextFrom(
DynamicElementTextItem::ElementInfo);
location_text->setInfoName("location");
QFont font = location_text->font();
font.setPointSize(6);
location_text->setFont(font);
location_text->setTextWidth(80);
if(comment_text)
location_text->setPos(
comment_text->x(),
comment_text->y()+10); //+10 is arbitrary, location_text must be below the comment
addDynamicTextItem(location_text);
}
//Create the group
ElementTextItemGroup *group =
addTextGroup(tr("Label + commentaire"));
if(comment_text)
addTextToGroup(comment_text, group);
if(location_text)
addTextToGroup(location_text, group);
group->setAlignment(Qt::AlignVCenter);
group->setVerticalAdjustment(-4);
group->setHoldToBottomPage(true);
}
}
}
m_state = QET::GIOK;
return(true);
}