1 /***************************************************************************
2 * (C) 2005-2006 Marius Roets <roets.marius@gmail.com> *
3 * (C) 2007 Rico Zenklusen <rico_z@users.sourceforge.net> *
4 * (C) 2007-2009 Michal Rudolf <mrudolf@kdewebdev.org> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12 #include <QtCore>
13 #include "indexitem.h"
14
15 #if defined(_MSC_VER) && defined(_DEBUG)
16 #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
17 #define new DEBUG_NEW
18 #endif // _MSC_VER
19
IndexItem()20 IndexItem::IndexItem()
21 {
22 }
23
~IndexItem()24 IndexItem::~IndexItem()
25 {
26 m_mapTagIndexToValueIndex.clear();
27 }
28
set(TagIndex tagIndex,ValueIndex valueIndex)29 void IndexItem::set(TagIndex tagIndex, ValueIndex valueIndex)
30 {
31 m_mapTagIndexToValueIndex[tagIndex] = valueIndex;
32 }
33
remove(TagIndex tagIndex)34 void IndexItem::remove(TagIndex tagIndex)
35 {
36 m_mapTagIndexToValueIndex.remove(tagIndex);
37 }
38
valueIndex(TagIndex tagIndex) const39 ValueIndex IndexItem::valueIndex(TagIndex tagIndex) const
40 {
41 return m_mapTagIndexToValueIndex.value(tagIndex,0);
42 }
43
hasTagIndex(TagIndex tagIndex) const44 bool IndexItem::hasTagIndex(TagIndex tagIndex) const
45 {
46 return (m_mapTagIndexToValueIndex.contains(tagIndex));
47 }
48
getTagIndices() const49 const QList<TagIndex> IndexItem::getTagIndices() const
50 {
51 return m_mapTagIndexToValueIndex.keys();
52 }
53
write(QDataStream & out) const54 void IndexItem::write(QDataStream& out) const
55 {
56 out << m_mapTagIndexToValueIndex;
57 }
58
read(QDataStream & in)59 void IndexItem::read(QDataStream& in)
60 {
61 in >> m_mapTagIndexToValueIndex;
62 }
63
64
operator <<(QDataStream & stream,const IndexItem & obj)65 QDataStream & operator<<(QDataStream & stream, const IndexItem & obj)
66 {
67 obj.write(stream);
68 return stream;
69 }
70
operator >>(QDataStream & stream,IndexItem & obj)71 QDataStream & operator>>(QDataStream & stream, IndexItem & obj)
72 {
73 obj.read(stream);
74 return stream;
75 }
76
isEqual(const IndexItem & rhs) const77 bool IndexItem::isEqual(const IndexItem &rhs) const
78 {
79 return (m_mapTagIndexToValueIndex == rhs.m_mapTagIndexToValueIndex);
80 }
81
replaceValue(QList<TagIndex> tags,ValueIndex valueIndex,ValueIndex newValueIndex)82 void IndexItem::replaceValue(QList<TagIndex> tags, ValueIndex valueIndex, ValueIndex newValueIndex)
83 {
84 for (auto ti: tags)
85 {
86 if (!m_mapTagIndexToValueIndex.contains(ti))
87 continue;
88 if (m_mapTagIndexToValueIndex[ti] == valueIndex)
89 {
90 m_mapTagIndexToValueIndex[ti] = newValueIndex;
91 }
92 }
93 }
94
95