114 lines
2.5 KiB
C++
114 lines
2.5 KiB
C++
/*
|
|
* MoveModuleOrConnection.cpp
|
|
*
|
|
* Created on: 2012-10-24
|
|
* Author: dev
|
|
*/
|
|
|
|
#include <QGraphicsView>
|
|
#include <QtDebug>
|
|
#include <QGraphicsItem>
|
|
|
|
#include "MoveModuleCmd.h"
|
|
#include "ModuleGraphicsItem.h"
|
|
#include "WorkflowSceneManager.h"
|
|
#include "ModuleInformation.h"
|
|
#include "PaiModuleStyle.h"
|
|
#include "GlobalWorkflowItems.h"
|
|
|
|
using namespace pai;
|
|
using namespace pai::graphics2d;
|
|
|
|
namespace pai
|
|
{
|
|
namespace graphics2d
|
|
{
|
|
|
|
static const int MoveModuleCmdId = 1;
|
|
|
|
MoveModuleCmd::MoveModuleCmd(pai::graphics2d::WorkflowSceneManager *pSceneManager,
|
|
QList<ModuleMovedInfo> moduleMovedInfoList, bool bKeyPressedMove, QUndoCommand *parent)
|
|
:QUndoCommand(parent)
|
|
{
|
|
m_pSceneManager = pSceneManager;
|
|
m_moduleMovedInfoList = moduleMovedInfoList;
|
|
m_bKeyPressedMove = bKeyPressedMove;
|
|
}
|
|
|
|
MoveModuleCmd::~MoveModuleCmd()
|
|
{
|
|
}
|
|
|
|
void MoveModuleCmd::undo()
|
|
{
|
|
foreach(ModuleMovedInfo movedInfo, m_moduleMovedInfoList)
|
|
{
|
|
ModuleGraphicsItem *pModule = GlobalWorkflowItems::GetInstance()->FindModule(m_pSceneManager, movedInfo.stepId);
|
|
if (!pModule)
|
|
{
|
|
continue;
|
|
}
|
|
pModule->GetModuleStyle()->SetPosition(movedInfo.mousePressPos, pModule);
|
|
}
|
|
}
|
|
|
|
void MoveModuleCmd::redo()
|
|
{
|
|
foreach(ModuleMovedInfo movedInfo, m_moduleMovedInfoList)
|
|
{
|
|
ModuleGraphicsItem *pModule = GlobalWorkflowItems::GetInstance()->FindModule(m_pSceneManager, movedInfo.stepId);
|
|
if (!pModule)
|
|
{
|
|
continue;
|
|
}
|
|
pModule->GetModuleStyle()->SetPosition(movedInfo.mouseReleasePos, pModule);
|
|
}
|
|
}
|
|
|
|
int MoveModuleCmd::id() const
|
|
{
|
|
if (m_bKeyPressedMove)
|
|
{
|
|
return MoveModuleCmdId;
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
bool MoveModuleCmd::mergeWith(const QUndoCommand *other)
|
|
{
|
|
const MoveModuleCmd *pMoveModuleCmd = static_cast<const MoveModuleCmd*>(other);
|
|
if (pMoveModuleCmd->id() != MoveModuleCmdId)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(m_moduleMovedInfoList.count() != pMoveModuleCmd->m_moduleMovedInfoList.count())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
for (int i = 0; i < m_moduleMovedInfoList.count(); ++i)
|
|
{
|
|
if (m_moduleMovedInfoList.at(i).stepId != pMoveModuleCmd->m_moduleMovedInfoList.at(i).stepId)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
for (int i = 0; i < m_moduleMovedInfoList.count(); ++i)
|
|
{
|
|
m_moduleMovedInfoList[i].mousePressPos = pMoveModuleCmd->m_moduleMovedInfoList.at(i).mousePressPos;
|
|
m_moduleMovedInfoList[i].mouseReleasePos = pMoveModuleCmd->m_moduleMovedInfoList.at(i).mouseReleasePos;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|