diff --git a/src/ui/Panel/DataPanel.h b/src/ui/Panel/DataPanel.h index 0e6ca4ce..0288353f 100644 --- a/src/ui/Panel/DataPanel.h +++ b/src/ui/Panel/DataPanel.h @@ -81,6 +81,13 @@ public: * @brief Refresh panel content (virtual function, implemented by derived classes) */ virtual void RefreshPanel() {} + + /** + * @brief Handle time change event (virtual function, implemented by derived classes) + * @param time Current time value from Timestep + */ + virtual void OnTimeChanged(double time) {} + /** * @brief Initialize UI (virtual function, derived classes implement specific layout) */ diff --git a/src/ui/Panel/DataPanelManager.cpp b/src/ui/Panel/DataPanelManager.cpp index f77759f5..1986f583 100644 --- a/src/ui/Panel/DataPanelManager.cpp +++ b/src/ui/Panel/DataPanelManager.cpp @@ -5,10 +5,12 @@ #include "ui/DockTitleBar.h" #include "ui/MainWindow.h" #include "workspace/FileEntry.h" +#include "workspace/Timestep.h" #include "common/SpdLogger.h" #include #include +#include const QString DataPanelManager::PANEL_OBJECT_NAME_PREFIX = "DataPanel_"; @@ -42,6 +44,18 @@ void DataPanelManager::SetWorkspace(WorkSpace* workspace) // Connect new workspace signals if (currentWorkspace_) { connect(currentWorkspace_, &WorkSpace::FilesChanged, this, &DataPanelManager::OnFilesChanged); + + // Connect to Timestep signals if available + if (currentWorkspace_->GetTimestep()) { + connect(currentWorkspace_->GetTimestep(), &Timestep::TimeChanged, this, &DataPanelManager::OnTimeChanged); + } + + // Connect to TimestepChanged signal to handle future Timestep changes + connect(currentWorkspace_, &WorkSpace::TimestepChanged, this, [this](Timestep* timestep) { + if (timestep) { + connect(timestep, &Timestep::TimeChanged, this, &DataPanelManager::OnTimeChanged); + } + }); } // Update all panel types @@ -293,12 +307,31 @@ QString DataPanelManager::GeneratePanelObjectName(FileEntryType fileType, int in int DataPanelManager::FindNextAvailableIndex(FileEntryType fileType) const { - int index = 0; - QString baseKey = QString("%1_").arg(FileEntryTypeToString(fileType)); + QSet usedIndices; + QString typeStr = FileEntryTypeToString(fileType); - while (dataPanels_.contains(baseKey + QString::number(index))) { - index++; + for (auto it = dataPanels_.constBegin(); it != dataPanels_.constEnd(); ++it) { + if (it.value()->GetFileType() == fileType) { + usedIndices.insert(it.value()->GetIndex()); + } } - return index; + for (int i = 1; i <= GetMaxPanelCount(); ++i) { + if (!usedIndices.contains(i)) { + return i; + } + } + + return -1; // No available index +} + +void DataPanelManager::OnTimeChanged(double time) +{ + // Notify all active panels about time change + for (auto it = dataPanels_.constBegin(); it != dataPanels_.constEnd(); ++it) { + DataPanel* panel = it.value(); + if (panel) { + panel->OnTimeChanged(time); + } + } } \ No newline at end of file diff --git a/src/ui/Panel/DataPanelManager.h b/src/ui/Panel/DataPanelManager.h index 084f4a33..f4d64cbd 100644 --- a/src/ui/Panel/DataPanelManager.h +++ b/src/ui/Panel/DataPanelManager.h @@ -68,6 +68,12 @@ public slots: */ void OnPanelClosed(); + /** + * @brief Handle time change event from Timestep + * @param time Current time value + */ + void OnTimeChanged(double time); + private: /** * @brief Update panels for specific file type