diff --git a/src/libs/models/AllocatedResourceItemModel.cpp b/src/libs/models/AllocatedResourceItemModel.cpp index 46aab6f1..71898aad 100644 --- a/src/libs/models/AllocatedResourceItemModel.cpp +++ b/src/libs/models/AllocatedResourceItemModel.cpp @@ -1,236 +1,215 @@ /* This file is part of the KDE project * Copyright (C) 2007 Dag Andersen * Copyright (C) 2011, 2012 Dag Andersen * Copyright (C) 2016 Dag Andersen * Copyright (C) 2019 Dag Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ // clazy:excludeall=qstring-arg #include "AllocatedResourceItemModel.h" #include "ResourceItemModel.h" #include "kptlocale.h" #include "kptcommonstrings.h" #include #include "kptcommand.h" #include "kptitemmodelbase.h" #include "kptcalendar.h" #include "kptduration.h" #include "kptnode.h" #include "kptproject.h" #include "kpttask.h" #include "kptresource.h" #include "kptdatetime.h" #include "kptdebug.h" #include #include #include #include #include #include #include #ifdef PLAN_KCONTACTS_FOUND #include #include #endif using namespace KPlato; AllocatedResourceItemModel::AllocatedResourceItemModel(QObject *parent) : QSortFilterProxyModel(parent), m_task(0) { setDynamicSortFilter(true); setSourceModel(new ResourceItemModel(this)); } int AllocatedResourceItemModel::columnCount(const QModelIndex &idx) const { Q_UNUSED(idx); return 2; } Project *AllocatedResourceItemModel::project() const { return static_cast(sourceModel())->project(); } void AllocatedResourceItemModel::setProject(Project *project) { debugPlan<project()<<"="<project(); if (p) { disconnect(p, &Project::nodeChanged, this, &AllocatedResourceItemModel::slotNodeChanged); } static_cast(sourceModel())->setProject(project); if (project) { connect(project, &Project::nodeChanged, this, &AllocatedResourceItemModel::slotNodeChanged); } debugPlan<rowCount(); } void AllocatedResourceItemModel::reset() { beginResetModel(); endResetModel(); emit expandAll(); emit resizeColumnToContents(0); } void AllocatedResourceItemModel::slotNodeChanged(Node *n) { debugPlan<<(n==m_task)<name(); if (n != m_task) { return; } reset(); } Task *AllocatedResourceItemModel::task() const { return m_task; } void AllocatedResourceItemModel::setTask(Task *task) { debugPlan<name():""); m_task = task; reset(); debugPlan<rowCount(); } -QObject* AllocatedResourceItemModel::object(const QModelIndex& idx) const -{ - return nullptr; //TODO static_cast(sourceModel())->object(mapToSource(idx)); -} - Resource *AllocatedResourceItemModel::resource(const QModelIndex &idx) const { QModelIndex sidx = mapToSource(idx); if (sidx.isValid() && sidx.internalPointer() == nullptr) { return project()->resourceAt(sidx.row()); } return nullptr; } QModelIndex AllocatedResourceItemModel::index(Resource *r) const { return mapFromSource(static_cast(sourceModel())->index(project()->indexOf(r), 0)); } Qt::ItemFlags AllocatedResourceItemModel::flags(const QModelIndex & index) const { Qt::ItemFlags f = QSortFilterProxyModel::flags(index); f &= ~Qt::ItemIsUserCheckable; return f; } QVariant AllocatedResourceItemModel::headerData(int section, Qt::Orientation orientation, int role) const { if (section == 1) { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { return xi18nc("@title:column", "Allocation"); } return QVariant(); } return QSortFilterProxyModel::headerData(section, orientation, role); } QVariant AllocatedResourceItemModel::allocation(const Resource *res, int role) const { ResourceRequest *rr = m_task->requests().find(res); if (rr == nullptr) { return QVariant(); } switch (role) { case Qt::DisplayRole: { case Qt::EditRole: // xgettext: no-c-format return i18nc("%", "%1%",rr->units()); } case Qt::ToolTipRole: { if (rr->units() == 0) { return xi18nc("@info:tooltip", "Not allocated"); } break; } default: break; } return QVariant(); } -QVariant AllocatedResourceItemModel::allocation(const ResourceGroup *res, int role) const -{ - // TODO - return QVariant(); -} - QVariant AllocatedResourceItemModel::data(const QModelIndex& idx, int role) const { if (m_task == 0 || role == Qt::CheckStateRole || role == Qt::DecorationRole) { return QVariant(); } if (idx.column() == 1) { switch (role) { case Qt::TextAlignmentRole: return Qt::AlignLeft; default: { - QObject *o = object(idx); - Resource *r = qobject_cast(o); + Resource *r = resource(idx); if (r) { return allocation(r, role); } - ResourceGroup *g = qobject_cast(o); - if (g) { - return allocation(g, role); - } break; } return QVariant(); } } return QSortFilterProxyModel::data(idx, role); } bool AllocatedResourceItemModel::filterAcceptsRow(int source_row, const QModelIndex & source_parent) const { - if (m_task == 0) { + if (m_task == nullptr || source_parent.isValid()) { return false; } QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); if (!idx.isValid()) { return false; } - bool result = false; - const ResourceRequestCollection &req = m_task->requests(); - if (source_parent.isValid()) { - const Resource *r = static_cast(sourceModel())->resource(idx); - result = (bool) req.find(r); - } else { - // TODO + const Resource *resource = static_cast(sourceModel())->resource(idx); + if (resource == nullptr) { + return false; } - debugPlan<requests().find(resource) != nullptr; } diff --git a/src/libs/models/AllocatedResourceItemModel.h b/src/libs/models/AllocatedResourceItemModel.h index df71078c..1830312e 100644 --- a/src/libs/models/AllocatedResourceItemModel.h +++ b/src/libs/models/AllocatedResourceItemModel.h @@ -1,90 +1,87 @@ /* This file is part of the KDE project * Copyright (C) 2019 Dag Andersen * Copyright (C) 2007 Dag Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef ALLOCATEDRESOURCEITEMMODEL_H #define ALLOCATEDRESOURCEITEMMODEL_H #include "planmodels_export.h" #include #include #include class QByteArray; namespace KIO { class Job; } class KJob; namespace KPlato { class Project; class Resource; -class ResourceGroup; class Calendar; class Task; class Node; class PLANMODELS_EXPORT AllocatedResourceItemModel : public QSortFilterProxyModel { Q_OBJECT public: explicit AllocatedResourceItemModel(QObject *parent = 0); int columnCount(const QModelIndex &idx) const override; Project *project() const; Task *task() const; Resource *resource(const QModelIndex &index) const; using QAbstractProxyModel::index; QModelIndex index(Resource *r) const; Qt::ItemFlags flags(const QModelIndex & index) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant data(const QModelIndex &idx, int role) const override; public Q_SLOTS: void setProject(KPlato::Project *project); void setTask(KPlato::Task *task); Q_SIGNALS: void expandAll(); void resizeColumnToContents(int); protected Q_SLOTS: void slotNodeChanged(KPlato::Node *n); protected: bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override; void reset(); - QObject *object(const QModelIndex &idx) const; QVariant allocation(const Resource *r, int role) const; - QVariant allocation(const ResourceGroup *g, int role) const; Task *m_task; }; } //KPlato namespace #endif