chalk

kis_transaction.cpp
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include "kis_types.h"
19#include "kis_global.h"
20#include "kis_tile.h"
21#include "kis_tileddatamanager.h"
22#include "kis_image.h"
23#include "kis_transaction.h"
24#include "kis_memento.h"
25#include "kis_paint_device.h"
26#include "kis_layer.h"
27
28class KisTransactionPrivate {
29public:
30 TQString m_name;
31 KisPaintDeviceSP m_device;
32 KisMementoSP m_memento;
33
34};
35
36KisTransaction::KisTransaction(const TQString& name, KisPaintDeviceSP device)
37{
38 m_private = new KisTransactionPrivate;
39
40 m_private->m_name = name;
41 m_private->m_device = device;
42 m_private->m_memento = device->getMemento();
43}
44
45KisTransaction::~KisTransaction()
46{
47 if (m_private->m_memento) {
48 // For debugging purposes
49 m_private->m_memento->setInvalid();
50 }
51 delete m_private;
52}
53
54void KisTransaction::execute()
55{
56 Q_ASSERT(m_private->m_memento != 0);
57
58 m_private->m_device->rollforward(m_private->m_memento);
59
60 TQRect rc;
61 TQ_INT32 x, y, width, height;
62 m_private->m_memento->extent(x,y,width,height);
63 rc.setRect(x + m_private->m_device->getX(), y + m_private->m_device->getY(), width, height);
64
65 KisLayerSP l = m_private->m_device->parentLayer();
66 if (l) l->setDirty(rc);
67}
68
69void KisTransaction::unexecute()
70{
71 Q_ASSERT(m_private->m_memento != 0);
72 m_private->m_device->rollback(m_private->m_memento);
73
74 TQRect rc;
75 TQ_INT32 x, y, width, height;
76 m_private->m_memento->extent(x,y,width,height);
77 rc.setRect(x + m_private->m_device->getX(), y + m_private->m_device->getY(), width, height);
78
79 KisLayerSP l = m_private->m_device->parentLayer();
80 if (l) l->setDirty(rc);
81
82}
83
84void KisTransaction::unexecuteNoUpdate()
85{
86 Q_ASSERT(m_private->m_memento != 0);
87
88 m_private->m_device->rollback(m_private->m_memento);
89}
90
91TQString KisTransaction::name() const
92{
93 return m_private->m_name;
94}