1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
* Copyright (C) 2005 by Riku Leino *
* riku@scribus.info *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "undostate.h"
#include "undoobject.h"
UndoState::UndoState(const QString& name, const QString& description, QPixmap* pixmap) :
transactionCode(0),
actionName_(name),
actionDescription_(description),
actionPixmap_(pixmap),
undoObject_(0)
{
}
QString UndoState::getName()
{
return actionName_;
}
void UndoState::setName(const QString &newName)
{
actionName_ = newName;
}
QString UndoState::getDescription()
{
return actionDescription_;
}
void UndoState::setDescription(const QString &newDescription)
{
actionDescription_ = newDescription;
}
QPixmap* UndoState::getPixmap()
{
return actionPixmap_;
}
void UndoState::setPixmap(QPixmap *pixmap)
{
actionPixmap_ = pixmap;
}
void UndoState::undo()
{
if (undoObject_) // if !undoObject_ there's an error, hmmm
undoObject_->restore(this, true);
}
void UndoState::redo()
{
if (undoObject_)
undoObject_->restore(this, false);
}
void UndoState::setUndoObject(UndoObject *object)
{
undoObject_ = object->undoObjectPtr();
}
UndoObject* UndoState::undoObject()
{
return undoObject_;
}
UndoState::~UndoState()
{
}
/*** SimpleState **************************************************************/
SimpleState::SimpleState(const QString& name, const QString& description, QPixmap* pixmap)
: UndoState(name, description, pixmap)
{
}
bool SimpleState::contains(const QString& key)
{
return values_.contains(key);
}
QVariant SimpleState::variant(const QString& key, const QVariant& def)
{
QMap<QString, QVariant>::const_iterator it = values_.find(key);
if (it != values_.end())
return it.value();
values_[key] = def;
return def;
}
QString SimpleState::get(const QString& key, const QString& def)
{
QMap<QString, QVariant>::const_iterator it = values_.find(key);
if (it != values_.end())
return it.value().toString();
values_[key] = def;
return def;
}
int SimpleState::getInt(const QString& key, int def)
{
bool ok = false;
QVariant retVar = variant(key, QVariant(def));
int ret = retVar.toInt(&ok);
if (!ok)
ret = def;
return ret;
}
uint SimpleState::getUInt(const QString& key, uint def)
{
bool ok = false;
QVariant retVar = variant(key, QVariant(def));
uint ret = retVar.toUInt(&ok);
if (!ok)
ret = def;
return ret;
}
double SimpleState::getDouble(const QString& key, double def)
{
bool ok = false;
QVariant retVar = variant(key, QVariant(def));
double ret = retVar.toDouble(&ok);
if (!ok)
ret = def;
return ret;
}
bool SimpleState::getBool(const QString& key, bool def)
{
bool ok = false;
QVariant retVar = variant(key, QVariant(def));
int ret = retVar.toInt(&ok);
if (!ok)
ret = def;
return ret;
}
void SimpleState::set(const QString& key, const QString& value)
{
values_[key] = QVariant(value);
}
void SimpleState::set(const QString& key, int value)
{
values_[key] = QVariant(value);
}
void SimpleState::set(const QString& key, uint value)
{
values_[key] = QVariant(value);
}
void SimpleState::set(const QString& key, double value)
{
values_[key] = QVariant(value);
}
void SimpleState::set(const QString& key, bool value)
{
values_[key] = QVariant(value);
}
SimpleState::~SimpleState()
{
}
|