kwave  18.07.70
UndoDeleteMetaDataAction.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  UndoAddLabelAction.cpp - Undo action for deleting labels
3  -------------------
4  begin : Wed Aug 16 2006
5  copyright : (C) 2006 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  const Kwave::MetaDataList &meta_data)
32  :UndoAction(), m_meta_data(meta_data)
33 {
34 }
35 
36 //***************************************************************************
38 {
39 }
40 
41 //***************************************************************************
43 {
44  // sanity check: list should not be empty
45  Q_ASSERT(!m_meta_data.isEmpty());
46  if (m_meta_data.isEmpty()) return _("");
47 
48  QString name;
49  {
50  const Kwave::MetaData &m = m_meta_data.values().first();
52  name = m[Kwave::MetaData::STDPROP_TYPE].toString();
53  }
54 
55  // if the meta data list contains only one object: try to find
56  // out the object's name
57  if ((m_meta_data.count() == 1) && name.length()) {
58  return i18nc(
59  "name of the undo action for deleting a meta data object",
60  "Delete %1",
61  name
62  );
63  }
64 
65  // check if the list contains only objects of the same type
66  bool all_same_type = true;
67  foreach (const Kwave::MetaData &m, m_meta_data) {
68  QString n = m[Kwave::MetaData::STDPROP_TYPE].toString();
69  if (!n.length() || (n != name)) {
70  all_same_type = false;
71  break;
72  }
73  }
74  if (all_same_type) {
75  return i18nc(
76  "name of the undo action for deleting multiple "
77  "meta data objects of the same type: "
78  "%1=number of elements, %2=name of one element in singular",
79  "Delete %1 %2 objects", m_meta_data.count(), name
80  );
81  }
82 
83  return i18n("Delete Meta Data");
84 }
85 
86 //***************************************************************************
88 {
89  return sizeof(*this);
90 }
91 
92 //***************************************************************************
94 {
95  return sizeof(Kwave::UndoAddMetaDataAction);
96 }
97 
98 //***************************************************************************
100 {
101  // nothing to do, all data has already
102  // been stored in the constructor
103  return true;
104 }
105 
106 //***************************************************************************
108  Kwave::SignalManager &manager, bool with_redo)
109 {
110  Q_ASSERT(!m_meta_data.isEmpty());
111  if (m_meta_data.isEmpty()) return Q_NULLPTR;
112 
113  Kwave::UndoAction *redo = Q_NULLPTR;
114 
115  // add the stored meta data to the signal managers' meta data
116  manager.metaData().merge(m_meta_data);
117 
118  // store data for redo
119  if (with_redo) {
120  redo = new(std::nothrow) Kwave::UndoAddMetaDataAction(m_meta_data);
121  Q_ASSERT(redo);
122  if (redo) redo->store(manager);
123  }
124 
125  return redo;
126 }
127 
128 //***************************************************************************
129 void Kwave::UndoDeleteMetaDataAction::dump(const QString &indent)
130 {
131  foreach (const Kwave::MetaData &m, m_meta_data) {
132  qDebug("%sundo delete meta data object '%s'",
133  DBG(indent), DBG(m.id()));
134 
135  // dump all properties of the object
136  foreach (const QString &key, m.keys()) {
137  QVariant v = m[key];
138  QString value;
139  if (v.type() == QVariant::List) {
140  foreach (const QVariant &v1, v.toList())
141  value += _("'") + v1.toString() + _("' ");
142  } else {
143  value = v.toString();
144  }
145  qDebug("%s '%s' = '%s", DBG(indent), DBG(key), DBG(value));
146  }
147  }
148 }
149 
150 //***************************************************************************
151 //***************************************************************************
bool hasProperty(const QString &p) const
Definition: MetaData.cpp:104
virtual Kwave::UndoAction * undo(Kwave::SignalManager &manager, bool with_redo) Q_DECL_OVERRIDE
QStringList keys() const
Definition: MetaData.cpp:149
UndoDeleteMetaDataAction(const Kwave::MetaDataList &meta_data)
Kwave::MetaDataList & metaData()
virtual bool store(Kwave::SignalManager &manager) Q_DECL_OVERRIDE
virtual QString description() Q_DECL_OVERRIDE
void merge(const MetaDataList &meta_data)
const char name[16]
Definition: memcpy.c:510
QString id() const
Definition: MetaData.cpp:75
static const QString STDPROP_TYPE
Definition: MetaData.h:41
virtual qint64 redoSize() Q_DECL_OVERRIDE
virtual ~UndoDeleteMetaDataAction() Q_DECL_OVERRIDE
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
virtual void dump(const QString &indent) Q_DECL_OVERRIDE
virtual qint64 undoSize() Q_DECL_OVERRIDE
virtual bool store(Kwave::SignalManager &manager)=0