From d8cb8b997918a5883346dd2c539b5dd708d89a2a Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Sun, 8 Dec 2024 23:00:40 +0100 Subject: [PATCH] Open person from tree view Completes #47 --- src/main/main_window.cpp | 5 ++++- src/main/main_window.h | 3 ++- src/tree_view/tree_view_window.cpp | 17 ++++++----------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/main_window.cpp b/src/main/main_window.cpp index 1771b90..e62a4fa 100644 --- a/src/main/main_window.cpp +++ b/src/main/main_window.cpp @@ -23,7 +23,7 @@ #include #include -void openOrSelectPerson(IntegerPrimaryKey personId) { +void openOrSelectPerson(IntegerPrimaryKey personId, bool activate) { auto allWindows = QApplication::topLevelWidgets(); const auto it = std::find_if(allWindows.constBegin(), allWindows.constEnd(), [](QWidget* element) { return qobject_cast(element) != nullptr; @@ -37,6 +37,9 @@ void openOrSelectPerson(IntegerPrimaryKey personId) { auto* mainWindow = qobject_cast(*it); assert(mainWindow != nullptr); mainWindow->openOrSelectPerson(personId); + if (activate) { + mainWindow->activateWindow(); + } } MainWindow::MainWindow() { diff --git a/src/main/main_window.h b/src/main/main_window.h index b031807..dea7a0e 100644 --- a/src/main/main_window.h +++ b/src/main/main_window.h @@ -25,8 +25,9 @@ class opaView; * TODO: is this the best way of doing this? * * @param personId The ID to open. + * @param activate If the window with the person should be activated. */ -void openOrSelectPerson(IntegerPrimaryKey personId); +void openOrSelectPerson(IntegerPrimaryKey personId, bool activate = false); /** * The main window of the program. diff --git a/src/tree_view/tree_view_window.cpp b/src/tree_view/tree_view_window.cpp index 65d071f..ed12294 100644 --- a/src/tree_view/tree_view_window.cpp +++ b/src/tree_view/tree_view_window.cpp @@ -8,6 +8,7 @@ #include "tree_view_window.h" #include "data/family.h" +#include "main/main_window.h" #include "person_tree_graph_model.h" #include "utils/formatted_identifier_delegate.h" @@ -51,16 +52,10 @@ TreeViewWindow::TreeViewWindow(IntegerPrimaryKey person, QWidget* parent) : QMai setCentralWidget(view); toolbar->setMovable(false); - view->setContextMenuPolicy(Qt::ActionsContextMenu); - auto* openPersonAction = new QAction(view); - openPersonAction->setText(i18n("Open person details")); - connect(openPersonAction, &QAction::triggered, [&]() { - // TODO: how can we get the current model here? - // Mouse position in scene coordinates. - // QPointF posView = view->mapToScene(view->mapFromGlobal(QCursor::pos())); - // const NodeId newId = graphModel.addNode(); - // graphModel.setNodeData(newId, NodeRole::Position, posView); + connect(scene, &QtNodes::BasicGraphicsScene::nodeDoubleClicked, this, [](NodeId nodeId) { + openOrSelectPerson(nodeId, true); }); - // TODO: remove some existing actions - view->addAction(openPersonAction); + + // // TODO: remove some existing actions + // view->addAction(openPersonAction); }