kwave  18.07.70
Kwave::UndoModifyAction Class Reference

#include <UndoModifyAction.h>

Inheritance diagram for Kwave::UndoModifyAction:
Inheritance graph
Collaboration diagram for Kwave::UndoModifyAction:
Collaboration graph

Public Member Functions

 UndoModifyAction (unsigned int track, sample_index_t offset, sample_index_t length)
 
virtual ~UndoModifyAction () Q_DECL_OVERRIDE
 
virtual QString description () Q_DECL_OVERRIDE
 
virtual qint64 undoSize () Q_DECL_OVERRIDE
 
virtual qint64 redoSize () Q_DECL_OVERRIDE
 
virtual bool store (Kwave::SignalManager &manager) Q_DECL_OVERRIDE
 
virtual UndoActionundo (Kwave::SignalManager &manager, bool with_redo) Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::UndoAction
virtual ~UndoAction ()
 
virtual bool containsModification () const
 
virtual void dump (const QString &indent)
 

Protected Attributes

unsigned int m_track
 
sample_index_t m_offset
 
sample_index_t m_length
 
QList< Kwave::Stripe::Listm_stripes
 

Detailed Description

Definition at line 33 of file UndoModifyAction.h.

Constructor & Destructor Documentation

◆ UndoModifyAction()

Kwave::UndoModifyAction::UndoModifyAction ( unsigned int  track,
sample_index_t  offset,
sample_index_t  length 
)

Constructor.

Parameters
trackindex of the track
offsetindex of the first modified sample
lengthnumber of samples

Definition at line 29 of file UndoModifyAction.cpp.

32  :UndoAction(), m_track(track), m_offset(offset), m_length(length),
33  m_stripes()
34 {
35 }
QList< Kwave::Stripe::List > m_stripes

◆ ~UndoModifyAction()

Kwave::UndoModifyAction::~UndoModifyAction ( )
virtual

Destructor

Definition at line 38 of file UndoModifyAction.cpp.

39 {
40 }

Member Function Documentation

◆ description()

QString Kwave::UndoModifyAction::description ( )
virtual
See also
UndoAction::description()

Implements Kwave::UndoAction.

Definition at line 43 of file UndoModifyAction.cpp.

44 {
45  return i18n("Modify Samples");
46 }

◆ redoSize()

virtual qint64 Kwave::UndoModifyAction::redoSize ( )
inlinevirtual
See also
UndoAction::redoSize()

Implements Kwave::UndoAction.

Definition at line 56 of file UndoModifyAction.h.

References store(), undo(), and undoSize().

56 { return undoSize(); }
virtual qint64 undoSize() Q_DECL_OVERRIDE
Here is the call graph for this function:

◆ store()

bool Kwave::UndoModifyAction::store ( Kwave::SignalManager manager)
virtual
See also
UndoAction::store()

Implements Kwave::UndoAction.

Definition at line 55 of file UndoModifyAction.cpp.

References m_length, m_offset, m_stripes, m_track, and Kwave::SignalManager::stripes().

Referenced by redoSize().

56 {
57  if (!m_length) return true; // shortcut: this is an empty action
58 
59  // fork off a multi track stripe list for the selected range
60  QList<unsigned int> track_list;
61  track_list.append(m_track);
62  const sample_index_t left = m_offset;
63  const sample_index_t right = m_offset + m_length - 1;
64  m_stripes = manager.stripes(track_list, left, right);
65  if (m_stripes.isEmpty())
66  return false; // retrieving the stripes failed
67 
68  return true;
69 }
quint64 sample_index_t
Definition: Sample.h:28
QList< Kwave::Stripe::List > m_stripes
QList< Kwave::Stripe::List > stripes(const QList< unsigned int > &track_list, sample_index_t left=0, sample_index_t right=SAMPLE_INDEX_MAX)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ undo()

Kwave::UndoAction * Kwave::UndoModifyAction::undo ( Kwave::SignalManager manager,
bool  with_redo 
)
virtual

Exchange samples from the current signal and the internal undo buffer. So this instance will be re-used for redo and so does not require any extra memory for redo.

See also
UndoAction::undo()

Implements Kwave::UndoAction.

Definition at line 72 of file UndoModifyAction.cpp.

References m_length, m_offset, m_stripes, m_track, Kwave::SignalManager::mergeStripes(), and Kwave::SignalManager::stripes().

Referenced by redoSize().

74 {
75  const sample_index_t left = m_offset;
76  const sample_index_t right = m_offset + m_length - 1;
77  QList<Kwave::Stripe::List> redo_data;
78  QList<unsigned int> track_list;
79  track_list.append(m_track);
80  bool ok = true;
81 
82  if (m_length && with_redo) {
83  // save the current stripes for later redo
84  redo_data = manager.stripes(track_list, left, right);
85  ok &= !redo_data.isEmpty();
86  }
87 
88  // merge the stripes back into the signal
89  if (m_length && ok) {
90  if (!manager.mergeStripes(m_stripes, track_list)) {
91  qWarning("UndoModifyAction::undo() FAILED [mergeStripes]");
92  return Q_NULLPTR;
93  }
94  }
95 
96  if (ok && with_redo) {
97  // now store the redo data in this object
98  m_stripes = redo_data;
99  }
100 
101  return (with_redo && ok) ? this : Q_NULLPTR;
102 }
quint64 sample_index_t
Definition: Sample.h:28
QList< Kwave::Stripe::List > m_stripes
QList< Kwave::Stripe::List > stripes(const QList< unsigned int > &track_list, sample_index_t left=0, sample_index_t right=SAMPLE_INDEX_MAX)
bool mergeStripes(const QList< Kwave::Stripe::List > &stripes, const QList< unsigned int > &track_list)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ undoSize()

qint64 Kwave::UndoModifyAction::undoSize ( )
virtual
See also
UndoAction::undoSize()

Implements Kwave::UndoAction.

Definition at line 49 of file UndoModifyAction.cpp.

References m_length.

Referenced by redoSize().

50 {
51  return sizeof(*this) + (m_length * sizeof(sample_t));
52 }
qint32 sample_t
Definition: Sample.h:37
Here is the caller graph for this function:

Member Data Documentation

◆ m_length

sample_index_t Kwave::UndoModifyAction::m_length
protected

number of samples

Definition at line 81 of file UndoModifyAction.h.

Referenced by store(), undo(), and undoSize().

◆ m_offset

sample_index_t Kwave::UndoModifyAction::m_offset
protected

first sample

Definition at line 78 of file UndoModifyAction.h.

Referenced by store(), and undo().

◆ m_stripes

QList<Kwave::Stripe::List> Kwave::UndoModifyAction::m_stripes
protected

storage for all deleted stripes

Definition at line 84 of file UndoModifyAction.h.

Referenced by store(), and undo().

◆ m_track

unsigned int Kwave::UndoModifyAction::m_track
protected

index of the modified track

Definition at line 75 of file UndoModifyAction.h.

Referenced by store(), and undo().


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