Files
BionxControl/nodes/services/ntxnodetree.h

99 lines
3.1 KiB
C
Raw Permalink Normal View History

2026-04-02 15:15:28 +02:00
#ifndef NTX_NODETREE_H
#define NTX_NODETREE_H
#include <ntxnode.h>
#include <ntxclipboard.h>
#include <ntxundostack.h>
#include <ntxnodecommands.h>
namespace ntx
{
/**
* @brief Service-Schicht für Knoten-Operationen mit Undo/Redo.
*
* Ist selbst ein NtxINode (Composite-Pattern): Kann als Wurzel
* eines Teilbaums dienen und in andere NtxNodeTrees eingehängt werden.
*
* Bietet:
* - Command-basierte Baum-Manipulation (add/delete/move)
* - Undo/Redo via NtxUndoStack
* - Copy/Cut/Paste via NtxClipboard
* - Listen-Operationen via NtxMacroCommand
*/
class NtxNodeTree //: public NtxNode
{
friend class NtxNodeFactory;
public:
//~NtxNodeTree() override = default;
NtxNodeTree(const NtxNodeTree&) = delete;
NtxNodeTree& operator=(const NtxNodeTree&) = delete;
NtxNodePtr clone() const;// override;
// =========================================================================
// Command-Ausführung
// =========================================================================
/// Führt ein beliebiges Command aus (mit Undo-Support).
bool execute(NtxCommandUPtr cmd);
bool undo();
bool redo();
bool canUndo() const;
bool canRedo() const;
NtxString undoText() const;
NtxString redoText() const;
void setClean();
bool isDirty() const;
// =========================================================================
// Einzel-Operationen (erzeugen intern Commands)
// =========================================================================
bool addNode(NtxNodePtr parent, NtxNodePtr node, size_t index);
bool deleteNode(NtxNodePtr node);
bool moveNode(NtxNodePtr node, NtxNodePtr newParent, size_t newIndex);
// =========================================================================
// Listen-Operationen (erzeugen NtxMacroCommand)
// =========================================================================
bool addNodes(NtxNodePtr parent, const NtxNodeList& nodes, size_t index);
bool deleteNodes(const NtxNodeList& nodes);
// =========================================================================
// Clipboard
// =========================================================================
void copyNodes(const NtxNodeList& nodes);
void cutNodes(const NtxNodeList& nodes);
NtxNodeList pasteNodes(NtxNodePtr parent, size_t index);
bool hasClipboard() const;
void clearClipboard();
// =========================================================================
// Zugriff auf Interna
// =========================================================================
NtxUndoStack& undoStack() { return m_undoStack; }
const NtxUndoStack& undoStack() const { return m_undoStack; }
private:
NtxNodeTree() = default;
explicit NtxNodeTree(NtxClassTypeId id);
NtxUndoStack m_undoStack;
NtxClipboard m_clipboard;
bool m_isCutOperation{false};
};
} // namespace ntx
#endif // NTX_NODETREE_H