mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-14 15:46:17 +00:00
Reimplemented array resizing
This commit is contained in:
@@ -1,31 +1,50 @@
|
||||
#ifndef CRESIZESCRIPTARRAYCOMMAND_H
|
||||
#define CRESIZESCRIPTARRAYCOMMAND_H
|
||||
|
||||
#include "IUndoCommand.h"
|
||||
#include "ObjReferences.h"
|
||||
#include "Editor/PropertyEdit/CPropertyModel.h"
|
||||
#include "Editor/WorldEditor/CWorldEditor.h"
|
||||
#include <QUndoCommand>
|
||||
#include "CEditScriptPropertyCommand.h"
|
||||
|
||||
// todo: make this more general... it shouldn't be relying on a CPropertyModel pointer
|
||||
//FIXME
|
||||
/*class CResizeScriptArrayCommand : public IUndoCommand
|
||||
class CResizeScriptArrayCommand : public CEditScriptPropertyCommand
|
||||
{
|
||||
CWorldEditor* mpEditor;
|
||||
IPropertyNew* mpArray;
|
||||
QVector<IPropertyNew*> mDeletedProperties;
|
||||
CPropertyModel *mpModel;
|
||||
|
||||
int mOldSize;
|
||||
int mNewSize;
|
||||
bool mNewSizeLarger;
|
||||
|
||||
public:
|
||||
CResizeScriptArrayCommand(IPropertyNew *pProp, CWorldEditor *pEditor, CPropertyModel *pModel, int NewSize);
|
||||
~CResizeScriptArrayCommand();
|
||||
void undo();
|
||||
void redo();
|
||||
bool AffectsCleanState() const { return true; }
|
||||
};*/
|
||||
CResizeScriptArrayCommand(CWorldEditor* pEditor, const QModelIndex& rkIndex, CPropertyModel* pInModel, const QString& rkCommandName = "Resize Array")
|
||||
: CEditScriptPropertyCommand(pEditor, rkIndex, pInModel, rkCommandName)
|
||||
{}
|
||||
|
||||
bool mergeWith(const QUndoCommand *pkOther)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note in some cases undo/redo may be called when the change has already been applied outside of the undo command
|
||||
// This is why we need to check the array's actual current size instead of assuming it will match one of the arrays
|
||||
void undo()
|
||||
{
|
||||
// unpleasant cast, but easiest/fastest way to access the sizes
|
||||
int NewSize = *((int*)mOldData.data());
|
||||
int OldSize = CurrentArrayCount();
|
||||
|
||||
mpModel->ArrayAboutToBeResized(mIndex, NewSize);
|
||||
CEditScriptPropertyCommand::undo();
|
||||
mpModel->ArrayResized(mIndex, OldSize);
|
||||
}
|
||||
|
||||
void redo()
|
||||
{
|
||||
// unpleasant cast, but easiest/fastest way to access the sizes
|
||||
int NewSize = *((int*)mNewData.data());
|
||||
int OldSize = CurrentArrayCount();
|
||||
|
||||
mpModel->ArrayAboutToBeResized(mIndex, NewSize);
|
||||
CEditScriptPropertyCommand::redo();
|
||||
mpModel->ArrayResized(mIndex, OldSize);
|
||||
}
|
||||
|
||||
int CurrentArrayCount()
|
||||
{
|
||||
void* pData = mpModel->DataPointerForIndex(mIndex);
|
||||
CArrayProperty* pArray = TPropCast<CArrayProperty>(mpProperty);
|
||||
return pArray->ArrayCount(pData);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CRESIZESCRIPTARRAYCOMMAND_H
|
||||
|
||||
Reference in New Issue
Block a user