From 67d573d98da247d2cd16ce65fdd37457c5ee74ec Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 10:30:31 +0100 Subject: ModelResult hasChildren, cleanup --- common/modelresult.cpp | 27 +++++++++++++++++++++------ common/modelresult.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'common') 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 qint64 ModelResult::parentId(const Ptr &value) { if (!mQuery.parentProperty.isEmpty()) { - return qHash(value->getProperty(mQuery.parentProperty).toByteArray()); + const auto property = value->getProperty(mQuery.parentProperty).toByteArray(); + if (!property.isEmpty()) { + return qHash(property); + } } - return qHash(QByteArray()); + return 0; } template int ModelResult::rowCount(const QModelIndex &parent) const { + qDebug() << "row count " << mTree[getIdentifier(parent)].size(); return mTree[getIdentifier(parent)].size(); } template int ModelResult::columnCount(const QModelIndex &parent) const { + qDebug() << "porperty count " << mPropertyColumns.size(); return mPropertyColumns.size(); } template QVariant ModelResult::data(const QModelIndex &index, int role) const { + qDebug() << index; if (role == DomainObjectRole) { Q_ASSERT(mEntities.contains(index.internalId())); return QVariant::fromValue(mEntities.value(index.internalId())); @@ -83,8 +89,8 @@ QVariant ModelResult::data(const QModelIndex &index, int role) const template QModelIndex ModelResult::index(int row, int column, const QModelIndex &parent) const { - auto id = getIdentifier(parent); - auto childId = mTree.value(id).at(row); + const auto id = getIdentifier(parent); + const auto childId = mTree.value(id).at(row); return createIndex(row, column, childId); } @@ -104,6 +110,15 @@ QModelIndex ModelResult::parent(const QModelIndex &index) const return createIndexFromId(parentId); } +template +bool ModelResult::hasChildren(const QModelIndex &parent) const +{ + if (mQuery.parentProperty.isEmpty() && parent.isValid()) { + return false; + } + return QAbstractItemModel::hasChildren(parent); +} + template bool ModelResult::canFetchMore(const QModelIndex &parent) const { @@ -121,8 +136,8 @@ void ModelResult::fetchMore(const QModelIndex &parent) template void ModelResult::add(const Ptr &value) { - auto childId = qHash(value->identifier()); - auto id = parentId(value); + const auto childId = qHash(value->identifier()); + const auto id = parentId(value); //Ignore updates we get before the initial fetch is done if (!mEntityChildrenFetched[id]) { return; diff --git a/common/modelresult.h b/common/modelresult.h index eb6c86b..3ccf629 100644 --- a/common/modelresult.h +++ b/common/modelresult.h @@ -45,6 +45,7 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; QModelIndex parent(const QModelIndex &index) const; + bool hasChildren(const QModelIndex &parent = QModelIndex()) const; bool canFetchMore(const QModelIndex &parent) const; void fetchMore(const QModelIndex &parent); -- cgit v1.2.3