diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index 079f17f1d..d3c948c56 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -139,15 +139,26 @@ QTreeWidgetItem *ElementsPanel::addProject(QETProject *project, Q_UNUSED(options) bool first_add = (first_reload_ || !projects_to_display_.contains(project)); + clearSelection(); - // create the QTreeWidgetItem representing the project + // create the QTreeWidgetItem representing the project QTreeWidgetItem *qtwi_project = GenericPanel::addProject(project, nullptr, GenericPanel::All); - // the project will be inserted right before the common tb templates collection + // the project will be inserted right before the common tb templates collection invisibleRootItem() -> insertChild( indexOfTopLevelItem(common_tbt_collection_item_), qtwi_project ); - if (first_add) qtwi_project -> setExpanded(true); + if (first_add){ + qtwi_project -> setExpanded(true); + // on adding an project select first diagram + setCurrentItem(qtwi_project -> child(0)); + qtwi_project -> child(0)->setSelected(true); + } + else { + // on adding an diagram to project select the last diagram + setCurrentItem(qtwi_project->child(qtwi_project->childCount()-2)); + qtwi_project->child(qtwi_project->childCount()-2)->setSelected(true); + } if (TitleBlockTemplatesCollection *tbt_collection = project -> embeddedTitleBlockTemplatesCollection()) { if (QTreeWidgetItem *tbt_collection_qtwi = itemForTemplatesCollection(tbt_collection)) { diff --git a/sources/genericpanel.cpp b/sources/genericpanel.cpp index e895d02bd..76c866d34 100644 --- a/sources/genericpanel.cpp +++ b/sources/genericpanel.cpp @@ -766,7 +766,6 @@ void GenericPanel::projectDiagramsOrderChanged(QETProject *project, if (!moved_qtwi_diagram) return; // remove the QTWI then insert it back at the adequate location - bool was_selected = moved_qtwi_diagram -> isSelected(); qtwi_project -> removeChild (moved_qtwi_diagram); qtwi_project -> insertChild (to, moved_qtwi_diagram); @@ -781,8 +780,8 @@ void GenericPanel::projectDiagramsOrderChanged(QETProject *project, updateDiagramItem(qtwi_diagram, diagram); } - if (was_selected) - setCurrentItem(moved_qtwi_diagram); + // select the moved diagram + setCurrentItem(qtwi_project -> child(from)); emit(panelContentChanged()); } diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index f4deb45df..f666ebcbd 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1841,6 +1841,18 @@ void QETDiagramEditor::addProjectView(ProjectView *project_view) } }); + //Highlight the current page in projectView on project activation + connect(this, &QETDiagramEditor::syncElementsPanel, this, [this]() { + if (pa && currentDiagramView()) { + // In the tree, find the element that corresponds to the diagram of the selected project. + QTreeWidgetItem *item = pa->elementsPanel().getItemForDiagram(currentDiagramView()->diagram()); + if (item) { + // select the diagram + pa->elementsPanel().setCurrentItem(item); + } + } + }); + //We maximise the new window if the current window is inexistent or maximized QWidget *current_window = m_workspace.activeSubWindow(); bool maximise = ((!current_window) @@ -2349,6 +2361,7 @@ void QETDiagramEditor::subWindowActivated(QMdiSubWindow *subWindows) slot_updateActions(); slot_updateWindowsMenu(); + emit syncElementsPanel(); } /** diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 966f2c6fa..4a7f0482f 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -98,6 +98,9 @@ class QETDiagramEditor : public QETMainWindow ProjectView *findProject(const QString &) const; QMdiSubWindow *subWindowForWidget(QWidget *) const; + signals: + void syncElementsPanel(); + public slots: void save(); void saveAs();