summaryrefslogtreecommitdiffstats
path: root/common/modelresult.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-11-30 10:30:31 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-11-30 10:30:31 +0100
commit67d573d98da247d2cd16ce65fdd37457c5ee74ec (patch)
tree9192a07e7e0a22d1285759f541336f024928766a /common/modelresult.cpp
parent887abffb3f712acaa23eae174d5890f337fe43cb (diff)
downloadsink-67d573d98da247d2cd16ce65fdd37457c5ee74ec.tar.gz
sink-67d573d98da247d2cd16ce65fdd37457c5ee74ec.zip
ModelResult hasChildren, cleanup
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r--common/modelresult.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp
index 930048f..582f8ff 100644
--- a/common/modelresult.cpp
+++ b/common/modelresult.cpp
@@ -44,26 +44,32 @@ template<class T, class Ptr>
44qint64 ModelResult<T, Ptr>::parentId(const Ptr &value) 44qint64 ModelResult<T, Ptr>::parentId(const Ptr &value)
45{ 45{
46 if (!mQuery.parentProperty.isEmpty()) { 46 if (!mQuery.parentProperty.isEmpty()) {
47 return qHash(value->getProperty(mQuery.parentProperty).toByteArray()); 47 const auto property = value->getProperty(mQuery.parentProperty).toByteArray();
48 if (!property.isEmpty()) {
49 return qHash(property);
50 }
48 } 51 }
49 return qHash(QByteArray()); 52 return 0;
50} 53}
51 54
52template<class T, class Ptr> 55template<class T, class Ptr>
53int ModelResult<T, Ptr>::rowCount(const QModelIndex &parent) const 56int ModelResult<T, Ptr>::rowCount(const QModelIndex &parent) const
54{ 57{
58 qDebug() << "row count " << mTree[getIdentifier(parent)].size();
55 return mTree[getIdentifier(parent)].size(); 59 return mTree[getIdentifier(parent)].size();
56} 60}
57 61
58template<class T, class Ptr> 62template<class T, class Ptr>
59int ModelResult<T, Ptr>::columnCount(const QModelIndex &parent) const 63int ModelResult<T, Ptr>::columnCount(const QModelIndex &parent) const
60{ 64{
65 qDebug() << "porperty count " << mPropertyColumns.size();
61 return mPropertyColumns.size(); 66 return mPropertyColumns.size();
62} 67}
63 68
64template<class T, class Ptr> 69template<class T, class Ptr>
65QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const 70QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const
66{ 71{
72 qDebug() << index;
67 if (role == DomainObjectRole) { 73 if (role == DomainObjectRole) {
68 Q_ASSERT(mEntities.contains(index.internalId())); 74 Q_ASSERT(mEntities.contains(index.internalId()));
69 return QVariant::fromValue(mEntities.value(index.internalId())); 75 return QVariant::fromValue(mEntities.value(index.internalId()));
@@ -83,8 +89,8 @@ QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const
83template<class T, class Ptr> 89template<class T, class Ptr>
84QModelIndex ModelResult<T, Ptr>::index(int row, int column, const QModelIndex &parent) const 90QModelIndex ModelResult<T, Ptr>::index(int row, int column, const QModelIndex &parent) const
85{ 91{
86 auto id = getIdentifier(parent); 92 const auto id = getIdentifier(parent);
87 auto childId = mTree.value(id).at(row); 93 const auto childId = mTree.value(id).at(row);
88 return createIndex(row, column, childId); 94 return createIndex(row, column, childId);
89} 95}
90 96
@@ -105,6 +111,15 @@ QModelIndex ModelResult<T, Ptr>::parent(const QModelIndex &index) const
105} 111}
106 112
107template<class T, class Ptr> 113template<class T, class Ptr>
114bool ModelResult<T, Ptr>::hasChildren(const QModelIndex &parent) const
115{
116 if (mQuery.parentProperty.isEmpty() && parent.isValid()) {
117 return false;
118 }
119 return QAbstractItemModel::hasChildren(parent);
120}
121
122template<class T, class Ptr>
108bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const 123bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const
109{ 124{
110 qDebug() << "Can fetch more: " << parent << mEntityChildrenFetched.value(parent.internalId()); 125 qDebug() << "Can fetch more: " << parent << mEntityChildrenFetched.value(parent.internalId());
@@ -121,8 +136,8 @@ void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent)
121template<class T, class Ptr> 136template<class T, class Ptr>
122void ModelResult<T, Ptr>::add(const Ptr &value) 137void ModelResult<T, Ptr>::add(const Ptr &value)
123{ 138{
124 auto childId = qHash(value->identifier()); 139 const auto childId = qHash(value->identifier());
125 auto id = parentId(value); 140 const auto id = parentId(value);
126 //Ignore updates we get before the initial fetch is done 141 //Ignore updates we get before the initial fetch is done
127 if (!mEntityChildrenFetched[id]) { 142 if (!mEntityChildrenFetched[id]) {
128 return; 143 return;