本文整理汇总了C++中UndoManager类的典型用法代码示例。如果您正苦于以下问题:C++ UndoManager类的具体用法?C++ UndoManager怎么用?C++ UndoManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UndoManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processDragSelection
void SelectionPlugin::onMouseButtonRelease( const MouseButtonEvent& event )
{
if( event.button != MouseButton::Left )
return;
SceneDocument* sceneDocument = (SceneDocument*) editor->getDocument();
sceneDocument->getRenderWindow()->setCursorCapture(false);
editor->getDocument()->getWindow()->flagRedraw();
SelectionOperation* selection = nullptr;
if(selections->dragRectangle)
selection = processDragSelection(event);
else
selection = processSelection(event);
if( !selection ) return;
const SelectionCollection& selected = selections->getSelections();
// Prevent duplication of selection events.
if( selected.isSame(selection->selections) )
{
LogDebug("Ignoring duplicated selection");
Deallocate(selection);
return;
}
selection->redo();
UndoManager* undoManager = sceneDocument->getUndoManager();
undoManager->registerOperation(selection);
}
示例2: submitUndo
void GuiRoadEditorCtrl::submitUndo( const UTF8 *name )
{
// Grab the mission editor undo manager.
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
Con::errorf( "GuiRoadEditorCtrl::submitUndo() - EUndoManager not found!" );
return;
}
// Setup the action.
GuiRoadEditorUndoAction *action = new GuiRoadEditorUndoAction( name );
action->mObjId = mSelRoad->getId();
action->mBreakAngle = mSelRoad->mBreakAngle;
action->mMaterialName = mSelRoad->mMaterialName;
action->mSegmentsPerBatch = mSelRoad->mSegmentsPerBatch;
action->mTextureLength = mSelRoad->mTextureLength;
action->mRoadEditor = this;
for( U32 i = 0; i < mSelRoad->mNodes.size(); i++ )
{
action->mNodes.push_back( mSelRoad->mNodes[i] );
}
undoMan->addAction( action );
}
示例3: deleteSelectedDecal
void GuiDecalEditorCtrl::deleteSelectedDecal()
{
if ( !mSELDecal )
return;
// Grab the mission editor undo manager.
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
return;
}
// Create the UndoAction.
DIDeleteUndoAction *action = new DIDeleteUndoAction("Delete Decal");
action->deleteDecal( *mSELDecal );
action->mEditor = this;
// Submit it.
undoMan->addAction( action );
if ( isMethod( "onDeleteInstance" ) )
{
char buffer[512];
dSprintf(buffer, 512, "%i", mSELDecal->mId);
Con::executef( this, "onDeleteInstance", String(buffer).c_str(), mSELDecal->mDataBlock->lookupName.c_str() );
}
gDecalManager->removeDecal( mSELDecal );
mSELDecal = NULL;
}
示例4: getScene
bool Object::destroyRenderer(qlib::uid_t uid)
{
// get renderer ptr/check consistency
rendtab_t::iterator i = m_rendtab.find(uid);
if (i==m_rendtab.end())
return false;
RendererPtr pRend = i->second;
ScenePtr pScene = getScene();
if (pScene.isnull() || pRend.isnull()) {
LOG_DPRINTLN("Object::destroyRenderer> fatal error pScene or pRend is NULL!");
return false;
}
// detach renderer from the view-related resources (DL, VBO, etc)
pRend->unloading();
// Detach the parent scene from the renderer event source
pRend->removeListener(pScene.get());
// Fire the SCE_REND_REMOVING Event, before removing the renderer
{
MB_DPRINTLN("Object> Firing SCE_REND_REMOVING event...");
SceneEvent ev;
ev.setType(SceneEvent::SCE_REND_REMOVING);
ev.setSource(getSceneID());
ev.setTarget(pRend->getUID());
pScene->fireSceneEvent(ev);
}
// remove the rend from the scene's cache list
pScene->removeRendCache(pRend);
// 2012/9/30
// Detach the rend from obj HERE is very important!!
// (This call remove the rend from object's event listener list.
// Otherwise, deleted ptr will remain in the listener list, and thus cause crash!!)
qlib::uid_t objid = pRend->detachObj();
// MB_ASSERT(objid==this->m_uid);
// 2012/9/30
// Setting scene ID to null will cause removing pRend from the scene's listener list
// (Without this, deleted ptr will remain in scene's listener list, after clearing the UNDO data!!)
pRend->setSceneID(qlib::invalid_uid);
// Remove from the renderer table
m_rendtab.erase(i);
// Record undo/redo info
UndoManager *pUM = pScene->getUndoMgr();
if (pUM->isOK()) {
ObjLoadEditInfo *pPEI = MB_NEW ObjLoadEditInfo;
pPEI->setupRendDestroy(getUID(), pRend);
pUM->addEditInfo(pPEI);
}
return true;
}
示例5: cancel
bool UndoTransaction::commit()
{
if (!m_data)
return false;
TransactionData* data = static_cast<TransactionData*>(m_data.data());
UndoManager* UM = data->UM;
int stackLevel = data->stackLevel;
if (!UM->undoEnabled_)
{
cancel();
return false;
}
UndoObject *tmpu = UM->transactions_.at(stackLevel)->transactionObject;
TransactionState *tmps = UM->transactions_.at(stackLevel)->transactionState;
switch (m_data->m_status)
{
case Transaction::STATE_OPEN:
// qDebug() << "UndoManager::commitTransaction" << data << data->transactionObject->getUName() << data->transactionState->getName() << stackLevel;
m_data->m_status = Transaction::STATE_COMMITTED;
// brutal for now:
assert (stackLevel + 1 == signed(UM->transactions_.size()));
if (stackLevel < signed(UM->transactions_.size()))
{
UM->transactions_.erase(UM->transactions_.begin() + stackLevel);
}
if (tmps->sizet() > 0) // are there any actions inside the committed transaction
{
if (tmps->getName().isEmpty())
tmps->useActionName();
UM->action(tmpu, tmps);
} // if not just delete objects
else
{
delete tmpu;
tmpu = 0;
delete tmps;
tmps = 0;
}
return true;
break;
case STATE_WILLFAIL:
return cancel();
break;
default:
// qDebug() << "UndoManager::commitTransaction ** already closed **";
// nothing
break;
}
return false;
}
示例6: retargetDecalDatablock
void GuiDecalEditorCtrl::retargetDecalDatablock( String dbFrom, String dbTo )
{
DecalData * ptrFrom = dynamic_cast<DecalData*> ( Sim::findObject(dbFrom.c_str()) );
DecalData * ptrTo = dynamic_cast<DecalData*> ( Sim::findObject(dbTo.c_str()) );
if( !ptrFrom || !ptrTo )
return;
// Grab the mission editor undo manager.
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
return;
}
// Create the UndoAction.
DBRetargetUndoAction *action = new DBRetargetUndoAction("Retarget Decal Datablock");
action->mEditor = this;
action->mDBFromId = ptrFrom->getId();
action->mDBToId = ptrTo->getId();
Vector<DecalInstance*> mDecalQueue;
Vector<DecalInstance *>::iterator iter;
mDecalQueue.clear();
const Vector<DecalSphere*> &grid = gDecalManager->getDecalDataFile()->getSphereList();
for ( U32 i = 0; i < grid.size(); i++ )
{
const DecalSphere *decalSphere = grid[i];
mDecalQueue.merge( decalSphere->mItems );
}
for ( iter = mDecalQueue.begin();iter != mDecalQueue.end();iter++ )
{
if( !(*iter) )
continue;
if( (*iter)->mDataBlock->lookupName.compare( dbFrom ) == 0 )
{
if( (*iter)->mId != -1 )
{
action->retargetDecal((*iter));
(*iter)->mDataBlock = ptrTo;
forceRedraw((*iter));
}
}
}
undoMan->addAction( action );
}
示例7: AssertFatal
void ForestTool::_submitUndo( UndoAction *action )
{
AssertFatal( action, "ForestTool::_submitUndo() - No undo action!" );
// Grab the mission editor undo manager.
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
Con::errorf( "ForestTool::_submitUndo() - EUndoManager not found!" );
return;
}
undoMan->addAction( action );
mEditor->updateCollision();
}
示例8: GetActiveProject
// ApplyChain returns true on success, false otherwise.
// Any error reporting to the user has already been done.
bool BatchCommands::ApplyChain(const wxString & filename)
{
mFileName = filename;
unsigned int i;
bool res = true;
mAbort = false;
for (i = 0; i < mCommandChain.GetCount(); i++) {
if (!ApplyCommandInBatchMode(mCommandChain[i], mParamsChain[i]) || mAbort) {
res = false;
break;
}
}
mFileName.Empty();
AudacityProject *proj = GetActiveProject();
if (!res)
{
if(proj) {
// Chain failed or was cancelled; revert to the previous state
UndoManager *um = proj->GetUndoManager();
proj->SetStateTo(um->GetCurrentState());
}
return false;
}
// Chain was successfully applied; save the new project state
wxString longDesc, shortDesc;
wxString name = gPrefs->Read(wxT("/Batch/ActiveChain"), wxEmptyString);
if (name.IsEmpty())
{
longDesc = wxT("Applied batch chain");
shortDesc = wxT("Apply chain");
}
else
{
longDesc = wxString::Format(wxT("Applied batch chain '%s'"), name.c_str());
shortDesc = wxString::Format(wxT("Apply '%s'"), name.c_str());
}
if (!proj)
return false;
proj->PushState(longDesc, shortDesc);
return true;
}
示例9: AssertFatal
void GuiRiverEditorCtrl::deleteSelectedRiver( bool undoAble )
{
AssertFatal( mSelRiver != NULL, "GuiRiverEditorCtrl::deleteSelectedRiver() - No River IS selected" );
// Not undoAble? Just delete it.
if ( !undoAble )
{
mSelRiver->deleteObject();
mIsDirty = true;
Con::executef( this, "onRiverSelected" );
mSelNode = -1;
return;
}
// Grab the mission editor undo manager.
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
// Couldn't find it? Well just delete the River.
Con::errorf( "GuiRiverEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
return;
}
else
{
// Create the UndoAction.
MEDeleteUndoAction *action = new MEDeleteUndoAction("Deleted River");
action->deleteObject( mSelRiver );
mIsDirty = true;
// Submit it.
undoMan->addAction( action );
}
// ScriptCallback with 'NULL' parameter for no River currently selected.
Con::executef( this, "onRiverSelected" );
// Clear the SelectedNode (it has been deleted along with the River).
setSelectedNode( -1 );
mSelNode = -1;
// SelectedRiver is a SimObjectPtr and will be NULL automatically.
}
示例10: CompoundUndoAction
void ForestEditorCtrl::deleteMeshSafe( ForestItemData *mesh )
{
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
Con::errorf( "ForestEditorCtrl::deleteMeshSafe() - EUndoManager not found." );
return;
}
// CompoundUndoAction which will delete the ForestItemData, ForestItem(s), and ForestBrushElement(s).
CompoundUndoAction *compoundAction = new CompoundUndoAction( "Delete Forest Mesh" );
// Find ForestItem(s) referencing this datablock and add their deletion
// to the undo action.
if ( mForest )
{
Vector<ForestItem> foundItems;
mForest->getData()->getItems( mesh, &foundItems );
ForestDeleteUndoAction *itemAction = new ForestDeleteUndoAction( mForest->getData(), this );
itemAction->removeItem( foundItems );
compoundAction->addAction( itemAction );
}
// Find ForestBrushElement(s) referencing this datablock.
SimGroup *brushGroup = ForestBrush::getGroup();
sKey = mesh;
Vector<SimObject*> foundElements;
brushGroup->findObjectByCallback( &findMeshReferences, foundElements );
// Add UndoAction to delete the ForestBrushElement(s) and the ForestItemData.
MEDeleteUndoAction *elementAction = new MEDeleteUndoAction();
elementAction->deleteObject( foundElements );
elementAction->deleteObject( mesh );
// Add compound action to the UndoManager. Done.
undoMan->addAction( compoundAction );
updateCollision();
}
示例11: MoveAllSelectedEffects
void EffectLayer::MoveAllSelectedEffects(int deltaMS, UndoManager& undo_mgr)
{
std::unique_lock<std::recursive_mutex> locker(lock);
for(int i=0; i<mEffects.size();i++)
{
if(mEffects[i]->GetSelected() == EFFECT_LT_SELECTED && mEffects[i]->GetTagged())
{
if( undo_mgr.GetCaptureUndo() ) {
undo_mgr.CaptureEffectToBeMoved( mParentElement->GetName(), mIndex, mEffects[i]->GetID(),
mEffects[i]->GetStartTimeMS(), mEffects[i]->GetEndTimeMS() );
}
mEffects[i]->SetStartTimeMS( mEffects[i]->GetStartTimeMS() + deltaMS);
}
else if(mEffects[i]->GetSelected() == EFFECT_RT_SELECTED && mEffects[i]->GetTagged())
{
if( undo_mgr.GetCaptureUndo() ) {
undo_mgr.CaptureEffectToBeMoved( mParentElement->GetName(), mIndex, mEffects[i]->GetID(),
mEffects[i]->GetStartTimeMS(), mEffects[i]->GetEndTimeMS() );
}
mEffects[i]->SetEndTimeMS( mEffects[i]->GetEndTimeMS() + deltaMS);
}
else if(mEffects[i]->GetSelected() == EFFECT_SELECTED && mEffects[i]->GetTagged())
{
if( undo_mgr.GetCaptureUndo() ) {
undo_mgr.CaptureEffectToBeMoved( mParentElement->GetName(), mIndex, mEffects[i]->GetID(),
mEffects[i]->GetStartTimeMS(), mEffects[i]->GetEndTimeMS() );
}
mEffects[i]->SetStartTimeMS( mEffects[i]->GetStartTimeMS() + deltaMS);
mEffects[i]->SetEndTimeMS( mEffects[i]->GetEndTimeMS() + deltaMS);
}
mEffects[i]->SetTagged(false);
}
}
示例12: AssertFatal
void GuiRoadEditorCtrl::deleteSelectedRoad( bool undoAble )
{
AssertFatal( mSelRoad != NULL, "GuiRoadEditorCtrl::deleteSelectedRoad() - No road IS selected" );
// Not undo-able? Just delete it.
if ( !undoAble )
{
DecalRoad *lastRoad = mSelRoad;
setSelectedRoad(NULL);
lastRoad->deleteObject();
mIsDirty = true;
return;
}
// Grab the mission editor undo manager.
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
// Couldn't find it? Well just delete the road.
Con::errorf( "GuiRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
return;
}
else
{
DecalRoad *lastRoad = mSelRoad;
setSelectedRoad(NULL);
// Create the UndoAction.
MEDeleteUndoAction *action = new MEDeleteUndoAction("Deleted Road");
action->deleteObject( lastRoad );
mIsDirty = true;
// Submit it.
undoMan->addAction( action );
}
}
示例13: ShownScene
void SceneStructureWindow::SetShownScene(const ScenePtr &newScene)
{
if (!scene.expired() && newScene == scene.lock())
return;
ScenePtr previous = ShownScene();
if (previous)
{
disconnect(previous.get());
Clear();
}
scene = newScene;
treeWidget->SetScene(newScene);
if (newScene)
{
// Now that treeWidget has scene, it also has UndoManager.
UndoManager *undoMgr = treeWidget->GetUndoManager();
undoButton_->setMenu(undoMgr->UndoMenu());
redoButton_->setMenu(undoMgr->RedoMenu());
connect(undoMgr, SIGNAL(CanUndoChanged(bool)), this, SLOT(SetUndoEnabled(bool)), Qt::UniqueConnection);
connect(undoMgr, SIGNAL(CanRedoChanged(bool)), this, SLOT(SetRedoEnabled(bool)), Qt::UniqueConnection);
connect(undoButton_, SIGNAL(clicked()), undoMgr, SLOT(Undo()), Qt::UniqueConnection);
connect(redoButton_, SIGNAL(clicked()), undoMgr, SLOT(Redo()), Qt::UniqueConnection);
Scene* s = ShownScene().get();
connect(s, SIGNAL(EntityAcked(Entity *, entity_id_t)), SLOT(AckEntity(Entity *, entity_id_t)));
connect(s, SIGNAL(EntityCreated(Entity *, AttributeChange::Type)), SLOT(AddEntity(Entity *)));
connect(s, SIGNAL(EntityTemporaryStateToggled(Entity *, AttributeChange::Type)), SLOT(UpdateEntityTemporaryState(Entity *)));
connect(s, SIGNAL(EntityRemoved(Entity *, AttributeChange::Type)), SLOT(RemoveEntity(Entity *)));
connect(s, SIGNAL(ComponentAdded(Entity *, IComponent *, AttributeChange::Type)), SLOT(AddComponent(Entity *, IComponent *)));
connect(s, SIGNAL(ComponentRemoved(Entity *, IComponent *, AttributeChange::Type)), SLOT(RemoveComponent(Entity *, IComponent *)));
connect(s, SIGNAL(SceneCleared(Scene*)), SLOT(Clear()));
Populate();
}
}
示例14: DeleteSelectedEffects
void EffectLayer::DeleteSelectedEffects(UndoManager& undo_mgr)
{
std::unique_lock<std::recursive_mutex> locker(lock);
for (std::vector<Effect*>::iterator it = mEffects.begin(); it != mEffects.end(); it++) {
if ((*it)->GetSelected() != EFFECT_NOT_SELECTED) {
IncrementChangeCount((*it)->GetStartTimeMS(), (*it)->GetEndTimeMS());
undo_mgr.CaptureEffectToBeDeleted( mParentElement->GetName(), mIndex, (*it)->GetEffectName(),
(*it)->GetSettingsAsString(), (*it)->GetPaletteAsString(),
(*it)->GetStartTimeMS(), (*it)->GetEndTimeMS(),
(*it)->GetSelected(), (*it)->GetProtected() );
}
}
mEffects.erase(std::remove_if(mEffects.begin(), mEffects.end(),ShouldDeleteSelected),mEffects.end());
}
示例15: deleteDecalDatablock
void GuiDecalEditorCtrl::deleteDecalDatablock( String lookupName )
{
DecalData * datablock = dynamic_cast<DecalData*> ( Sim::findObject(lookupName.c_str()) );
if( !datablock )
return;
// Grab the mission editor undo manager.
UndoManager *undoMan = NULL;
if ( !Sim::findObject( "EUndoManager", undoMan ) )
{
Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" );
return;
}
// Create the UndoAction.
DBDeleteUndoAction *action = new DBDeleteUndoAction("Delete Decal Datablock");
action->mEditor = this;
action->mDatablockId = datablock->getId();
Vector<DecalInstance*> mDecalQueue;
Vector<DecalInstance *>::iterator iter;
mDecalQueue.clear();
const Vector<DecalSphere*> &grid = gDecalManager->getDecalDataFile()->getSphereList();
for ( U32 i = 0; i < grid.size(); i++ )
{
const DecalSphere *decalSphere = grid[i];
mDecalQueue.merge( decalSphere->mItems );
}
for ( iter = mDecalQueue.begin();iter != mDecalQueue.end();iter++ )
{
if( !(*iter) )
continue;
if( (*iter)->mDataBlock->lookupName.compare( lookupName ) == 0 )
{
if( (*iter)->mId != -1 )
{
//make sure to call onDeleteInstance as well
if ( isMethod( "onDeleteInstance" ) )
{
char buffer[512];
dSprintf(buffer, 512, "%i", (*iter)->mId);
Con::executef( this, "onDeleteInstance", String(buffer).c_str(), (*iter)->mDataBlock->lookupName.c_str() );
}
action->deleteDecal( *(*iter) );
if( mSELDecal == (*iter) )
mSELDecal = NULL;
if( mHLDecal == (*iter) )
mHLDecal = NULL;
}
gDecalManager->removeDecal( (*iter) );
}
}
undoMan->addAction( action );
mCurrentDecalData = NULL;
}