summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmdatachangecommand.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kpovmodeler/pmdatachangecommand.cpp
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpovmodeler/pmdatachangecommand.cpp')
-rw-r--r--kpovmodeler/pmdatachangecommand.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/kpovmodeler/pmdatachangecommand.cpp b/kpovmodeler/pmdatachangecommand.cpp
new file mode 100644
index 00000000..0793986e
--- /dev/null
+++ b/kpovmodeler/pmdatachangecommand.cpp
@@ -0,0 +1,111 @@
+/*
+**************************************************************************
+ description
+ --------------------
+ copyright : (C) 2000-2001 by Andreas Zehender
+ email : zehender@kde.org
+**************************************************************************
+
+**************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+**************************************************************************/
+
+
+#include "pmdatachangecommand.h"
+#include "pmcommandmanager.h"
+#include "pmmemento.h"
+#include "pmobject.h"
+#include <klocale.h>
+
+PMDataChangeCommand::PMDataChangeCommand( PMMemento* memento )
+ : PMCommand( )
+{
+ QString text = memento->originator( )->name( );
+ if( text.isEmpty( ) )
+ text = memento->originator( )->description( );
+ setText( i18n( "Change %1" ).arg( text ) );
+
+ // the data is already changed when the command is created
+ m_executed = true;
+ m_unexecuted = false;
+ m_pOldState = memento;
+ m_pNewState = 0;
+}
+
+PMDataChangeCommand::~PMDataChangeCommand( )
+{
+ if( m_pOldState )
+ delete m_pOldState;
+ if( m_pNewState )
+ delete m_pNewState;
+}
+
+void PMDataChangeCommand::execute( PMCommandManager* theManager )
+{
+ PMObject* obj = m_pOldState->originator( );
+ if( !m_executed )
+ {
+ // if the command is not executed
+ // restore the memento
+ if( m_pNewState )
+ {
+ if( m_pNewState->containsChanges( ) )
+ {
+ obj->restoreMemento( m_pNewState );
+
+ if( m_pOldState->idChanged( ) )
+ theManager->cmdIDChanged( obj, m_pOldState->oldID( ) );
+ signalChanges( theManager, m_pNewState );
+ }
+ }
+ m_executed = true;
+ }
+ else if( !m_unexecuted )
+ {
+ // the data can be changed multiple times
+ // if the command was never unexecuted, emit the signal
+ // ( the data was already changed, so this is not necessary here )
+ if( m_pOldState->idChanged( ) )
+ theManager->cmdIDChanged( obj, m_pOldState->oldID( ) );
+ signalChanges( theManager, m_pOldState );
+ }
+}
+
+void PMDataChangeCommand::undo( PMCommandManager* theManager )
+{
+ if( m_executed )
+ {
+ if( m_pOldState->containsChanges( ) )
+ {
+ PMObject* obj = m_pOldState->originator( );
+ if( !m_pNewState )
+ obj->createMemento( );
+
+ obj->restoreMemento( m_pOldState );
+
+ if( !m_pNewState )
+ m_pNewState = obj->takeMemento( );
+
+ if( m_pNewState->idChanged( ) )
+ theManager->cmdIDChanged( obj, m_pNewState->oldID( ) );
+ signalChanges( theManager, m_pOldState );
+ }
+ m_executed = false;
+ m_unexecuted = true;
+ }
+}
+
+void PMDataChangeCommand::signalChanges( PMCommandManager* theManager,
+ PMMemento* memento )
+{
+ PMObjectChangeListIterator it( memento->changedObjects( ) );
+
+ for( ; it.current( ); ++it )
+ theManager->cmdObjectChanged( it.current( )->object( ),
+ it.current( )->mode( ) );
+}