Changeset View
Changeset View
Standalone View
Standalone View
src/maps.h
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
50 | { | 50 | { | ||
51 | Q_OBJECT | 51 | Q_OBJECT | ||
52 | 52 | | |||
53 | public: | 53 | public: | ||
54 | virtual int count() const = 0; | 54 | virtual int count() const = 0; | ||
55 | virtual QObject *objectAt(int index) const = 0; | 55 | virtual QObject *objectAt(int index) const = 0; | ||
56 | virtual int indexOfObject(QObject *object) const = 0; | 56 | virtual int indexOfObject(QObject *object) const = 0; | ||
57 | 57 | | |||
58 | signals: | 58 | Q_SIGNALS: | ||
59 | void aboutToBeAdded(int index); | 59 | void aboutToBeAdded(int index); | ||
60 | void added(int index); | 60 | void added(int index); | ||
61 | void aboutToBeRemoved(int index); | 61 | void aboutToBeRemoved(int index); | ||
62 | void removed(int index); | 62 | void removed(int index); | ||
63 | }; | 63 | }; | ||
64 | 64 | | |||
65 | /** | 65 | /** | ||
66 | * Maps a specific index to a specific object pointer. | 66 | * Maps a specific index to a specific object pointer. | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 112 | { | |||
115 | int modelIndex = 0; | 115 | int modelIndex = 0; | ||
116 | for (auto it = m_data.constBegin(); it != m_data.constEnd(); ++it) { | 116 | for (auto it = m_data.constBegin(); it != m_data.constEnd(); ++it) { | ||
117 | if (object->index() < it.key()) { | 117 | if (object->index() < it.key()) { | ||
118 | break; | 118 | break; | ||
119 | } | 119 | } | ||
120 | modelIndex++; | 120 | modelIndex++; | ||
121 | } | 121 | } | ||
122 | 122 | | |||
123 | emit aboutToBeAdded(modelIndex); | 123 | Q_EMIT aboutToBeAdded(modelIndex); | ||
124 | m_data.insert(object->index(), object); | 124 | m_data.insert(object->index(), object); | ||
125 | Q_ASSERT(modelIndex == m_data.keys().indexOf(object->index())); | 125 | Q_ASSERT(modelIndex == m_data.keys().indexOf(object->index())); | ||
126 | emit added(modelIndex); | 126 | Q_EMIT added(modelIndex); | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | // Context is passed in as parent because context needs to include the maps | 129 | // Context is passed in as parent because context needs to include the maps | ||
130 | // so we'd cause a circular dep if we were to try to use the instance here. | 130 | // so we'd cause a circular dep if we were to try to use the instance here. | ||
131 | // Plus that's weird separation anyway. | 131 | // Plus that's weird separation anyway. | ||
132 | void updateEntry(const PAInfo *info, QObject *parent) | 132 | void updateEntry(const PAInfo *info, QObject *parent) | ||
133 | { | 133 | { | ||
134 | Q_ASSERT(info); | 134 | Q_ASSERT(info); | ||
Show All 15 Lines | |||||
150 | } | 150 | } | ||
151 | 151 | | |||
152 | void removeEntry(quint32 index) | 152 | void removeEntry(quint32 index) | ||
153 | { | 153 | { | ||
154 | if (!m_data.contains(index)) { | 154 | if (!m_data.contains(index)) { | ||
155 | m_pendingRemovals.insert(index); | 155 | m_pendingRemovals.insert(index); | ||
156 | } else { | 156 | } else { | ||
157 | const int modelIndex = m_data.keys().indexOf(index); | 157 | const int modelIndex = m_data.keys().indexOf(index); | ||
158 | emit aboutToBeRemoved(modelIndex); | 158 | Q_EMIT aboutToBeRemoved(modelIndex); | ||
159 | delete m_data.take(index); | 159 | delete m_data.take(index); | ||
160 | emit removed(modelIndex); | 160 | Q_EMIT removed(modelIndex); | ||
161 | } | 161 | } | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | protected: | 164 | protected: | ||
165 | QMap<quint32, Type *> m_data; | 165 | QMap<quint32, Type *> m_data; | ||
166 | QSet<quint32> m_pendingRemovals; | 166 | QSet<quint32> m_pendingRemovals; | ||
167 | }; | 167 | }; | ||
168 | 168 | | |||
Show All 12 Lines |