kwave  18.07.70
UndoDeleteTrack.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  UndoDeleteTrack.cpp - Undo action for deletion of tracks
3  -------------------
4  begin : Mon Jun 25 2001
5  copyright : (C) 2001 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <Thomas.Eschenbacher@gmx.de>
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "config.h"
20 
21 #include <new>
22 
23 #include <KLocalizedString>
24 
25 #include "libkwave/SignalManager.h"
28 
29 //***************************************************************************
31  unsigned int track)
32  :UndoAction(), m_signal(signal), m_track(track),
33  m_length(signal.length()), m_stripes(), m_uuid(signal.uuidOfTrack(track))
34 {
35 }
36 
37 //***************************************************************************
39 {
40 }
41 
42 //***************************************************************************
44 {
45  return i18n("Delete Track");
46 }
47 
48 //***************************************************************************
50 {
51  return sizeof(*this) + m_length * sizeof(sample_t);
52 }
53 
54 //***************************************************************************
56 {
57  return sizeof(Kwave::UndoInsertTrack);
58 }
59 
60 //***************************************************************************
62 {
63  if (!m_length) return true; // shortcut: this is an empty action
64 
65  // fork off a multi track stripe list for the selected range
66  QList<unsigned int> track_list;
67  track_list.append(m_track);
68  m_stripes = manager.stripes(track_list, 0, m_length - 1);
69  if (m_stripes.isEmpty())
70  return false; // retrieving the stripes failed
71 
72  return true;
73 }
74 
75 //***************************************************************************
77  bool with_redo)
78 {
79  Kwave::UndoAction *redo_action = Q_NULLPTR;
80 
81  // create a redo action
82  if (with_redo) {
83  redo_action =
84  new(std::nothrow) Kwave::UndoInsertTrack(m_signal, m_track);
85  Q_ASSERT(redo_action);
86  if (redo_action) redo_action->store(manager);
87  }
88 
89  // insert an empty track into the signal
91 
92  // merge the stripes back into the signal
93  QList<unsigned int> track_list;
94  track_list.append(m_track);
95  if (!manager.mergeStripes(m_stripes, track_list)) {
96  qWarning("UndoDeleteTrack::undo() FAILED [mergeStripes]");
97  delete redo_action;
98  return Q_NULLPTR;
99  }
100 
101  return redo_action;
102 }
103 
104 //***************************************************************************
105 //***************************************************************************
virtual qint64 redoSize() Q_DECL_OVERRIDE
virtual qint64 undoSize() Q_DECL_OVERRIDE
Kwave::Signal & m_signal
virtual bool store(SignalManager &manager) Q_DECL_OVERRIDE
sample_index_t m_length
virtual Kwave::UndoAction * undo(Kwave::SignalManager &manager, bool with_redo) Q_DECL_OVERRIDE
QList< Kwave::Stripe::List > m_stripes
Kwave::Track * insertTrack(unsigned int index, sample_index_t length, QUuid *uuid)
Definition: Signal.cpp:69
UndoDeleteTrack(Kwave::Signal &signal, unsigned int track)
virtual ~UndoDeleteTrack() Q_DECL_OVERRIDE
virtual QString description() Q_DECL_OVERRIDE
virtual bool store(Kwave::SignalManager &manager)=0
QList< Kwave::Stripe::List > stripes(const QList< unsigned int > &track_list, sample_index_t left=0, sample_index_t right=SAMPLE_INDEX_MAX)
qint32 sample_t
Definition: Sample.h:37
bool mergeStripes(const QList< Kwave::Stripe::List > &stripes, const QList< unsigned int > &track_list)