kwave  18.07.70
UndoTransaction.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  UndoTransaction.cpp - groups multiple UndoAction objects together
3  -------------------
4  begin : Fri May 25 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <QListIterator>
21 
22 #include "libkwave/String.h"
25 
26 //***************************************************************************
28  :QList<UndoAction *>(), m_description(name), m_aborted(false)
29 {
30 }
31 
32 //***************************************************************************
34 {
35  while (!isEmpty()) {
36  UndoAction *action = takeLast();
37  if (action) delete action;
38  }
39 }
40 
41 //***************************************************************************
43 {
44  qint64 s = 0;
45  QListIterator<UndoAction *> it(*this);
46  while (it.hasNext()) {
47  UndoAction *undo = it.next();
48  if (undo) s += undo->undoSize();
49  }
50  return s;
51 }
52 
53 //***************************************************************************
55 {
56  qint64 s = 0;
57  QListIterator<UndoAction *> it(*this);
58  while (it.hasNext()) {
59  UndoAction *undo = it.next();
60  if (undo) s += undo->redoSize();
61  }
62  return s;
63 }
64 
65 //***************************************************************************
67 {
68  // if description exists, return it
69  if (m_description.length()) return m_description;
70 
71  QString str;
72  QListIterator<UndoAction *> it(*this);
73  while (it.hasNext()) {
74  UndoAction *undo = it.next();
75  if (!undo) continue;
76  QString d = undo->description();
77 
78  // skip duplicates
79  if (str.contains(_(", ") + d) || (str == d)) continue;
80 
81  // append others
82  if (str.length()) str += _(", ");
83  str += d;
84  }
85  return str;
86 }
87 
88 //***************************************************************************
90 {
91  if (isEmpty()) return false;
92  QListIterator<UndoAction *> it(*this);
93  while (it.hasNext()) {
94  UndoAction *action = it.next();
95  if (!action) continue;
96  if (action->containsModification()) return true;
97  }
98  return false;
99 }
100 
101 //***************************************************************************
103 {
104  m_aborted = true;
105 }
106 
107 //***************************************************************************
108 void Kwave::UndoTransaction::dump(const QString &indent)
109 {
110  qDebug("%s [%s]", DBG(indent), DBG(description()));
111  if (isEmpty()) return;
112 
113  QListIterator<UndoAction *> it(*this);
114  it.toBack();
115  while (it.hasPrevious()) {
116  UndoAction *action = it.previous();
117  Q_ASSERT(action);
118  if (!action) continue;
119  action->dump(_(" "));
120  }
121 }
122 
123 //***************************************************************************
124 //***************************************************************************
UndoTransaction(const QString &name)
bool containsModification() const
const char name[16]
Definition: memcpy.c:510
virtual void dump(const QString &indent)
virtual void dump(const QString &indent)
Definition: UndoAction.h:105
virtual qint64 redoSize()=0
virtual QString description()=0
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
virtual bool containsModification() const
Definition: UndoAction.h:102
virtual qint64 undoSize()=0