kwave  18.07.70
Kwave::UndoAddMetaDataAction Class Reference

#include <UndoAddMetaDataAction.h>

Inheritance diagram for Kwave::UndoAddMetaDataAction:
Inheritance graph
Collaboration diagram for Kwave::UndoAddMetaDataAction:
Collaboration graph

Public Member Functions

 UndoAddMetaDataAction (const Kwave::MetaDataList &meta_data)
 
virtual ~UndoAddMetaDataAction () Q_DECL_OVERRIDE
 
QString description () Q_DECL_OVERRIDE
 
virtual qint64 undoSize () Q_DECL_OVERRIDE
 
virtual qint64 redoSize () Q_DECL_OVERRIDE
 
virtual bool store (SignalManager &manager) Q_DECL_OVERRIDE
 
virtual Kwave::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

QString m_description
 
sample_index_t m_offset
 
sample_index_t m_length
 
QList< unsigned int > m_tracks
 

Detailed Description

Undo action for inserting meta data.

Definition at line 40 of file UndoAddMetaDataAction.h.

Constructor & Destructor Documentation

◆ UndoAddMetaDataAction()

Kwave::UndoAddMetaDataAction::UndoAddMetaDataAction ( const Kwave::MetaDataList meta_data)
explicit

Constructor

Parameters
meta_datareference to the meta data that has been inserted

Definition at line 34 of file UndoAddMetaDataAction.cpp.

References Kwave::MetaData::hasProperty(), m_description, m_length, m_offset, m_tracks, name, Kwave::MetaData::positionBoundPropertyNames(), SAMPLE_INDEX_MAX, Kwave::MetaData::STDPROP_TRACKS, and Kwave::MetaData::STDPROP_TYPE.

37  m_description(),
38  m_offset(0),
40  m_tracks()
41 {
43  sample_index_t last = 0;
44 
45  // sanity check: list should not be empty
46  Q_ASSERT(!meta_data.isEmpty());
47  if (meta_data.isEmpty()) return;
48 
49  /*
50  * loop over the list to find out the first/last sample offset
51  * and the list of affected tracks
52  */
53  foreach (const Kwave::MetaData &m, meta_data)
54  {
55  // search over a list of known properties which contain range/position
56  QStringList properties = Kwave::MetaData::positionBoundPropertyNames();
57  foreach (const QString &tag, properties) {
58  // check for a "start" property
59  QVariant v = m[tag];
60  bool ok = false;
61  sample_index_t pos = static_cast<sample_index_t>(v.toULongLong(&ok));
62  if (ok && (pos < first)) first = pos;
63  if (ok && (pos > last)) last = pos;
64  }
65 
66  // convert the track list into a usable list of unsigned int
67  const QList<QVariant> v_track_list =
69  QList<unsigned int> bound_tracks;
70  foreach (const QVariant &v, v_track_list) {
71  bool ok = false;
72  unsigned int t = v.toUInt(&ok);
73  if (ok) bound_tracks += t;
74  }
75 
76  foreach (unsigned int t, bound_tracks)
77  if (!m_tracks.contains(t)) m_tracks.append(t);;
78  }
79 
80  // fix first/last in case that nothing was found, select everything
81  if (first > last) {
83  m_length = 0;
84  } else {
85  m_offset = first;
86  m_length = (last - first) + 1;
87  }
88  if (!m_tracks.isEmpty())
89  std::sort(m_tracks.begin(),
90  m_tracks.end(), std::greater<unsigned int>());
91 
92  /*
93  * determine the description of the action
94  */
95 
96  for (;;) {
97  QString name;
98  QList<Kwave::MetaData> values = meta_data.values();
99  Q_ASSERT(!values.isEmpty());
100  if (!values.isEmpty()) {
101  const Kwave::MetaData &m = values.first();
103  name = m[Kwave::MetaData::STDPROP_TYPE].toString();
104  }
105 
106  // if the meta data list contains only one object: try to find
107  // out the object's name
108  if ((meta_data.count() == 1) && name.length()) {
109  m_description = i18nc(
110  "name of the undo action for inserting a meta data object",
111  "Insert %1",
112  name
113  );
114  break;
115  }
116 
117  // check if the list contains only objects of the same type
118  bool all_same_type = true;
119  foreach (const Kwave::MetaData &m, meta_data) {
120  QString n = m[Kwave::MetaData::STDPROP_TYPE].toString();
121  if (!n.length() || (n != name)) {
122  all_same_type = false;
123  break;
124  }
125  }
126  if (all_same_type) {
127  m_description = i18nc(
128  "name of the undo action for inserting multiple "
129  "meta data objects of the same type: "
130  "%1=number of elements, %2=name of one element in singular",
131  "Insert %1 %2 objects", meta_data.count(), name
132  );
133  break;
134  }
135 
136  m_description = i18n("Insert Meta Data");
137  break;
138  }
139 }
static QStringList positionBoundPropertyNames()
Definition: MetaData.cpp:155
bool hasProperty(const QString &p) const
Definition: MetaData.cpp:104
static const QString STDPROP_TRACKS
Definition: MetaData.h:44
quint64 sample_index_t
Definition: Sample.h:28
const char name[16]
Definition: memcpy.c:510
static const QString STDPROP_TYPE
Definition: MetaData.h:41
#define SAMPLE_INDEX_MAX
Definition: Sample.h:31
Here is the call graph for this function:

◆ ~UndoAddMetaDataAction()

Kwave::UndoAddMetaDataAction::~UndoAddMetaDataAction ( )
virtual

Destructor

Definition at line 142 of file UndoAddMetaDataAction.cpp.

143 {
144 }

Member Function Documentation

◆ description()

QString Kwave::UndoAddMetaDataAction::description ( )
virtual

Returns a verbose short description of the action.

Implements Kwave::UndoAction.

Definition at line 147 of file UndoAddMetaDataAction.cpp.

References m_description.

148 {
149  return m_description;
150 }

◆ redoSize()

qint64 Kwave::UndoAddMetaDataAction::redoSize ( )
virtual
See also
UndoAction::redoSize()

Implements Kwave::UndoAction.

Definition at line 159 of file UndoAddMetaDataAction.cpp.

160 {
161  return sizeof(UndoDeleteMetaDataAction);
162 }

◆ store()

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

Implements Kwave::UndoAction.

Definition at line 165 of file UndoAddMetaDataAction.cpp.

166 {
167  // nothing to do, all data has already
168  // been stored in the constructor
169  return true;
170 }

◆ undo()

Kwave::UndoAction * Kwave::UndoAddMetaDataAction::undo ( Kwave::SignalManager manager,
bool  with_redo 
)
virtual
See also
UndoAction::undo()

Implements Kwave::UndoAction.

Definition at line 173 of file UndoAddMetaDataAction.cpp.

References Kwave::MetaDataList::copy(), Kwave::MetaDataList::deleteRange(), m_length, m_offset, m_tracks, Kwave::SignalManager::metaData(), and Kwave::UndoAction::store().

175 {
176  Kwave::UndoAction *redo = Q_NULLPTR;
177 
178  Kwave::MetaDataList meta_data =
179  manager.metaData().copy(m_offset, m_length, m_tracks);
180 
181  // store data for redo
182  if (with_redo && !meta_data.isEmpty()) {
183  redo = new(std::nothrow) Kwave::UndoDeleteMetaDataAction(meta_data);
184  Q_ASSERT(redo);
185  if (redo) redo->store(manager);
186  }
187 
188  // remove the meta data from the signal manager
190 
191  return redo;
192 }
virtual MetaDataList copy(sample_index_t offset, sample_index_t length, const QList< unsigned int > &tracks) const
Kwave::MetaDataList & metaData()
virtual void deleteRange(sample_index_t offset, sample_index_t length, const QList< unsigned int > &tracks)
virtual bool store(Kwave::SignalManager &manager)=0
Here is the call graph for this function:

◆ undoSize()

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

Implements Kwave::UndoAction.

Definition at line 153 of file UndoAddMetaDataAction.cpp.

154 {
155  return sizeof(*this);
156 }

Member Data Documentation

◆ m_description

QString Kwave::UndoAddMetaDataAction::m_description
protected

description of the action

Definition at line 74 of file UndoAddMetaDataAction.h.

Referenced by description(), and UndoAddMetaDataAction().

◆ m_length

sample_index_t Kwave::UndoAddMetaDataAction::m_length
protected

number of affected samples

Definition at line 80 of file UndoAddMetaDataAction.h.

Referenced by undo(), and UndoAddMetaDataAction().

◆ m_offset

sample_index_t Kwave::UndoAddMetaDataAction::m_offset
protected

index of the first sample position

Definition at line 77 of file UndoAddMetaDataAction.h.

Referenced by undo(), and UndoAddMetaDataAction().

◆ m_tracks

QList<unsigned int> Kwave::UndoAddMetaDataAction::m_tracks
protected

list of affected track inidices

Definition at line 83 of file UndoAddMetaDataAction.h.

Referenced by undo(), and UndoAddMetaDataAction().


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