kwave  18.07.70
Kwave::UndoModifyMetaDataAction Class Reference

#include <UndoModifyMetaDataAction.h>

Inheritance diagram for Kwave::UndoModifyMetaDataAction:
Inheritance graph
Collaboration diagram for Kwave::UndoModifyMetaDataAction:
Collaboration graph

Public Member Functions

 UndoModifyMetaDataAction (const Kwave::MetaDataList &meta_data)
 
virtual ~UndoModifyMetaDataAction () Q_DECL_OVERRIDE
 
virtual QString description () Q_DECL_OVERRIDE
 
virtual qint64 undoSize () Q_DECL_OVERRIDE
 
virtual qint64 redoSize () Q_DECL_OVERRIDE
 
virtual bool store (Kwave::SignalManager &manager) Q_DECL_OVERRIDE
 
virtual Kwave::UndoActionundo (Kwave::SignalManager &manager, bool with_redo) Q_DECL_OVERRIDE
 
virtual void dump (const QString &indent) Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::UndoAction
virtual ~UndoAction ()
 
virtual bool containsModification () const
 

Protected Attributes

Kwave::MetaDataList m_saved_data
 

Detailed Description

Undo action for modifying meta data

Definition at line 36 of file UndoModifyMetaDataAction.h.

Constructor & Destructor Documentation

◆ UndoModifyMetaDataAction()

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

Constructor

Parameters
meta_datalist of meta data that has been changed

Definition at line 27 of file UndoModifyMetaDataAction.cpp.

29  :UndoAction(), m_saved_data(meta_data)
30 {
31 }

◆ ~UndoModifyMetaDataAction()

Kwave::UndoModifyMetaDataAction::~UndoModifyMetaDataAction ( )
virtual

Destructor

Definition at line 34 of file UndoModifyMetaDataAction.cpp.

35 {
36 }

Member Function Documentation

◆ description()

QString Kwave::UndoModifyMetaDataAction::description ( )
virtual

Returns a verbose short description of the action.

Implements Kwave::UndoAction.

Definition at line 39 of file UndoModifyMetaDataAction.cpp.

References _, Kwave::MetaData::hasProperty(), m_saved_data, name, and Kwave::MetaData::STDPROP_TYPE.

40 {
41  // sanity check: list should not be empty
42  Q_ASSERT(!m_saved_data.isEmpty());
43  if (m_saved_data.isEmpty()) return _("");
44 
45  QString name;
46  {
47  const Kwave::MetaData &m = m_saved_data.values().first();
49  name = m[Kwave::MetaData::STDPROP_TYPE].toString();
50  }
51 
52  // if the meta data list contains only one object: try to find
53  // out the object's name
54  if ((m_saved_data.count() == 1) && name.length()) {
55  return i18nc(
56  "name of the undo action for modifying a meta data object",
57  "Modify %1",
58  name
59  );
60  }
61 
62  // check if the list contains only objects of the same type
63  bool all_same_type = true;
64  foreach (const Kwave::MetaData &m, m_saved_data) {
65  QString n = m[Kwave::MetaData::STDPROP_TYPE].toString();
66  if (!n.length() || (n != name)) {
67  all_same_type = false;
68  break;
69  }
70  }
71  if (all_same_type) {
72  return i18nc(
73  "name of the undo action for modifying multiple "
74  "meta data objects of the same type: "
75  "%1=number of elements, %2=name of one element in singular",
76  "Modify %1 %2 objects",
77  m_saved_data.count(), name
78  );
79  }
80 
81  return i18n("Modify Meta Data");
82 }
bool hasProperty(const QString &p) const
Definition: MetaData.cpp:104
const char name[16]
Definition: memcpy.c:510
static const QString STDPROP_TYPE
Definition: MetaData.h:41
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:

◆ dump()

void Kwave::UndoModifyMetaDataAction::dump ( const QString &  indent)
virtual

dump, for debugging purposes

Reimplemented from Kwave::UndoAction.

Definition at line 142 of file UndoModifyMetaDataAction.cpp.

References _, DBG, Kwave::MetaData::id(), Kwave::MetaData::keys(), and m_saved_data.

143 {
144  foreach (const Kwave::MetaData &m, m_saved_data) {
145  qDebug("%sundo modify meta data object '%s'",
146  DBG(indent), DBG(m.id()));
147 
148  // dump all properties of the object
149  foreach (const QString &key, m.keys()) {
150  QVariant v = m[key];
151  QString value;
152  if (v.type() == QVariant::List) {
153  foreach (const QVariant &v1, v.toList())
154  value += _("'") + v1.toString() + _("' ");
155  } else {
156  value = v.toString();
157  }
158  qDebug("%s '%s' = '%s",
159  DBG(indent), DBG(key), DBG(value));
160  }
161  }
162 }
QStringList keys() const
Definition: MetaData.cpp:149
QString id() const
Definition: MetaData.cpp:75
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
Here is the call graph for this function:

◆ redoSize()

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

Implements Kwave::UndoAction.

Definition at line 91 of file UndoModifyMetaDataAction.cpp.

References undoSize().

92 {
93  return undoSize();
94 }
virtual qint64 undoSize() Q_DECL_OVERRIDE
Here is the call graph for this function:

◆ store()

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

Implements Kwave::UndoAction.

Definition at line 97 of file UndoModifyMetaDataAction.cpp.

98 {
99  // nothing to do, all data has already
100  // been stored in the constructor
101  return true;
102 }

◆ undo()

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

Implements Kwave::UndoAction.

Definition at line 105 of file UndoModifyMetaDataAction.cpp.

References Kwave::MetaDataList::add(), Kwave::MetaDataList::contains(), Kwave::MetaData::id(), m_saved_data, Kwave::SignalManager::mergeMetaData(), and Kwave::SignalManager::metaData().

107 {
108  if (m_saved_data.isEmpty()) return Q_NULLPTR;
109 
110  // store data for redo
111  if (with_redo) {
112  Kwave::MetaDataList old_data;
113  const Kwave::MetaDataList &current_data = manager.metaData();
114 
115  foreach (const Kwave::MetaData &meta, m_saved_data) {
116  if (current_data.contains(meta)) {
117  // add a new entry that will replace the old one
118  old_data.add(current_data[meta.id()]);
119  } else {
120  // add an empty entry that will delete the old one when added
121  Kwave::MetaData empty_element(meta);
122  old_data.add(empty_element);
123  old_data[empty_element.id()].clear();
124  }
125  }
126 
127  // restore the saved meta data
128  manager.mergeMetaData(m_saved_data);
129 
130  // take the previous values as new undo data
131  m_saved_data = old_data;
132 
133  return this;
134  } else {
135  // restore the saved meta data
136  manager.mergeMetaData(m_saved_data);
137  return Q_NULLPTR;
138  }
139 }
virtual bool contains(const MetaData &metadata) const
void mergeMetaData(const Kwave::MetaDataList &meta_data)
Kwave::MetaDataList & metaData()
virtual void add(const MetaData &metadata)
QString id() const
Definition: MetaData.cpp:75
Here is the call graph for this function:

◆ undoSize()

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

Implements Kwave::UndoAction.

Definition at line 85 of file UndoModifyMetaDataAction.cpp.

References m_saved_data.

Referenced by redoSize().

86 {
87  return sizeof(*this) + sizeof(m_saved_data);
88 }
Here is the caller graph for this function:

Member Data Documentation

◆ m_saved_data

Kwave::MetaDataList Kwave::UndoModifyMetaDataAction::m_saved_data
protected

the unmodified metadata

Definition at line 73 of file UndoModifyMetaDataAction.h.

Referenced by description(), dump(), undo(), and undoSize().


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