kwave  18.07.70
Kwave::MetaData Class Reference

#include <MetaData.h>

Inheritance diagram for Kwave::MetaData:
Inheritance graph
Collaboration diagram for Kwave::MetaData:
Collaboration graph

Classes

class  MetaDataPriv
 

Public Types

enum  Scope {
  None = 0, Signal = (1 << 0), Track = (1 << 1), Range = (1 << 2),
  Position = (1 << 3), All = ~0
}
 
typedef QMap< QString, QVariant > PropertyList
 

Public Member Functions

 MetaData ()
 
 MetaData (const MetaData &other)
 
 MetaData (Scope scope)
 
virtual ~MetaData ()
 
virtual void clear ()
 
virtual bool isNull () const
 
QString id () const
 
Scope scope () const
 
void setScope (Scope scope)
 
void setProperty (const QString &p, const QVariant &value)
 
bool hasProperty (const QString &p) const
 
QVariant property (const QString &p) const
 
QVariant operator[] (const QString p) const
 
QVariant & property (const QString &p)
 
QVariant & operator[] (const QString p)
 
bool operator== (const MetaData &other) const
 
bool operator!= (const MetaData &other) const
 
QStringList keys () const
 
sample_index_t firstSample () const
 
sample_index_t lastSample () const
 
QList< unsigned int > boundTracks () const
 
virtual void dump () const
 

Static Public Member Functions

static QStringList positionBoundPropertyNames ()
 

Static Public Attributes

static const QString STDPROP_TYPE
 
static const QString STDPROP_TRACKS
 
static const QString STDPROP_START
 
static const QString STDPROP_END
 
static const QString STDPROP_POS
 
static const QString STDPROP_DESCRIPTION
 

Private Attributes

QSharedDataPointer< MetaDataPrivm_data
 

Detailed Description

Definition at line 37 of file MetaData.h.

Member Typedef Documentation

◆ PropertyList

typedef QMap<QString, QVariant> Kwave::MetaData::PropertyList

List of metadata properties

Definition at line 91 of file MetaData.h.

Member Enumeration Documentation

◆ Scope

Enumerator
None 

no scope

Signal 

whole signal

Track 

bound to a (list of) tracks, requires the property "STDPROP_TRACKS" with a QVariant::List of track indices encoded as QVariant::UInt

Range 

bound to a range of samples, requires the properties "STDPROP_START" and "STDPROP_END" with data type QVariant::ULongLong

Position 

bound to a single sample, requires the property "STDPROP_POS" with data type "QVariant::ULongLong"

All 

can be used for selecting all the scopes above

Definition at line 58 of file MetaData.h.

59  {
61  None = 0,
62 
64  Signal = (1 << 0),
65 
71  Track = (1 << 1),
72 
78  Range = (1 << 2),
79 
84  Position = (1 << 3),
85 
87  All = ~0
88  } Scope;

Constructor & Destructor Documentation

◆ MetaData() [1/3]

Kwave::MetaData::MetaData ( )

default constructor, generates a metadata object with a new ID

Definition at line 38 of file MetaData.cpp.

39  :m_data(Q_NULLPTR)
40 {
41 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250

◆ MetaData() [2/3]

Kwave::MetaData::MetaData ( const MetaData other)

copy constructor

Parameters
otherthe other meta data object to copy from

Definition at line 44 of file MetaData.cpp.

45  :m_data(other.m_data)
46 {
47 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250

◆ MetaData() [3/3]

Kwave::MetaData::MetaData ( Scope  scope)
explicit

constructor

Definition at line 50 of file MetaData.cpp.

References setScope().

51  :m_data(new MetaDataPriv)
52 {
53  setScope(scope);
54 }
Scope scope() const
Definition: MetaData.cpp:81
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
void setScope(Scope scope)
Definition: MetaData.cpp:87
Here is the call graph for this function:

◆ ~MetaData()

Kwave::MetaData::~MetaData ( )
virtual

destructor

Definition at line 57 of file MetaData.cpp.

References m_data.

58 {
59  m_data = Q_NULLPTR;
60 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250

Member Function Documentation

◆ boundTracks()

QList< unsigned int > Kwave::MetaData::boundTracks ( ) const

Returns a list of tracks a meta data item is bound to

Returns
list of bound tracks or empty list if not bound

Definition at line 225 of file MetaData.cpp.

References hasProperty(), property(), and STDPROP_TRACKS.

Referenced by Kwave::MetaDataList::deleteRange(), Kwave::MetaDataList::merge(), Kwave::MetaDataList::scalePositions(), Kwave::MetaDataList::shiftLeft(), Kwave::MetaDataList::shiftRight(), and Kwave::MetaDataList::split().

226 {
227  QList<unsigned int> tracks;
229  const QList<QVariant> v_track_list =
231  foreach (const QVariant &v, v_track_list) {
232  bool ok = false;
233  unsigned int t = v.toUInt(&ok);
234  if (ok) tracks += t;
235  }
236  }
237  return tracks;
238 }
bool hasProperty(const QString &p) const
Definition: MetaData.cpp:104
static const QString STDPROP_TRACKS
Definition: MetaData.h:44
QVariant property(const QString &p) const
Definition: MetaData.cpp:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void Kwave::MetaData::clear ( )
virtual

removes all properties

Definition at line 63 of file MetaData.cpp.

References m_data.

Referenced by Kwave::MetaDataList::cropByTracks().

64 {
65  if (m_data) m_data->m_properties.clear();
66 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
Here is the caller graph for this function:

◆ dump()

void Kwave::MetaData::dump ( ) const
virtual

dump all properties to stdout, for debugging

Reimplemented in Kwave::FileInfo.

Definition at line 241 of file MetaData.cpp.

References _, All, DBG, keys(), Kwave::MetaData::MetaDataPriv::m_id_counter, Kwave::MetaData::MetaDataPriv::m_id_lock, Position, property(), Range, and scope().

Referenced by Kwave::MetaDataList::dump().

242 {
243  QString scope_list;
244  const Scope s = scope();
245  if (s == All)
246  scope_list = _("all");
247  else {
248  if (s & Signal) scope_list += _(" signal");
249  if (s & Track) scope_list += _(" track");
250  if (s & Range) scope_list += _(" range");
251  if (s & Position) scope_list += _(" position");
252  }
253  qDebug(" scope =%s", DBG(scope_list));
254  const QStringList props = keys();
255  foreach (const QString &p, props) {
256  QVariant prop = property(p);
257  const QList<QVariant> v_vals = prop.toList();
258  QString value;
259  if (!v_vals.isEmpty()) {
260  foreach (QVariant v, v_vals)
261  value += _("{") + v.toString() + _("'} ");
262  } else {
263  value += _("'") + prop.toString() + _("'");
264  }
265 
266  qDebug(" '%s' = %s", DBG(p), DBG(value));
267  }
268 }
QStringList keys() const
Definition: MetaData.cpp:149
Scope scope() const
Definition: MetaData.cpp:81
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
QVariant property(const QString &p) const
Definition: MetaData.cpp:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ firstSample()

sample_index_t Kwave::MetaData::firstSample ( ) const

Returns the index of the first sample covered by a given meta data item

Returns
index of the first sample

Definition at line 165 of file MetaData.cpp.

References hasProperty(), Position, property(), Range, scope(), STDPROP_POS, and STDPROP_START.

Referenced by Kwave::MetaDataList::deleteRange(), isLessThan(), Kwave::MetaDataList::merge(), Kwave::MetaDataList::scalePositions(), Kwave::MetaDataList::shiftLeft(), Kwave::MetaDataList::shiftRight(), and Kwave::MetaDataList::split().

166 {
167  // single position?
168  if ((scope() & Kwave::MetaData::Position) &&
170  bool ok = false;
171  sample_index_t pos =
172  property(Kwave::MetaData::STDPROP_POS).toULongLong(&ok);
173  if (ok) return pos;
174  }
175 
176  // start sample index given
177  if ((scope() & Kwave::MetaData::Range) &&
179  bool ok = false;
180  sample_index_t start = static_cast<sample_index_t>(
181  property(Kwave::MetaData::STDPROP_START).toULongLong(&ok));
182  if (ok) return start;
183  }
184 
185  // fallback: start at zero
186  return 0;
187 }
bool hasProperty(const QString &p) const
Definition: MetaData.cpp:104
static const QString STDPROP_POS
Definition: MetaData.h:53
Scope scope() const
Definition: MetaData.cpp:81
quint64 sample_index_t
Definition: Sample.h:28
static const QString STDPROP_START
Definition: MetaData.h:47
QVariant property(const QString &p) const
Definition: MetaData.cpp:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasProperty()

◆ id()

QString Kwave::MetaData::id ( ) const

returns the ID of the meta data

Definition at line 75 of file MetaData.cpp.

References m_data.

Referenced by Kwave::MetaDataList::add(), Kwave::MetaDataList::contains(), Kwave::UndoDeleteMetaDataAction::dump(), Kwave::UndoModifyMetaDataAction::dump(), Kwave::MetaDataList::remove(), Kwave::MetaDataList::selectByTracks(), and Kwave::UndoModifyMetaDataAction::undo().

76 {
77  return (m_data) ? m_data->m_id : QString();
78 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
Here is the caller graph for this function:

◆ isNull()

bool Kwave::MetaData::isNull ( ) const
virtual

◆ keys()

QStringList Kwave::MetaData::keys ( ) const

returns a list with all property names

Definition at line 149 of file MetaData.cpp.

References m_data.

Referenced by Kwave::UndoDeleteMetaDataAction::dump(), Kwave::UndoModifyMetaDataAction::dump(), dump(), and Kwave::MetaDataList::merge().

150 {
151  return (m_data) ? m_data->m_properties.keys() : QStringList();
152 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
Here is the caller graph for this function:

◆ lastSample()

sample_index_t Kwave::MetaData::lastSample ( ) const

Returns the index of the last sample covered by a given meta data item

Returns
index of the last sample

Definition at line 190 of file MetaData.cpp.

References hasProperty(), Position, property(), Range, SAMPLE_INDEX_MAX, scope(), STDPROP_END, STDPROP_POS, and STDPROP_START.

Referenced by Kwave::MetaDataList::deleteRange(), Kwave::MetaDataList::merge(), Kwave::MetaDataList::scalePositions(), Kwave::MetaDataList::shiftLeft(), Kwave::MetaDataList::shiftRight(), and Kwave::MetaDataList::split().

191 {
192  // single position?
193  if ((scope() & Kwave::MetaData::Position) &&
195  bool ok = false;
196  sample_index_t pos =
197  property(Kwave::MetaData::STDPROP_POS).toULongLong(&ok);
198  if (ok) return pos;
199  }
200 
201  // bound to a scope
202  if (scope() & Kwave::MetaData::Range) {
203  // end sample index given
205  bool ok = false;
206  sample_index_t end = static_cast<sample_index_t>(
207  property(Kwave::MetaData::STDPROP_END).toULongLong(&ok));
208  if (ok) return end;
209  }
210 
211  // fallback: no end => use start
213  bool ok = false;
214  sample_index_t start = static_cast<sample_index_t>(
215  property(Kwave::MetaData::STDPROP_START).toULongLong(&ok));
216  if (ok) return start;
217  }
218  }
219 
220  // fallback: infinite
221  return SAMPLE_INDEX_MAX;
222 }
bool hasProperty(const QString &p) const
Definition: MetaData.cpp:104
static const QString STDPROP_POS
Definition: MetaData.h:53
Scope scope() const
Definition: MetaData.cpp:81
quint64 sample_index_t
Definition: Sample.h:28
static const QString STDPROP_START
Definition: MetaData.h:47
QVariant property(const QString &p) const
Definition: MetaData.cpp:110
static const QString STDPROP_END
Definition: MetaData.h:50
#define SAMPLE_INDEX_MAX
Definition: Sample.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool Kwave::MetaData::operator!= ( const MetaData other) const
inline

not equal operator, compares by data (not by ID)

Definition at line 178 of file MetaData.h.

179  {
180  return !(operator == (other));
181  }
bool operator==(const MetaData &other) const
Definition: MetaData.cpp:131

◆ operator==()

bool Kwave::MetaData::operator== ( const MetaData other) const

equal operator, compares by data (not by ID)

Definition at line 131 of file MetaData.cpp.

References m_data.

132 {
133  if (!m_data && !other.m_data)
134  return true; // both are null objects
135 
136  if ((!m_data) ^ (!other.m_data))
137  return false; // only one is a null object
138 
139  if (m_data->m_scope != other.m_data->m_scope)
140  return false; // different scope
141 
142  if (m_data->m_properties != other.m_data->m_properties)
143  return false; // properties differ
144 
145  return true; // no mismatch found
146 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250

◆ operator[]() [1/2]

QVariant Kwave::MetaData::operator[] ( const QString  p) const
inline

Same as above, for using through the [] operator

Definition at line 155 of file MetaData.h.

156  {
157  return property(p);
158  }
QVariant property(const QString &p) const
Definition: MetaData.cpp:110

◆ operator[]() [2/2]

QVariant& Kwave::MetaData::operator[] ( const QString  p)
inline

Same as above, for using through the [] operator

Definition at line 169 of file MetaData.h.

170  {
171  return property(p);
172  }
QVariant property(const QString &p) const
Definition: MetaData.cpp:110

◆ positionBoundPropertyNames()

QStringList Kwave::MetaData::positionBoundPropertyNames ( )
static

returns a list of position bount property names

Definition at line 155 of file MetaData.cpp.

References STDPROP_END, STDPROP_POS, and STDPROP_START.

Referenced by Kwave::MetaDataList::merge(), Kwave::SampleRatePlugin::run(), and Kwave::UndoAddMetaDataAction::UndoAddMetaDataAction().

156 {
157  QStringList list;
161  return list;
162 }
static const QString STDPROP_POS
Definition: MetaData.h:53
static const QString STDPROP_START
Definition: MetaData.h:47
static const QString STDPROP_END
Definition: MetaData.h:50
Here is the caller graph for this function:

◆ property() [1/2]

QVariant Kwave::MetaData::property ( const QString &  p) const

Returns a QVariant with the copy of the value of a property or an empty QVariant if the property does not exist.

Parameters
pname of the property
Returns
value of the property or an empty QVariant

Definition at line 110 of file MetaData.cpp.

References m_data.

Referenced by boundTracks(), dump(), firstSample(), Kwave::FileInfo::get(), lastSample(), Kwave::Label::name(), and Kwave::Label::pos().

111 {
112  if (m_data && m_data->m_properties.contains(p))
113  return m_data->m_properties[p];
114  else
115  return QVariant();
116 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
Here is the caller graph for this function:

◆ property() [2/2]

QVariant & Kwave::MetaData::property ( const QString &  p)

Returns a mutable reference to an existing property (or the reference to an empty dummy if it did not exist).

Parameters
pname of the property
Returns
reference to the value of the property

Definition at line 119 of file MetaData.cpp.

References m_data.

120 {
121  if (m_data && m_data->m_properties.contains(p))
122  return m_data->m_properties[p];
123  else {
124  static QVariant dummy;
125  dummy.clear();
126  return dummy;
127  }
128 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250

◆ scope()

Kwave::MetaData::Scope Kwave::MetaData::scope ( ) const

returns the scope of the meta data

Definition at line 81 of file MetaData.cpp.

References m_data, and None.

Referenced by Kwave::MetaDataList::cropByRange(), Kwave::MetaDataList::cropByTracks(), Kwave::MetaDataList::deleteRange(), dump(), firstSample(), lastSample(), Kwave::MetaDataList::merge(), Kwave::MetaDataList::selectByPosition(), Kwave::MetaDataList::selectByRange(), Kwave::MetaDataList::selectByScope(), and setScope().

82 {
83  return (m_data) ? m_data->m_scope : None;
84 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
Here is the caller graph for this function:

◆ setProperty()

void Kwave::MetaData::setProperty ( const QString &  p,
const QVariant &  value 
)

Sets a property to a new value. If the property already exists it will be created and if it did not exist, a new one will be created. If the value is not valid (null), the property will be deleted.

Parameters
pname of the property
valuea QVariant with the property's data

Definition at line 93 of file MetaData.cpp.

References m_data.

Referenced by Kwave::MetaDataList::deleteRange(), Kwave::FileInfo::FileInfo(), Kwave::Label::Label(), Kwave::MetaDataList::merge(), Kwave::Label::moveTo(), Kwave::Label::rename(), Kwave::MetaDataList::scalePositions(), Kwave::FileInfo::set(), Kwave::MetaDataList::shiftLeft(), Kwave::MetaDataList::shiftRight(), and Kwave::MetaDataList::split().

94 {
95  if (m_data) {
96  if (value.isValid())
97  m_data->m_properties[p] = value;
98  else
99  m_data->m_properties.remove(p);
100  }
101 }
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
Here is the caller graph for this function:

◆ setScope()

void Kwave::MetaData::setScope ( Scope  scope)

Sets the scope of the meta data

Parameters
scopethe new scope

Definition at line 87 of file MetaData.cpp.

References m_data, and scope().

Referenced by MetaData().

88 {
89  if (m_data) m_data->m_scope = scope;
90 }
Scope scope() const
Definition: MetaData.cpp:81
QSharedDataPointer< MetaDataPriv > m_data
Definition: MetaData.h:250
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_data

QSharedDataPointer<MetaDataPriv> Kwave::MetaData::m_data
private

pointer to the shared meta data

Definition at line 250 of file MetaData.h.

Referenced by clear(), hasProperty(), id(), isNull(), keys(), operator==(), property(), scope(), setProperty(), setScope(), and ~MetaData().

◆ STDPROP_DESCRIPTION

const QString Kwave::MetaData::STDPROP_DESCRIPTION
static

standard property: description (string)

Definition at line 56 of file MetaData.h.

Referenced by Kwave::Label::Label(), Kwave::Label::name(), and Kwave::Label::rename().

◆ STDPROP_END

◆ STDPROP_POS

◆ STDPROP_START

◆ STDPROP_TRACKS

◆ STDPROP_TYPE


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