modify curve entity

This commit is contained in:
brige 2025-11-03 23:52:10 +08:00
parent afe42180ce
commit d74a02e0c4

View File

@ -2,6 +2,7 @@
#include <QBoxLayout> #include <QBoxLayout>
#include <QDebug> #include <QDebug>
#include <QSet>
#include "PropertyBrowser/qttreepropertybrowser.h" #include "PropertyBrowser/qttreepropertybrowser.h"
#include "PropertyBrowser/qtpropertymanager.h" #include "PropertyBrowser/qtpropertymanager.h"
@ -49,6 +50,10 @@ void PropertyBrowser::OnWorkSpaceChange(const QVariant& value) {
} }
browser_->clear(); browser_->clear();
// Reset local mappings when workspace changes
propertyToId_.clear();
idToProperty_.clear();
idToExpanded_.clear();
QtProperty* property; QtProperty* property;
@ -65,19 +70,21 @@ void PropertyBrowser::OnWorkSpaceChange(const QVariant& value) {
QObject::connect(currentWorkspace_, &WorkSpace::FilesChanged, QObject::connect(currentWorkspace_, &WorkSpace::FilesChanged,
this, &PropertyBrowser::OnWorkspaceFilesChanged); this, &PropertyBrowser::OnWorkspaceFilesChanged);
// Mount first curve entry if available // Mount all curve entries, each as its own top-level group
auto curves = currentWorkspace_->GetFileEntries(FileEntryType::Curve); auto curves = currentWorkspace_->GetFileEntries(FileEntryType::Curve);
if (!curves.empty()) { for (const auto& entry : curves) {
auto entry = curves.front(); if (!entry) continue;
if (entry) { auto curve = entry->AsCurve();
auto curve = entry->AsCurve(); if (!curve) continue;
if (curve) {
QtProperty* cprop = curveEntryManager_->addProperty(tr("CurveEntry")); // Use filename as stable unique id, and include display name in group title
QCurveEntryAttribute attr(curve); const QString id = QString("CurveEntry:%1").arg(entry->GetFileName());
curveEntryManager_->setValue(cprop, attr); const QString title = QString("CurveEntry - %1").arg(entry->GetName());
addProperty(cprop, tr("CurveEntry"));
} QtProperty* cprop = curveEntryManager_->addProperty(title);
} QCurveEntryAttribute attr(curve);
curveEntryManager_->setValue(cprop, attr);
addProperty(cprop, id);
} }
} }
@ -211,25 +218,49 @@ void PropertyBrowser::OnWorkspaceFilesChanged(FileEntryType type, std::shared_pt
} }
} }
// Refresh curve entry when curve files mutate // Refresh curve entry groups when curve files mutate
if (type == FileEntryType::Curve) { if (type == FileEntryType::Curve) {
auto curves = currentWorkspace_->GetFileEntries(FileEntryType::Curve); const auto curves = currentWorkspace_->GetFileEntries(FileEntryType::Curve);
QCurveEntryAttribute attr(nullptr);
if (!curves.empty()) { // Desired ids for current curves
auto entry = curves.front(); QSet<QString> desiredIds;
if (entry) { for (const auto& entry : curves) {
auto curve = entry->AsCurve(); if (!entry) continue;
if (curve) attr = QCurveEntryAttribute(curve); desiredIds.insert(QString("CurveEntry:%1").arg(entry->GetFileName()));
}
// Add or update properties for all current curves
for (const auto& entry : curves) {
if (!entry) continue;
auto curve = entry->AsCurve();
if (!curve) continue;
const QString id = QString("CurveEntry:%1").arg(entry->GetFileName());
const QString title = QString("CurveEntry - %1").arg(entry->GetName());
QCurveEntryAttribute attr(curve);
auto it = idToProperty_.find(id);
if (it != idToProperty_.end()) {
// Update existing group
curveEntryManager_->setValue(it.value(), attr);
} else {
// Create new group for this curve
QtProperty* prop = curveEntryManager_->addProperty(title);
curveEntryManager_->setValue(prop, attr);
addProperty(prop, id);
} }
} }
auto it = idToProperty_.find(tr("CurveEntry")); // Remove groups for curves that no longer exist
if (it != idToProperty_.end()) { QList<QString> existingIds = idToProperty_.keys();
curveEntryManager_->setValue(it.value(), attr); for (const auto& id : existingIds) {
} else if (attr.GetEntry()) { if (id.startsWith("CurveEntry:") && !desiredIds.contains(id)) {
QtProperty* prop = curveEntryManager_->addProperty(tr("CurveEntry")); QtProperty* prop = idToProperty_[id];
curveEntryManager_->setValue(prop, attr); browser_->removeProperty(prop);
addProperty(prop, tr("CurveEntry")); propertyToId_.remove(prop);
idToExpanded_.remove(id);
idToProperty_.remove(id);
}
} }
} }
} }