29,64 → 29,64 |
|
UndoState::UndoState(const QString& name, const QString& description, QPixmap* pixmap) : |
transactionCode(0), |
actionName_(name), |
actionDescription_(description), |
actionPixmap_(pixmap), |
undoObject_(nullptr) |
m_actionName(name), |
m_actionDescription(description), |
m_actionPixmap(pixmap), |
m_undoObject(nullptr) |
{ |
|
} |
|
QString UndoState::getName() |
const QString& UndoState::getName() const |
{ |
return actionName_; |
return m_actionName; |
} |
|
void UndoState::setName(const QString &newName) |
{ |
actionName_ = newName; |
m_actionName = newName; |
} |
|
QString UndoState::getDescription() |
const QString& UndoState::getDescription() const |
{ |
return actionDescription_; |
return m_actionDescription; |
} |
|
void UndoState::setDescription(const QString &newDescription) |
{ |
actionDescription_ = newDescription; |
m_actionDescription = newDescription; |
} |
|
QPixmap* UndoState::getPixmap() |
{ |
return actionPixmap_; |
return m_actionPixmap; |
} |
|
void UndoState::setPixmap(QPixmap *pixmap) |
{ |
actionPixmap_ = pixmap; |
m_actionPixmap = pixmap; |
} |
|
void UndoState::undo() |
{ |
if (undoObject_) // if !undoObject_ there's an error, hmmm |
undoObject_->restore(this, true); |
if (m_undoObject) // if !m_undoObject there's an error, hmmm |
m_undoObject->restore(this, true); |
} |
|
void UndoState::redo() |
{ |
if (undoObject_) |
undoObject_->restore(this, false); |
if (m_undoObject) |
m_undoObject->restore(this, false); |
} |
|
void UndoState::setUndoObject(UndoObject *object) |
{ |
undoObject_ = object->undoObjectPtr(); |
m_undoObject = object->undoObjectPtr(); |
} |
|
UndoObject* UndoState::undoObject() |
{ |
return undoObject_; |
return m_undoObject; |
} |
|
UndoState::~UndoState() |
207,28 → 207,28 |
|
TransactionState::TransactionState() : UndoState("") |
{ |
size_ = 0; |
m_size = 0; |
} |
|
UndoState* TransactionState::at(int index) const |
{ |
if (index >= 0 && static_cast<uint>(index) < sizet()) |
return states_[index]; |
return m_states[index]; |
return nullptr; |
} |
|
UndoState* TransactionState::last() const |
{ |
if (!states_.empty()) |
return states_.at(size_ - 1); |
if (!m_states.empty()) |
return m_states.at(m_size - 1); |
return nullptr; |
} |
|
bool TransactionState::contains(int uid) const |
{ |
for (int i = 0; i < states_.size(); ++i) |
for (size_t i = 0; i < m_states.size(); ++i) |
{ |
UndoObject* undoObject = states_[i]->undoObject(); |
UndoObject* undoObject = m_states[i]->undoObject(); |
if (undoObject && undoObject->getUId() == static_cast<uint>(uid)) |
return true; |
} |
237,9 → 237,9 |
|
bool TransactionState::containsOnly(int uid) const |
{ |
for (int i = 0; i < states_.size(); ++i) |
for (size_t i = 0; i < m_states.size(); ++i) |
{ |
UndoObject* undoObject = states_[i]->undoObject(); |
UndoObject* undoObject = m_states[i]->undoObject(); |
if (undoObject && undoObject->getUId() != static_cast<uint>(uid)) |
return false; |
} |
251,34 → 251,34 |
if (target && state) |
{ |
state->setUndoObject(target); |
states_.push_back(state); |
++size_; |
m_states.push_back(state); |
++m_size; |
} |
} |
|
uint TransactionState::sizet() const |
{ |
return size_; |
return m_size; |
} |
|
void TransactionState::useActionName() |
{ |
if (size_ > 0) |
setName(states_[size_ - 1]->getName()); |
if (m_size > 0) |
setName(m_states[m_size - 1]->getName()); |
} |
|
UndoObject* TransactionState::replace(ulong uid, UndoObject *newUndoObject) |
{ |
UndoObject *tmp = nullptr; |
for (int i = 0; i < states_.size(); ++i) |
for (size_t i = 0; i < m_states.size(); ++i) |
{ |
TransactionState *ts = dynamic_cast<TransactionState*>(states_[i]); |
TransactionState *ts = dynamic_cast<TransactionState*>(m_states[i]); |
if (ts) // are we having a transaction_inside a transaction |
ts->replace(uid, newUndoObject); |
else if (states_[i]->undoObject() && states_[i]->undoObject()->getUId() == uid) |
else if (m_states[i]->undoObject() && m_states[i]->undoObject()->getUId() == uid) |
{ |
tmp = states_[i]->undoObject(); |
states_[i]->setUndoObject(newUndoObject); |
tmp = m_states[i]->undoObject(); |
m_states[i]->setUndoObject(newUndoObject); |
} |
} |
return tmp; |
328,12 → 328,12 |
|
TransactionState::~TransactionState() |
{ |
for (int i = 0; i < states_.size(); ++i) |
for (size_t i = 0; i < m_states.size(); ++i) |
{ |
if (states_[i]) |
if (m_states[i]) |
{ |
delete states_[i]; |
states_[i] = nullptr; |
delete m_states[i]; |
m_states[i] = nullptr; |
} |
} |
} |