File indexing completed on 2024-04-28 16:24:39

0001 /* This file is part of the KDE project
0002   Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
0003   Copyright (C) 2002 - 2010 Dag Andersen <danders@get2net.dk>
0004   Copyright (C) 2019 Dag Andersen <danders@get2net.dk>
0005   
0006   This library is free software; you can redistribute it and/or
0007   modify it under the terms of the GNU Library General Public
0008   License as published by the Free Software Foundation; either
0009   version 2 of the License, or (at your option) any later version.
0010 
0011   This library is distributed in the hope that it will be useful,
0012   but WITHOUT ANY WARRANTY; without even the implied warranty of
0013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014   Library General Public License for more details.
0015 
0016   You should have received a copy of the GNU Library General Public License
0017   along with this library; see the file COPYING.LIB.  If not, write to
0018   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019 * Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KPTVIEW_H
0023 #define KPTVIEW_H
0024 
0025 #include "plan_export.h"
0026 
0027 #include <KoView.h>
0028 
0029 #include "kptcontext.h"
0030 #include "kptviewbase.h"
0031 
0032 #include <QActionGroup>
0033 #include <QDockWidget>
0034 #include <QMap>
0035 
0036 #include <kconfigdialog.h>
0037 
0038 class QMenu;
0039 class QPrintDialog;
0040 class QStackedWidget;
0041 class QSplitter;
0042 class QUrl;
0043 class QToolButton;
0044 class KUndo2Command;
0045 class QAction;
0046 
0047 class KToggleAction;
0048 class QLabel;
0049 class KConfigSkeleton;
0050 class KConfigSkeletonItem;
0051 class KPageWidgetItem;
0052 
0053 class KoView;
0054 
0055 namespace KPlato
0056 {
0057 
0058 class View;
0059 class ViewBase;
0060 class ViewListItem;
0061 class ViewListWidget;
0062 struct ViewInfo;
0063 class AccountsView;
0064 class ResourceCoverageView;
0065 class GanttView;
0066 class PertEditor;
0067 class AccountsEditor;
0068 class TaskEditor;
0069 class CalendarEditor;
0070 class ScheduleEditor;
0071 class ScheduleManager;
0072 class CalculateScheduleCmd;
0073 class ResourceAssignmentView;
0074 class TaskStatusView;
0075 class Calendar;
0076 class MainDocument;
0077 class Part;
0078 class Node;
0079 class Project;
0080 class Task;
0081 class MainSchedule;
0082 class Schedule;
0083 class Resource;
0084 class ResourceGroup;
0085 class Relation;
0086 class Context;
0087 class ViewAdaptor;
0088 class ReportView;
0089 
0090 class ReportDesignDialog;
0091 
0092 class DockWidget;
0093 
0094 
0095 class PLAN_EXPORT View : public KoView
0096 {
0097     Q_OBJECT
0098 
0099 public:
0100     explicit View(KoPart *part, MainDocument *doc, QWidget *parent = 0);
0101     ~View() override;
0102 
0103     MainDocument *getPart() const;
0104 
0105     KoPart *getKoPart() const;
0106 
0107     Project& getProject() const;
0108 
0109     QMenu *popupMenu(const QString& name);
0110 
0111     virtual bool loadContext();
0112     virtual void saveContext(QDomElement &context) const;
0113 
0114     QWidget *canvas() const;
0115 
0116     KoPageLayout pageLayout() const override;
0117     void setPageLayout(const KoPageLayout &pageLayout) override;
0118 
0119     ScheduleManager *currentScheduleManager() const;
0120     long activeScheduleId() const;
0121     void setActiveSchedule(long id);
0122 
0123     /// Returns the default view information like standard name and tooltip for view type @p type
0124     ViewInfo defaultViewInfo(const QString &type) const;
0125     /// Returns the default category information like standard name and tooltip for category type @p type
0126     ViewInfo defaultCategoryInfo(const QString &type) const;
0127 
0128     ViewBase *createTaskEditor(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0129     ViewBase *createResourceEditor(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0130     ViewBase *createAccountsEditor(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0131     ViewBase *createCalendarEditor(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0132     ViewBase *createScheduleHandler(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0133     ScheduleEditor *createScheduleEditor(QWidget *parent);
0134     ViewBase *createScheduleEditor(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0135     ViewBase *createDependencyEditor(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0136     ViewBase *createPertEditor(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0137     ViewBase *createProjectStatusView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0138     ViewBase *createPerformanceStatusView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0139     ViewBase *createTaskStatusView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0140     ViewBase *createTaskView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0141     ViewBase *createTaskWorkPackageView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0142     ViewBase *createGanttView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0143     ViewBase *createMilestoneGanttView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0144     ViewBase *createResourceAppointmentsView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0145     ViewBase *createResourceAppointmentsGanttView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0146     ViewBase *createAccountsView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0147     ViewBase *createResourceAssignmentView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0148     ViewBase *createChartView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0149     ViewBase *createReportView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0150     ViewBase *createReportsGeneratorView(ViewListItem *cat, const QString &tag, const QString &name = QString(), const QString &tip = QString(), int index = -1);
0151 
0152     KoPrintJob * createPrintJob() override;
0153     QPrintDialog* createPrintDialog(KoPrintJob*, QWidget*) override;
0154 
0155 Q_SIGNALS:
0156     void currentScheduleManagerChanged(KPlato::ScheduleManager *sm);
0157     void taskModulesChanged(const QStringList &modules);
0158     void workPackagesAvailable(bool);
0159 
0160 public Q_SLOTS:
0161     void slotUpdate();
0162     void slotCreateNewProject();
0163     void slotEditCurrentResource();
0164     void slotEditResource(KPlato::Resource *resource);
0165     void slotEditCut();
0166     void slotEditCopy();
0167     void slotEditPaste();
0168     void slotRefreshView();
0169     void slotViewSelector(bool show);
0170 
0171     void slotAddTask();
0172     void slotAddSubTask();
0173     void slotAddMilestone();
0174     void slotAddSubMilestone();
0175     void slotProjectEdit();
0176     void slotDefineWBS();
0177     void slotCurrencyConfig();
0178 
0179     void slotCreateView();
0180 
0181     void openRelationDialog(KPlato::Node *par, KPlato::Node *child);
0182     void slotEditRelation(KPlato::Relation *rel);
0183     void slotAddRelation(KPlato::Node *par, KPlato::Node *child, int linkType);
0184     void slotModifyRelation(KPlato::Relation *rel, int linkType);
0185     void slotModifyCurrentRelation();
0186     void slotDeleteRelation();
0187 
0188     void slotRenameNode(KPlato::Node *node, const QString& name);
0189 
0190     void slotPopupMenuRequested(const QString& menuname, const QPoint &pos);
0191     void slotPopupMenu(const QString& menuname, const QPoint &pos, KPlato::ViewListItem *item);
0192 
0193     void addViewListItem(const KPlato::ViewListItem *item, const KPlato::ViewListItem *parent, int index);
0194     void removeViewListItem(const KPlato::ViewListItem *item);
0195 
0196     void slotOpenReportFile();
0197 
0198     void slotSelectionChanged(KPlato::ScheduleManager *sm);
0199     void slotUpdateViewInfo(KPlato::ViewListItem *itm);
0200 
0201     /// Load the workpackages from @p urls into @p project.
0202     void loadWorkPackage(KPlato::Project *project, const QList<QUrl> &urls);
0203 
0204     void slotCreateTemplate();
0205 
0206 protected Q_SLOTS:
0207     void slotGuiActivated(KPlato::ViewBase *view, bool);
0208     void slotViewActivated(KPlato::ViewListItem*, KPlato::ViewListItem*);
0209     void slotPlugScheduleActions();
0210     void slotViewSchedule(QAction *act);
0211     void slotScheduleAdded(const KPlato::ScheduleManager*);
0212     void slotScheduleRemoved(const KPlato::ScheduleManager*);
0213     void slotScheduleSwapped(KPlato::ScheduleManager *from, KPlato::ScheduleManager *to);
0214     void slotScheduleCalculated(KPlato::Project *project, KPlato::ScheduleManager *manager);
0215 
0216     void slotAddScheduleManager(KPlato::Project *project);
0217     void slotDeleteScheduleManager(KPlato::Project *project, KPlato::ScheduleManager *sm);
0218     void slotMoveScheduleManager(KPlato::ScheduleManager *sm, KPlato::ScheduleManager *parent, int index);
0219     void slotCalculateSchedule(KPlato::Project*, KPlato::ScheduleManager*);
0220     void slotBaselineSchedule(KPlato::Project *project, KPlato::ScheduleManager *sm);
0221 
0222     void slotProjectWorktime();
0223 
0224     void slotOpenCurrentNode();
0225     void slotOpenNode(KPlato::Node *node);
0226     void slotTaskProgress();
0227     void slotOpenProjectDescription();
0228     void slotTaskDescription();
0229     void slotOpenTaskDescription(bool);
0230     void slotDocuments();
0231     void slotDeleteTaskList(QList<KPlato::Node*> lst);
0232     void slotDeleteTask(KPlato::Node *node);
0233     void slotDeleteCurrentTask();
0234     void slotIndentTask();
0235     void slotUnindentTask();
0236     void slotMoveTaskUp();
0237     void slotMoveTaskDown();
0238 
0239     void slotConnectNode();
0240 
0241     void slotDeleteResource(KPlato::Resource *resource);
0242     void slotDeleteResourceGroup(KPlato::ResourceGroup *group);
0243     void slotDeleteResourceObjects(QObjectList);
0244 
0245     void slotCurrentChanged(int);
0246     void slotSelectDefaultView();
0247 
0248     void slotInsertResourcesFile(const QString&, const QUrl &projects);
0249     void slotInsertFile();
0250 
0251     void slotLoadSharedProjects();
0252 
0253     void slotWorkPackageLoaded();
0254     void slotMailWorkpackage(KPlato::Node *node, KPlato::Resource *resource = 0);
0255     void slotPublishWorkpackages(const QList<KPlato::Node*> &nodes, KPlato::Resource *resource, bool mailTo);
0256 
0257     void createReportView(const QDomDocument &doc);
0258 
0259     void saveTaskModule(const QUrl &url, KPlato::Project *project);
0260     void removeTaskModule(const QUrl &url);
0261 
0262 protected:
0263     void guiActivateEvent(bool activated) override;
0264     void updateReadWrite(bool readwrite) override;
0265 
0266     QList<QAction*> sortedActionList();
0267     QAction *addScheduleAction(ScheduleManager *sch);
0268     void setLabel(ScheduleManager *sm = 0);
0269     Task *currentTask() const;
0270     Node *currentNode() const;
0271     Resource *currentResource();
0272     ResourceGroup *currentResourceGroup();
0273     Calendar *currentCalendar();
0274     void updateView(QWidget *widget);
0275 
0276     ViewBase *currentView() const;
0277 
0278 private Q_SLOTS:
0279     void slotActionDestroyed(QObject *o);
0280     void slotViewListItemRemoved(KPlato::ViewListItem *item);
0281     void slotViewListItemInserted(KPlato::ViewListItem *item, KPlato::ViewListItem *parent, int index);
0282 
0283     void slotProjectEditFinished(int result);
0284     void slotTaskEditFinished(int result);
0285     void slotSummaryTaskEditFinished(int result);
0286     void slotEditResourceFinished(int result);
0287     void slotProjectWorktimeFinished(int result);
0288     void slotDefineWBSFinished(int result);
0289     void slotCurrencyConfigFinished(int result);
0290     void slotInsertFileFinished(int result);
0291     void slotAddSubTaskFinished(int result);
0292     void slotAddTaskFinished(int result);
0293     void slotAddSubMilestoneFinished(int result);
0294     void slotAddMilestoneFinished(int result);
0295     void slotTaskProgressFinished(int result);
0296     void slotMilestoneProgressFinished(int result);
0297     void slotTaskDescriptionFinished(int result);
0298     void slotDocumentsFinished(int result);
0299     void slotAddRelationFinished(int result);
0300     void slotModifyRelationFinished(int result);
0301     void slotReportDesignFinished(int result);
0302     void slotOpenReportFileFinished(int result);
0303     void slotCreateViewFinished(int result);
0304     void slotLoadSharedProjectsFinished(int result);
0305     void openWorkPackageMergeDialog();
0306     void workPackageMergeDialogFinished(int result);
0307     void slotRemoveCommands();
0308 
0309     void initiateViews();
0310     void slotViewScheduleManager(KPlato::ScheduleManager *sm);
0311 
0312 private:
0313     void createViews();
0314     ViewBase *createView(ViewListItem *cat, const QString &type, const QString &tag, const QString &name, const QString &tip, int index = -1);
0315 
0316     QString standardTaskStatusReport() const;
0317 
0318 private:
0319     QSplitter *m_sp;
0320     QStackedWidget *m_tab;
0321 
0322     ViewListWidget *m_viewlist;
0323     ViewListItem *m_viewlistItem; // requested popupmenu item
0324 
0325     //QDockWidget *m_toolbox;
0326 
0327     int m_viewGrp;
0328     int m_defaultFontSize;
0329     int m_currentEstimateType;
0330 
0331     bool m_updateAccountsview;
0332     bool m_updateResourceAssignmentView;
0333     bool m_updatePertEditor;
0334 
0335     QLabel *m_estlabel;
0336     QToolButton *m_workPackageButton;
0337 
0338     ViewAdaptor* m_dbus;
0339 
0340     QActionGroup *m_scheduleActionGroup;
0341     QMap<QAction*, ScheduleManager*> m_scheduleActions;
0342 
0343     QMultiMap<ScheduleManager*, CalculateScheduleCmd*> m_calculationcommands;
0344     QList<KUndo2Command*> m_undocommands;
0345 
0346     bool m_readWrite;
0347     int m_defaultView;
0348     QList<int> m_visitedViews;
0349 
0350     QList<DockWidget*> m_dockers;
0351 
0352     // ------ File
0353     QAction *actionCreateTemplate;
0354     QAction *actionCreateNewProject;
0355 
0356     // ------ Edit
0357     QAction *actionCut;
0358     QAction *actionCopy;
0359     QAction *actionPaste;
0360 
0361     // ------ View
0362     KToggleAction *actionViewSelector;
0363 
0364     // ------ Insert
0365     // ------ Project
0366     QAction *actionEditMainProject;
0367 
0368     // ------ Tools
0369     QAction *actionEditStandardWorktime;
0370     QAction *actionDefineWBS;
0371     QAction *actionInsertFile;
0372     QAction *actionCurrencyConfig;
0373     QAction *actionLoadSharedProjects;
0374     QAction *actionOpenReportFile;
0375 
0376     // ------ Settings
0377     QAction *actionConfigure;
0378 
0379     // ------ Popup
0380     QAction *actionOpenNode;
0381     QAction *actionTaskProgress;
0382     QAction *actionTaskDescription;
0383     QAction *actionDocuments;
0384     QAction *actionDeleteTask;
0385     QAction *actionIndentTask;
0386     QAction *actionUnindentTask;
0387     QAction *actionMoveTaskUp;
0388     QAction *actionMoveTaskDown;
0389 
0390     QAction *actionEditResource;
0391     QAction *actionEditRelation;
0392     QAction *actionDeleteRelation;
0393 
0394     //Test
0395     QAction *actNoInformation;
0396 
0397     QMap<ViewListItem*, QAction*> m_reportActionMap;
0398 
0399     KoPart *m_partpart;
0400 };
0401 
0402 
0403 } //Kplato namespace
0404 
0405 #endif