diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index a454f301a..2b90e57e5 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -171,7 +171,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt) * @brief DynamicElementTextItem::ParentElement * @return a pointer to the parent element. Note the pointer can be null. */ -Element *DynamicElementTextItem::ParentElement() const { +Element *DynamicElementTextItem::parentElement() const { return m_parent_element; } diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h index 3bff68534..4a79f12a6 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.h +++ b/sources/qetgraphicsitem/dynamicelementtextitem.h @@ -67,7 +67,7 @@ class DynamicElementTextItem : public DiagramTextItem QDomElement toXml(QDomDocument &dom_doc) const override; void fromXml(const QDomElement &dom_elmt) override; - Element *ParentElement() const; + Element *parentElement() const; DynamicElementTextItem::TextFrom textFrom() const; void setTextFrom (DynamicElementTextItem::TextFrom text_from); diff --git a/sources/ui/compositetexteditdialog.cpp b/sources/ui/compositetexteditdialog.cpp index 0da6588ff..54a57658f 100644 --- a/sources/ui/compositetexteditdialog.cpp +++ b/sources/ui/compositetexteditdialog.cpp @@ -34,7 +34,7 @@ QString CompositeTextEditDialog::plainText() const { void CompositeTextEditDialog::setUpComboBox() { QStringList qstrl; - Element *elmt = m_text->ParentElement(); + Element *elmt = m_text->parentElement(); if(!elmt) return; diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp index 35c58c9ce..5cde748a4 100644 --- a/sources/ui/diagrampropertieseditordockwidget.cpp +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -128,13 +128,13 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() //We already edit an element, just update the editor with a new element if (m_edited_qgi_type == Element::Type) { - static_cast(editors().first())->setElement(deti->ParentElement()); + static_cast(editors().first())->setDynamicText(deti); return; } clear(); m_edited_qgi_type = Element::Type; - addEditor(new ElementPropertiesWidget(deti->ParentElement(), this)); + addEditor(new ElementPropertiesWidget(deti, this)); break; } default: diff --git a/sources/ui/dynamicelementtextitemeditor.cpp b/sources/ui/dynamicelementtextitemeditor.cpp index 429081e99..3175ec9c2 100644 --- a/sources/ui/dynamicelementtextitemeditor.cpp +++ b/sources/ui/dynamicelementtextitemeditor.cpp @@ -105,6 +105,21 @@ void DynamicElementTextItemEditor::apply() deti->blockSignals(false); } +/** + * @brief DynamicElementTextItemEditor::setCurrentText + * Expand and select the item for text @text + * @param text + */ +void DynamicElementTextItemEditor::setCurrentText(DynamicElementTextItem *text) +{ + QModelIndex index = m_model->indexFromText(text); + if(!index.isValid()) + return; + + m_tree_view->expand(index); + m_tree_view->setCurrentIndex(index); +} + void DynamicElementTextItemEditor::dataEdited(QStandardItem *qsi) { Q_UNUSED(qsi) diff --git a/sources/ui/dynamicelementtextitemeditor.h b/sources/ui/dynamicelementtextitemeditor.h index 4007a2cf9..79282f09d 100644 --- a/sources/ui/dynamicelementtextitemeditor.h +++ b/sources/ui/dynamicelementtextitemeditor.h @@ -41,6 +41,7 @@ class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidge QString title() const override {return tr("Textes");} bool setLiveEdit(bool live_edit) override; void apply() override; + void setCurrentText(DynamicElementTextItem *text); private: void dataEdited(QStandardItem *qsi); diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index 38de27cdf..2267fa8ea 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -107,7 +107,7 @@ void DynamicElementTextModel::addText(DynamicElementTextItem *deti) QStandardItem *compositea = new QStandardItem(deti->compositeText().isEmpty() ? tr("Mon texte composé") : - autonum::AssignVariables::replaceVariable(deti->compositeText(), deti->ParentElement()->elementInformations())); + autonum::AssignVariables::replaceVariable(deti->compositeText(), deti->parentElement()->elementInformations())); compositea->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); compositea->setData(DynamicElementTextModel::compositeText, Qt::UserRole+1); //Use to know the edited thing compositea->setData(deti->compositeText(), Qt::UserRole+2); //Use to know to element composite formula @@ -219,6 +219,19 @@ DynamicElementTextItem *DynamicElementTextModel::textFromItem(QStandardItem *ite return nullptr; } +/** + * @brief DynamicElementTextModel::indexFromText + * @param text + * @return the QModelIndex for @text, or a default QModelIndex if not match + */ +QModelIndex DynamicElementTextModel::indexFromText(DynamicElementTextItem *text) const +{ + if(!m_texts_list.contains(text)) + return QModelIndex(); + + return m_texts_list.value(text)->index(); +} + /** * @brief DynamicElementTextModel::undoForEditedText * @param deti @@ -332,15 +345,15 @@ void DynamicElementTextModel::dataEdited(QStandardItem *qsi) QString text = qsi->data(Qt::DisplayRole).toString(); m_texts_list.value(deti)->setData(text, Qt::DisplayRole); } - else if (qsi->data().toInt() == infoText && deti->ParentElement()) + else if (qsi->data().toInt() == infoText && deti->parentElement()) { QString info = qsi->data(Qt::UserRole+2).toString(); - m_texts_list.value(deti)->setData(deti->ParentElement()->elementInformations().value(info), Qt::DisplayRole); + m_texts_list.value(deti)->setData(deti->parentElement()->elementInformations().value(info), Qt::DisplayRole); } - else if (qsi->data().toInt() == compositeText && deti->ParentElement()) + else if (qsi->data().toInt() == compositeText && deti->parentElement()) { QString compo = qsi->data(Qt::UserRole+2).toString(); - m_texts_list.value(deti)->setData(autonum::AssignVariables::replaceVariable(compo, deti->ParentElement()->elementInformations()), Qt::DisplayRole); + m_texts_list.value(deti)->setData(autonum::AssignVariables::replaceVariable(compo, deti->parentElement()->elementInformations()), Qt::DisplayRole); } blockSignals(false); @@ -546,7 +559,7 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel * DynamicElementTextItem *deti = detm->textFromIndex(index); if(deti) { - DiagramContext dc = deti->ParentElement()->elementInformations(); + DiagramContext dc = deti->parentElement()->elementInformations(); assigned_text = autonum::AssignVariables::replaceVariable(edited_text, dc); } @@ -569,7 +582,7 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel * QStringList DynamicTextItemDelegate::availableInfo(DynamicElementTextItem *deti) const { QStringList qstrl; - Element *elmt = deti->ParentElement(); + Element *elmt = deti->parentElement(); if(!elmt) return qstrl; diff --git a/sources/ui/dynamicelementtextmodel.h b/sources/ui/dynamicelementtextmodel.h index d048d3663..07fc2a53d 100644 --- a/sources/ui/dynamicelementtextmodel.h +++ b/sources/ui/dynamicelementtextmodel.h @@ -52,6 +52,7 @@ class DynamicElementTextModel : public QStandardItemModel void removeText(DynamicElementTextItem *deti); DynamicElementTextItem *textFromIndex(const QModelIndex &index) const; DynamicElementTextItem *textFromItem(QStandardItem *item) const; + QModelIndex indexFromText(DynamicElementTextItem *text) const; QUndoCommand *undoForEditedText(DynamicElementTextItem *deti) const; private: diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 734abea1c..ceef69a18 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -25,6 +25,7 @@ #include "diagramposition.h" #include "qeticons.h" #include "dynamicelementtextitemeditor.h" +#include "dynamicelementtextitem.h" #include #include @@ -46,6 +47,27 @@ ElementPropertiesWidget::ElementPropertiesWidget(Element *elmt, QWidget *parent) setElement(elmt); } +/** + * @brief ElementPropertiesWidget::ElementPropertiesWidget + * Same as default constructor, the edited element, is the parent element of @text. + * The only difference with default constructor, is that the current tab is the tab for dynamic texts, + * and the item in the tree that represent @text is expanded and selected. + * @param text + * @param parent + */ +ElementPropertiesWidget::ElementPropertiesWidget(DynamicElementTextItem *text, QWidget *parent) : + AbstractElementPropertiesEditorWidget (parent), + m_tab (nullptr), + m_general_widget(nullptr) +{ + if(text->parentElement()) + { + m_diagram = text->parentElement()->diagram(); + buildGui(); + setDynamicText(text); + } +} + /** * @brief ElementPropertiesWidget::setElement * Set @element to be the edited element @@ -73,6 +95,29 @@ void ElementPropertiesWidget::setElement(Element *element) updateUi(); } +/** + * @brief ElementPropertiesWidget::setDynamicText + * convenience function: same as call : ElementPropertiesWidget::setElement, with parameter the parent element of @text. + * Set the dynamics text tab as current tab, expand and select the item that represent @text + * @param text + */ +void ElementPropertiesWidget::setDynamicText(DynamicElementTextItem *text) +{ + if(text->parentElement()) + { + setElement(text->parentElement()); + for(AbstractElementPropertiesEditorWidget *aepew : m_list_editor) + { + if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor") + { + DynamicElementTextItemEditor *detie = static_cast(aepew); + m_tab->setCurrentWidget(detie); + detie->setCurrentText(text); + } + } + } +} + /** * @brief ElementPropertiesWidget::apply * Apply the new properties by pushing an undo command diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index 3d6f1c66f..b3e835c60 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -24,6 +24,7 @@ class Element; class Diagram; class QTabWidget; class ElementsLocation; +class DynamicElementTextItem; class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget @@ -32,7 +33,9 @@ class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget public: explicit ElementPropertiesWidget(Element *elmt, QWidget *parent = nullptr); + explicit ElementPropertiesWidget(DynamicElementTextItem *text, QWidget *parent = nullptr); void setElement(Element *element) override; + void setDynamicText(DynamicElementTextItem *text); void apply() override; void reset() override; bool setLiveEdit(bool live_edit) override; diff --git a/sources/undocommand/deleteqgraphicsitemcommand.cpp b/sources/undocommand/deleteqgraphicsitemcommand.cpp index 68f1c34c0..f361c35fc 100644 --- a/sources/undocommand/deleteqgraphicsitemcommand.cpp +++ b/sources/undocommand/deleteqgraphicsitemcommand.cpp @@ -38,13 +38,13 @@ DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(Diagram *diagram, const D const QSet elmt_set = m_removed_contents.m_element_texts; for(DynamicElementTextItem *deti : elmt_set) { - if (m_removed_contents.m_elements.contains(deti->ParentElement())) + if (m_removed_contents.m_elements.contains(deti->parentElement())) m_removed_contents.m_element_texts.remove(deti); } for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts) - m_elmt_text_hash.insert(deti, deti->ParentElement()); + m_elmt_text_hash.insert(deti, deti->parentElement()); setText(QString(QObject::tr("supprimer %1", "undo caption - %1 is a sentence listing the removed content")).arg(m_removed_contents.sentence(DiagramContent::All))); m_diagram->qgiManager().manage(m_removed_contents.items(DiagramContent::All)); @@ -109,7 +109,7 @@ void DeleteQGraphicsItemCommand::redo() for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts) { - deti->ParentElement()->removeDynamicTextItem(deti); + deti->parentElement()->removeDynamicTextItem(deti); deti->setParentItem(nullptr); }