refactor: replace raw object pointers with SmartPointer in ObjectsContext and update dependent codebases

This commit is contained in:
AndreaRigoni
2026-04-17 13:28:24 +00:00
parent 506b8f037f
commit 390fc44043
8 changed files with 57 additions and 41 deletions

View File

@@ -38,8 +38,8 @@ void ContextModel::setContext(uLib::ObjectsContext* context) {
});
// Connect existing objects
for (auto* obj : m_rootContext->GetObjects()) {
uLib::Object::connect(obj, &uLib::Object::Updated, refresh);
for (const auto& obj : m_rootContext->GetObjects()) {
uLib::Object::connect(obj.get(), &uLib::Object::Updated, refresh);
}
}
endResetModel();
@@ -229,8 +229,8 @@ bool ContextModel::dropMimeData(const QMimeData* data, Qt::DropAction action, in
[&findAndRemoveRecursive](uLib::Object* current, uLib::Object* target) {
if (auto ctx = current->GetChildren()) {
ctx->RemoveObject(target);
for (auto* obj : ctx->GetObjects()) {
findAndRemoveRecursive(obj, target);
for (const auto& obj : ctx->GetObjects()) {
findAndRemoveRecursive(obj.get(), target);
}
}
};
@@ -244,12 +244,12 @@ bool ContextModel::dropMimeData(const QMimeData* data, Qt::DropAction action, in
// check if targetCtx is descendant of obj
std::function<bool(uLib::Object*, uLib::Object*)> isDescendant =
[&isDescendant](uLib::Object* root, uLib::Object* target) -> bool {
if (auto ctx = root->GetChildren()) {
for (auto* child : ctx->GetObjects()) {
if (child == target) return true;
if (isDescendant(child, target)) return true;
}
}
if (auto ctx = root->GetChildren()) {
for (const auto& child : ctx->GetObjects()) {
if (child.get() == target) return true;
if (isDescendant(child.get(), target)) return true;
}
}
return false;
};
if (isDescendant(obj, (uLib::Object*)targetCtx)) invalid = true;

View File

@@ -182,8 +182,8 @@ void MainPanel::setContext(uLib::ObjectsContext* context) {
// Add any prop3ds that were created during m_mainVtkContext's construction to all panes
auto panes = this->findChildren<ViewportPane*>();
for (auto* obj : context->GetObjects()) {
if (auto* p = m_mainVtkContext->GetProp3D(obj)) {
for (const auto& obj : context->GetObjects()) {
if (auto* p = m_mainVtkContext->GetProp3D(obj.get())) {
for (auto* pane : panes) {
if (auto* vp = qobject_cast<uLib::Vtk::QViewport*>(pane->currentViewport())) {
vp->AddProp3D(*p);

View File

@@ -426,15 +426,15 @@ void ReferencePropertyWidget::refreshCombo() {
if (m_Context) {
const auto& objects = m_Context->GetObjects();
for (auto* obj : objects) {
if (m_RefProp->IsCompatible(obj)) {
for (const auto& obj : objects) {
if (m_RefProp->IsCompatible(obj.get())) {
QString label = QString::fromStdString(obj->GetInstanceName());
if (label.isEmpty()) {
label = QString::fromStdString(std::string(obj->GetClassName()));
}
// Add index suffix if name is empty to disambiguate
m_Combo->addItem(label, QVariant::fromValue((quintptr)obj));
if (obj == currentRef) {
m_Combo->addItem(label, QVariant::fromValue((quintptr)obj.get()));
if (obj.get() == currentRef) {
selectedIdx = m_Combo->count() - 1;
}
}