diff options
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r-- | common/modelresult.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp index 8e92365..6695484 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp | |||
@@ -34,8 +34,8 @@ static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type) | |||
34 | } | 34 | } |
35 | 35 | ||
36 | template <class T, class Ptr> | 36 | template <class T, class Ptr> |
37 | ModelResult<T, Ptr>::ModelResult(const Sink::Query &query, const QList<QByteArray> &propertyColumns) | 37 | ModelResult<T, Ptr>::ModelResult(const Sink::Query &query, const QList<QByteArray> &propertyColumns, const Sink::Log::Context &ctx) |
38 | : QAbstractItemModel(), mPropertyColumns(propertyColumns), mQuery(query) | 38 | : QAbstractItemModel(), mLogCtx(ctx.subContext("modelresult")), mPropertyColumns(propertyColumns), mQuery(query) |
39 | { | 39 | { |
40 | } | 40 | } |
41 | 41 | ||
@@ -176,7 +176,7 @@ bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const | |||
176 | template <class T, class Ptr> | 176 | template <class T, class Ptr> |
177 | void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent) | 177 | void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent) |
178 | { | 178 | { |
179 | SinkTrace() << "Fetching more: " << parent; | 179 | SinkTraceCtx(mLogCtx) << "Fetching more: " << parent; |
180 | fetchEntities(parent); | 180 | fetchEntities(parent); |
181 | } | 181 | } |
182 | 182 | ||
@@ -187,7 +187,7 @@ void ModelResult<T, Ptr>::add(const Ptr &value) | |||
187 | const auto id = parentId(value); | 187 | const auto id = parentId(value); |
188 | // Ignore updates we get before the initial fetch is done | 188 | // Ignore updates we get before the initial fetch is done |
189 | if (!mEntityChildrenFetched.contains(id)) { | 189 | if (!mEntityChildrenFetched.contains(id)) { |
190 | SinkTrace() << "Too early" << id; | 190 | SinkTraceCtx(mLogCtx) << "Too early" << id; |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | if (mEntities.contains(childId)) { | 193 | if (mEntities.contains(childId)) { |
@@ -195,7 +195,7 @@ void ModelResult<T, Ptr>::add(const Ptr &value) | |||
195 | return; | 195 | return; |
196 | } | 196 | } |
197 | auto parent = createIndexFromId(id); | 197 | auto parent = createIndexFromId(id); |
198 | SinkTrace() << "Added entity " << childId << "id: " << value->identifier() << "parent: " << id; | 198 | SinkTraceCtx(mLogCtx) << "Added entity " << childId << "id: " << value->identifier() << "parent: " << id; |
199 | const auto keys = mTree[id]; | 199 | const auto keys = mTree[id]; |
200 | int index = 0; | 200 | int index = 0; |
201 | for (; index < keys.size(); index++) { | 201 | for (; index < keys.size(); index++) { |
@@ -203,13 +203,13 @@ void ModelResult<T, Ptr>::add(const Ptr &value) | |||
203 | break; | 203 | break; |
204 | } | 204 | } |
205 | } | 205 | } |
206 | // SinkTrace() << "Inserting rows " << index << parent; | 206 | // SinkTraceCtx(mLogCtx) << "Inserting rows " << index << parent; |
207 | beginInsertRows(parent, index, index); | 207 | beginInsertRows(parent, index, index); |
208 | mEntities.insert(childId, value); | 208 | mEntities.insert(childId, value); |
209 | mTree[id].insert(index, childId); | 209 | mTree[id].insert(index, childId); |
210 | mParents.insert(childId, id); | 210 | mParents.insert(childId, id); |
211 | endInsertRows(); | 211 | endInsertRows(); |
212 | // SinkTrace() << "Inserted rows " << mTree[id].size(); | 212 | // SinkTraceCtx(mLogCtx) << "Inserted rows " << mTree[id].size(); |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
@@ -219,7 +219,7 @@ void ModelResult<T, Ptr>::remove(const Ptr &value) | |||
219 | auto childId = qHash(*value); | 219 | auto childId = qHash(*value); |
220 | auto id = parentId(value); | 220 | auto id = parentId(value); |
221 | auto parent = createIndexFromId(id); | 221 | auto parent = createIndexFromId(id); |
222 | SinkTrace() << "Removed entity" << childId; | 222 | SinkTraceCtx(mLogCtx) << "Removed entity" << childId; |
223 | auto index = mTree[id].indexOf(childId); | 223 | auto index = mTree[id].indexOf(childId); |
224 | beginRemoveRows(parent, index, index); | 224 | beginRemoveRows(parent, index, index); |
225 | mEntities.remove(childId); | 225 | mEntities.remove(childId); |
@@ -236,18 +236,18 @@ void ModelResult<T, Ptr>::fetchEntities(const QModelIndex &parent) | |||
236 | const auto id = getIdentifier(parent); | 236 | const auto id = getIdentifier(parent); |
237 | mEntityChildrenFetchComplete.remove(id); | 237 | mEntityChildrenFetchComplete.remove(id); |
238 | mEntityChildrenFetched.insert(id); | 238 | mEntityChildrenFetched.insert(id); |
239 | SinkTrace() << "Loading child entities of parent " << id; | 239 | SinkTraceCtx(mLogCtx) << "Loading child entities of parent " << id; |
240 | if (loadEntities) { | 240 | if (loadEntities) { |
241 | loadEntities(parent.data(DomainObjectRole).template value<Ptr>()); | 241 | loadEntities(parent.data(DomainObjectRole).template value<Ptr>()); |
242 | } else { | 242 | } else { |
243 | SinkWarning() << "No way to fetch entities"; | 243 | SinkWarningCtx(mLogCtx) << "No way to fetch entities"; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | template <class T, class Ptr> | 247 | template <class T, class Ptr> |
248 | void ModelResult<T, Ptr>::setFetcher(const std::function<void(const Ptr &parent)> &fetcher) | 248 | void ModelResult<T, Ptr>::setFetcher(const std::function<void(const Ptr &parent)> &fetcher) |
249 | { | 249 | { |
250 | SinkTrace() << "Setting fetcher"; | 250 | SinkTraceCtx(mLogCtx) << "Setting fetcher"; |
251 | loadEntities = fetcher; | 251 | loadEntities = fetcher; |
252 | } | 252 | } |
253 | 253 | ||
@@ -262,7 +262,7 @@ void ModelResult<T, Ptr>::setEmitter(const typename Sink::ResultEmitter<Ptr>::Pt | |||
262 | }); | 262 | }); |
263 | }); | 263 | }); |
264 | emitter->onModified([this](const Ptr &value) { | 264 | emitter->onModified([this](const Ptr &value) { |
265 | SinkTrace() << "Received modification: " << value->identifier(); | 265 | SinkTraceCtx(mLogCtx) << "Received modification: " << value->identifier(); |
266 | threadBoundary.callInMainThread([this, value]() { | 266 | threadBoundary.callInMainThread([this, value]() { |
267 | modify(value); | 267 | modify(value); |
268 | }); | 268 | }); |
@@ -273,7 +273,7 @@ void ModelResult<T, Ptr>::setEmitter(const typename Sink::ResultEmitter<Ptr>::Pt | |||
273 | }); | 273 | }); |
274 | }); | 274 | }); |
275 | emitter->onInitialResultSetComplete([this](const Ptr &parent, bool fetchedAll) { | 275 | emitter->onInitialResultSetComplete([this](const Ptr &parent, bool fetchedAll) { |
276 | SinkTrace() << "Initial result set complete"; | 276 | SinkTraceCtx(mLogCtx) << "Initial result set complete"; |
277 | const qint64 parentId = parent ? qHash(*parent) : 0; | 277 | const qint64 parentId = parent ? qHash(*parent) : 0; |
278 | const auto parentIndex = createIndexFromId(parentId); | 278 | const auto parentIndex = createIndexFromId(parentId); |
279 | mEntityChildrenFetchComplete.insert(parentId); | 279 | mEntityChildrenFetchComplete.insert(parentId); |
@@ -297,7 +297,7 @@ void ModelResult<T, Ptr>::modify(const Ptr &value) | |||
297 | auto childId = qHash(*value); | 297 | auto childId = qHash(*value); |
298 | if (!mEntities.contains(childId)) { | 298 | if (!mEntities.contains(childId)) { |
299 | //Happens because the DatabaseQuery emits modifiations also if the item used to be filtered. | 299 | //Happens because the DatabaseQuery emits modifiations also if the item used to be filtered. |
300 | SinkTrace() << "Tried to modify a value that is not yet part of the model"; | 300 | SinkTraceCtx(mLogCtx) << "Tried to modify a value that is not yet part of the model"; |
301 | add(value); | 301 | add(value); |
302 | return; | 302 | return; |
303 | } | 303 | } |
@@ -307,7 +307,7 @@ void ModelResult<T, Ptr>::modify(const Ptr &value) | |||
307 | return; | 307 | return; |
308 | } | 308 | } |
309 | auto parent = createIndexFromId(id); | 309 | auto parent = createIndexFromId(id); |
310 | SinkTrace() << "Modified entity" << childId; | 310 | SinkTraceCtx(mLogCtx) << "Modified entity" << childId; |
311 | auto i = mTree[id].indexOf(childId); | 311 | auto i = mTree[id].indexOf(childId); |
312 | Q_ASSERT(i >= 0); | 312 | Q_ASSERT(i >= 0); |
313 | mEntities.remove(childId); | 313 | mEntities.remove(childId); |