kwave  18.07.70
Kwave::UndoTransaction Class Reference

#include <UndoTransaction.h>

Inheritance diagram for Kwave::UndoTransaction:
Inheritance graph
Collaboration diagram for Kwave::UndoTransaction:
Collaboration graph

Public Member Functions

 UndoTransaction (const QString &name)
 
virtual ~UndoTransaction ()
 
qint64 undoSize ()
 
qint64 redoSize ()
 
QString description ()
 
bool containsModification () const
 
void abort ()
 
bool isAborted () const
 
virtual void dump (const QString &indent)
 

Private Attributes

QString m_description
 
bool m_aborted
 

Detailed Description

Groups multiple UndoAction objects together to one transaction. As most user actions consist of a number of small actions that belong together and don't make sense or leave an inconsistent state if separated, they get grouped together to one transaction.

Definition at line 37 of file UndoTransaction.h.

Constructor & Destructor Documentation

◆ UndoTransaction()

Kwave::UndoTransaction::UndoTransaction ( const QString &  name)
explicit

Constructor.

Parameters
namedescription of the undo transaction as a user-readable localized string.

Definition at line 27 of file UndoTransaction.cpp.

28  :QList<UndoAction *>(), m_description(name), m_aborted(false)
29 {
30 }
const char name[16]
Definition: memcpy.c:510

◆ ~UndoTransaction()

Kwave::UndoTransaction::~UndoTransaction ( )
virtual

Destructor

Definition at line 33 of file UndoTransaction.cpp.

34 {
35  while (!isEmpty()) {
36  UndoAction *action = takeLast();
37  if (action) delete action;
38  }
39 }

Member Function Documentation

◆ abort()

void Kwave::UndoTransaction::abort ( )

aborts the undo transaction

Definition at line 102 of file UndoTransaction.cpp.

References m_aborted.

Referenced by Kwave::SignalManager::abortUndoTransaction().

103 {
104  m_aborted = true;
105 }
Here is the caller graph for this function:

◆ containsModification()

bool Kwave::UndoTransaction::containsModification ( ) const

Loops over all undo actions to determine whether there is at least one undo action that contains a modification of the signal.

See also
UndoAction::containsModification()
Returns
true if a modification is contained, false if not.

Definition at line 89 of file UndoTransaction.cpp.

References Kwave::UndoAction::containsModification().

Referenced by Kwave::SignalManager::redo(), and Kwave::SignalManager::undo().

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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ description()

QString Kwave::UndoTransaction::description ( )

Returns the description of the undo transaction as a user-readable localized string. If no name has been passed at initialization time, a list of all action's descriptions will be generated.

Todo:
avoid duplicates, give a useful name/description

Definition at line 66 of file UndoTransaction.cpp.

References _, Kwave::UndoAction::description(), and m_description.

Referenced by dump(), Kwave::SignalManager::emitUndoRedoInfo(), Kwave::SignalManager::redo(), and Kwave::SignalManager::undo().

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 }
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump()

void Kwave::UndoTransaction::dump ( const QString &  indent)
virtual

dump, for debugging purposes

Definition at line 108 of file UndoTransaction.cpp.

References _, DBG, description(), and Kwave::UndoAction::dump().

Referenced by isAborted().

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 }
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isAborted()

bool Kwave::UndoTransaction::isAborted ( ) const
inline

Returns true if the undo transaction has been aborted

Definition at line 82 of file UndoTransaction.h.

References dump(), and m_aborted.

Referenced by Kwave::SignalManager::closeUndoTransaction(), Kwave::SignalManager::continueWithoutUndo(), and Kwave::SignalManager::registerUndoAction().

82 { return m_aborted; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ redoSize()

qint64 Kwave::UndoTransaction::redoSize ( )

Returns the additional memory needed for storing redo data

Definition at line 54 of file UndoTransaction.cpp.

References Kwave::UndoAction::redoSize().

Referenced by Kwave::SignalManager::redo(), and Kwave::SignalManager::undo().

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 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ undoSize()

qint64 Kwave::UndoTransaction::undoSize ( )

Returns the size in bytes summed up over all undo actions

Definition at line 42 of file UndoTransaction.cpp.

References Kwave::UndoAction::undoSize().

Referenced by Kwave::SignalManager::freeUndoMemory(), Kwave::SignalManager::redo(), Kwave::SignalManager::undo(), and Kwave::SignalManager::usedUndoRedoMemory().

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 }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_aborted

bool Kwave::UndoTransaction::m_aborted
private

if true, the transaction has been aborted

Definition at line 93 of file UndoTransaction.h.

Referenced by abort(), and isAborted().

◆ m_description

QString Kwave::UndoTransaction::m_description
private

name of the action

Definition at line 90 of file UndoTransaction.h.

Referenced by description().


The documentation for this class was generated from the following files: