1 /***************************************************************************
2     UndoInsertTrack.cpp  -  Undo action for insertion of tracks
3 			     -------------------
4     begin                : Sun Jun 24 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 <KLocalizedString>
22 
23 #include <new>
24 
25 #include "libkwave/SignalManager.h"
26 #include "libkwave/undo/UndoDeleteTrack.h"
27 #include "libkwave/undo/UndoInsertTrack.h"
28 
29 //***************************************************************************
UndoInsertTrack(Kwave::Signal & signal,unsigned int track)30 Kwave::UndoInsertTrack::UndoInsertTrack(Kwave::Signal &signal,
31                                         unsigned int track)
32     :UndoAction(), m_signal(signal), m_track(track)
33 {
34 }
35 
36 //***************************************************************************
~UndoInsertTrack()37 Kwave::UndoInsertTrack::~UndoInsertTrack()
38 {
39 }
40 
41 //***************************************************************************
description()42 QString Kwave::UndoInsertTrack::description()
43 {
44     return i18n("Insert Track");
45 }
46 
47 //***************************************************************************
undoSize()48 qint64 Kwave::UndoInsertTrack::undoSize()
49 {
50     return sizeof(*this);
51 }
52 
53 //***************************************************************************
redoSize()54 qint64 Kwave::UndoInsertTrack::redoSize()
55 {
56     return (m_signal.length() * sizeof(sample_t)) + sizeof(UndoDeleteTrack);
57 }
58 
59 //***************************************************************************
store(Kwave::SignalManager &)60 bool Kwave::UndoInsertTrack::store(Kwave::SignalManager &)
61 {
62     // nothing to do, the track number has already
63     // been stored in the constructor
64     return true;
65 }
66 
67 //***************************************************************************
undo(Kwave::SignalManager & manager,bool with_redo)68 Kwave::UndoAction *Kwave::UndoInsertTrack::undo(
69     Kwave::SignalManager &manager, bool with_redo)
70 {
71     Kwave::UndoAction *redo = Q_NULLPTR;
72 
73     // store data for redo
74     if (with_redo) {
75 	redo = new(std::nothrow) Kwave::UndoDeleteTrack(m_signal, m_track);
76 	Q_ASSERT(redo);
77 	if (redo) redo->store(manager);
78     }
79 
80     // remove the track from the signal
81     m_signal.deleteTrack(m_track);
82 
83     return redo;
84 }
85 
86 //***************************************************************************
87 //***************************************************************************
88