Skip to content

Commit

Permalink
Open person from tree view
Browse files Browse the repository at this point in the history
Completes #47
  • Loading branch information
niknetniko committed Dec 8, 2024
1 parent a84d0ff commit d8cb8b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <QDockWidget>
#include <QFileDialog>

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<MainWindow*>(element) != nullptr;
Expand All @@ -37,6 +37,9 @@ void openOrSelectPerson(IntegerPrimaryKey personId) {
auto* mainWindow = qobject_cast<MainWindow*>(*it);
assert(mainWindow != nullptr);
mainWindow->openOrSelectPerson(personId);
if (activate) {
mainWindow->activateWindow();
}
}

MainWindow::MainWindow() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 6 additions & 11 deletions src/tree_view/tree_view_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}

0 comments on commit d8cb8b9

Please sign in to comment.