diff --git a/src/presentation/workdaypagemodel.cpp b/src/presentation/workdaypagemodel.cpp --- a/src/presentation/workdaypagemodel.cpp +++ b/src/presentation/workdaypagemodel.cpp @@ -99,18 +99,26 @@ return task ? (defaultFlags | Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled) : defaultFlags; }; - using AdditionalInfo = Domain::QueryResult::Ptr; // later on we'll want a struct with the context query as well + struct AdditionalData + { + bool childTask = false; + Domain::QueryResult::Ptr projectQueryResult; + // later on we'll want the context query as well + }; + using AdditionalInfo = QSharedPointer; - auto data = [](const Domain::Task::Ptr &task, int role, const AdditionalInfo &projectQueryResult) -> QVariant { + auto data = [](const Domain::Task::Ptr &task, int role, const AdditionalInfo &info) -> QVariant { switch (role) { case Qt::DisplayRole: case Qt::EditRole: return task->title(); case Qt::CheckStateRole: return task->isDone() ? Qt::Checked : Qt::Unchecked; case Presentation::QueryTreeModelBase::AdditionalInfoRole: - if (projectQueryResult && !projectQueryResult->data().isEmpty()) { - Domain::Project::Ptr project = projectQueryResult->data().at(0); + if (!info || info->childTask) + return QString(); + if (info->projectQueryResult && !info->projectQueryResult->data().isEmpty()) { + Domain::Project::Ptr project = info->projectQueryResult->data().at(0); return i18n("Project: %1", project->name()); } return i18n("Inbox"); // TODO add source name @@ -121,19 +129,22 @@ }; auto fetchAdditionalInfo = [this](const QModelIndex &index, const Domain::Task::Ptr &task) -> AdditionalInfo { - if (index.parent().isValid()) // children are in the same collection as their parent, so the same project - return nullptr; + AdditionalInfo info = AdditionalInfo::create(); + if (index.parent().isValid()) { // children are in the same collection as their parent, so the same project + info->childTask = true; + return info; + } - AdditionalInfo projectQueryResult = m_taskQueries->findProject(task); - if (projectQueryResult) { + info->projectQueryResult = m_taskQueries->findProject(task); + if (info->projectQueryResult) { QPersistentModelIndex persistentIndex(index); - projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { + info->projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { // When a project was found (inserted into the result), update the rendering of the item auto model = const_cast(persistentIndex.model()); model->dataChanged(persistentIndex, persistentIndex); }); } - return projectQueryResult; + return info; }; auto setData = [this](const Domain::Task::Ptr &task, const QVariant &value, int role) { diff --git a/tests/units/presentation/workdaypagemodeltest.cpp b/tests/units/presentation/workdaypagemodeltest.cpp --- a/tests/units/presentation/workdaypagemodeltest.cpp +++ b/tests/units/presentation/workdaypagemodeltest.cpp @@ -172,6 +172,8 @@ QCOMPARE(model->data(task1Index, Presentation::QueryTreeModelBase::AdditionalInfoRole).toString(), QString("Inbox")); QCOMPARE(model->data(task2Index, Presentation::QueryTreeModelBase::AdditionalInfoRole).toString(), QString("Project: KDE")); + QCOMPARE(model->data(childTask11Index, Presentation::QueryTreeModelBase::AdditionalInfoRole).toString(), QString()); + QCOMPARE(model->data(childTask12Index, Presentation::QueryTreeModelBase::AdditionalInfoRole).toString(), QString()); // WHEN taskRepositoryMock(&Domain::TaskRepository::update).when(task1).thenReturn(new FakeJob(this));