Remove retro compatibility of element text item prior to qet 0.7

Compatibility is not maintained anymore with the old project which
contain old element text item.
This commit is contained in:
joshua 2021-02-25 19:35:04 +01:00
parent b71aec9548
commit 1f53c39290
3 changed files with 1 additions and 286 deletions

View File

@ -222,11 +222,6 @@ void DiagramEventAddElement::addElement()
element -> setPos(m_element->pos());
element -> setRotation(m_element -> rotation());
m_diagram -> addItem(element);
//The element is dropped by the user, the dynamic text field stored in m_converted_text_from_xml_description
//can be moved to m_dynamic_text_list, because we are sure fromXml will be not called.
element->m_dynamic_text_list.append(element->m_converted_text_from_xml_description.keys());
element->m_converted_text_from_xml_description.clear();
QUndoCommand *undo_object = new QUndoCommand(tr("Ajouter %1").arg(element->name()));
new AddGraphicsObjectCommand(element, m_diagram, m_element -> pos(), undo_object);

View File

@ -623,7 +623,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;
}
}
@ -848,99 +848,6 @@ bool Element::fromXml(
deti->fromXml(qde);
}
//************************//
//***Element texts item***//
//************************//
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
//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",
@ -985,181 +892,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);
}

View File

@ -202,18 +202,6 @@ class Element : public QetGraphicsItem
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
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)
// 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
QHash <DynamicElementTextItem *, QPointF>
m_converted_text_from_xml_description;
//ATTRIBUTES related to linked element
QList <Element *> connected_elements;
QList <QUuid> tmp_uuids_link;