diff --git a/src/libs/ui/kptresourceappointmentsview.cpp b/src/libs/ui/kptresourceappointmentsview.cpp index eb475361..61bc20a0 100644 --- a/src/libs/ui/kptresourceappointmentsview.cpp +++ b/src/libs/ui/kptresourceappointmentsview.cpp @@ -1,427 +1,427 @@ /* This file is part of the KDE project Copyright (C) 2005 - 2010, 2012 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 "kptresourceappointmentsview.h" #include "kptappointment.h" #include "kptcommand.h" #include "kpteffortcostmap.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 "kptitemviewsettup.h" #include "kptviewbase.h" #include "Help.h" #include "kptdebug.h" #include "KoPageLayoutWidget.h" #include #include #include #include #include #include namespace KPlato { //-------------------- ResourceAppointmentsDisplayOptionsPanel::ResourceAppointmentsDisplayOptionsPanel(ResourceAppointmentsItemModel *model, QWidget *parent) : QWidget(parent), m_model(model) { setupUi(this); setValues(*model); connect(ui_internalAppointments, &QCheckBox::stateChanged, this, &ResourceAppointmentsDisplayOptionsPanel::changed); connect(ui_externalAppointments, &QCheckBox::stateChanged, this, &ResourceAppointmentsDisplayOptionsPanel::changed); } void ResourceAppointmentsDisplayOptionsPanel::slotOk() { m_model->setShowInternalAppointments(ui_internalAppointments->checkState() == Qt::Checked); m_model->setShowExternalAppointments(ui_externalAppointments->checkState() == Qt::Checked); } void ResourceAppointmentsDisplayOptionsPanel::setValues(const ResourceAppointmentsItemModel &m) { ui_internalAppointments->setCheckState(m.showInternalAppointments() ? Qt::Checked : Qt::Unchecked); ui_externalAppointments->setCheckState(m.showExternalAppointments() ? Qt::Checked : Qt::Unchecked); } void ResourceAppointmentsDisplayOptionsPanel::setDefault() { ResourceAppointmentsItemModel m; setValues(m); } //---- ResourceAppointmentsSettingsDialog::ResourceAppointmentsSettingsDialog(ViewBase *view, ResourceAppointmentsItemModel *model, QWidget *parent, bool selectPrint) : KPageDialog(parent), m_view(view) { ResourceAppointmentsDisplayOptionsPanel *panel = new ResourceAppointmentsDisplayOptionsPanel(model); KPageWidgetItem *page = addPage(panel, i18n("General")); page->setHeader(i18n("Resource Assignments View Settings")); QTabWidget *tab = new QTabWidget(); QWidget *w = ViewBase::createPageLayoutWidget(view); tab->addTab(w, w->windowTitle()); m_pagelayout = w->findChild(); Q_ASSERT(m_pagelayout); m_headerfooter = ViewBase::createHeaderFooterWidget(view); m_headerfooter->setOptions(view->printingOptions()); tab->addTab(m_headerfooter, m_headerfooter->windowTitle()); page = addPage(tab, i18n("Printing")); page->setHeader(i18n("Printing Options")); if (selectPrint) { setCurrentPage(page); } connect(this, &QDialog::accepted, this, &ResourceAppointmentsSettingsDialog::slotOk); connect(this, &QDialog::accepted, panel, &ResourceAppointmentsDisplayOptionsPanel::slotOk); //TODO: there was no default button configured, should there? // connect(button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked(bool)), panel, SLOT(setDefault())); } void ResourceAppointmentsSettingsDialog::slotOk() { m_view->setPageLayout(m_pagelayout->pageLayout()); m_view->setPrintingOptions(m_headerfooter->options()); } //--------------------------------------- ResourceAppointmentsTreeView::ResourceAppointmentsTreeView(QWidget *parent) : DoubleTreeViewBase(true, parent) { // header()->setContextMenuPolicy(Qt::CustomContextMenu); m_rightview->setStretchLastSection(false); ResourceAppointmentsItemModel *m = new ResourceAppointmentsItemModel(this); setModel(m); setSelectionMode(QAbstractItemView::ExtendedSelection); QList lst1; lst1 << 2 << -1; QList lst2; lst2 << 0 << 1; hideColumns(lst1, lst2); m_leftview->resizeColumnToContents (1); connect(m, &QAbstractItemModel::modelReset, this, &ResourceAppointmentsTreeView::slotRefreshed); m_rightview->setObjectName("ResourceAppointments"); } bool ResourceAppointmentsTreeView::loadContext(const KoXmlElement &context) { debugPlan; KoXmlElement e = context.namedItem("common").toElement(); if (! e.isNull()) { model()->setShowInternalAppointments((bool)(e.attribute("show-internal-appointments", "0").toInt())); model()->setShowExternalAppointments((bool)(e.attribute("show-external-appointments", "0").toInt())); } DoubleTreeViewBase::loadContext(QMetaEnum(), context); return true; } void ResourceAppointmentsTreeView::saveContext(QDomElement &settings) const { debugPlan; QDomElement e = settings.ownerDocument().createElement("common"); settings.appendChild(e); e.setAttribute("show-internal-appointments", QString::number(model()->showInternalAppointments())); e.setAttribute("show-external-appointments", QString::number(model()->showExternalAppointments())); DoubleTreeViewBase::saveContext(QMetaEnum(), settings); } void ResourceAppointmentsTreeView::slotRefreshed() { //debugPlan<columnCount()<<", "<header()->count()<<", "<header()->count()<<", "<header()->hiddenSectionCount()<<", "<header()->hiddenSectionCount(); ResourceAppointmentsItemModel *m = model(); setModel(0); setModel(m); setSelectionMode(QAbstractItemView::ExtendedSelection); QList lst1; lst1 << 2 << -1; QList lst2; lst2 << 0 << 1; hideColumns(lst1, lst2); } QModelIndex ResourceAppointmentsTreeView::currentIndex() const { return selectionModel()->currentIndex(); } //----------------------------------- ResourceAppointmentsView::ResourceAppointmentsView(KoPart *part, KoDocument *doc, QWidget *parent) : ViewBase(part, doc, parent) { debugPlan<<"------------------- ResourceAppointmentsView -----------------------"; setXMLFile("ResourceAppointmentsViewUi.rc"); setupGui(); QVBoxLayout * l = new QVBoxLayout(this); l->setMargin(0); m_view = new ResourceAppointmentsTreeView(this); connect(this, &ViewBase::expandAll, m_view, &DoubleTreeViewBase::slotExpand); connect(this, &ViewBase::collapseAll, m_view, &DoubleTreeViewBase::slotCollapse); l->addWidget(m_view); m_view->setEditTriggers(m_view->editTriggers() | QAbstractItemView::EditKeyPressed); connect(model(), &ItemModelBase::executeCommand, doc, &KoDocument::addCommand); connect(m_view, &DoubleTreeViewBase::currentChanged, this, &ResourceAppointmentsView::slotCurrentChanged); connect(m_view, &DoubleTreeViewBase::selectionChanged, this, &ResourceAppointmentsView::slotSelectionChanged); connect(m_view, &DoubleTreeViewBase::contextMenuRequested, this, &ResourceAppointmentsView::slotContextMenuRequested); connect(m_view, &DoubleTreeViewBase::headerContextMenuRequested, this, &ViewBase::slotHeaderContextMenuRequested); Help::add(this, xi18nc("@info:whatsthis", "Resource Assignments View" "" "Displays the scheduled resource - task assignments." "" "This view supports configuration and printing using the context menu." "More..." - "", Help::page("Resource_Assignment_Gantt_View"))); + "", Help::page("Resource_Assignment_View"))); } void ResourceAppointmentsView::draw(Project &project) { setProject(&project); } void ResourceAppointmentsView::setProject(Project *project) { m_view->setProject(project); } void ResourceAppointmentsView::setScheduleManager(ScheduleManager *sm) { if (!sm && scheduleManager()) { // we should only get here if the only schedule manager is scheduled, // or when last schedule manager is deleted m_domdoc.clear(); QDomElement element = m_domdoc.createElement("expanded"); m_domdoc.appendChild(element); m_view->masterView()->saveExpanded(element); } bool tryexpand = sm && !scheduleManager(); bool expand = sm && scheduleManager() && sm != scheduleManager(); QDomDocument doc; if (expand) { QDomElement element = doc.createElement("expanded"); doc.appendChild(element); m_view->masterView()->saveExpanded(element); } ViewBase::setScheduleManager(sm); m_view->setScheduleManager(sm); if (expand) { m_view->masterView()->doExpand(doc); } else if (tryexpand) { m_view->masterView()->doExpand(m_domdoc); } } void ResourceAppointmentsView::draw() { } void ResourceAppointmentsView::setGuiActive(bool activate) { debugPlan<selectionModel()->currentIndex().isValid()) { m_view->selectionModel()->setCurrentIndex(m_view->model()->index(0, 0), QItemSelectionModel::NoUpdate); } } void ResourceAppointmentsView::slotContextMenuRequested(const QModelIndex &index, const QPoint& pos) { debugPlan<model()->node(index); if (n) { name = "taskview_popup"; } } m_view->setContextMenuIndex(index); if (name.isEmpty()) { slotHeaderContextMenuRequested(pos); m_view->setContextMenuIndex(QModelIndex()); return; } emit requestPopupMenu(name, pos); m_view->setContextMenuIndex(QModelIndex()); } Node *ResourceAppointmentsView::currentNode() const { return m_view->model()->node(m_view->currentIndex()); } Resource *ResourceAppointmentsView::currentResource() const { //return qobject_cast(m_view->currentObject()); return 0; } ResourceGroup *ResourceAppointmentsView::currentResourceGroup() const { //return qobject_cast(m_view->currentObject()); return 0; } void ResourceAppointmentsView::slotCurrentChanged(const QModelIndex &) { //debugPlan<project(); QList groupList = m_view->selectedGroups(); bool nogroup = groupList.isEmpty(); bool group = groupList.count() == 1; QList resourceList = m_view->selectedResources(); bool noresource = resourceList.isEmpty(); bool resource = resourceList.count() == 1; bool any = !nogroup || !noresource; actionAddResource->setEnabled(o && ((group && noresource) || (resource && nogroup))); actionAddGroup->setEnabled(o); actionDeleteSelection->setEnabled(o && any);*/ } void ResourceAppointmentsView::setupGui() { // Add the context menu actions for the view options createOptionActions(ViewBase::OptionAll); } void ResourceAppointmentsView::slotOptions() { debugPlan; ResourceAppointmentsSettingsDialog *dlg = new ResourceAppointmentsSettingsDialog(this, m_view->model(), this, sender()->objectName() == "print_options"); connect(dlg, SIGNAL(finished(int)), SLOT(slotOptionsFinished(int))); dlg->open(); } void ResourceAppointmentsView::slotAddResource() { //debugPlan; /* QList gl = m_view->selectedGroups(); if (gl.count() > 1) { return; } ResourceGroup *g = 0; if (!gl.isEmpty()) { g = gl.first(); } else { QList rl = m_view->selectedResources(); if (rl.count() != 1) { return; } g = rl.first()->parentGroup(); } if (g == 0) { return; } Resource *r = new Resource(); QModelIndex i = m_view->model()->insertResource(g, r); if (i.isValid()) { m_view->selectionModel()->setCurrentIndex(i, QItemSelectionModel::NoUpdate); m_view->edit(i); } */ } void ResourceAppointmentsView::slotAddGroup() { //debugPlan; /* ResourceGroup *g = new ResourceGroup(); QModelIndex i = m_view->model()->insertGroup(g); if (i.isValid()) { m_view->selectionModel()->setCurrentIndex(i, QItemSelectionModel::NoUpdate); m_view->edit(i); }*/ } void ResourceAppointmentsView::slotDeleteSelection() { /* QObjectList lst = m_view->selectedObjects(); //debugPlan<loadContext(context); } void ResourceAppointmentsView::saveContext(QDomElement &context) const { ViewBase::saveContext(context); m_view->saveContext(context); } KoPrintJob *ResourceAppointmentsView::createPrintJob() { return m_view->createPrintJob(this); } } // namespace KPlato diff --git a/src/libs/ui/kptscheduleeditor.cpp b/src/libs/ui/kptscheduleeditor.cpp index 90ec1ee2..f771749d 100644 --- a/src/libs/ui/kptscheduleeditor.cpp +++ b/src/libs/ui/kptscheduleeditor.cpp @@ -1,848 +1,848 @@ /* This file is part of the KDE project * Copyright (C) 2019 Dag Andersen * Copyright (C) 2006-2011, 2012 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 "kptscheduleeditor.h" #include "kptcommand.h" #include "kptcalendar.h" #include "kptduration.h" #include "kptnode.h" #include "kptproject.h" #include "kpttask.h" #include "kptschedule.h" #include "kptdatetime.h" #include "kptpertresult.h" #include "kptitemviewsettup.h" #include "kptrecalculatedialog.h" #include "Help.h" #include "kptdebug.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace KPlato { ScheduleTreeView::ScheduleTreeView(QWidget *parent) : TreeViewBase(parent) { header()->setStretchLastSection (false); ScheduleItemModel *m = new ScheduleItemModel(this); setModel(m); //setSelectionBehavior(QAbstractItemView::SelectItems); setSelectionMode(QAbstractItemView::SingleSelection); setSelectionBehavior(QAbstractItemView::SelectRows); setTreePosition(-1); // always visual index 0 createItemDelegates(m); } void ScheduleTreeView::selectionChanged(const QItemSelection &sel, const QItemSelection &desel) { //debugPlan<selectedIndexes()) { Q_UNUSED(i); //debugPlan<selectedIndexes()); } void ScheduleTreeView::currentChanged(const QModelIndex & current, const QModelIndex & previous) { //debugPlan<select(current, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); } ScheduleManager *ScheduleTreeView::manager(const QModelIndex &idx) const { return model()->manager(idx); } ScheduleManager *ScheduleTreeView::currentManager() const { return model()->manager(currentIndex()); } QModelIndexList ScheduleTreeView::selectedRows() const { QModelIndexList lst = selectionModel()->selectedRows(); debugPlan<manager(lst.first()); } return sm; } //----------------------------------- ScheduleEditor::ScheduleEditor(KoPart *part, KoDocument *doc, QWidget *parent) : ViewBase(part, doc, parent) { if (doc && doc->isReadWrite()) { setXMLFile("ScheduleEditorUi.rc"); } else { setXMLFile("ScheduleEditorUi_readonly.rc"); } setupGui(); slotEnableActions(); QVBoxLayout * l = new QVBoxLayout(this); l->setMargin(0); m_schedulingRange = new SchedulingRange(doc, this); l->addWidget(m_schedulingRange); m_view = new ScheduleTreeView(this); connect(this, &ViewBase::expandAll, m_view, &TreeViewBase::slotExpand); connect(this, &ViewBase::collapseAll, m_view, &TreeViewBase::slotCollapse); l->addWidget(m_view); m_view->setEditTriggers(m_view->editTriggers() | QAbstractItemView::EditKeyPressed); QList show; show << ScheduleModel::ScheduleName << ScheduleModel::ScheduleState << ScheduleModel::ScheduleDirection << ScheduleModel::ScheduleOverbooking << ScheduleModel::ScheduleDistribution << ScheduleModel::SchedulePlannedStart << ScheduleModel::SchedulePlannedFinish << ScheduleModel::ScheduleScheduler << ScheduleModel::ScheduleGranularity << ScheduleModel::ScheduleMode ; QList lst; for (int c = 0; c < model()->columnCount(); ++c) { if (! show.contains(c)) { lst << c; } } m_view->setColumnsHidden(lst); m_view->setDefaultColumns(show); connect(model(), &ItemModelBase::executeCommand, doc, &KoDocument::addCommand); connect(m_view, SIGNAL(currentChanged(QModelIndex)), this, SLOT(slotCurrentChanged(QModelIndex))); connect(m_view, SIGNAL(selectionChanged(QModelIndexList)), this, SLOT(slotSelectionChanged(QModelIndexList))); connect(model(), &QAbstractItemModel::dataChanged, this, &ScheduleEditor::updateActionsEnabled); connect(m_view, &TreeViewBase::contextMenuRequested, this, &ScheduleEditor::slotContextMenuRequested); connect(m_view, &TreeViewBase::headerContextMenuRequested, this, &ViewBase::slotHeaderContextMenuRequested); Help::add(this, xi18nc("@info:whatsthis", "Schedule Editor" "" "The Schedule Editor is used to create, edit, calculate and delete schedules." "" "If Mode is set to Auto, the schedule is calculated automatically." " Only one schedule can be in Auto Mode simultaneously" " and it must be a top level schedule without sub-schedules." "" "A schedule can have sub-schedules. A sub-schedule can use the projects progress data" " in order to reschedule only tasks that are not yet finished." " Rescheduling will then use e.g. actual start and remaining effort for the tasks." "More..." - "", Help::page("Schedule_Editor"))); + "", Help::page("Schedules_Editor"))); } void ScheduleEditor::draw(Project &project) { m_view->setProject(&project); m_schedulingRange->setProject(&project); } void ScheduleEditor::draw() { } void ScheduleEditor::setGuiActive(bool activate) { //debugPlan<currentIndex().isValid()) { m_view->selectionModel()->setCurrentIndex(m_view->model()->index(0, 0), QItemSelectionModel::NoUpdate); } } void ScheduleEditor::slotContextMenuRequested(const QModelIndex &index, const QPoint& pos) { debugPlan<setContextMenuIndex(index); if (name.isEmpty()) { slotHeaderContextMenuRequested(pos); m_view->setContextMenuIndex(QModelIndex()); return; } debugPlan<setContextMenuIndex(QModelIndex()); } void ScheduleEditor::slotCurrentChanged(const QModelIndex &) { //debugPlan<selectedRows(); // gets column 0 in each row (should be 1 or 0 rows) if (lst.count() == 1) { ScheduleManager *sm = m_view->model()->manager(lst.first()); emit scheduleSelectionChanged(sm); } else { emit scheduleSelectionChanged(0); } slotEnableActions(); } void ScheduleEditor::updateActionsEnabled(const QModelIndex &index) { debugPlan<setEnabled(false); actionAddSubSchedule->setEnabled(false); actionDeleteSelection->setEnabled(false); actionCalculateSchedule->setEnabled(false); actionBaselineSchedule->setEnabled(false); actionMoveLeft->setEnabled(false); return; } QModelIndexList lst = m_view->selectedRows(); if (lst.isEmpty()) { actionAddSchedule->setEnabled(true); actionAddSubSchedule->setEnabled(false); actionDeleteSelection->setEnabled(false); actionCalculateSchedule->setEnabled(false); actionBaselineSchedule->setEnabled(false); actionMoveLeft->setEnabled(false); return; } if (lst.count() > 1) { actionAddSchedule->setEnabled(false); actionAddSubSchedule->setEnabled(false); actionDeleteSelection->setEnabled(false); actionCalculateSchedule->setEnabled(false); actionBaselineSchedule->setEnabled(false); actionMoveLeft->setEnabled(false); return; } // one and only one manager selected ScheduleManager *sm = m_view->manager(lst.first()); Q_ASSERT(sm); actionAddSchedule->setEnabled(true); actionAddSubSchedule->setEnabled(sm->isScheduled()); actionDeleteSelection->setEnabled(! (sm->isBaselined() || sm->isChildBaselined())); actionCalculateSchedule->setEnabled(! sm->scheduling() && sm->childCount() == 0 && ! (sm->isBaselined() || sm->isChildBaselined())); const char *const actionBaselineScheduleIconName = sm->isBaselined() ? koIconNameCStr("view-time-schedule-baselined-remove") : koIconNameCStr("view-time-schedule-baselined-add"); actionBaselineSchedule->setIcon(QIcon::fromTheme(QLatin1String(actionBaselineScheduleIconName))); // enable if scheduled and no one else is baselined bool en = sm->isScheduled() && (sm->isBaselined() || ! m_view->project()->isBaselined()); actionBaselineSchedule->setEnabled(en); actionMoveLeft->setEnabled(sm->parentManager()); } void ScheduleEditor::setupGui() { actionAddSchedule = new QAction(koIcon("view-time-schedule-insert"), i18n("Add Schedule"), this); actionCollection()->setDefaultShortcut(actionAddSchedule, Qt::CTRL + Qt::Key_I); actionCollection()->addAction("add_schedule", actionAddSchedule); connect(actionAddSchedule, &QAction::triggered, this, &ScheduleEditor::slotAddSchedule); actionAddSubSchedule = new QAction(koIcon("view-time-schedule-child-insert"), i18n("Add Sub-schedule"), this); actionCollection()->setDefaultShortcut(actionAddSubSchedule, Qt::CTRL + Qt::SHIFT + Qt::Key_I); actionCollection()->addAction("add_subschedule", actionAddSubSchedule); connect(actionAddSubSchedule, &QAction::triggered, this, &ScheduleEditor::slotAddSubSchedule); actionDeleteSelection = new QAction(koIcon("edit-delete"), xi18nc("@action", "Delete"), this); actionCollection()->setDefaultShortcut(actionDeleteSelection, Qt::Key_Delete); actionCollection()->addAction("delete_selection", actionDeleteSelection); connect(actionDeleteSelection, &QAction::triggered, this, &ScheduleEditor::slotDeleteSelection); actionCalculateSchedule = new QAction(koIcon("view-time-schedule-calculus"), i18n("Calculate"), this); // actionCollection()->setDefaultShortcut(actionCalculateSchedule, Qt::CTRL + Qt::Key_C); actionCollection()->addAction("calculate_schedule", actionCalculateSchedule); connect(actionCalculateSchedule, &QAction::triggered, this, &ScheduleEditor::slotCalculateSchedule); actionBaselineSchedule = new QAction(koIcon("view-time-schedule-baselined-add"), i18n("Baseline"), this); // actionCollection()->setDefaultShortcut(actionBaselineSchedule, Qt::CTRL + Qt::Key_B); actionCollection()->addAction("schedule_baseline", actionBaselineSchedule); connect(actionBaselineSchedule, &QAction::triggered, this, &ScheduleEditor::slotBaselineSchedule); actionMoveLeft = new QAction(koIcon("go-first"), xi18nc("@action", "Detach"), this); actionCollection()->addAction("schedule_move_left", actionMoveLeft); connect(actionMoveLeft, &QAction::triggered, this, &ScheduleEditor::slotMoveLeft); // Add the context menu actions for the view options createOptionActions(ViewBase::OptionExpand | ViewBase::OptionCollapse | ViewBase::OptionViewConfig); } void ScheduleEditor::updateReadWrite(bool readwrite) { debugPlan<setReadWrite(readwrite); m_schedulingRange->setReadWrite(readwrite); slotEnableActions(); } void ScheduleEditor::slotOptions() { debugPlan; ItemViewSettupDialog *dlg = new ItemViewSettupDialog(this, m_view, true, this); connect(dlg, SIGNAL(finished(int)), SLOT(slotOptionsFinished(int))); dlg->open(); } void ScheduleEditor::slotCalculateSchedule() { //debugPlan; ScheduleManager *sm = m_view->selectedManager(); if (sm == 0) { return; } if (sm->parentManager() || (sm->isScheduled() && project()->isStarted())) { RecalculateDialog dlg; if (dlg.exec() == QDialog::Rejected) { return; } sm->setRecalculate(true); sm->setRecalculateFrom(DateTime(dlg.dateTime())); } emit calculateSchedule(m_view->project(), sm); } void ScheduleEditor::slotAddSchedule() { //debugPlan; int idx = -1; ScheduleManager *sm = m_view->selectedManager(); if (sm) { idx = sm->parentManager() ? sm->parentManager()->indexOf(sm) : m_view->project()->indexOf(sm); if (idx >= 0) { ++idx; } } if (sm && sm->parentManager()) { sm = sm->parentManager(); ScheduleManager *m = m_view->project()->createScheduleManager(sm->name() + QString(".%1").arg(sm->children().count() + 1)); part()->addCommand(new AddScheduleManagerCmd(sm, m, idx, kundo2_i18n("Create sub-schedule"))); QModelIndex idx = model()->index(m); if (idx.isValid()) { m_view->setFocus(); m_view->scrollTo(idx); m_view->selectionModel()->select(idx, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); m_view->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::NoUpdate); } } else { Project *p = m_view->project(); ScheduleManager *m = p->createScheduleManager(); AddScheduleManagerCmd *cmd = new AddScheduleManagerCmd(*p, m, idx, kundo2_i18n("Add schedule %1", m->name())); part() ->addCommand(cmd); QModelIndex idx = model()->index(m); if (idx.isValid()) { m_view->setFocus(); m_view->scrollTo(idx); m_view->selectionModel()->select(idx, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); m_view->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::NoUpdate); } } } void ScheduleEditor::slotAddSubSchedule() { //debugPlan; ScheduleManager *sm = m_view->selectedManager(); if (sm) { int row = sm->parentManager() ? sm->parentManager()->indexOf(sm) : m_view->project()->indexOf(sm); if (row >= 0) { ++row; } ScheduleManager *m = m_view->project()->createScheduleManager(sm->name() + QString(".%1").arg(sm->children().count() + 1)); part()->addCommand(new AddScheduleManagerCmd(sm, m, row, kundo2_i18n("Create sub-schedule"))); m_view->expand(model()->index(sm)); QModelIndex idx = model()->index(m); if (idx.isValid()) { m_view->selectionModel()->select(idx, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); m_view->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::NoUpdate); } } else { slotAddSchedule(); } } void ScheduleEditor::slotBaselineSchedule() { //debugPlan; ScheduleManager *sm = m_view->selectedManager(); if (sm) { emit baselineSchedule(m_view->project(), sm); } } void ScheduleEditor::slotDeleteSelection() { //debugPlan; ScheduleManager *sm = m_view->selectedManager(); if (sm) { emit deleteScheduleManager(m_view->project(), sm); } } void ScheduleEditor::slotMoveLeft() { ScheduleManager *sm = m_view->selectedManager(); if (sm) { int index = -1; for (ScheduleManager *m = sm; m != 0; m = m->parentManager()) { if (m->parentManager() == 0) { index = m->project().indexOf(m) + 1; } } debugPlan<name()<loadContext(model()->columnMap(), context); } void ScheduleEditor::saveContext(QDomElement &context) const { m_view->saveContext(model()->columnMap(), context); } KoPrintJob *ScheduleEditor::createPrintJob() { return m_view->createPrintJob(this); } //----------------------------------------- ScheduleLogTreeView::ScheduleLogTreeView(QWidget *parent) : QTreeView(parent) { header()->setStretchLastSection (true); header()->setContextMenuPolicy(Qt::CustomContextMenu); m_model = new QSortFilterProxyModel(this); m_model->setFilterRole(Qt::UserRole+1); m_model->setFilterKeyColumn (2); // severity m_model->setFilterWildcard("[^0]"); // Filter out Debug m_model->setSourceModel(new ScheduleLogItemModel(this)); setModel(m_model); setRootIsDecorated(false); setSelectionMode(QAbstractItemView::ExtendedSelection); setSelectionBehavior(QAbstractItemView::SelectRows); setAlternatingRowColors(true); connect(header(), &QWidget::customContextMenuRequested, this, &ScheduleLogTreeView::headerContextMenuRequested); actionShowDebug = new KToggleAction(xi18nc("@action", "Show Debug Information"), this); connect(actionShowDebug, &QAction::toggled, this, &ScheduleLogTreeView::slotShowDebug); } void ScheduleLogTreeView::setFilterWildcard(const QString &filter) { m_model->setFilterWildcard(filter); } QRegExp ScheduleLogTreeView::filterRegExp() const { return m_model->filterRegExp(); } void ScheduleLogTreeView::slotShowDebug(bool on) { on ? setFilterWildcard(QString()) : setFilterWildcard("[^0]"); } void ScheduleLogTreeView::contextMenuEvent (QContextMenuEvent *e) { debugPlan<pos())<<" at"<pos(); emit contextMenuRequested(indexAt(e->pos()), e->globalPos()); } void ScheduleLogTreeView::headerContextMenuRequested(const QPoint &pos) { //debugPlan<logicalIndexAt(pos)<<" at"<addAction(actionShowDebug); m->exec(mapToGlobal(pos)); delete m; } void ScheduleLogTreeView::selectionChanged(const QItemSelection &sel, const QItemSelection &desel) { //debugPlan<selectedIndexes()) { Q_UNUSED(i); //debugPlan<selectedIndexes()); } void ScheduleLogTreeView::currentChanged(const QModelIndex & current, const QModelIndex & previous) { //debugPlan<select(current, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); } void ScheduleLogTreeView::slotEditCopy() { QStringList lst; // int row = 0; QString s; QHeaderView *h = header(); foreach(const QModelIndex &i, selectionModel()->selectedRows()) { QString s; for (int section = 0; section < h->count(); ++section) { QModelIndex idx = model()->index(i.row(), h->logicalIndex(section)); if (! idx.isValid() || isColumnHidden(idx.column())) { continue; } if (! s.isEmpty()) { s += ' '; } s = QString("%1%2").arg(s).arg(idx.data().toString(), -10); } if (! s.isEmpty()) { lst << s; } } if (! lst.isEmpty()) { QApplication::clipboard()->setText(lst.join("\n")); } } //----------------------------------- ScheduleLogView::ScheduleLogView(KoPart *part, KoDocument *doc, QWidget *parent) : ViewBase(part, doc, parent) { setupGui(); slotEnableActions(0); QVBoxLayout * l = new QVBoxLayout(this); m_view = new ScheduleLogTreeView(this); l->addWidget(m_view); // m_view->setEditTriggers(m_view->editTriggers() | QAbstractItemView::EditKeyPressed); connect(m_view, SIGNAL(currentChanged(QModelIndex)), this, SLOT(slotCurrentChanged(QModelIndex))); connect(m_view, SIGNAL(selectionChanged(QModelIndexList)), this, SLOT(slotSelectionChanged(QModelIndexList))); connect(baseModel(), &QAbstractItemModel::dataChanged, this, &ScheduleLogView::updateActionsEnabled); connect(m_view, &ScheduleLogTreeView::contextMenuRequested, this, &ScheduleLogView::slotContextMenuRequested); } void ScheduleLogView::setProject(Project *project) { m_view->setProject(project); } void ScheduleLogView::draw(Project &project) { setProject(&project); } void ScheduleLogView::setGuiActive(bool activate) { //debugPlan<currentIndex().isValid()) { m_view->selectionModel()->setCurrentIndex(m_view->model()->index(0, 0), QItemSelectionModel::NoUpdate); }*/ } void ScheduleLogView::slotEdit() { QString id = sender()->property("p_identity").toString(); if (id.isEmpty()) { emit editNode(project()); return; } Node *n = project()->findNode(id); if (n) { emit editNode(n); return; } Resource *r = project()->findResource(id); if (r) { emit editResource(r); return; } warnPlan<<"No object"; } void ScheduleLogView::slotContextMenuRequested(const QModelIndex &index, const QPoint& pos) { if (! isReadWrite() || ! index.isValid()) { return; } QMenu *m = new QMenu(this); QString id = index.data(ScheduleLogItemModel::IdentityRole).toString(); if (id.isEmpty()) { return; } QAction *a = new QAction(koIcon("document-edit"), i18n("Edit..."), m); a->setProperty("p_identity", id); m->addAction(a); connect(a, &QAction::triggered, this, &ScheduleLogView::slotEdit); m->addSeparator(); m->exec(pos); delete m; } void ScheduleLogView::slotScheduleSelectionChanged(ScheduleManager *sm) { baseModel()->setManager(sm); } void ScheduleLogView::slotCurrentChanged(const QModelIndex &) { //debugPlan<setReadWrite(readwrite); //slotEnableActions(m_view->currentManager()); } void ScheduleLogView::slotOptions() { debugPlan; } void ScheduleLogView::slotEditCopy() { m_view->slotEditCopy(); } bool ScheduleLogView::loadContext(const KoXmlElement &/*context */) { debugPlan; return true;//m_view->loadContext(model()->columnMap(), context); } void ScheduleLogView::saveContext(QDomElement &/*context */) const { //m_view->saveContext(model()->columnMap(), context); } //--------------------------- ScheduleHandlerView::ScheduleHandlerView(KoPart *part, KoDocument *doc, QWidget *parent) : SplitterView(part, doc, parent) { debugPlan<<"---------------- Create ScheduleHandlerView ------------------"; m_scheduleEditor = new ScheduleEditor(part, doc, this); m_scheduleEditor->setObjectName("ScheduleEditor"); addView(m_scheduleEditor); insertChildClient(m_scheduleEditor); QTabWidget *tab = addTabWidget(); PertResult *p = new PertResult(part, doc, tab); p->setObjectName("PertResult"); addView(p, tab, i18n("Result")); connect(m_scheduleEditor, &ScheduleEditor::scheduleSelectionChanged, p, &PertResult::slotScheduleSelectionChanged); PertCpmView *c = new PertCpmView(part, doc, tab); c->setObjectName("PertCpmView"); addView(c, tab, i18n("Critical Path")); connect(m_scheduleEditor, &ScheduleEditor::scheduleSelectionChanged, c, &PertCpmView::slotScheduleSelectionChanged); ScheduleLogView *v = new ScheduleLogView(part, doc, tab); v->setObjectName("ScheduleLogView"); addView(v, tab, i18n("Scheduling Log")); connect(m_scheduleEditor, SIGNAL(scheduleSelectionChanged(KPlato::ScheduleManager*)), v, SLOT(slotScheduleSelectionChanged(KPlato::ScheduleManager*))); connect(v, &ScheduleLogView::editNode, this, &ScheduleHandlerView::editNode); connect(v, &ScheduleLogView::editResource, this, &ScheduleHandlerView::editResource); } void ScheduleHandlerView::currentTabChanged(int) { } ViewBase *ScheduleHandlerView::hitView(const QPoint &/*glpos */) { //debugPlan<"<()) { v->setGuiActive(active); } m_activeview = active ? this : 0; emit guiActivated(this, active); } void ScheduleHandlerView::slotGuiActivated(ViewBase *, bool) { } SchedulingRange::SchedulingRange(KoDocument *doc, QWidget *parent) : QWidget(parent) , m_doc(doc) , m_project(0) { setupUi(this); connect(targetStartTime, &QAbstractSpinBox::editingFinished, this, &SchedulingRange::slotStartChanged); connect(targetEndTime, &QAbstractSpinBox::editingFinished, this, &SchedulingRange::slotEndChanged); } void SchedulingRange::setReadWrite(bool rw) { targetStartTime->setEnabled(rw); targetEndTime->setEnabled(rw); } void SchedulingRange::setProject(Project *project) { if (m_project) { disconnect(m_project, &Project::nodeChanged, this, &SchedulingRange::slotProjectChanged); } m_project = project; if (m_project) { connect(m_project, &Project::nodeChanged, this, &SchedulingRange::slotProjectChanged); slotProjectChanged(m_project); } } void SchedulingRange::slotProjectChanged(Node *node) { if (node != m_project) { return; } if (targetStartTime->dateTime() != m_project->constraintStartTime()) { targetStartTime->setDateTime(m_project->constraintStartTime()); } if (targetEndTime->dateTime() != m_project->constraintEndTime()) { targetEndTime->setDateTime(m_project->constraintEndTime()); } } void SchedulingRange::slotStartChanged() { if (!m_project || !m_doc) { return; } if (targetStartTime->dateTime() == m_project->constraintStartTime()) { return; } ProjectModifyStartTimeCmd *cmd = new ProjectModifyStartTimeCmd(*m_project, targetStartTime->dateTime(), kundo2_i18n("Modify project target start time")); m_doc->addCommand(cmd); } void SchedulingRange::slotEndChanged() { if (!m_project || !m_doc) { return; } if (targetEndTime->dateTime() == m_project->constraintEndTime()) { return; } ProjectModifyEndTimeCmd *cmd = new ProjectModifyEndTimeCmd(*m_project, targetEndTime->dateTime(), kundo2_i18n("Modify project target end time")); m_doc->addCommand(cmd); } } // namespace KPlato