diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-30 10:30:31 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-30 10:30:31 +0100 |
commit | 67d573d98da247d2cd16ce65fdd37457c5ee74ec (patch) | |
tree | 9192a07e7e0a22d1285759f541336f024928766a /common/modelresult.cpp | |
parent | 887abffb3f712acaa23eae174d5890f337fe43cb (diff) | |
download | sink-67d573d98da247d2cd16ce65fdd37457c5ee74ec.tar.gz sink-67d573d98da247d2cd16ce65fdd37457c5ee74ec.zip |
ModelResult hasChildren, cleanup
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r-- | common/modelresult.cpp | 27 |
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> | |||
44 | qint64 ModelResult<T, Ptr>::parentId(const Ptr &value) | 44 | qint64 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 | ||
52 | template<class T, class Ptr> | 55 | template<class T, class Ptr> |
53 | int ModelResult<T, Ptr>::rowCount(const QModelIndex &parent) const | 56 | int 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 | ||
58 | template<class T, class Ptr> | 62 | template<class T, class Ptr> |
59 | int ModelResult<T, Ptr>::columnCount(const QModelIndex &parent) const | 63 | int 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 | ||
64 | template<class T, class Ptr> | 69 | template<class T, class Ptr> |
65 | QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const | 70 | QVariant 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 | |||
83 | template<class T, class Ptr> | 89 | template<class T, class Ptr> |
84 | QModelIndex ModelResult<T, Ptr>::index(int row, int column, const QModelIndex &parent) const | 90 | QModelIndex 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 | ||
107 | template<class T, class Ptr> | 113 | template<class T, class Ptr> |
114 | bool 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 | |||
122 | template<class T, class Ptr> | ||
108 | bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const | 123 | bool 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) | |||
121 | template<class T, class Ptr> | 136 | template<class T, class Ptr> |
122 | void ModelResult<T, Ptr>::add(const Ptr &value) | 137 | void 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; |