XPlor/app/fieldeditcommand.h
njohnson 05c70c1108 Add field editing UI with undo support and dirty state tracking
Implement infrastructure for editing parsed binary fields:

FieldEditCommand (QUndoCommand):
- Undo/redo support for field value changes
- Stores old and new values with field metadata
- Integrates with Qt's undo stack

DirtyStateManager:
- Tracks modified state per-tab
- Emits signals when dirty state changes
- Enables save prompts and tab indicators

ScriptTypeEditorWidget enhancements:
- Add recompilation debouncing (300ms) for responsive editing
- Build form layout only for fields with values (skip unexecuted branches)
- Support edit signals for modified fields
- Improved table and form layout building

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 20:54:23 -05:00

46 lines
1.3 KiB
C++

#ifndef FIELDEDITCOMMAND_H
#define FIELDEDITCOMMAND_H
#include <QUndoCommand>
#include <QVariant>
#include <QString>
#include <functional>
/**
* @brief QUndoCommand for field value edits in ScriptTypeEditorWidget
*
* Stores old and new values for a field, allowing undo/redo of edits.
* Uses callbacks to apply values since the actual application logic
* is in the editor widget.
*/
class FieldEditCommand : public QUndoCommand
{
public:
using ApplyCallback = std::function<void(const QString& fieldName, const QVariant& value)>;
FieldEditCommand(int journalId,
const QString& fieldName,
const QVariant& oldValue,
const QVariant& newValue,
ApplyCallback applyCallback,
QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
int id() const override;
bool mergeWith(const QUndoCommand* other) override;
QString fieldName() const { return m_fieldName; }
int journalId() const { return m_journalId; }
private:
int m_journalId;
QString m_fieldName;
QVariant m_oldValue;
QVariant m_newValue;
ApplyCallback m_applyCallback;
bool m_firstRedo = true; // Skip first redo since value is already applied
};
#endif // FIELDEDITCOMMAND_H