krita
kis_transaction.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "kis_types.h"
00019 #include "kis_global.h"
00020 #include "kis_tile.h"
00021 #include "kis_tileddatamanager.h"
00022 #include "kis_image.h"
00023 #include "kis_transaction.h"
00024 #include "kis_memento.h"
00025 #include "kis_paint_device.h"
00026 #include "kis_layer.h"
00027
00028 class KisTransactionPrivate {
00029 public:
00030 QString m_name;
00031 KisPaintDeviceSP m_device;
00032 KisMementoSP m_memento;
00033
00034 };
00035
00036 KisTransaction::KisTransaction(const QString& name, KisPaintDeviceSP device)
00037 {
00038 m_private = new KisTransactionPrivate;
00039
00040 m_private->m_name = name;
00041 m_private->m_device = device;
00042 m_private->m_memento = device->getMemento();
00043 }
00044
00045 KisTransaction::~KisTransaction()
00046 {
00047 if (m_private->m_memento) {
00048
00049 m_private->m_memento->setInvalid();
00050 }
00051 delete m_private;
00052 }
00053
00054 void KisTransaction::execute()
00055 {
00056 Q_ASSERT(m_private->m_memento != 0);
00057
00058 m_private->m_device->rollforward(m_private->m_memento);
00059
00060 QRect rc;
00061 Q_INT32 x, y, width, height;
00062 m_private->m_memento->extent(x,y,width,height);
00063 rc.setRect(x + m_private->m_device->getX(), y + m_private->m_device->getY(), width, height);
00064
00065 KisLayerSP l = m_private->m_device->parentLayer();
00066 if (l) l->setDirty(rc);
00067 }
00068
00069 void KisTransaction::unexecute()
00070 {
00071 Q_ASSERT(m_private->m_memento != 0);
00072 m_private->m_device->rollback(m_private->m_memento);
00073
00074 QRect rc;
00075 Q_INT32 x, y, width, height;
00076 m_private->m_memento->extent(x,y,width,height);
00077 rc.setRect(x + m_private->m_device->getX(), y + m_private->m_device->getY(), width, height);
00078
00079 KisLayerSP l = m_private->m_device->parentLayer();
00080 if (l) l->setDirty(rc);
00081
00082 }
00083
00084 void KisTransaction::unexecuteNoUpdate()
00085 {
00086 Q_ASSERT(m_private->m_memento != 0);
00087
00088 m_private->m_device->rollback(m_private->m_memento);
00089 }
00090
00091 QString KisTransaction::name() const
00092 {
00093 return m_private->m_name;
00094 }
|