mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-05-02 19:39:58 +02:00
Merge pull request #456 from Kellermorph/makro-fix
Fixed: Prevented the selection in the project tree from jumping to the last page when saving.
This commit is contained in:
@@ -141,6 +141,14 @@ QTreeWidgetItem *ElementsPanel::addProject(QETProject *project,
|
|||||||
Q_UNUSED(parent_item)
|
Q_UNUSED(parent_item)
|
||||||
Q_UNUSED(options)
|
Q_UNUSED(options)
|
||||||
|
|
||||||
|
// 1. Save the current chart before clearing the selection
|
||||||
|
Diagram *current_diagram = nullptr;
|
||||||
|
if (QTreeWidgetItem *current_qtwi = currentItem()) {
|
||||||
|
if (current_qtwi->type() == QET::Diagram) {
|
||||||
|
current_diagram = valueForItem<Diagram *>(current_qtwi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool first_add = (first_reload_ || !projects_to_display_.contains(project));
|
bool first_add = (first_reload_ || !projects_to_display_.contains(project));
|
||||||
clearSelection();
|
clearSelection();
|
||||||
|
|
||||||
@@ -151,6 +159,7 @@ QTreeWidgetItem *ElementsPanel::addProject(QETProject *project,
|
|||||||
indexOfTopLevelItem(common_tbt_collection_item_),
|
indexOfTopLevelItem(common_tbt_collection_item_),
|
||||||
qtwi_project
|
qtwi_project
|
||||||
);
|
);
|
||||||
|
|
||||||
if (first_add){
|
if (first_add){
|
||||||
qtwi_project -> setExpanded(true);
|
qtwi_project -> setExpanded(true);
|
||||||
// on adding an project select first diagram
|
// on adding an project select first diagram
|
||||||
@@ -158,10 +167,28 @@ QTreeWidgetItem *ElementsPanel::addProject(QETProject *project,
|
|||||||
qtwi_project -> child(0)->setSelected(true);
|
qtwi_project -> child(0)->setSelected(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// 2. Check whether we can restore the previous selection
|
||||||
|
bool restored = false;
|
||||||
|
if (current_diagram) {
|
||||||
|
// Browse the children of the project node to find our diagram
|
||||||
|
for (int i = 0; i < qtwi_project->childCount(); ++i) {
|
||||||
|
QTreeWidgetItem *child = qtwi_project->child(i);
|
||||||
|
if (child->type() == QET::Diagram && valueForItem<Diagram *>(child) == current_diagram) {
|
||||||
|
setCurrentItem(child);
|
||||||
|
child->setSelected(true);
|
||||||
|
restored = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Fallback: Only if NOTHING could be restored (e.g., actually adding a new page)
|
||||||
|
if (!restored && qtwi_project->childCount() >= 2) {
|
||||||
// on adding an diagram to project select the last diagram
|
// on adding an diagram to project select the last diagram
|
||||||
setCurrentItem(qtwi_project->child(qtwi_project->childCount()-2));
|
setCurrentItem(qtwi_project->child(qtwi_project->childCount()-2));
|
||||||
qtwi_project->child(qtwi_project->childCount()-2)->setSelected(true);
|
qtwi_project->child(qtwi_project->childCount()-2)->setSelected(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (TitleBlockTemplatesCollection *tbt_collection = project -> embeddedTitleBlockTemplatesCollection()) {
|
if (TitleBlockTemplatesCollection *tbt_collection = project -> embeddedTitleBlockTemplatesCollection()) {
|
||||||
if (QTreeWidgetItem *tbt_collection_qtwi = itemForTemplatesCollection(tbt_collection)) {
|
if (QTreeWidgetItem *tbt_collection_qtwi = itemForTemplatesCollection(tbt_collection)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user