added nodes.
This commit is contained in:
102
nodes/services/ntxnodecommands.h
Normal file
102
nodes/services/ntxnodecommands.h
Normal file
@@ -0,0 +1,102 @@
|
||||
#ifndef NTX_NODECOMMANDS_H
|
||||
#define NTX_NODECOMMANDS_H
|
||||
|
||||
#include <ntxicommand.h>
|
||||
|
||||
namespace ntx
|
||||
{
|
||||
|
||||
// =========================================================================
|
||||
// Atomar: Knoten einfügen
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* @brief Fügt einen Knoten an einer Position ein.
|
||||
* Undo entfernt ihn wieder.
|
||||
*/
|
||||
class NtxInsertNodeCmd : public NtxICommand
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NtxInsertNodeCmd(NtxNodePtr parent, NtxNodePtr node, size_t index);
|
||||
|
||||
bool execute() override;
|
||||
bool undo() override;
|
||||
bool canExecute() const override;
|
||||
|
||||
private:
|
||||
|
||||
NtxNodePtr m_parent;
|
||||
NtxNodePtr m_node;
|
||||
size_t m_index;
|
||||
bool m_executed{false};
|
||||
};
|
||||
|
||||
// =========================================================================
|
||||
// Atomar: Knoten entfernen
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* @brief Entfernt einen Knoten. Merkt sich Parent + Position für Undo.
|
||||
*/
|
||||
class NtxRemoveNodeCmd : public NtxICommand
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
explicit NtxRemoveNodeCmd(NtxNodePtr node);
|
||||
|
||||
bool execute() override;
|
||||
bool undo() override;
|
||||
bool canExecute() const override;
|
||||
|
||||
private:
|
||||
|
||||
NtxNodePtr m_node;
|
||||
NtxNodePtr m_parent;
|
||||
size_t m_index{0};
|
||||
bool m_executed{false};
|
||||
};
|
||||
|
||||
// =========================================================================
|
||||
// Makro-Command (Composite Command)
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* @brief Führt mehrere Commands als atomare Einheit aus.
|
||||
*
|
||||
* execute(): Alle Commands vorwärts ausführen.
|
||||
* undo(): Alle Commands rückwärts rückgängig machen.
|
||||
* Bei Fehler: Rollback der bereits ausgeführten.
|
||||
*/
|
||||
class NtxMacroCommand : public NtxICommand
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NtxMacroCommand() = default;
|
||||
explicit NtxMacroCommand(const NtxString& description);
|
||||
|
||||
/// Factory: Erzeugt ein Makro aus einer Liste von Commands.
|
||||
static NtxCommandUPtr create(
|
||||
const NtxString& description,
|
||||
std::vector<NtxCommandUPtr> commands);
|
||||
|
||||
void add(NtxCommandUPtr cmd);
|
||||
|
||||
bool execute() override;
|
||||
bool undo() override;
|
||||
bool canExecute() const override;
|
||||
|
||||
size_t commandCount() const { return m_commands.size(); }
|
||||
|
||||
private:
|
||||
|
||||
std::vector<NtxCommandUPtr> m_commands;
|
||||
size_t m_executedCount{0};
|
||||
};
|
||||
|
||||
} // namespace ntx
|
||||
|
||||
#endif // NTX_NODECOMMANDS_H
|
||||
Reference in New Issue
Block a user