kwave  18.07.70
UndoSelection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  UndoSelection.cpp - Undo action for selection
3  -------------------
4  begin : Tue Jun 05 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 #include <KLocalizedString>
21 
22 #include "libkwave/SignalManager.h"
24 
25 //***************************************************************************
27  :UndoAction(),
28  m_manager(manager), m_offset(0), m_length(0), m_selected_tracks()
29 {
30 }
31 
32 //***************************************************************************
34  QList<unsigned int> selected_tracks,
35  sample_index_t offset,
36  sample_index_t length)
37  :UndoAction(),
38  m_manager(manager), m_offset(offset), m_length(length),
39  m_selected_tracks(selected_tracks)
40 {
41 }
42 
43 //***************************************************************************
45 {
46 }
47 
48 //***************************************************************************
50 {
51  return i18n("Selection");
52 }
53 
54 //***************************************************************************
56 {
57  return sizeof(*this) +
58  (m_selected_tracks.count() * sizeof(unsigned int));
59 }
60 
61 //***************************************************************************
63 {
64  return sizeof(*this) +
65  (m_manager.selectedTracks().count() * sizeof(unsigned int));
66 }
67 
68 //***************************************************************************
70 {
71  m_offset = manager.selection().offset();
72  m_length = manager.selection().length();
74 
75  return true;
76 }
77 
78 //***************************************************************************
80  bool with_redo)
81 {
82  // store current selection for later redo
83  sample_index_t old_offset = manager.selection().offset();
84  sample_index_t old_length = manager.selection().length();
85  QList<unsigned int> old_selected_tracks = manager.selectedTracks();
86 
87  // restore the previous selection
88  manager.selectRange(m_offset, m_length);
90 
91  // store data for redo
92  if (with_redo) {
93  m_offset = old_offset;
94  m_length = old_length;
95  m_selected_tracks = old_selected_tracks;
96  return this;
97  } else {
98  return Q_NULLPTR;
99  }
100 }
101 
102 //***************************************************************************
103 void Kwave::UndoSelection::dump(const QString &indent)
104 {
105  qDebug("%sselect from [%lu ... %lu] (%lu)", DBG(indent),
106  static_cast<unsigned long int>(m_offset),
107  static_cast<unsigned long int>(m_offset + ((m_length) ?
108  (m_length - 1) : m_length)),
109  static_cast<unsigned long int>(m_length));
110 }
111 
112 //***************************************************************************
113 //***************************************************************************
sample_index_t m_offset
Definition: UndoSelection.h:93
sample_index_t m_length
Definition: UndoSelection.h:96
virtual qint64 redoSize() Q_DECL_OVERRIDE
void selectRange(sample_index_t offset, sample_index_t length)
virtual ~UndoSelection() Q_DECL_OVERRIDE
virtual qint64 undoSize() Q_DECL_OVERRIDE
Kwave::Selection & selection()
virtual void dump(const QString &indent) Q_DECL_OVERRIDE
quint64 sample_index_t
Definition: Sample.h:28
sample_index_t length() const
Definition: Selection.h:66
UndoSelection(Kwave::SignalManager &manager)
virtual bool store(Kwave::SignalManager &manager) Q_DECL_OVERRIDE
QList< unsigned int > m_selected_tracks
Definition: UndoSelection.h:99
#define DBG(qs)
Definition: String.h:55
const QList< unsigned int > selectedTracks()
void selectTracks(QList< unsigned int > &track_list)
virtual Kwave::UndoAction * undo(Kwave::SignalManager &manager, bool with_redo) Q_DECL_OVERRIDE
Kwave::SignalManager & m_manager
Definition: UndoSelection.h:90
sample_index_t offset() const
Definition: Selection.h:61
virtual QString description() Q_DECL_OVERRIDE