1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/***************************************************************************
UndoDeleteAction.cpp - UndoAction for deletion of a range of samples
-------------------
begin : Jun 08 2001
copyright : (C) 2001 by Thomas Eschenbacher
email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "config.h"
#include <new>
#include <KLocalizedString>
#include "libkwave/MultiTrackReader.h"
#include "libkwave/SignalManager.h"
#include "libkwave/undo/UndoAction.h"
#include "libkwave/undo/UndoDeleteAction.h"
#include "libkwave/undo/UndoDeleteMetaDataAction.h"
#include "libkwave/undo/UndoInsertAction.h"
//***************************************************************************
Kwave::UndoDeleteAction::UndoDeleteAction(
QWidget *parent_widget,
const QVector<unsigned int> &track_list,
sample_index_t offset,
sample_index_t length
)
:Kwave::UndoAction(),
m_parent_widget(parent_widget),
m_stripes(), m_meta_data(),
m_track_list(track_list),
m_offset(offset), m_length(length),
m_undo_size(sizeof(*this))
{
// undo size needed for samples
m_undo_size += m_length * sizeof(sample_t) * m_track_list.count();
}
//***************************************************************************
Kwave::UndoDeleteAction::~UndoDeleteAction()
{
m_stripes.clear();
}
//***************************************************************************
QString Kwave::UndoDeleteAction::description()
{
return i18n("Delete");
}
//***************************************************************************
qint64 Kwave::UndoDeleteAction::undoSize()
{
return m_undo_size;
}
//***************************************************************************
qint64 Kwave::UndoDeleteAction::redoSize()
{
return sizeof(Kwave::UndoInsertAction);
}
//***************************************************************************
bool Kwave::UndoDeleteAction::store(Kwave::SignalManager &manager)
{
if (!m_length) return true; // shortcut: this is an empty action
// fork off a multi track stripe list for the selected range
const sample_index_t left = m_offset;
const sample_index_t right = m_offset + m_length - 1;
m_stripes = manager.stripes(m_track_list, left, right);
if (m_stripes.isEmpty())
return false; // retrieving the stripes failed
// save the meta data
m_meta_data = manager.metaData().copy(m_offset, m_length);
return true;
}
//***************************************************************************
Kwave::UndoAction *Kwave::UndoDeleteAction::undo(Kwave::SignalManager &manager,
bool with_redo)
{
Kwave::UndoAction *redo_action = nullptr;
// store data for redo
if (with_redo) {
redo_action = new(std::nothrow) Kwave::UndoInsertAction(
m_parent_widget, m_track_list,
m_offset, m_length
);
Q_ASSERT(redo_action);
if (!redo_action) return nullptr;
redo_action->store(manager);
}
if (!m_length) return redo_action; // shortcut: this is an empty action
// insert space for the stripes
if (!manager.insertSpace(m_offset, m_length, m_track_list)) {
qWarning("UndoDeleteAction::undo() FAILED [insertSpace]");
delete redo_action;
return nullptr;
}
// merge the stripes back into the signal
if (!manager.mergeStripes(m_stripes, m_track_list)) {
qWarning("UndoDeleteAction::undo() FAILED [mergeStripes]");
delete redo_action;
return nullptr;
}
// restore the saved meta data
manager.metaData().add(m_meta_data);
return redo_action;
}
//***************************************************************************
void Kwave::UndoDeleteAction::dump(const QString &indent)
{
qDebug("%sundo delete from [%lu ... %lu] (%lu)", DBG(indent),
static_cast<unsigned long int>(m_offset),
static_cast<unsigned long int>(m_offset + ((m_length) ?
(m_length - 1) : m_length)),
static_cast<unsigned long int>(m_length));
}
//***************************************************************************
//***************************************************************************
|