Reimplemented array resizing

This commit is contained in:
Aruki
2018-07-09 06:53:56 -06:00
parent 641cf81dd8
commit a90f1d0441
11 changed files with 320 additions and 328 deletions

View File

@@ -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