@@ -457,60 +457,45 @@ DataTree::DataObject::DataObject (const Identifier& treeType)
457457{
458458}
459459
460- DataTree::DataObject::~DataObject ()
461- {
462- ownerTree = nullptr ;
463- }
460+ DataTree::DataObject::~DataObject () = default ;
464461
465462void DataTree::DataObject::sendPropertyChangeMessage (const Identifier& property)
466463{
467- if (auto tree = getDataTree ())
464+ DataTree treeObj (shared_from_this ());
465+ listeners.call ([&] (DataTree::Listener& l)
468466 {
469- DataTree treeObj (shared_from_this ());
470- listeners.call ([&] (DataTree::Listener& l)
471- {
472- l.propertyChanged (treeObj, property);
473- });
474- }
467+ l.propertyChanged (treeObj, property);
468+ });
475469}
476470
477471void DataTree::DataObject::sendChildAddedMessage (const DataTree& child)
478472{
479- if (auto tree = getDataTree ())
473+ DataTree treeObj (shared_from_this ());
474+ DataTree childTree (child.object );
475+ listeners.call ([&] (DataTree::Listener& l)
480476 {
481- DataTree treeObj (shared_from_this ());
482- DataTree childTree (child.object );
483- listeners.call ([&] (DataTree::Listener& l)
484- {
485- l.childAdded (treeObj, childTree);
486- });
487- }
477+ l.childAdded (treeObj, childTree);
478+ });
488479}
489480
490481void DataTree::DataObject::sendChildRemovedMessage (const DataTree& child, int formerIndex)
491482{
492- if (auto tree = getDataTree ())
483+ DataTree treeObj (shared_from_this ());
484+ DataTree childTree (child.object );
485+ listeners.call ([&] (DataTree::Listener& l)
493486 {
494- DataTree treeObj (shared_from_this ());
495- DataTree childTree (child.object );
496- listeners.call ([&] (DataTree::Listener& l)
497- {
498- l.childRemoved (treeObj, childTree, formerIndex);
499- });
500- }
487+ l.childRemoved (treeObj, childTree, formerIndex);
488+ });
501489}
502490
503491void DataTree::DataObject::sendChildMovedMessage (const DataTree& child, int oldIndex, int newIndex)
504492{
505- if (auto tree = getDataTree ())
493+ DataTree treeObj (shared_from_this ());
494+ DataTree childTree (child.object );
495+ listeners.call ([&] (DataTree::Listener& l)
506496 {
507- DataTree treeObj (shared_from_this ());
508- DataTree childTree (child.object );
509- listeners.call ([&] (DataTree::Listener& l)
510- {
511- l.childMoved (treeObj, childTree, oldIndex, newIndex);
512- });
513- }
497+ l.childMoved (treeObj, childTree, oldIndex, newIndex);
498+ });
514499}
515500
516501std::shared_ptr<DataTree::DataObject> DataTree::DataObject::clone () const
@@ -529,19 +514,13 @@ std::shared_ptr<DataTree::DataObject> DataTree::DataObject::clone() const
529514 return newObject;
530515}
531516
532- DataTree* DataTree::DataObject::getDataTree () const
533- {
534- return ownerTree;
535- }
536-
537517// ==============================================================================
538518
539519DataTree::DataTree () noexcept = default ;
540520
541521DataTree::DataTree (const Identifier& type)
542522 : object (std::make_shared<DataObject> (type))
543523{
544- object->ownerTree = this ;
545524}
546525
547526DataTree::DataTree (const DataTree& other) noexcept
@@ -593,8 +572,6 @@ DataTree& DataTree::operator= (DataTree&& other) noexcept
593572DataTree::DataTree (std::shared_ptr<DataObject> objectToUse)
594573 : object (std::move (objectToUse))
595574{
596- if (object)
597- object->ownerTree = this ;
598575}
599576
600577// ==============================================================================
@@ -1552,9 +1529,9 @@ void DataTree::Transaction::applyChanges()
15521529
15531530// ==============================================================================
15541531
1555- DataTree::ValidatedTransaction::ValidatedTransaction (DataTree& tree, DataTreeSchema* schema, const String& description, UndoManager* undoManager)
1532+ DataTree::ValidatedTransaction::ValidatedTransaction (DataTree& tree, ReferenceCountedObjectPtr< DataTreeSchema> schema, const String& description, UndoManager* undoManager)
15561533 : transaction (std::make_unique<Transaction> (tree.beginTransaction (description, undoManager)))
1557- , schema (schema)
1534+ , schema (std::move ( schema) )
15581535 , nodeType (tree.getType())
15591536{
15601537}
@@ -1576,6 +1553,7 @@ DataTree::ValidatedTransaction& DataTree::ValidatedTransaction::operator= (Valid
15761553 nodeType = other.nodeType ;
15771554 hasValidationErrors = other.hasValidationErrors ;
15781555 }
1556+
15791557 return *this ;
15801558}
15811559
@@ -1685,6 +1663,7 @@ void DataTree::ValidatedTransaction::abort()
16851663 if (transaction && transaction->isActive ())
16861664 {
16871665 transaction->abort ();
1666+
16881667 hasValidationErrors = false ; // Reset error state
16891668 }
16901669}
0 commit comments