diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-16 17:43:22 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-16 17:43:22 +0100 |
commit | 529dd17eec62a9702b8837f8f1976dfbf28fdd82 (patch) | |
tree | 3fe5581a76b83cd9c4360b67e7dd99ceb8c0eaab /common/modelresult.cpp | |
parent | 8acaae496f9e816c4c1b1126fc6409b6fafe6500 (diff) | |
download | sink-529dd17eec62a9702b8837f8f1976dfbf28fdd82.tar.gz sink-529dd17eec62a9702b8837f8f1976dfbf28fdd82.zip |
Prepared sort indexes
Diffstat (limited to 'common/modelresult.cpp')
-rw-r--r-- | common/modelresult.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp index f28c665..5b5a473 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp | |||
@@ -27,9 +27,9 @@ | |||
27 | #undef DEBUG_AREA | 27 | #undef DEBUG_AREA |
28 | #define DEBUG_AREA "client.modelresult" | 28 | #define DEBUG_AREA "client.modelresult" |
29 | 29 | ||
30 | static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type) | 30 | static uint qHash(const Sink::ApplicationDomain::ApplicationDomainType &type) |
31 | { | 31 | { |
32 | Q_ASSERT(!type.resourceInstanceIdentifier().isEmpty()); | 32 | // Q_ASSERT(!type.resourceInstanceIdentifier().isEmpty()); |
33 | Q_ASSERT(!type.identifier().isEmpty()); | 33 | Q_ASSERT(!type.identifier().isEmpty()); |
34 | return qHash(type.resourceInstanceIdentifier() + type.identifier()); | 34 | return qHash(type.resourceInstanceIdentifier() + type.identifier()); |
35 | } | 35 | } |
@@ -88,18 +88,18 @@ QVariant ModelResult<T, Ptr>::headerData(int section, Qt::Orientation orientatio | |||
88 | template<class T, class Ptr> | 88 | template<class T, class Ptr> |
89 | QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const | 89 | QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const |
90 | { | 90 | { |
91 | if (role == DomainObjectRole) { | 91 | if (role == DomainObjectRole && index.isValid()) { |
92 | Q_ASSERT(mEntities.contains(index.internalId())); | 92 | Q_ASSERT(mEntities.contains(index.internalId())); |
93 | return QVariant::fromValue(mEntities.value(index.internalId())); | 93 | return QVariant::fromValue(mEntities.value(index.internalId())); |
94 | } | 94 | } |
95 | if (role == DomainObjectBaseRole) { | 95 | if (role == DomainObjectBaseRole && index.isValid()) { |
96 | Q_ASSERT(mEntities.contains(index.internalId())); | 96 | Q_ASSERT(mEntities.contains(index.internalId())); |
97 | return QVariant::fromValue(mEntities.value(index.internalId()). template staticCast<Sink::ApplicationDomain::ApplicationDomainType>()); | 97 | return QVariant::fromValue(mEntities.value(index.internalId()). template staticCast<Sink::ApplicationDomain::ApplicationDomainType>()); |
98 | } | 98 | } |
99 | if (role == ChildrenFetchedRole) { | 99 | if (role == ChildrenFetchedRole) { |
100 | return childrenFetched(index); | 100 | return childrenFetched(index); |
101 | } | 101 | } |
102 | if (role == Qt::DisplayRole) { | 102 | if (role == Qt::DisplayRole && index.isValid()) { |
103 | if (index.column() < mPropertyColumns.size()) { | 103 | if (index.column() < mPropertyColumns.size()) { |
104 | Q_ASSERT(mEntities.contains(index.internalId())); | 104 | Q_ASSERT(mEntities.contains(index.internalId())); |
105 | auto entity = mEntities.value(index.internalId()); | 105 | auto entity = mEntities.value(index.internalId()); |
@@ -115,8 +115,13 @@ template<class T, class Ptr> | |||
115 | QModelIndex ModelResult<T, Ptr>::index(int row, int column, const QModelIndex &parent) const | 115 | QModelIndex ModelResult<T, Ptr>::index(int row, int column, const QModelIndex &parent) const |
116 | { | 116 | { |
117 | const auto id = getIdentifier(parent); | 117 | const auto id = getIdentifier(parent); |
118 | const auto childId = mTree.value(id).at(row); | 118 | const auto list = mTree.value(id); |
119 | return createIndex(row, column, childId); | 119 | if (list.size() > row) { |
120 | const auto childId = list.at(row); | ||
121 | return createIndex(row, column, childId); | ||
122 | } | ||
123 | Warning() << "Index not available " << row << column << parent; | ||
124 | return QModelIndex(); | ||
120 | } | 125 | } |
121 | 126 | ||
122 | template<class T, class Ptr> | 127 | template<class T, class Ptr> |
@@ -156,6 +161,7 @@ bool ModelResult<T, Ptr>::canFetchMore(const QModelIndex &parent) const | |||
156 | template<class T, class Ptr> | 161 | template<class T, class Ptr> |
157 | void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent) | 162 | void ModelResult<T, Ptr>::fetchMore(const QModelIndex &parent) |
158 | { | 163 | { |
164 | Trace() << "Fetching more: " << parent; | ||
159 | fetchEntities(parent); | 165 | fetchEntities(parent); |
160 | } | 166 | } |
161 | 167 | ||