From 899caeabe955e7caaafd0ddd4ceef2ed78095925 Mon Sep 17 00:00:00 2001 From: joshua Date: Wed, 25 May 2022 23:16:13 +0200 Subject: [PATCH] Fix wrong behavior when edit the element information In the diagram editor, when we edit the element information in the side panel, each time we tip something in the text field the cursor always go to the end if the "label" information is empty. --- sources/qetgraphicsitem/element.cpp | 8 ++++++-- sources/ui/elementinfowidget.cpp | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 4c09aa1a2..1b49b5283 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -1347,9 +1347,13 @@ void Element::setElementInformations(DiagramContext dc) return; } - DiagramContext old_info = m_data.m_informations; + const auto old_info = m_data.m_informations; m_data.m_informations = dc; - m_data.m_informations.addValue(QStringLiteral("label"), actualLabel()); //Update the label if there is a formula + + const auto actual_label{actualLabel()}; + if (!actual_label.isEmpty()) { + m_data.m_informations.addValue(QStringLiteral("label"), actual_label); //Update the label if there is a formula + } emit elementInfoChange(old_info, m_data.m_informations); } diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index e4978d624..8c51e64b5 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -191,6 +191,7 @@ void ElementInfoWidget::buildInterface() ui->scroll_vlayout->addWidget(eipw); m_eipw_list << eipw; } + ui->scroll_vlayout->addStretch(); } @@ -277,6 +278,22 @@ void ElementInfoWidget::firstActivated() */ void ElementInfoWidget::elementInfoChange() { - if(currentInfo() != m_element->elementInformations()) + auto elmt_info = m_element->elementInformations(); + auto current_info = currentInfo(); + + //If both info have a formula, we remove the label + //value before compare the equality, because the + //label of the information returned by the element + //can be different of the current label because + //updated by the element to reflect the actual + //displayed label according the current formula. + if (current_info.contains(QETInformation::ELMT_FORMULA) && + elmt_info.contains(QETInformation::ELMT_FORMULA)) + { + elmt_info.remove(QETInformation::ELMT_LABEL); + current_info.remove((QETInformation::ELMT_LABEL )); + } + + if(current_info != elmt_info) updateUi(); }