Fix : in some condition, dynamic text are not at the same position when open a project.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5406 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2018-06-21 17:57:33 +00:00
parent 2be0af2f43
commit 749e0e5e78
4 changed files with 58 additions and 17 deletions

View File

@ -32,6 +32,13 @@ namespace QET {
const QString displayedVersion = "0.70-dev";
QString license();
//Describe the current state of a graphic item
enum GraphicsItemState {
GIOK, ///<General state
GIBuildingFromXml, ///<Item is currently building from a xml description (element)
GILoadingFromXml ///<Item is loading her properties from a xml description.
};
/// List the various kind of changes for the zValue
enum DepthOption {
BringForward, ///< Bring item to the foreground so they have the highest zValue

View File

@ -88,11 +88,14 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg
- 8 : Aucune partie du dessin n'a pu etre chargee
@return true si le chargement a reussi, false sinon
*/
bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state)
{
m_state = QET::GIBuildingFromXml;
if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element")
{
if (state) *state = 4;
m_state = QET::GIOK;
return(false);
}
@ -121,6 +124,7 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
!validOrientationAttribute(xml_def_elmt)
) {
if (state) *state = 5;
m_state = QET::GIOK;
return(false);
}
@ -131,6 +135,7 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
if (xml_def_elmt.firstChild().isNull())
{
if (state) *state = 6;
m_state = QET::GIOK;
return(false);
}
@ -203,7 +208,7 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
{
if (state)
*state = 7;
m_state = QET::GIOK;
return(false);
}
}
@ -220,14 +225,14 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
{
if (state)
*state = 8;
m_state = QET::GIOK;
return(false);
}
else
{
if (state)
*state = 0;
m_state = QET::GIOK;
return(true);
}
}

View File

@ -1314,31 +1314,43 @@ void DynamicElementTextItem::updateXref()
void DynamicElementTextItem::setPlainText(const QString &text)
{
if(toPlainText() == text)
if (toPlainText() == text)
return;
prepareAlignment();
bool update_alignment = true;
if (diagram() && (diagram()->project()->state() == QETProject::ProjectParsingRunning))
update_alignment = false;
if (m_parent_element.data()->state() == QET::GIBuildingFromXml ||
m_parent_element.data()->state() == QET::GILoadingFromXml)
update_alignment = false;
if (update_alignment) {
prepareAlignment();
}
DiagramTextItem::setPlainText(text);
//User define a text width
if(m_text_width > 0)
if (m_text_width > 0)
{
if(document()->size().width() > m_text_width)
if (document()->size().width() > m_text_width)
{
document()->setTextWidth(m_text_width);
if(document()->size().width() > m_text_width)
if (document()->size().width() > m_text_width)
{
document()->setTextWidth(document()->idealWidth());
}
}
}
finishAlignment();
if (update_alignment) {
finishAlignment();
}
if(m_Xref_item)
if (m_Xref_item) {
m_Xref_item->autoPos();
else if(m_slave_Xref_item)
}
else if (m_slave_Xref_item)
{
QRectF r = boundingRect();
QPointF pos(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,

View File

@ -356,6 +356,7 @@ bool Element::valideXml(QDomElement &e) {
*/
bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool handle_inputs_rotation)
{
m_state = QET::GILoadingFromXml;
/*
les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle
ce recensement servira lors de la mise en place des fils
@ -383,13 +384,20 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
}
}
if (terminals_non_trouvees > 0) {
if (terminals_non_trouvees > 0)
{
m_state = QET::GIOK;
return(false);
} else {
}
else
{
// verifie que les associations id / adr n'entrent pas en conflit avec table_id_adr
foreach(int id_trouve, priv_id_adr.keys()) {
if (table_id_adr.contains(id_trouve)) {
foreach(int id_trouve, priv_id_adr.keys())
{
if (table_id_adr.contains(id_trouve))
{
// cet element possede un id qui est deja reference (= conflit)
m_state = QET::GIOK;
return(false);
}
}
@ -597,7 +605,10 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
//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);
@ -613,7 +624,10 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
//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);
@ -628,7 +642,10 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
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);
@ -691,7 +708,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
}
}
}
m_state = QET::GIOK;
return(true);
}