diff --git a/pj_proto_app/CMakeLists.txt b/pj_proto_app/CMakeLists.txt index 7dc27197..fc64a1bd 100644 --- a/pj_proto_app/CMakeLists.txt +++ b/pj_proto_app/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable(pj_proto_app src/main_window.cpp src/plugin_registry.cpp src/data_source_session.cpp + src/toolbox_session.cpp src/series_tree_model.cpp src/chart_panel.cpp src/time_range_slider.cpp diff --git a/pj_proto_app/src/main_window.cpp b/pj_proto_app/src/main_window.cpp index 7433ea73..a7930d23 100644 --- a/pj_proto_app/src/main_window.cpp +++ b/pj_proto_app/src/main_window.cpp @@ -187,6 +187,10 @@ MainWindow::MainWindow(const std::string& plugin_dir, QWidget* parent) }); connect(&refresh_timer_, &QTimer::timeout, this, &MainWindow::onRefreshTimer); + // --- Tools menu --- + auto* tools_menu = menuBar()->addMenu("&Tools"); + setupToolboxPanels(tools_menu); + setWindowTitle("PlotJuggler Proto"); } @@ -692,4 +696,34 @@ void MainWindow::onOpenMarketplace() { } } +void MainWindow::setupToolboxPanels(QMenu* tools_menu) { + for (const auto& tb : registry_.allToolboxes()) { + auto session = + std::make_unique(engine_, const_cast(tb.library), tb.name, this); + if (!session->init()) { + continue; + } + + connect(session.get(), &ToolboxSession::dataChanged, this, [this]() { + auto [begin, end] = computeVisibleRange(); + chart_panel_->updateData(begin, end); + tree_model_.rebuildIfChanged(); + }); + + ToolboxSession* raw_session = session.get(); + + tools_menu->addAction(QString::fromStdString(tb.name), this, [this, raw_session]() { + if (raw_session->hasDialog()) { + if (raw_session->runDialog(this)) { + auto [begin, end] = computeVisibleRange(); + chart_panel_->updateData(begin, end); + tree_model_.rebuildIfChanged(); + } + } + }); + + toolbox_sessions_.push_back(std::move(session)); + } +} + } // namespace proto diff --git a/pj_proto_app/src/main_window.hpp b/pj_proto_app/src/main_window.hpp index f26a1b94..3aa978ea 100644 --- a/pj_proto_app/src/main_window.hpp +++ b/pj_proto_app/src/main_window.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include #include #include @@ -13,6 +15,7 @@ #include "pj_datastore/engine.hpp" #include "plugin_registry.hpp" #include "series_tree_model.hpp" +#include "toolbox_session.hpp" #include "pj_marketplace/extension_manager.hpp" @@ -43,6 +46,8 @@ class MainWindow : public QMainWindow { void onTreeContextMenu(const QPoint& pos); private: + void setupToolboxPanels(QMenu* tools_menu); + /// Compute the current visible time range based on data and streaming state. std::pair computeVisibleRange() const; @@ -66,6 +71,8 @@ class MainWindow : public QMainWindow { QTimer refresh_timer_; int refresh_tick_ = 0; bool streaming_active_ = false; + + std::vector> toolbox_sessions_; }; } // namespace proto