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 <QDebug>
#include <QSet>
#include "PropertyBrowser/qttreepropertybrowser.h"
#include "PropertyBrowser/qtpropertymanager.h"
@ -49,6 +50,10 @@ void PropertyBrowser::OnWorkSpaceChange(const QVariant& value) {
}
browser_->clear();
// Reset local mappings when workspace changes
propertyToId_.clear();
idToProperty_.clear();
idToExpanded_.clear();
QtProperty* property;
@ -65,19 +70,21 @@ void PropertyBrowser::OnWorkSpaceChange(const QVariant& value) {
QObject::connect(currentWorkspace_, &WorkSpace::FilesChanged,
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);
if (!curves.empty()) {
auto entry = curves.front();
if (entry) {
auto curve = entry->AsCurve();
if (curve) {
QtProperty* cprop = curveEntryManager_->addProperty(tr("CurveEntry"));
QCurveEntryAttribute attr(curve);
curveEntryManager_->setValue(cprop, attr);
addProperty(cprop, tr("CurveEntry"));
}
}
for (const auto& entry : curves) {
if (!entry) continue;
auto curve = entry->AsCurve();
if (!curve) continue;
// Use filename as stable unique id, and include display name in group title
const QString id = QString("CurveEntry:%1").arg(entry->GetFileName());
const QString title = QString("CurveEntry - %1").arg(entry->GetName());
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) {
auto curves = currentWorkspace_->GetFileEntries(FileEntryType::Curve);
QCurveEntryAttribute attr(nullptr);
if (!curves.empty()) {
auto entry = curves.front();
if (entry) {
auto curve = entry->AsCurve();
if (curve) attr = QCurveEntryAttribute(curve);
const auto curves = currentWorkspace_->GetFileEntries(FileEntryType::Curve);
// Desired ids for current curves
QSet<QString> desiredIds;
for (const auto& entry : curves) {
if (!entry) continue;
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"));
if (it != idToProperty_.end()) {
curveEntryManager_->setValue(it.value(), attr);
} else if (attr.GetEntry()) {
QtProperty* prop = curveEntryManager_->addProperty(tr("CurveEntry"));
curveEntryManager_->setValue(prop, attr);
addProperty(prop, tr("CurveEntry"));
// Remove groups for curves that no longer exist
QList<QString> existingIds = idToProperty_.keys();
for (const auto& id : existingIds) {
if (id.startsWith("CurveEntry:") && !desiredIds.contains(id)) {
QtProperty* prop = idToProperty_[id];
browser_->removeProperty(prop);
propertyToId_.remove(prop);
idToExpanded_.remove(id);
idToProperty_.remove(id);
}
}
}
}