diff --git a/src/libs/models/kptschedulemodel.cpp b/src/libs/models/kptschedulemodel.cpp index 8c2d6613..60115ec1 100644 --- a/src/libs/models/kptschedulemodel.cpp +++ b/src/libs/models/kptschedulemodel.cpp @@ -1,1356 +1,1358 @@ /* This file is part of the KDE project Copyright (C) 2007, 2012 Dag Andersen danders@get2net> Copyright (C) 2016 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 "kptschedulemodel.h" #include "kptglobal.h" #include "kptcommonstrings.h" #include "kptcommand.h" #include "kptitemmodelbase.h" #include "kptduration.h" #include "kptnode.h" #include "kptproject.h" #include "kpttask.h" #include "kptresource.h" #include "kptschedule.h" #include "kptdatetime.h" #include "kptschedulerplugin.h" #include "kptdebug.h" #include #include #include #include #include namespace KPlato { //-------------------------------------- // internal, for displaying schedule name + state #define SpecialScheduleDisplayRole 99999999 ScheduleModel::ScheduleModel(QObject *parent) : QObject(parent) { } ScheduleModel::~ScheduleModel() { } const QMetaEnum ScheduleModel::columnMap() const { return metaObject()->enumerator(metaObject()->indexOfEnumerator("Properties")); } int ScheduleModel::propertyCount() const { return columnMap().keyCount(); } //-------------------------------------- ScheduleItemModel::ScheduleItemModel(QObject *parent) : ItemModelBase(parent), m_manager(0), m_flat(false) { } ScheduleItemModel::~ScheduleItemModel() { } void ScheduleItemModel::slotScheduleManagerToBeInserted(const ScheduleManager *parent, int row) { //debugPlan<(parent); beginInsertRows(index(parent), row, row); } void ScheduleItemModel::slotScheduleManagerInserted(const ScheduleManager *manager) { //debugPlan<name(); if (m_flat) { int row = m_project->allScheduleManagers().indexOf(const_cast(manager)); Q_ASSERT(row >= 0); beginInsertRows(QModelIndex(), row, row); m_managerlist.insert(row, const_cast(manager)); endInsertRows(); emit scheduleManagerAdded(const_cast(manager)); return; } Q_ASSERT(manager->parentManager() == m_manager); endInsertRows(); m_manager = 0; emit scheduleManagerAdded(const_cast(manager)); } void ScheduleItemModel::slotScheduleManagerToBeRemoved(const ScheduleManager *manager) { //debugPlan<name(); if (m_flat) { int row = m_managerlist.indexOf(const_cast(manager)); beginRemoveRows(QModelIndex(), row, row); m_managerlist.removeAt(row); return; } Q_ASSERT(m_manager == 0); m_manager = const_cast(manager); QModelIndex i = index(manager); int row = i.row(); beginRemoveRows(parent(i), row, row); } void ScheduleItemModel::slotScheduleManagerRemoved(const ScheduleManager *manager) { //debugPlan<name(); if (m_flat) { endRemoveRows(); return; } Q_ASSERT(manager == m_manager); Q_UNUSED(manager); endRemoveRows(); m_manager = 0; } void ScheduleItemModel::slotScheduleManagerToBeMoved(const ScheduleManager *manager) { //debugPlan<name()<<"from"<<(manager->parentManager()?manager->parentManager()->name():"project"); slotScheduleManagerToBeRemoved(manager); } void ScheduleItemModel::slotScheduleManagerMoved(const ScheduleManager *manager, int index) { //debugPlan<name()<<"to"<parentManager()<parentManager(), index); slotScheduleManagerInserted(manager); } void ScheduleItemModel::slotScheduleToBeInserted(const ScheduleManager *, int /*row*/) { } void ScheduleItemModel::slotScheduleInserted(const MainSchedule *) { } void ScheduleItemModel::slotScheduleToBeRemoved(const MainSchedule *) { } void ScheduleItemModel::slotScheduleRemoved(const MainSchedule *) { } void ScheduleItemModel::setProject(Project *project) { beginResetModel(); if (m_project) { disconnect(m_project, &Project::aboutToBeDeleted, this, &ScheduleItemModel::projectDeleted); disconnect(m_project, &Project::scheduleManagerChanged, this, &ScheduleItemModel::slotManagerChanged); disconnect(m_project, &Project::scheduleManagerToBeAdded, this, &ScheduleItemModel::slotScheduleManagerToBeInserted); disconnect(m_project, &Project::scheduleManagerToBeRemoved, this, &ScheduleItemModel::slotScheduleManagerToBeRemoved); disconnect(m_project, &Project::scheduleManagerAdded, this, &ScheduleItemModel::slotScheduleManagerInserted); disconnect(m_project, &Project::scheduleManagerRemoved, this, &ScheduleItemModel::slotScheduleManagerRemoved); disconnect(m_project, &Project::scheduleManagerToBeMoved, this, &ScheduleItemModel::slotScheduleManagerToBeMoved); disconnect(m_project, &Project::scheduleManagerMoved, this, &ScheduleItemModel::slotScheduleManagerMoved); disconnect(m_project, &Project::scheduleChanged, this, &ScheduleItemModel::slotScheduleChanged); disconnect(m_project, &Project::scheduleToBeAdded, this, &ScheduleItemModel::slotScheduleToBeInserted); disconnect(m_project, &Project::scheduleToBeRemoved, this, &ScheduleItemModel::slotScheduleToBeRemoved); disconnect(m_project, &Project::scheduleAdded, this, &ScheduleItemModel::slotScheduleInserted); disconnect(m_project, &Project::scheduleRemoved, this, &ScheduleItemModel::slotScheduleRemoved); } m_project = project; if (m_project) { connect(m_project, &Project::aboutToBeDeleted, this, &ScheduleItemModel::projectDeleted); connect(m_project, &Project::scheduleManagerChanged, this, &ScheduleItemModel::slotManagerChanged); connect(m_project, &Project::scheduleManagerToBeAdded, this, &ScheduleItemModel::slotScheduleManagerToBeInserted); connect(m_project, &Project::scheduleManagerToBeRemoved, this, &ScheduleItemModel::slotScheduleManagerToBeRemoved); connect(m_project, &Project::scheduleManagerAdded, this, &ScheduleItemModel::slotScheduleManagerInserted); connect(m_project, &Project::scheduleManagerRemoved, this, &ScheduleItemModel::slotScheduleManagerRemoved); connect(m_project, &Project::scheduleManagerToBeMoved, this, &ScheduleItemModel::slotScheduleManagerToBeMoved); connect(m_project, &Project::scheduleManagerMoved, this, &ScheduleItemModel::slotScheduleManagerMoved); connect(m_project, &Project::scheduleChanged, this, &ScheduleItemModel::slotScheduleChanged); connect(m_project, &Project::scheduleToBeAdded, this, &ScheduleItemModel::slotScheduleToBeInserted); connect(m_project, &Project::scheduleToBeRemoved, this, &ScheduleItemModel::slotScheduleToBeRemoved); connect(m_project, &Project::scheduleAdded, this, &ScheduleItemModel::slotScheduleInserted); connect(m_project, &Project::scheduleRemoved, this, &ScheduleItemModel::slotScheduleRemoved); } setFlat(m_flat); // update m_managerlist endResetModel(); } void ScheduleItemModel::slotManagerChanged(ScheduleManager *sch) { if (m_flat) { int row = m_managerlist.indexOf(sch); emit dataChanged(createIndex(row, 0, sch), createIndex(row, columnCount() - 1, sch)); return; } int r = sch->parentManager() ? sch->parentManager()->indexOf(sch) : m_project->indexOf(sch); //debugPlan<schedulerPlugin(); if (pl == 0) { return flags; } int capabilities = pl->capabilities(); flags &= ~Qt::ItemIsEditable; if (sm && ! sm->isBaselined()) { switch (index.column()) { case ScheduleModel::ScheduleName: if (!hasChildren(index) && !index.parent().isValid()) { flags |= Qt::ItemIsUserCheckable; } flags |= Qt::ItemIsEditable; break; case ScheduleModel::ScheduleState: break; case ScheduleModel::ScheduleMode: if (!sm->isBaselined() && !hasChildren(index) && !index.parent().isValid()) { flags |= Qt::ItemIsEditable; } break; case ScheduleModel::ScheduleOverbooking: if (capabilities & SchedulerPlugin::AllowOverbooking && capabilities & SchedulerPlugin::AvoidOverbooking) { flags |= Qt::ItemIsEditable; } break; case ScheduleModel::ScheduleDirection: if (sm->parentManager() == 0 && capabilities & SchedulerPlugin::ScheduleForward && capabilities & SchedulerPlugin::ScheduleBackward) { flags |= Qt::ItemIsEditable; } break; case ScheduleModel::SchedulePlannedStart: break; case ScheduleModel::SchedulePlannedFinish: break; case ScheduleModel::ScheduleGranularity: if (! sm->supportedGranularities().isEmpty()) { flags |= Qt::ItemIsEditable; } break; default: flags |= Qt::ItemIsEditable; break; } } return flags; } QModelIndex ScheduleItemModel::parent(const QModelIndex &inx) const { if (!inx.isValid() || m_project == 0 || m_flat) { return QModelIndex(); } //debugPlan<parentManager()); } QModelIndex ScheduleItemModel::index(int row, int column, const QModelIndex &parent) const { //debugPlan<= columnCount() || row < 0 || row >= rowCount(parent)) { //debugPlan<children().value(row)); } return createIndex(row, column, m_project->scheduleManagers().value(row)); } QModelIndex ScheduleItemModel::index(const ScheduleManager *manager) const { if (m_project == 0 || manager == 0) { return QModelIndex(); } if (m_flat) { return createIndex(m_managerlist.indexOf(const_cast(manager)), 0, const_cast(manager)); } if (manager->parentManager() == 0) { return createIndex(m_project->indexOf(manager), 0, const_cast(manager)); } return createIndex(manager->parentManager()->indexOf(manager), 0, const_cast(manager)); } int ScheduleItemModel::columnCount(const QModelIndex &/*parent*/) const { return m_model.propertyCount(); } int ScheduleItemModel::rowCount(const QModelIndex &parent) const { if (m_project == 0) { return 0; } if (m_flat) { return m_managerlist.count(); } if (!parent.isValid()) { return m_project->numScheduleManagers(); } ScheduleManager *sm = manager(parent); if (sm) { //debugPlan<name()<<","<children().count(); return sm->children().count(); } return 0; } QVariant ScheduleItemModel::name(const QModelIndex &index, int role) const { ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::DisplayRole: case Qt::EditRole: return sm->name(); case Qt::StatusTipRole: case Qt::ToolTipRole: case Qt::WhatsThisRole: break; case Qt::DecorationRole: if (sm->isBaselined()) { return koIcon("view-time-schedule-baselined"); } return QVariant(); default: break; } return QVariant(); } bool ScheduleItemModel::setName(const QModelIndex &index, const QVariant &value, int role) { ScheduleManager *sm = manager (index); if (sm == 0) { return false; } switch (role) { case Qt::EditRole: emit executeCommand(new ModifyScheduleManagerNameCmd(*sm, value.toString(), kundo2_i18n("Modify schedule name"))); return true; default: break; } return false; } QVariant ScheduleItemModel::schedulingMode(const QModelIndex &index, int role) const { ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::DisplayRole: return schedulingMode(index, Role::EnumList).toList().value(sm->schedulingMode()); case Qt::EditRole: return sm->schedulingMode(); case Qt::StatusTipRole: break; case Qt::ToolTipRole: if (sm->schedulingMode() == ScheduleManager::ManualMode) { return xi18nc("@info:tooltip", "The schedule is in Manual Mode, calculation must be initiated manually"); } return xi18nc("@info:tooltip", "The schedule is in Auto Mode, it will be calculated automatically"); case Qt::WhatsThisRole: break; case Role::EnumList: return QStringList() << xi18nc("@label:listbox", "Manual") << xi18nc("@label:listbox", "Auto"); case Role::EnumListValue: return sm->schedulingMode(); default: break; } return QVariant(); } bool ScheduleItemModel::setSchedulingMode(const QModelIndex &index, const QVariant &value, int role) { ScheduleManager *sm = manager (index); if (sm == 0) { return false; } switch (role) { case Qt::EditRole: emit executeCommand(new ModifyScheduleManagerSchedulingModeCmd(*sm, value.toInt(), kundo2_i18n("Modify scheduling mode"))); return true; default: break; } return false; } QVariant ScheduleItemModel::state(const QModelIndex &index, int role) const { ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::DisplayRole: { if (sm->progress() > 0) { return sm->progress(); } QStringList l = sm->state(); if (l.isEmpty()) { return ""; } return l.first(); } case Qt::EditRole: { QStringList l = sm->state(); if (l.isEmpty()) { return ""; } return l.first(); } case Qt::ToolTipRole: return sm->state().join(", "); case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); case Role::Maximum: return sm->maxProgress(); case Role::Minimum: return 0; case SpecialScheduleDisplayRole: { QString st; if (!sm->isScheduled()) { st = sm->state().value(0); if (sm->progress() > 0) { st = QString("%1 %2%").arg(st).arg(sm->progress()); } } return st; } } return QVariant(); } bool ScheduleItemModel::setState(const QModelIndex &, const QVariant &, int role) { switch (role) { case Qt::EditRole: return false; } return false; } QVariant ScheduleItemModel::allowOverbooking(const QModelIndex &index, int role) const { ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } SchedulerPlugin *pl = sm->schedulerPlugin(); if (pl == 0) { return QVariant(); } int capabilities = pl->capabilities(); switch (role) { case Qt::EditRole: return sm->allowOverbooking(); case Qt::DisplayRole: if (capabilities & SchedulerPlugin::AllowOverbooking && capabilities & SchedulerPlugin::AvoidOverbooking) { return sm->allowOverbooking() ? i18n("Allow") : i18n("Avoid"); } if (capabilities & SchedulerPlugin::AllowOverbooking) { return sm->allowOverbooking() ? i18n("Allow") : i18n("(Avoid)"); } if (capabilities & SchedulerPlugin::AvoidOverbooking) { return sm->allowOverbooking() ? i18n("(Allow)") : i18n("Avoid"); } break; case Qt::ToolTipRole: if (capabilities & SchedulerPlugin::AllowOverbooking && capabilities & SchedulerPlugin::AvoidOverbooking) { return sm->allowOverbooking() ? xi18nc("@info:tooltip", "Allow overbooking resources") : xi18nc("@info:tooltip", "Avoid overbooking resources"); } if (capabilities & SchedulerPlugin::AllowOverbooking) { return sm->allowOverbooking() ? xi18nc("@info:tooltip", "Allow overbooking of resources") : xi18nc("@info:tooltip 1=scheduler name", "%1 always allows overbooking of resources", pl->name()); } if (capabilities & SchedulerPlugin::AvoidOverbooking) { return sm->allowOverbooking() ? xi18nc("@info:tooltip 1=scheduler name", "%1 always avoids overbooking of resources", pl->name()) : xi18nc("@info:tooltip", "Avoid overbooking resources"); } break; case Role::EnumList: return QStringList() << xi18nc("@label:listbox", "Avoid") << xi18nc("@label:listbox", "Allow"); case Role::EnumListValue: return sm->allowOverbooking() ? 1 : 0; case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); } return QVariant(); } bool ScheduleItemModel::setAllowOverbooking(const QModelIndex &index, const QVariant &value, int role) { ScheduleManager *sm = manager (index); if (sm == 0) { return false; } switch (role) { case Qt::EditRole: emit executeCommand(new ModifyScheduleManagerAllowOverbookingCmd(*sm, value.toBool(), kundo2_i18n("Modify allow overbooking"))); return true; } return false; } QVariant ScheduleItemModel::usePert(const QModelIndex &index, int role) const { ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::EditRole: return sm->usePert(); case Qt::DisplayRole: return sm->usePert() ? i18n("PERT") : i18n("None"); case Qt::ToolTipRole: return sm->usePert() ? xi18nc("@info:tooltip", "Use PERT distribution to calculate expected estimate for the tasks") : xi18nc("@info:tooltip", "Use the tasks expected estimate directly"); case Role::EnumList: return QStringList() << xi18nc("@label:listbox", "None") << xi18nc("@label:listbox", "PERT"); case Role::EnumListValue: return sm->usePert() ? 1 : 0; case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); } return QVariant(); } bool ScheduleItemModel::setUsePert(const QModelIndex &index, const QVariant &value, int role) { ScheduleManager *sm = manager (index); if (sm == 0) { return false; } switch (role) { case Qt::EditRole: emit executeCommand(new ModifyScheduleManagerDistributionCmd(*sm, value.toBool(), kundo2_i18n("Modify scheduling distribution"))); slotManagerChanged(static_cast(sm)); return true; } return false; } QVariant ScheduleItemModel::projectStart(const QModelIndex &index, int role) const { if (m_project == 0) { return QVariant(); } ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::DisplayRole: if (sm->isScheduled()) { return QLocale().toString(sm->expected()->start(), QLocale::ShortFormat); } break; case Qt::EditRole: if (sm->isScheduled()) { return sm->expected()->start(); } break; case Qt::ToolTipRole: if (sm->isScheduled()) { return xi18nc("@info:tooltip", "Planned start: %1Target start: %2", QLocale().toString(sm->expected()->start(), QLocale::ShortFormat), QLocale().toString(m_project->constraintStartTime(), QLocale::ShortFormat)); } else { return xi18nc("@info:tooltip", "Target start: %1", QLocale().toString(m_project->constraintStartTime(), QLocale::ShortFormat)); } break; case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); } return QVariant(); } QVariant ScheduleItemModel::projectEnd(const QModelIndex &index, int role) const { if (m_project == 0) { return QVariant(); } ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::DisplayRole: if (sm->isScheduled()) { return QLocale().toString(sm->expected()->end(), QLocale::ShortFormat); } break; case Qt::EditRole: if (sm->isScheduled()) { return sm->expected()->end(); } break; case Qt::ToolTipRole: if (sm->isScheduled()) { return xi18nc("@info:tooltip", "Planned finish: %1Target finish: %2", QLocale().toString(sm->expected()->end(), QLocale::ShortFormat), QLocale().toString(m_project->constraintEndTime(), QLocale::ShortFormat)); } else { return xi18nc("@info:tooltip", "Target finish: %1", QLocale().toString(m_project->constraintEndTime(), QLocale::ShortFormat)); } break; case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); } return QVariant(); } QVariant ScheduleItemModel::schedulingDirection(const QModelIndex &index, int role) const { ScheduleManager *sm = manager (index); if (sm == 0) { return QVariant(); } SchedulerPlugin *pl = sm->schedulerPlugin(); if (pl == 0) { return QVariant(); } int capabilities = pl->capabilities(); switch (role) { case Qt::EditRole: return sm->schedulingDirection(); case Qt::DisplayRole: if (capabilities & SchedulerPlugin::ScheduleForward && capabilities & SchedulerPlugin::ScheduleBackward) { return sm->schedulingDirection() ? i18n("Backwards") : i18n("Forward"); } if (capabilities & SchedulerPlugin::ScheduleForward) { return sm->schedulingDirection() ? i18n("(Backwards)") : i18n("Forward"); } if (capabilities & SchedulerPlugin::ScheduleBackward) { return sm->schedulingDirection() ? i18n("Backwards") : i18n("(Forward)"); } break; case Qt::ToolTipRole: if (capabilities & SchedulerPlugin::ScheduleForward && capabilities & SchedulerPlugin::ScheduleBackward) { return sm->schedulingDirection() ? xi18nc("@info:tooltip", "Schedule project from target end time") : xi18nc("@info:tooltip", "Schedule project from target start time"); } if (capabilities & SchedulerPlugin::ScheduleForward) { return sm->schedulingDirection() ? xi18nc("@info:tooltip 1=scheduler name", "%1 always schedules from target start time", pl->name()) : xi18nc("@info:tooltip", "Schedule project from target start time"); } if (capabilities & SchedulerPlugin::ScheduleBackward) { return sm->schedulingDirection() ? xi18nc("@info:tooltip", "Schedule project from target end time") : xi18nc("@info:tooltip 1=scheduler name", "%1 always schedules from target end time", pl->name()); } break; case Role::EnumList: return QStringList() << xi18nc("@label:listbox", "Forward") << xi18nc("@label:listbox", "Backwards"); case Role::EnumListValue: return sm->schedulingDirection() ? 1 : 0; case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); } return QVariant(); } bool ScheduleItemModel::setSchedulingDirection(const QModelIndex &index, const QVariant &value, int role) { ScheduleManager *sm = manager (index); if (sm == 0) { return false; } switch (role) { case Qt::EditRole: emit executeCommand(new ModifyScheduleManagerSchedulingDirectionCmd(*sm, value.toBool(), kundo2_i18n("Modify scheduling direction"))); slotManagerChanged(static_cast(sm)); return true; } return false; } QVariant ScheduleItemModel::scheduler(const QModelIndex &index, int role) const { ScheduleManager *sm = manager(index); if (sm == 0) { return QVariant(); } SchedulerPlugin *pl = sm->schedulerPlugin(); if (pl) { switch (role) { case Qt::EditRole: return sm->schedulerPluginId(); case Qt::DisplayRole: return pl ? pl->name() : i18n("Unknown"); case Qt::ToolTipRole: return pl ? pl->comment() : QString(); case Role::EnumList: return sm->schedulerPluginNames(); case Role::EnumListValue: return sm->schedulerPluginIndex(); case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: return QVariant(); case Qt::WhatsThisRole: { QString s = pl->description(); return s.isEmpty() ? QVariant() : QVariant(s); } } } return QVariant(); } bool ScheduleItemModel::setScheduler(const QModelIndex &index, const QVariant &value, int role) { ScheduleManager *sm = manager(index); if (sm != 0) { switch (role) { case Qt::EditRole: { emit executeCommand(new ModifyScheduleManagerSchedulerCmd(*sm, value.toInt(), kundo2_i18n("Modify scheduler"))); return true; } } } return false; } QVariant ScheduleItemModel::isScheduled(const QModelIndex &index, int role) const { ScheduleManager *sm = manager(index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::EditRole: return sm->isScheduled(); case Qt::DisplayRole: return sm->isScheduled() ? i18n("Scheduled") : i18n("Not scheduled"); case Qt::ToolTipRole: break; case Qt::TextAlignmentRole: return Qt::AlignCenter; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); } return QVariant(); } QVariant ScheduleItemModel::granularity(const QModelIndex &index, int role) const { ScheduleManager *sm = manager(index); if (sm == 0) { return QVariant(); } switch (role) { case Qt::EditRole: case Role::EnumListValue: return qMin(sm->granularity(), sm->supportedGranularities().count() - 1); case Qt::DisplayRole: { QList lst = sm->supportedGranularities(); if (lst.isEmpty()) { return i18nc("Scheduling granularity not supported", "None"); } int idx = sm->granularity(); qulonglong g = idx < lst.count() ? lst[ idx ] : lst.last(); return KFormat().formatDuration(g); } case Qt::ToolTipRole: { QList lst = sm->supportedGranularities(); if (lst.isEmpty()) { return xi18nc("@info:tooltip", "Scheduling granularity not supported"); } int idx = sm->granularity(); qulonglong g = idx < lst.count() ? lst[ idx ] : lst.last(); return xi18nc("@info:tooltip", "Selected scheduling granularity: %1", KFormat().formatDuration(g)); } case Qt::TextAlignmentRole: return Qt::AlignRight; case Qt::StatusTipRole: case Qt::WhatsThisRole: return QVariant(); case Role::EnumList: { QStringList sl; KFormat format; foreach (long unsigned int v, sm->supportedGranularities()) { sl << format.formatDuration(v); } return sl; } } return QVariant(); } bool ScheduleItemModel::setGranularity(const QModelIndex &index, const QVariant &value, int role) { ScheduleManager *sm = manager(index); if (sm != 0) { switch (role) { case Qt::EditRole: { emit executeCommand(new ModifyScheduleManagerSchedulingGranularityCmd(*sm, value.toInt(), kundo2_i18n("Modify scheduling granularity"))); return true; } } } return false; } QVariant ScheduleItemModel::data(const QModelIndex &index, int role) const { //debugPlan<isScheduleManager(index.internalPointer())) { o = static_cast(index.internalPointer()); Q_ASSERT(o); } return o; } void ScheduleItemModel::setFlat(bool flat) { m_flat = flat; m_managerlist.clear(); if (! flat || m_project == 0) { return; } m_managerlist = m_project->allScheduleManagers(); } //-------------------------------------- ScheduleSortFilterModel::ScheduleSortFilterModel(QObject *parent) : QSortFilterProxyModel(parent) { } ScheduleSortFilterModel::~ScheduleSortFilterModel() { } ScheduleManager *ScheduleSortFilterModel::manager(const QModelIndex &index) const { QModelIndex i = mapToSource(index); const ScheduleItemModel *m = qobject_cast(i.model()); return m == 0 ? 0 : m->manager(i); } QVariant ScheduleSortFilterModel::data(const QModelIndex &index, int role) const { QVariant v = QSortFilterProxyModel::data(index, role); if (role == Qt::DisplayRole && index.column() == ScheduleModel::ScheduleName) { QModelIndex state = index.sibling(index.row(), ScheduleModel::ScheduleState); if (state.data(Qt::EditRole).toString() != "Scheduled") { QString s = state.data(SpecialScheduleDisplayRole).toString(); - return QString("%1 (%2)").arg(v.toString(), s); + if (!s.isEmpty()) { + return QString("%1 (%2)").arg(v.toString(), s); // TODO i18n + } } } return v; } //-------------------------------------- ScheduleLogItemModel::ScheduleLogItemModel(QObject *parent) : QStandardItemModel(parent), m_project(0), m_manager(0), m_schedule(0) { } ScheduleLogItemModel::~ScheduleLogItemModel() { } void ScheduleLogItemModel::slotScheduleManagerToBeRemoved(const ScheduleManager *manager) { if (m_manager == manager) { setManager(0); } } void ScheduleLogItemModel::slotScheduleManagerRemoved(const ScheduleManager *manager) { debugPlan<name(); } void ScheduleLogItemModel::slotScheduleToBeInserted(const ScheduleManager *manager, int row) { Q_UNUSED(manager); Q_UNUSED(row); if (m_manager && m_manager->expected() /*== ??*/) { //TODO } } //FIXME remove const on MainSchedule void ScheduleLogItemModel::slotScheduleInserted(const MainSchedule *sch) { debugPlan<manager() && sch == m_manager->expected()) { m_schedule = const_cast(sch); refresh(); } } void ScheduleLogItemModel::slotScheduleToBeRemoved(const MainSchedule *sch) { debugPlan<"<"<expected(); refresh(); connect(m_manager, &ScheduleManager::logInserted, this, &ScheduleLogItemModel::slotLogInserted); } } } void ScheduleLogItemModel::slotLogInserted(MainSchedule *s, int firstrow, int lastrow) { for (int i = firstrow; i <= lastrow; ++i) { addLogEntry(s->logs().value(i), i + 1); } } //FIXME: This only add logs (insert is not used atm) void ScheduleLogItemModel::addLogEntry(const Schedule::Log &log, int /*row*/) { // debugPlan< lst; if (log.resource) { lst.append(new QStandardItem(log.resource->name())); } else if (log.node) { lst.append(new QStandardItem(log.node->name())); } else { lst.append( new QStandardItem("")); } lst.append(new QStandardItem(m_schedule->logPhase(log.phase))); QStandardItem *item = new QStandardItem(m_schedule->logSeverity(log.severity)); item->setData(log.severity, SeverityRole); lst.append(item); lst.append(new QStandardItem(log.message)); foreach (QStandardItem *itm, lst) { if (log.resource) { itm->setData(log.resource->id(), IdentityRole); } else if (log.node) { itm->setData(log.node->id(), IdentityRole); } switch (log.severity) { case Schedule::Log::Type_Debug: itm->setData(QColor(Qt::darkYellow), Qt::ForegroundRole); break; case Schedule::Log::Type_Info: break; case Schedule::Log::Type_Warning: itm->setData(QColor(Qt::blue), Qt::ForegroundRole); break; case Schedule::Log::Type_Error: itm->setData(QColor(Qt::red), Qt::ForegroundRole); break; default: break; } } appendRow(lst); // debugPlan<<"added:"<logs().count(); int i = 1; foreach (const Schedule::Log &l, m_schedule->logs()) { addLogEntry(l, i++); } } QString ScheduleLogItemModel::identity(const QModelIndex &idx) const { QStandardItem *itm = itemFromIndex(idx); return itm ? itm->data(IdentityRole).toString() : QString(); } void ScheduleLogItemModel::slotManagerChanged(ScheduleManager *manager) { debugPlan<