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
|
/***************************************************************************
UndoTransaction.cpp - groups multiple UndoAction objects together
-------------------
begin : Fri May 25 2001
copyright : (C) 2001 by Thomas Eschenbacher
email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
***************************************************************************/
/***************************************************************************
* *
* 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 "config.h"
#include <QListIterator>
#include "libkwave/String.h"
#include "libkwave/undo/UndoAction.h"
#include "libkwave/undo/UndoTransaction.h"
//***************************************************************************
Kwave::UndoTransaction::UndoTransaction(const QString &name)
:QList<UndoAction *>(), m_description(name), m_aborted(false)
{
}
//***************************************************************************
Kwave::UndoTransaction::~UndoTransaction()
{
while (!isEmpty()) {
delete takeLast();
}
}
//***************************************************************************
qint64 Kwave::UndoTransaction::undoSize()
{
qint64 s = 0;
QListIterator<UndoAction *> it(*this);
while (it.hasNext()) {
UndoAction *undo = it.next();
if (undo) s += undo->undoSize();
}
return s;
}
//***************************************************************************
qint64 Kwave::UndoTransaction::redoSize()
{
qint64 s = 0;
QListIterator<UndoAction *> it(*this);
while (it.hasNext()) {
UndoAction *undo = it.next();
if (undo) s += undo->redoSize();
}
return s;
}
//***************************************************************************
QString Kwave::UndoTransaction::description()
{
// if description exists, return it
if (m_description.length()) return m_description;
QString str;
QListIterator<UndoAction *> it(*this);
while (it.hasNext()) {
UndoAction *undo = it.next();
if (!undo) continue;
QString d = undo->description();
// skip duplicates
if (str.contains(_(", ") + d) || (str == d)) continue;
// append others
if (str.length()) str += _(", ");
str += d;
}
return str;
}
//***************************************************************************
bool Kwave::UndoTransaction::containsModification() const
{
if (isEmpty()) return false;
QListIterator<UndoAction *> it(*this);
while (it.hasNext()) {
UndoAction *action = it.next();
if (!action) continue;
if (action->containsModification()) return true;
}
return false;
}
//***************************************************************************
void Kwave::UndoTransaction::abort()
{
m_aborted = true;
}
//***************************************************************************
void Kwave::UndoTransaction::dump(const QString &indent)
{
qDebug("%s [%s]", DBG(indent), DBG(description()));
if (isEmpty()) return;
QListIterator<UndoAction *> it(*this);
it.toBack();
while (it.hasPrevious()) {
UndoAction *action = it.previous();
Q_ASSERT(action);
if (!action) continue;
action->dump(_(" "));
}
}
//***************************************************************************
//***************************************************************************
|