kplato

kptview.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
3 Copyright (C) 2002 - 2005 Dag Andersen <danders@get2net.dk>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <kprinter.h>
22#include <tdemessagebox.h>
23
24#include <KoMainWindow.h>
25
26#include <tqapplication.h>
27#include <tqpainter.h>
28#include <tqiconset.h>
29#include <tqlayout.h>
30#include <tqsplitter.h>
31#include <tqcanvas.h>
32#include <tqscrollview.h>
33#include <tqcolor.h>
34#include <tqlabel.h>
35#include <tqstring.h>
36#include <tqstringlist.h>
37#include <tqvbox.h>
38#include <tqgrid.h>
39#include <tqsize.h>
40#include <tqheader.h>
41#include <tqtabwidget.h>
42#include <tqwidgetstack.h>
43#include <tqtimer.h>
44#include <tqpopupmenu.h>
45#include <tqpair.h>
46
47#include <kiconloader.h>
48#include <tdeaction.h>
49#include <kstdaction.h>
50#include <tdelocale.h>
51#include <kdebug.h>
52#include <tdelistview.h>
53#include <tdestdaccel.h>
54#include <tdeaccelgen.h>
55#include <kstatusbar.h>
56#include <kxmlguifactory.h>
57
58#include <kstandarddirs.h>
59#include <kdesktopfile.h>
60#include <kcommand.h>
61#include <tdefiledialog.h>
62
63#include "kptview.h"
64#include "kptaccountsview.h"
65#include "kptfactory.h"
66#include "kptmilestoneprogressdialog.h"
67#include "kptnode.h"
68#include "kptpart.h"
69#include "kptproject.h"
70#include "kptmainprojectdialog.h"
71#include "kptprojectdialog.h"
72#include "kpttask.h"
73#include "kptsummarytaskdialog.h"
74#include "kpttaskdialog.h"
75#include "kpttaskprogressdialog.h"
76#include "kptganttview.h"
77#include "kptpertview.h"
78//#include "kptreportview.h"
79#include "kptdatetime.h"
80#include "kptcommand.h"
81#include "kptrelation.h"
82#include "kptrelationdialog.h"
83#include "kptresourceview.h"
84#include "kptresourcedialog.h"
85#include "kptresource.h"
86#include "kptresourcesdialog.h"
87#include "kptcalendarlistdialog.h"
88#include "kptstandardworktimedialog.h"
89#include "kptcanvasitem.h"
90#include "kptconfigdialog.h"
91#include "kptwbsdefinitiondialog.h"
92#include "kptaccountsdialog.h"
93
94#include "KDGanttView.h"
95#include "KDGanttViewTaskItem.h"
96#include "KPtViewIface.h"
97
98namespace KPlato
99{
100
101View::View(Part* part, TQWidget* parent, const char* /*name*/)
102 : KoView(part, parent, "Main View"),
103 m_ganttview(0),
104 m_ganttlayout(0),
105 m_pertview(0),
106 m_pertlayout(0),
107// m_reportview(0),
108 m_baselineMode(false),
109 m_currentEstimateType(Effort::Use_Expected)
110{
111 //kdDebug()<<k_funcinfo<<endl;
112 getProject().setCurrentSchedule(Schedule::Expected);
113
114 setInstance(Factory::global());
115 if ( !part->isReadWrite() )
116 setXMLFile("kplato_readonly.rc");
117 else
118 setXMLFile("kplato.rc");
119 m_dcop = 0L;
120 // build the DCOP object
121 dcopObject();
122
123 m_tab = new TQWidgetStack(this);
124 TQVBoxLayout *layout = new TQVBoxLayout(this);
125 layout->add(m_tab);
126
127 m_ganttview = new GanttView(m_tab, part->isReadWrite());
128 m_tab->addWidget(m_ganttview);
129 m_updateGanttview = false;
130 m_ganttview->draw(getPart()->getProject());
131
132 m_pertview = new PertView( this, m_tab, layout );
133 m_tab->addWidget(m_pertview);
134
135 m_resourceview = new ResourceView( this, m_tab );
136 m_updateResourceview = true;
137 m_tab->addWidget(m_resourceview);
138
139 m_accountsview = new AccountsView( getProject(), this, m_tab );
140 m_updateAccountsview = true;
141 m_tab->addWidget(m_accountsview);
142
143 //m_reportview = new ReportView(this, m_tab);
144 //m_tab->addWidget(m_reportview);
145
146 connect(m_tab, TQ_SIGNAL(aboutToShow(TQWidget *)), this, TQ_SLOT(slotAboutToShow(TQWidget *)));
147
148 connect(m_pertview, TQ_SIGNAL(addRelation(Node*, Node*)), TQ_SLOT(slotAddRelation(Node*, Node*)));
149 connect(m_pertview, TQ_SIGNAL(modifyRelation(Relation*)), TQ_SLOT(slotModifyRelation(Relation*)));
150
151 connect(m_ganttview, TQ_SIGNAL(enableActions(bool)), TQ_SLOT(setTaskActionsEnabled(bool)));
152 connect(m_ganttview, TQ_SIGNAL(addRelation(Node*, Node*, int)), TQ_SLOT(slotAddRelation(Node*, Node*, int)));
153 connect(m_ganttview, TQ_SIGNAL(modifyRelation(Relation*, int)), TQ_SLOT(slotModifyRelation(Relation*, int)));
154 connect(m_ganttview, TQ_SIGNAL(modifyRelation(Relation*)), TQ_SLOT(slotModifyRelation(Relation*)));
155 connect(m_ganttview, TQ_SIGNAL(itemDoubleClicked()), TQ_SLOT(slotOpenNode()));
156 connect(m_ganttview, TQ_SIGNAL(itemRenamed(Node*, const TQString&)),this, TQ_SLOT(slotRenameNode(Node*, const TQString&)));
157 connect(m_ganttview, TQ_SIGNAL(requestPopupMenu(const TQString&, const TQPoint &)),this, TQ_SLOT(slotPopupMenu(const TQString&, const TQPoint&)));
158 connect(m_resourceview, TQ_SIGNAL(itemDoubleClicked()), TQ_SLOT(slotEditResource()));
159
160 // The menu items
161 // ------ Edit
162 actionCut = KStdAction::cut( this, TQ_SLOT( slotEditCut() ), actionCollection(), "edit_cut" );
163 actionCopy = KStdAction::copy( this, TQ_SLOT( slotEditCopy() ), actionCollection(), "edit_copy" );
164 actionPaste = KStdAction::paste( this, TQ_SLOT( slotEditPaste() ), actionCollection(), "edit_paste" );
165
166 actionIndentTask = new TDEAction(i18n("Indent Task"), "indent_task", 0, this,
167 TQ_SLOT(slotIndentTask()), actionCollection(), "indent_task");
168 actionUnindentTask = new TDEAction(i18n("Unindent Task"), "unindent_task", 0, this,
169 TQ_SLOT(slotUnindentTask()), actionCollection(), "unindent_task");
170 actionMoveTaskUp = new TDEAction(i18n("Move Up"), "move_task_up", 0, this,
171 TQ_SLOT(slotMoveTaskUp()), actionCollection(), "move_task_up");
172 actionMoveTaskDown = new TDEAction(i18n("Move Down"), "move_task_down", 0, this,
173 TQ_SLOT(slotMoveTaskDown()), actionCollection(), "move_task_down");
174
175 // ------ View
176 actionViewGantt = new TDEAction(i18n("Gantt"), "gantt_chart", 0, this, TQ_SLOT(slotViewGantt()), actionCollection(), "view_gantt");
177
178 TQString group = "EstimationType";
179 actionViewExpected = new TDERadioAction(i18n("Expected"), 0, 0, this, TQ_SLOT(slotViewExpected()), actionCollection(), "view_expected");
180 actionViewExpected->setExclusiveGroup(group);
181 actionViewOptimistic = new TDERadioAction(i18n("Optimistic"), 0, 0, this, TQ_SLOT(slotViewOptimistic()), actionCollection(), "view_optimistic");
182 actionViewOptimistic->setExclusiveGroup(group);
183 actionViewPessimistic = new TDERadioAction(i18n("Pessimistic"), 0, 0, this, TQ_SLOT(slotViewPessimistic()), actionCollection(), "view_pessimistic");
184 actionViewPessimistic->setExclusiveGroup(group);
185
186 actionViewGanttResources = new TDEToggleAction(i18n("Resources"), 0, 0, this, TQ_SLOT(slotViewGanttResources()), actionCollection(), "view_gantt_showResources");
187 actionViewGanttTaskName = new TDEToggleAction(i18n("Task Name"), 0, 0, this, TQ_SLOT(slotViewGanttTaskName()), actionCollection(), "view_gantt_showTaskName");
188 actionViewGanttTaskLinks = new TDEToggleAction(i18n("Task Links"), 0, 0, this, TQ_SLOT(slotViewGanttTaskLinks()), actionCollection(), "view_gantt_showTaskLinks");
189 actionViewGanttProgress = new TDEToggleAction(i18n("Progress"), 0, 0, this, TQ_SLOT(slotViewGanttProgress()), actionCollection(), "view_gantt_showProgress");
190 actionViewGanttFloat = new TDEToggleAction(i18n("Float"), 0, 0, this, TQ_SLOT(slotViewGanttFloat()), actionCollection(), "view_gantt_showFloat");
191 actionViewGanttCriticalTasks = new TDEToggleAction(i18n("Critical Tasks"), 0, 0, this, TQ_SLOT(slotViewGanttCriticalTasks()), actionCollection(), "view_gantt_showCriticalTasks");
192 actionViewGanttCriticalPath = new TDEToggleAction(i18n("Critical Path"), 0, 0, this, TQ_SLOT(slotViewGanttCriticalPath()), actionCollection(), "view_gantt_showCriticalPath");
193
194// actionViewGanttNotScheduled = new TDEToggleAction(i18n("Not Scheduled"), 0, 0, this, TQ_SLOT(slotViewGanttNotScheduled()), actionCollection(), "view_gantt_showNotScheduled");
195
196 actionViewTaskAppointments = new TDEToggleAction(i18n("Show Allocations"), 0, 0, this, TQ_SLOT(slotViewTaskAppointments()), actionCollection(), "view_task_appointments");
197
198 actionViewPert = new TDEAction(i18n("Network"), "pert_chart", 0, this, TQ_SLOT(slotViewPert()), actionCollection(), "view_pert");
199
200 actionViewResources = new TDEAction(i18n("Resources"), "resources", 0, this, TQ_SLOT(slotViewResources()), actionCollection(), "view_resources");
201
202 actionViewResourceAppointments = new TDEToggleAction(i18n("Show Allocations"), 0, 0, this, TQ_SLOT(slotViewResourceAppointments()), actionCollection(), "view_resource_appointments");
203
204 actionViewAccounts = new TDEAction(i18n("Accounts"), "accounts", 0, this, TQ_SLOT(slotViewAccounts()), actionCollection(), "view_accounts");
205
206 //actionViewReports = new TDEAction(i18n("Reports"), "reports", 0, this, TQ_SLOT(slotViewReports()), actionCollection(), "view_reports");
207
208 // ------ Insert
209 actionAddTask = new TDEAction(i18n("Task..."), "add_task", 0, this,
210 TQ_SLOT(slotAddTask()), actionCollection(), "add_task");
211 actionAddSubtask = new TDEAction(i18n("Sub-Task..."), "add_sub_task", 0, this,
212 TQ_SLOT(slotAddSubTask()), actionCollection(), "add_sub_task");
213 actionAddMilestone = new TDEAction(i18n("Milestone..."), "add_milestone", 0, this,
214 TQ_SLOT(slotAddMilestone()), actionCollection(), "add_milestone");
215
216 // ------ Project
217 actionEditMainProject = new TDEAction(i18n("Edit Main Project..."), "edit", 0, this, TQ_SLOT(slotProjectEdit()), actionCollection(), "project_edit");
218 actionEditStandardWorktime = new TDEAction(i18n("Edit Standard Worktime..."), "edit", 0, this, TQ_SLOT(slotProjectWorktime()), actionCollection(), "project_worktime");
219 actionEditCalendar = new TDEAction(i18n("Edit Calendar..."), "edit", 0, this, TQ_SLOT(slotProjectCalendar()), actionCollection(), "project_calendar");
220 actionEditAccounts = new TDEAction(i18n("Edit Accounts..."), "edit", 0, this, TQ_SLOT(slotProjectAccounts()), actionCollection(), "project_accounts");
221 actionEditResources = new TDEAction(i18n("Edit Resources..."), "edit", 0, this, TQ_SLOT(slotProjectResources()), actionCollection(), "project_resources");
222
223 actionCalculate = new TDEActionMenu(i18n("Calculate"), "project_calculate", actionCollection(), "project_calculate");
224 connect(actionCalculate, TQ_SIGNAL(activated()), TQ_SLOT(slotProjectCalculate()));
225
226 actionCalculateExpected = new TDEAction(i18n("Expected"), 0, 0, this, TQ_SLOT(slotProjectCalculateExpected()), actionCollection(), "project_calculate_expected");
227 actionCalculate->insert(actionCalculateExpected);
228
229 actionCalculateOptimistic = new TDEAction(i18n("Optimistic"), 0, 0, this, TQ_SLOT(slotProjectCalculateOptimistic()), actionCollection(), "project_calculate_optimistic");
230 actionCalculate->insert(actionCalculateOptimistic);
231
232 actionCalculatePessimistic = new TDEAction(i18n("Pessimistic"), 0, 0, this, TQ_SLOT(slotProjectCalculatePessimistic()), actionCollection(), "project_calculate_pessimistic");
233 actionCalculate->insert(actionCalculatePessimistic);
234
235/* // ------ Reports
236 actionFirstpage = KStdAction::firstPage(m_reportview,TQ_SLOT(slotPrevPage()),actionCollection(),"go_firstpage");
237 connect(m_reportview, TQ_SIGNAL(setFirstPageActionEnabled(bool)), actionFirstpage, TQ_SLOT(setEnabled(bool)));
238 actionPriorpage = KStdAction::prior(m_reportview,TQ_SLOT(slotPrevPage()),actionCollection(),"go_prevpage");
239 connect(m_reportview, TQ_SIGNAL(setPriorPageActionEnabled(bool)), actionPriorpage, TQ_SLOT(setEnabled(bool)));
240 actionNextpage = KStdAction::next(m_reportview,TQ_SLOT(slotNextPage()),actionCollection(), "go_nextpage");
241 connect(m_reportview, TQ_SIGNAL(setNextPageActionEnabled(bool)), actionNextpage, TQ_SLOT(setEnabled(bool)));
242 actionLastpage = KStdAction::lastPage(m_reportview,TQ_SLOT(slotLastPage()),actionCollection(), "go_lastpage");
243 connect(m_reportview, TQ_SIGNAL(setLastPageActionEnabled(bool)), actionLastpage, TQ_SLOT(setEnabled(bool)));
244 m_reportview->enableNavigationBtn();*/
245 mainWindow()->toolBar("report")->hide();
246
247// new TDEAction(i18n("Design..."), "report_design", 0, this,
248// TQ_SLOT(slotReportDesign()), actionCollection(), "report_design");
249
250
251 // ------ Tools
252 actionDefineWBS =
253 new TDEAction(i18n("Define WBS Pattern..."), "tools_define_wbs", 0, this,
254 TQ_SLOT(slotDefineWBS()), actionCollection(), "tools_generate_wbs");
255 actionGenerateWBS =
256 new TDEAction(i18n("Generate WBS Code"), "tools_generate_wbs", 0, this,
257 TQ_SLOT(slotGenerateWBS()), actionCollection(), "tools_define_wbs");
258
259 // ------ Export (testing)
260 //actionExportGantt = new TDEAction(i18n("Export Ganttview"), "export_gantt", 0, this,
261 // TQ_SLOT(slotExportGantt()), actionCollection(), "export_gantt");
262
263 // ------ Settings
264 actionConfigure = new TDEAction(i18n("Configure KPlato..."), "configure", 0, this,
265 TQ_SLOT(slotConfigure()), actionCollection(), "configure");
266
267 // ------ Popup
268 actionOpenNode = new TDEAction(i18n("Edit..."), "edit", 0, this,
269 TQ_SLOT(slotOpenNode()), actionCollection(), "node_properties");
270 actionTaskProgress = new TDEAction(i18n("Progress..."), "edit", 0, this,
271 TQ_SLOT(slotTaskProgress()), actionCollection(), "task_progress");
272 actionDeleteTask = new TDEAction(i18n("Delete Task"), "edit-delete", 0, this,
273 TQ_SLOT(slotDeleteTask()), actionCollection(), "delete_task");
274
275 actionEditResource = new TDEAction(i18n("Edit Resource..."), "edit", 0, this,
276 TQ_SLOT(slotEditResource()), actionCollection(), "edit_resource");
277
278 // ------------------- Actions with a key binding and no GUI item
279 // Temporary, till we get a menu entry
280 actNoInformation = new TDEAction("Toggle no information", CTRL+SHIFT+Key_T, this, TQ_SLOT(slotViewGanttNoInformation()), actionCollection(), "show_noinformation");
281
282#ifndef NDEBUG
283 //new TDEAction("Print Debug", CTRL+SHIFT+Key_P, this, TQ_SLOT( slotPrintDebug()), actionCollection(), "print_debug");
284 new TDEAction("Print Debug", CTRL+SHIFT+Key_P, this, TQ_SLOT(slotPrintSelectedDebug()), actionCollection(), "print_debug");
285 new TDEAction("Print Calendar Debug", CTRL+SHIFT+Key_C, this, TQ_SLOT(slotPrintCalendarDebug()), actionCollection(), "print_calendar_debug");
286// new TDEAction("Print Test Debug", CTRL+SHIFT+Key_T, this, TQ_SLOT(slotPrintTestDebug()), actionCollection(), "print_test_debug");
287
288 TDEAction* actExportGantt = new TDEAction( i18n( "Export Gantt" ), CTRL+SHIFT+Key_G,
289 this, TQ_SLOT( slotExportGantt() ), actionCollection(), "export_gantt" );
290
291#endif
292 // Stupid compilers ;)
293#ifndef NDEBUG
294/* Q_UNUSED( actPrintSelectedDebug );
295 Q_UNUSED( actPrintCalendarDebug );*/
296 Q_UNUSED( actExportGantt );
297#endif
298
299 m_estlabel = new KStatusBarLabel("", 0);
300 addStatusBarItem(m_estlabel, 0, true);
301 actionViewExpected->setChecked(true); //TODO: context
302 setScheduleActionsEnabled();
303 slotViewExpected();
304
305 setTaskActionsEnabled(false);
306}
307
308View::~View()
309{
310 delete m_dcop;
311 removeStatusBarItem(m_estlabel);
312 delete m_estlabel;
313}
314
315DCOPObject * View::dcopObject()
316{
317 if ( !m_dcop )
318 m_dcop = new ViewIface( this );
319
320 return m_dcop;
321}
322
323
324Project& View::getProject() const
325{
326 return getPart()->getProject();
327}
328
329void View::setZoom(double zoom) {
330 m_ganttview->setZoom(zoom);
331 m_pertview->setZoom(zoom);
332}
333
334void View::setupPrinter(KPrinter &/*printer*/) {
335 //kdDebug()<<k_funcinfo<<endl;
336}
337
338void View::print(KPrinter &printer) {
339 //kdDebug()<<k_funcinfo<<endl;
340 if (printer.previewOnly()) {
341 //HACK: KoMainWindow shows setup on print, but not on print preview!
342 if (!printer.setup()) {
343 return;
344 }
345 }
346 if (m_tab->visibleWidget() == m_ganttview)
347 {
348 m_ganttview->print(printer);
349 }
350 else if (m_tab->visibleWidget() == m_pertview)
351 {
352 m_pertview->print(printer);
353 }
354 else if (m_tab->visibleWidget() == m_resourceview)
355 {
356 m_resourceview->print(printer);
357 }
358 else if (m_tab->visibleWidget() == m_accountsview)
359 {
360 m_accountsview->print(printer);
361 }
362// else if (m_tab->visibleWidget() == m_reportview)
363// {
364// m_reportview->print(printer);
365// }
366
367}
368
369void View::slotEditCut() {
370 //kdDebug()<<k_funcinfo<<endl;
371}
372
373void View::slotEditCopy() {
374 //kdDebug()<<k_funcinfo<<endl;
375}
376
377void View::slotEditPaste() {
378 //kdDebug()<<k_funcinfo<<endl;
379}
380
381void View::slotViewExpected() {
382 //kdDebug()<<k_funcinfo<<endl;
383 m_currentEstimateType = Effort::Use_Expected;
384 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Expected));
385 slotUpdate(false);
386}
387
388void View::slotViewOptimistic() {
389 //kdDebug()<<k_funcinfo<<endl;
390 m_currentEstimateType = Effort::Use_Optimistic;
391 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Optimistic));
392 slotUpdate(false);
393}
394
395void View::slotViewPessimistic() {
396 //kdDebug()<<k_funcinfo<<endl;
397 m_currentEstimateType = Effort::Use_Pessimistic;
398 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Pessimistic));
399 slotUpdate(false);
400}
401
402void View::slotViewGanttResources() {
403 //kdDebug()<<k_funcinfo<<endl;
404 m_ganttview->setShowResources(actionViewGanttResources->isChecked());
405 if (m_tab->visibleWidget() == m_ganttview)
406 slotUpdate(false);
407}
408
409void View::slotViewGanttTaskName() {
410 //kdDebug()<<k_funcinfo<<endl;
411 m_ganttview->setShowTaskName(actionViewGanttTaskName->isChecked());
412 if (m_tab->visibleWidget() == m_ganttview)
413 slotUpdate(false);
414}
415
416void View::slotViewGanttTaskLinks() {
417 //kdDebug()<<k_funcinfo<<endl;
418 m_ganttview->setShowTaskLinks(actionViewGanttTaskLinks->isChecked());
419 if (m_tab->visibleWidget() == m_ganttview)
420 slotUpdate(false);
421}
422
423void View::slotViewGanttProgress() {
424 //kdDebug()<<k_funcinfo<<endl;
425 m_ganttview->setShowProgress(actionViewGanttProgress->isChecked());
426 if (m_tab->visibleWidget() == m_ganttview)
427 slotUpdate(false);
428}
429
430void View::slotViewGanttFloat() {
431 //kdDebug()<<k_funcinfo<<endl;
432 m_ganttview->setShowPositiveFloat(actionViewGanttFloat->isChecked());
433 if (m_tab->visibleWidget() == m_ganttview)
434 slotUpdate(false);
435}
436
437void View::slotViewGanttCriticalTasks() {
438 //kdDebug()<<k_funcinfo<<endl;
439 m_ganttview->setShowCriticalTasks(actionViewGanttCriticalTasks->isChecked());
440 if (m_tab->visibleWidget() == m_ganttview)
441 slotUpdate(false);
442}
443
444void View::slotViewGanttCriticalPath() {
445 //kdDebug()<<k_funcinfo<<endl;
446 m_ganttview->setShowCriticalPath(actionViewGanttCriticalPath->isChecked());
447 if (m_tab->visibleWidget() == m_ganttview)
448 slotUpdate(false);
449}
450
451void View::slotViewGanttNoInformation() {
452 kdDebug()<<k_funcinfo<<m_ganttview->showNoInformation()<<endl;
453 m_ganttview->setShowNoInformation(!m_ganttview->showNoInformation()); //Toggle
454 if (m_tab->visibleWidget() == m_ganttview)
455 slotUpdate(false);
456}
457
458void View::slotViewTaskAppointments() {
459 //kdDebug()<<k_funcinfo<<endl;
460 m_ganttview->setShowAppointments(actionViewTaskAppointments->isChecked());
461 m_updateGanttview = true;
462 if (m_tab->visibleWidget() == m_ganttview)
463 slotUpdate(false);
464}
465
466void View::slotViewGantt() {
467 //kdDebug()<<k_funcinfo<<endl;
468 m_tab->raiseWidget(m_ganttview);
469}
470
471void View::slotViewPert() {
472 //kdDebug()<<k_funcinfo<<endl;
473 m_tab->raiseWidget(m_pertview);
474}
475
476void View::slotViewResources() {
477 //kdDebug()<<k_funcinfo<<endl;
478 m_tab->raiseWidget(m_resourceview);
479}
480
481void View::slotViewResourceAppointments() {
482 //kdDebug()<<k_funcinfo<<endl;
483 m_resourceview->setShowAppointments(actionViewResourceAppointments->isChecked());
484 m_updateResourceview = true;
485 if (m_tab->visibleWidget() == m_resourceview)
486 slotUpdate(false);
487}
488
489void View::slotViewAccounts() {
490 //kdDebug()<<k_funcinfo<<endl;
491 m_tab->raiseWidget(m_accountsview);
492}
493
494void View::slotProjectEdit() {
495 MainProjectDialog *dia = new MainProjectDialog(getProject());
496 if (dia->exec()) {
497 KCommand *cmd = dia->buildCommand(getPart());
498 if (cmd) {
499 getPart()->addCommand(cmd);
500 }
501 }
502 delete dia;
503}
504
505void View::slotProjectCalendar() {
506 CalendarListDialog *dia = new CalendarListDialog(getProject());
507 if (dia->exec()) {
508 KCommand *cmd = dia->buildCommand(getPart());
509 if (cmd) {
510 //kdDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
511 getPart()->addCommand(cmd); //also executes
512 }
513 }
514 delete dia;
515}
516
517void View::slotProjectAccounts() {
518 AccountsDialog *dia = new AccountsDialog(getProject().accounts());
519 if (dia->exec()) {
520 KCommand *cmd = dia->buildCommand(getPart());
521 if (cmd) {
522 //kdDebug()<<k_funcinfo<<"Modifying account(s)"<<endl;
523 getPart()->addCommand(cmd); //also executes
524 }
525 }
526 delete dia;
527}
528
529void View::slotProjectWorktime() {
530 StandardWorktimeDialog *dia = new StandardWorktimeDialog(getProject());
531 if (dia->exec()) {
532 KCommand *cmd = dia->buildCommand(getPart());
533 if (cmd) {
534 //kdDebug()<<k_funcinfo<<"Modifying calendar(s)"<<endl;
535 getPart()->addCommand(cmd); //also executes
536 }
537 }
538 delete dia;
539}
540
541void View::slotProjectResources() {
542 ResourcesDialog *dia = new ResourcesDialog(getProject());
543 if (dia->exec()) {
544 KCommand *cmd = dia->buildCommand(getPart());
545 if (cmd) {
546 //kdDebug()<<k_funcinfo<<"Modifying resources"<<endl;
547 getPart()->addCommand(cmd); //also executes
548 }
549 }
550 delete dia;
551}
552
553void View::slotProjectCalculate() {
554 //kdDebug()<<k_funcinfo<<endl;
555 slotUpdate(true);
556}
557
558void View::slotProjectCalculateExpected() {
559 m_currentEstimateType = Effort::Use_Expected;
560 m_updateGanttview = true;
561 m_updateResourceview = true;
562 m_updateAccountsview = true;
563 slotUpdate(true);
564}
565
566void View::slotProjectCalculateOptimistic() {
567 m_currentEstimateType = Effort::Use_Optimistic;
568 m_updateGanttview = true;
569 m_updateResourceview = true;
570 m_updateAccountsview = true;
571 slotUpdate(true);
572}
573
574void View::slotProjectCalculatePessimistic() {
575 m_currentEstimateType = Effort::Use_Pessimistic;
576 m_updateGanttview = true;
577 m_updateResourceview = true;
578 m_updateAccountsview = true;
579 slotUpdate(true);
580}
581
582void View::projectCalculate() {
583 if (false /*getProject().actualEffort() > 0*/) {
584 // NOTE: This can be removed when proper baselining etc is implemented
585 if (KMessageBox::warningContinueCancel(this, i18n("Progress information will be deleted if the project is recalculated."), i18n("Calculate"), i18n("Calculate")) == KMessageBox::Cancel) {
586 return;
587 }
588 }
589 TQApplication::setOverrideCursor(TQt::waitCursor);
590 Schedule *ns = getProject().findSchedule((Schedule::Type)m_currentEstimateType);
591 KCommand *cmd;
592 if (ns) {
593 cmd = new RecalculateProjectCmd(getPart(), getProject(), *ns, i18n("Calculate"));
594 } else {
595 cmd = new CalculateProjectCmd(getPart(), getProject(), i18n("Standard"), (Effort::Use)m_currentEstimateType, i18n("Calculate"));
596 }
597 getPart()->addCommand(cmd);
598 TQApplication::restoreOverrideCursor();
599}
600
601void View::slotViewReportDesign() {
602 //kdDebug()<<k_funcinfo<<endl;
603}
604
605void View::slotViewReports() {
606 //kdDebug()<<k_funcinfo<<endl;
607 //m_tab->raiseWidget(m_reportview);
608}
609
610void View::slotAddSubTask() {
611 // If we are positionend on the root project, then what we really want to
612 // do is to add a first project. We will silently accept the challenge
613 // and will not complain.
614 Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
615 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
616 if (dia->exec()) {
617 Node *currNode = currentTask();
618 if (currNode)
619 {
620 KCommand *m = dia->buildCommand(getPart());
621 m->execute(); // do changes to task
622 delete m;
623 SubtaskAddCmd *cmd = new SubtaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Subtask"));
624 getPart()->addCommand(cmd); // add task to project
625 return;
626 }
627 else
628 kdDebug()<<k_funcinfo<<"Cannot insert new project. Hmm, no current node!?"<<endl;
629 }
630 delete node;
631 delete dia;
632}
633
634
635void View::slotAddTask() {
636 Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
637 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
638 if (dia->exec()) {
639 Node* currNode = currentTask();
640 if (currNode)
641 {
642 KCommand *m = dia->buildCommand(getPart());
643 m->execute(); // do changes to task
644 delete m;
645 TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Task"));
646 getPart()->addCommand(cmd); // add task to project
647 return;
648 }
649 else
650 kdDebug()<<k_funcinfo<<"Cannot insert new task. Hmm, no current node!?"<<endl;
651 }
652 delete node;
653 delete dia;
654}
655
656void View::slotAddMilestone() {
657 Task* node = getProject().createTask(currentTask());
658 node->effort()->set(Duration::zeroDuration);
659
660 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
661 if (dia->exec()) {
662 Node *currNode = currentTask();
663 if (currNode)
664 {
665 KCommand *m = dia->buildCommand(getPart());
666 m->execute(); // do changes to task
667 delete m;
668 TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Milestone"));
669 getPart()->addCommand(cmd); // add task to project
670 return;
671 }
672 else
673 kdDebug()<<k_funcinfo<<"Cannot insert new milestone. Hmm, no current node!?"<<endl;
674 }
675 delete node;
676 delete dia;
677}
678
679void View::slotDefineWBS() {
680 //kdDebug()<<k_funcinfo<<endl;
681 WBSDefinitionDialog *dia = new WBSDefinitionDialog(getPart()->wbsDefinition());
682 dia->exec();
683
684 delete dia;
685}
686
687void View::slotGenerateWBS() {
688 //kdDebug()<<k_funcinfo<<endl;
689 getPart()->generateWBS();
690 slotUpdate(false);
691}
692
693void View::slotConfigure() {
694 //kdDebug()<<k_funcinfo<<endl;
695 ConfigDialog *dia = new ConfigDialog(getPart()->config(), getProject());
696 dia->exec();
697 delete dia;
698}
699
700Node *View::currentTask()
701{
702 Node* task = 0;
703 if (m_tab->visibleWidget() == m_ganttview) {
704 task = m_ganttview->currentNode();
705 }
706 else if (m_tab->visibleWidget() == m_pertview) {
707 task = m_pertview->currentNode();
708 }
709 else if (m_tab->visibleWidget() == m_resourceview) {
710 task = m_resourceview->currentNode();
711 }
712 if ( 0 != task ) {
713 return task;
714 }
715 return &(getProject());
716}
717
718void View::slotOpenNode() {
719 //kdDebug()<<k_funcinfo<<endl;
720 Node *node = currentTask();
721 if (!node)
722 return;
723
724 switch (node->type()) {
725 case Node::Type_Project: {
726 Project *project = dynamic_cast<Project *>(node);
727 MainProjectDialog *dia = new MainProjectDialog(*project);
728 if (dia->exec()){
729 KCommand *m = dia->buildCommand(getPart());
730 if (m) {
731 getPart()->addCommand(m);
732 }
733 }
734 delete dia;
735 break;
736 }
737 case Node::Type_Subproject:
738 //TODO
739 break;
740 case Node::Type_Task: {
741 Task *task = dynamic_cast<Task *>(node);
742 TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
743 if (dia->exec()) {
744 KCommand *m = dia->buildCommand(getPart());
745 if (m) {
746 getPart()->addCommand(m);
747 }
748 }
749 delete dia;
750 break;
751 }
752 case Node::Type_Milestone: {
753 // Use the normal task dialog for now.
754 // Maybe milestone should have it's own dialog, but we need to be able to
755 // enter a duration in case we accidentally set a tasks duration to zero
756 // and hence, create a milestone
757 Task *task = dynamic_cast<Task *>(node);
758 TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
759 if (dia->exec()) {
760 KCommand *m = dia->buildCommand(getPart());
761 if (m) {
762 getPart()->addCommand(m);
763 }
764 }
765 delete dia;
766 break;
767 }
768 case Node::Type_Summarytask: {
769 Task *task = dynamic_cast<Task *>(node);
770 SummaryTaskDialog *dia = new SummaryTaskDialog(*task);
771 if (dia->exec()) {
772 KCommand *m = dia->buildCommand(getPart());
773 if (m) {
774 getPart()->addCommand(m);
775 }
776 }
777 delete dia;
778 break;
779 }
780 default:
781 break; // avoid warnings
782 }
783}
784
785void View::slotTaskProgress() {
786 //kdDebug()<<k_funcinfo<<endl;
787 Node *node = currentTask();
788 if (!node)
789 return;
790
791 switch (node->type()) {
792 case Node::Type_Project: {
793 break;
794 }
795 case Node::Type_Subproject:
796 //TODO
797 break;
798 case Node::Type_Task: {
799 Task *task = dynamic_cast<Task *>(node);
800 TaskProgressDialog *dia = new TaskProgressDialog(*task, getProject().standardWorktime());
801 if (dia->exec()) {
802 KCommand *m = dia->buildCommand(getPart());
803 if (m) {
804 getPart()->addCommand(m);
805 }
806 }
807 delete dia;
808 break;
809 }
810 case Node::Type_Milestone: {
811 Task *task = dynamic_cast<Task *>(node);
812 MilestoneProgressDialog *dia = new MilestoneProgressDialog(*task);
813 if (dia->exec()) {
814 KCommand *m = dia->buildCommand(getPart());
815 if (m) {
816 getPart()->addCommand(m);
817 }
818 }
819 delete dia;
820 break;
821 }
822 case Node::Type_Summarytask: {
823 // TODO
824 break;
825 }
826 default:
827 break; // avoid warnings
828 }
829}
830
831void View::slotDeleteTask()
832{
833 //kdDebug()<<k_funcinfo<<endl;
834 Node *node = currentTask();
835 if (node == 0 || node->getParent() == 0) {
836 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
837 return;
838 }
839 KMacroCommand *cmd = new KMacroCommand(i18n("Delete Task"));
840 cmd->addCommand(new NodeDeleteCmd(getPart(), node));
841 TQPtrListIterator<Relation> it = node->dependChildNodes();
842 for (; it.current(); ++it) {
843 cmd->addCommand(new DeleteRelationCmd(getPart(), it.current()));
844 }
845 it = node->dependParentNodes();
846 for (; it.current(); ++it) {
847 cmd->addCommand(new DeleteRelationCmd(getPart(),it.current()));
848 }
849 getPart()->addCommand(cmd);
850}
851
852void View::slotIndentTask()
853{
854 //kdDebug()<<k_funcinfo<<endl;
855 Node *node = currentTask();
856 if (node == 0 || node->getParent() == 0) {
857 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
858 return;
859 }
860 if (getProject().canIndentTask(node)) {
861 NodeIndentCmd *cmd = new NodeIndentCmd(getPart(), *node, i18n("Indent Task"));
862 getPart()->addCommand(cmd);
863 }
864}
865
866void View::slotUnindentTask()
867{
868 //kdDebug()<<k_funcinfo<<endl;
869 Node *node = currentTask();
870 if (node == 0 || node->getParent() == 0) {
871 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
872 return;
873 }
874 if (getProject().canUnindentTask(node)) {
875 NodeUnindentCmd *cmd = new NodeUnindentCmd(getPart(), *node, i18n("Unindent Task"));
876 getPart()->addCommand(cmd);
877 }
878}
879
880void View::slotMoveTaskUp()
881{
882 //kdDebug()<<k_funcinfo<<endl;
883
884 Node* task = currentTask();
885 if ( 0 == task ) {
886 // is always != 0. At least we would get the Project, but you never know who might change that
887 // so better be careful
888 kdError()<<k_funcinfo<<"No current task"<<endl;
889 return;
890 }
891
892 if ( Node::Type_Project == task->type() ) {
893 kdDebug()<<k_funcinfo<<"The root node cannot be moved up"<<endl;
894 return;
895 }
896 if (getProject().canMoveTaskUp(task)) {
897 NodeMoveUpCmd *cmd = new NodeMoveUpCmd(getPart(), *task, i18n("Move Task Up"));
898 getPart()->addCommand(cmd);
899 }
900}
901
902void View::slotMoveTaskDown()
903{
904 //kdDebug()<<k_funcinfo<<endl;
905
906 Node* task = currentTask();
907 if ( 0 == task ) {
908 // is always != 0. At least we would get the Project, but you never know who might change that
909 // so better be careful
910 return;
911 }
912
913 if ( Node::Type_Project == task->type() ) {
914 kdDebug()<<k_funcinfo<<"The root node cannot be moved down"<<endl;
915 return;
916 }
917 if (getProject().canMoveTaskDown(task)) {
918 NodeMoveDownCmd *cmd = new NodeMoveDownCmd(getPart(), *task, i18n("Move Task Down"));
919 getPart()->addCommand(cmd);
920 }
921}
922
923void View::slotAddRelation(Node *par, Node *child) {
924 //kdDebug()<<k_funcinfo<<endl;
925 Relation *rel = new Relation(par, child);
926 AddRelationDialog *dia = new AddRelationDialog(rel, this);
927 if (dia->exec()) {
928 KCommand *cmd = dia->buildCommand(getPart());
929 if (cmd)
930 getPart()->addCommand(cmd);
931 } else {
932 delete rel;
933 }
934 delete dia;
935}
936
937void View::slotAddRelation(Node *par, Node *child, int linkType) {
938 //kdDebug()<<k_funcinfo<<endl;
939 if (linkType == Relation::FinishStart ||
940 linkType == Relation::StartStart ||
941 linkType == Relation::FinishFinish)
942 {
943 Relation *rel = new Relation(par, child, static_cast<Relation::Type>(linkType));
944 getPart()->addCommand(new AddRelationCmd(getPart(), rel, i18n("Add Relation")));
945 } else {
946 slotAddRelation(par, child);
947 }
948}
949
950void View::slotModifyRelation(Relation *rel) {
951 //kdDebug()<<k_funcinfo<<endl;
952 ModifyRelationDialog *dia = new ModifyRelationDialog(rel, this);
953 if (dia->exec()) {
954 if (dia->relationIsDeleted()) {
955 getPart()->addCommand(new DeleteRelationCmd(getPart(), rel, i18n("Delete Relation")));
956 } else {
957 KCommand *cmd = dia->buildCommand(getPart());
958 if (cmd) {
959 getPart()->addCommand(cmd);
960 }
961 }
962 }
963 delete dia;
964}
965
966void View::slotModifyRelation(Relation *rel, int linkType) {
967 //kdDebug()<<k_funcinfo<<endl;
968 if (linkType == Relation::FinishStart ||
969 linkType == Relation::StartStart ||
970 linkType == Relation::FinishFinish)
971 {
972 getPart()->addCommand(new ModifyRelationTypeCmd(getPart(), rel, static_cast<Relation::Type>(linkType)));
973 } else {
974 slotModifyRelation(rel);
975 }
976}
977
978// testing
979void View::slotExportGantt() {
980 //kdDebug()<<k_funcinfo<<endl;
981 if (!m_ganttview) {
982 return;
983 }
984 TQString fn = KFileDialog::getSaveFileName( TQString(), TQString(), this );
985 if (!fn.isEmpty()) {
986 TQFile f(fn);
987 m_ganttview->exportGantt(&f);
988 }
989}
990
991void View::slotEditResource() {
992 //kdDebug()<<k_funcinfo<<endl;
993 Resource *r = m_resourceview->currentResource();
994 if (!r)
995 return;
996 ResourceDialog *dia = new ResourceDialog(getProject(), r);
997 if (dia->exec()) {
998 KCommand *cmd = dia->buildCommand(getPart());
999 if (cmd)
1000 getPart()->addCommand(cmd);
1001 }
1002 delete dia;
1003}
1004
1005void View::updateReadWrite(bool /*readwrite*/) {
1006}
1007
1008Part *View::getPart()const {
1009 return (Part *)koDocument();
1010}
1011
1012void View::slotConnectNode() {
1013 //kdDebug()<<k_funcinfo<<endl;
1014/* NodeItem *curr = m_ganttview->currentItem();
1015 if (curr) {
1016 kdDebug()<<k_funcinfo<<"node="<<curr->getNode().name()<<endl;
1017 }*/
1018}
1019
1020TQPopupMenu * View::popupMenu( const TQString& name )
1021{
1022 //kdDebug()<<k_funcinfo<<endl;
1023 Q_ASSERT(factory());
1024 if ( factory() )
1025 return ((TQPopupMenu*)factory()->container( name, this ));
1026 return 0L;
1027}
1028
1029void View::slotChanged(TQWidget *)
1030{
1031 //kdDebug()<<k_funcinfo<<endl;
1032 slotUpdate(false);
1033}
1034
1035void View::slotChanged()
1036{
1037 //kdDebug()<<k_funcinfo<<endl;
1038 slotUpdate(false);
1039}
1040
1041void View::slotUpdate(bool calculate)
1042{
1043 //kdDebug()<<k_funcinfo<<"calculate="<<calculate<<endl;
1044 if (calculate)
1045 projectCalculate();
1046
1047 m_updateGanttview = true;
1048 m_updateResourceview = true;
1049 m_updateAccountsview = true;
1050
1051 updateView(m_tab->visibleWidget());
1052}
1053
1054void View::slotAboutToShow(TQWidget *widget) {
1055 updateView(widget);
1056}
1057
1058void View::updateView(TQWidget *widget)
1059{
1060 TQApplication::setOverrideCursor(TQt::waitCursor);
1061 setScheduleActionsEnabled();
1062 setTaskActionsEnabled(false);
1063 mainWindow()->toolBar("report")->hide();
1064 if (widget == m_ganttview)
1065 {
1066 //kdDebug()<<k_funcinfo<<"draw gantt"<<endl;
1067 m_ganttview->setShowExpected(actionViewExpected->isChecked());
1068 m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
1069 m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
1070 if (m_updateGanttview)
1071 m_ganttview->drawChanges(getProject());
1072 setTaskActionsEnabled(widget, true);
1073 m_updateGanttview = false;
1074 }
1075 else if (widget == m_pertview)
1076 {
1077 //kdDebug()<<k_funcinfo<<"draw pertview"<<endl;
1078 m_pertview->draw();
1079 }
1080 else if (widget == m_resourceview)
1081 {
1082 //kdDebug()<<k_funcinfo<<"draw resourceview"<<endl;
1083 if (m_updateResourceview)
1084 m_resourceview->draw(getPart()->getProject());
1085 m_updateResourceview = false;
1086 }
1087 else if (widget == m_accountsview)
1088 {
1089 //kdDebug()<<k_funcinfo<<"draw accountsview"<<endl;
1090 if (m_updateAccountsview)
1091 m_accountsview->draw();
1092 m_updateAccountsview = false;
1093 }
1094/* else if (widget == m_reportview)
1095 {
1096 mainWindow()->toolBar("report")->show();
1097 m_reportview->enableNavigationBtn();
1098 }*/
1099 TQApplication::restoreOverrideCursor();
1100}
1101
1102void View::slotRenameNode(Node *node, const TQString& name) {
1103 //kdDebug()<<k_funcinfo<<name<<endl;
1104 if (node) {
1105 NodeModifyNameCmd *cmd = new NodeModifyNameCmd(getPart(), *node, name, i18n("Modify Name"));
1106 getPart()->addCommand(cmd);
1107 }
1108}
1109
1110void View::slotPopupMenu(const TQString& menuname, const TQPoint & pos)
1111{
1112 TQPopupMenu* menu = this->popupMenu(menuname);
1113 if (menu)
1114 menu->exec(pos);
1115}
1116
1117bool View::setContext(Context &context) {
1118 //kdDebug()<<k_funcinfo<<endl;
1119 m_currentEstimateType = context.currentEstimateType;
1120 getProject().setCurrentSchedule(context.currentSchedule);
1121 actionViewExpected->setChecked(context.actionViewExpected);
1122 actionViewOptimistic->setChecked(context.actionViewOptimistic);
1123 actionViewPessimistic->setChecked(context.actionViewPessimistic);
1124
1125 m_ganttview->setContext(context.ganttview, getProject());
1126 // hmmm, can't decide if these should be here or actions moved to ganttview
1127 actionViewGanttResources->setChecked(context.ganttview.showResources);
1128 actionViewGanttTaskName->setChecked(context.ganttview.showTaskName);
1129 actionViewGanttTaskLinks->setChecked(context.ganttview.showTaskLinks);
1130 actionViewGanttProgress->setChecked(context.ganttview.showProgress);
1131 actionViewGanttFloat->setChecked(context.ganttview.showPositiveFloat);
1132 actionViewGanttCriticalTasks->setChecked(context.ganttview.showCriticalTasks);
1133 actionViewGanttCriticalPath->setChecked(context.ganttview.showCriticalPath);
1134
1135 m_pertview->setContext(context.pertview);
1136 m_resourceview->setContext(context.resourceview);
1137 m_accountsview->setContext(context.accountsview);
1138// m_reportview->setContext(context.reportview);
1139
1140 if (context.currentView == "ganttview") {
1141 m_ganttview->setShowExpected(actionViewExpected->isChecked());
1142 m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
1143 m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
1144 slotViewGantt();
1145 } else if (context.currentView == "pertview") {
1146 slotViewPert();
1147 } else if (context.currentView == "resourceview") {
1148 slotViewResources();
1149 } else if (context.currentView == "accountsview") {
1150 slotViewAccounts();
1151 } else if (context.currentView == "reportview") {
1152 //slotViewReport();
1153 } else {
1154 slotViewGantt();
1155 }
1156 slotUpdate(false);
1157 return true;
1158}
1159
1160void View::getContext(Context &context) const {
1161 //kdDebug()<<k_funcinfo<<endl;
1162 context.currentEstimateType = m_currentEstimateType;
1163 if (getProject().currentSchedule())
1164 context.currentSchedule = getProject().currentSchedule()->id();
1165 context.actionViewExpected = actionViewExpected->isChecked();
1166 context.actionViewOptimistic = actionViewOptimistic->isChecked();
1167 context.actionViewPessimistic = actionViewPessimistic->isChecked();
1168
1169 if (m_tab->visibleWidget() == m_ganttview) {
1170 context.currentView = "ganttview";
1171 } else if (m_tab->visibleWidget() == m_pertview) {
1172 context.currentView = "pertview";
1173 } else if (m_tab->visibleWidget() == m_resourceview) {
1174 context.currentView = "resourceview";
1175 } else if (m_tab->visibleWidget() == m_accountsview) {
1176 context.currentView = "accountsview";
1177/* } else if (m_tab->visibleWidget() == m_reportview) {
1178 context.currentView = "reportview";*/
1179 }
1180 m_ganttview->getContext(context.ganttview);
1181 m_pertview->getContext(context.pertview);
1182 m_resourceview->getContext(context.resourceview);
1183 m_accountsview->getContext(context.accountsview);
1184// m_reportview->getContext(context.reportview);
1185}
1186
1187void View::setBaselineMode(bool /*on*/) {
1188 //kdDebug()<<k_funcinfo<<endl;
1189/* m_baselineMode = on;
1190
1191 m_ganttview->setReadWriteMode(!on);
1192
1193 actionCut->setEnabled(!on);
1194 actionCopy->setEnabled(!on);
1195 actionPaste->setEnabled(!on);
1196
1197 actionDeleteTask->setEnabled(!on);
1198 actionIndentTask->setEnabled(!on);
1199 actionUnindentTask->setEnabled(!on);
1200 actionMoveTaskUp->setEnabled(!on);
1201 actionMoveTaskDown->setEnabled(!on);
1202
1203 actionAddTask->setEnabled(!on);
1204 actionAddSubtask->setEnabled(!on);
1205 actionAddMilestone->setEnabled(!on);
1206
1207 actionEditStandardWorktime->setEnabled(!on);
1208 actionEditCalendar->setEnabled(!on);
1209 actionEditResources->setEnabled(!on);
1210 actionCalculate->setEnabled(!on);
1211
1212 actionEditResource->setEnabled(!on);*/
1213}
1214
1215// called when widget w is about to be shown
1216void View::setTaskActionsEnabled(TQWidget *w, bool on) {
1217 Node *n = 0;
1218 if (w == m_ganttview) {
1219 n = m_ganttview->currentNode();
1220 }// else pert, etc when implemented
1221
1222 actionAddTask->setEnabled(on);
1223 actionAddMilestone->setEnabled(on);
1224 // only enabled when we have a task selected
1225 bool o = (on && n);
1226 actionAddSubtask->setEnabled(o);
1227 actionDeleteTask->setEnabled(o);
1228 actionMoveTaskUp->setEnabled(o && getProject().canMoveTaskUp(n));
1229 actionMoveTaskDown->setEnabled(o && getProject().canMoveTaskDown(n));
1230 actionIndentTask->setEnabled(o && getProject().canIndentTask(n));
1231 actionUnindentTask->setEnabled(o && getProject().canUnindentTask(n));
1232}
1233
1234void View::setTaskActionsEnabled(bool on) {
1235 setTaskActionsEnabled(m_ganttview, on); //FIXME if more than ganttview can do this
1236}
1237
1238void View::setScheduleActionsEnabled() {
1239 actionViewExpected->setEnabled(getProject().findSchedule(Schedule::Expected));
1240 actionViewOptimistic->setEnabled(getProject().findSchedule(Schedule::Optimistic));
1241 actionViewPessimistic->setEnabled(getProject().findSchedule(Schedule::Pessimistic));
1242 if (getProject().notScheduled()) {
1243 m_estlabel->setText(i18n("Not scheduled"));
1244 return;
1245 }
1246 Schedule *ns = getProject().currentSchedule();
1247 if (ns->type() == Schedule::Expected) {
1248 actionViewExpected->setChecked(true);
1249 m_estlabel->setText(i18n("Expected"));
1250 } else if (ns->type() == Schedule::Optimistic) {
1251 actionViewOptimistic->setChecked(true);
1252 m_estlabel->setText(i18n("Optimistic"));
1253 } else if (ns->type() == Schedule::Pessimistic) {
1254 actionViewPessimistic->setChecked(true);
1255 m_estlabel->setText(i18n("Pessimistic"));
1256 }
1257}
1258
1259
1260#ifndef NDEBUG
1261void View::slotPrintDebug() {
1262 kdDebug()<<"-------- Debug printout: Node list" <<endl;
1263/* Node *curr = m_ganttview->currentNode();
1264 if (curr) {
1265 curr->printDebug(true,"");
1266 } else*/
1267 getPart()->getProject().printDebug(true, "");
1268}
1269void View::slotPrintSelectedDebug() {
1270 Node *curr = m_ganttview->currentNode();
1271 if (curr) {
1272 kdDebug()<<"-------- Debug printout: Selected node" <<endl;
1273 curr->printDebug(true,"");
1274 } else
1275 slotPrintDebug();
1276}
1277void View::slotPrintCalendarDebug() {
1278 kdDebug()<<"-------- Debug printout: Node list" <<endl;
1279/* Node *curr = m_ganttview->currentNode();
1280 if (curr) {
1281 curr->printDebug(true,"");
1282 } else*/
1283 getPart()->getProject().printCalendarDebug("");
1284}
1285void View::slotPrintTestDebug() {
1286 const TQStringList &lst = getPart()->xmlLoader().log();
1287
1288 for ( TQStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
1289 kdDebug()<<*it<<endl;
1290 }
1291// kdDebug()<<"------------Test 1---------------------"<<endl;
1292// {
1293// DateTime d1(TQDate(2006,1,2), TQTime(8,0,0));
1294// DateTime d2 = d1.addSecs(3600);
1295// Duration d = d2 - d1;
1296// bool b = d==Duration(0,0,0,3600);
1297// kdDebug()<<"1: Success="<<b<<" "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
1298// d = d1 - d2;
1299// b = d==Duration(0,0,0,3600);
1300// kdDebug()<<"2: Success="<<b<<" "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
1301// d2 = d2.addDays(-2);
1302// d = d1 - d2;
1303// b = d==Duration(2,0,0)-Duration(0,0,0,3600);
1304// kdDebug()<<"3: Success="<<b<<" "<<d1.toString()<<"-"<<d2.toString()<<"="<<d.toString()<<endl;
1305// d = d2 - d1;
1306// b = d==Duration(2,0,0)-Duration(0,0,0,3600);
1307// kdDebug()<<"4: Success="<<b<<" "<<d2.toString()<<"-"<<d1.toString()<<"="<<d.toString()<<endl;
1308// kdDebug()<<endl;
1309// b = (d2 + d)==d1;
1310// kdDebug()<<"5: Success="<<b<<" "<<d2<<"+"<<d.toString()<<"="<<d1<<endl;
1311// b = (d1 - d)==d2;
1312// kdDebug()<<"6: Success="<<b<<" "<<d1<<"-"<<d.toString()<<"="<<d2<<endl;
1313// } // end test 1
1314// kdDebug()<<endl;
1315// kdDebug()<<"------------Test 2 Single calendar-----------------"<<endl;
1316// {
1317// Calendar *t = new Calendar("Test 2");
1318// TQDate wdate(2006,1,2);
1319// DateTime before = DateTime(wdate.addDays(-1));
1320// DateTime after = DateTime(wdate.addDays(1));
1321// TQTime t1(8,0,0);
1322// TQTime t2(10,0,0);
1323// DateTime wdt1(wdate, t1);
1324// DateTime wdt2(wdate, t2);
1325// CalendarDay *day = new CalendarDay(TQDate(2006,1,2), Map::Working);
1326// day->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1327// if (!t->addDay(day)) {
1328// kdDebug()<<"Failed to add day"<<endl;
1329// delete day;
1330// delete t;
1331// return;
1332// }
1333// kdDebug()<<"Added date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
1334// kdDebug()<<"Found date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay()<<endl;
1335//
1336// CalendarDay *d = t->findDay(wdate);
1337// bool b = (day == d);
1338// kdDebug()<<"1: Success="<<b<<" Find same day"<<endl;
1339//
1340// DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
1341// b = !dt.isValid();
1342// kdDebug()<<"2: Success="<<b<<" firstAvailableAfter("<<after<<"): ="<<dt<<endl;
1343//
1344// dt = t->firstAvailableBefore(before, before.addDays(-10));
1345// b = !dt.isValid();
1346// kdDebug()<<"3: Success="<<b<<" firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
1347//
1348// dt = t->firstAvailableAfter(before, after);
1349// b = dt == wdt1;
1350// kdDebug()<<"4: Success="<<b<<" firstAvailableAfter("<<before<<"): ="<<dt<<endl;
1351//
1352// dt = t->firstAvailableBefore(after, before);
1353// b = dt == wdt2;
1354// kdDebug()<<"5: Success="<<b<<" firstAvailableBefore("<<after<<"): ="<<dt<<endl;
1355//
1356// b = t->hasInterval(before, after);
1357// kdDebug()<<"6: Success="<<b<<" hasInterval("<<before<<", "<<after<<")"<<endl;
1358//
1359// b = !t->hasInterval(after, after.addDays(1));
1360// kdDebug()<<"7: Success="<<b<<" !hasInterval("<<after<<", "<<after.addDays(1)<<")"<<endl;
1361//
1362// b = !t->hasInterval(before, before.addDays(-1));
1363// kdDebug()<<"8: Success="<<b<<" !hasInterval("<<before<<", "<<before.addDays(-1)<<")"<<endl;
1364//
1365// Duration e1(0, 2, 0); // 2 hours
1366// Duration e2 = t->effort(before, after);
1367// b = e1==e2;
1368// kdDebug()<<"9: Success="<<b<<" effort"<<e1.toString()<<" = "<<e2.toString()<<endl;
1369//
1370// delete t;
1371// }// end test 2
1372//
1373// kdDebug()<<endl;
1374// kdDebug()<<"------------Test 3 Parent calendar-----------------"<<endl;
1375// {
1376// Calendar *t = new Calendar("Test 3");
1377// Calendar *p = new Calendar("Test 3 parent");
1378// t->setParent(p);
1379// TQDate wdate(2006,1,2);
1380// DateTime before = DateTime(wdate.addDays(-1));
1381// DateTime after = DateTime(wdate.addDays(1));
1382// TQTime t1(8,0,0);
1383// TQTime t2(10,0,0);
1384// DateTime wdt1(wdate, t1);
1385// DateTime wdt2(wdate, t2);
1386// CalendarDay *day = new CalendarDay(TQDate(2006,1,2), Map::Working);
1387// day->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1388// if (!p->addDay(day)) {
1389// kdDebug()<<"Failed to add day"<<endl;
1390// delete day;
1391// delete t;
1392// return;
1393// }
1394// kdDebug()<<"Added date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1395// kdDebug()<<"Found date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1396//
1397// CalendarDay *d = p->findDay(wdate);
1398// bool b = (day == d);
1399// kdDebug()<<"1: Success="<<b<<" Find same day"<<endl;
1400//
1401// DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
1402// b = !dt.isValid();
1403// kdDebug()<<"2: Success="<<b<<" firstAvailableAfter("<<after.toString()<<"): ="<<!b<<endl;
1404//
1405// dt = t->firstAvailableBefore(before, before.addDays(-10));
1406// b = !dt.isValid();
1407// kdDebug()<<"3: Success="<<b<<" firstAvailableBefore("<<before.toString()<<"): ="<<!b<<endl;
1408//
1409// dt = t->firstAvailableAfter(before, after);
1410// b = dt == wdt1;
1411// kdDebug()<<"4: Success="<<b<<" firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
1412//
1413// dt = t->firstAvailableBefore(after, before);
1414// b = dt == wdt2;
1415// kdDebug()<<"5: Success="<<b<<" firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
1416//
1417// b = t->hasInterval(before, after);
1418// kdDebug()<<"6: Success="<<b<<" hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
1419//
1420// b = !t->hasInterval(after, after.addDays(1));
1421// kdDebug()<<"7: Success="<<b<<" !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
1422//
1423// b = !t->hasInterval(before, before.addDays(-1));
1424// kdDebug()<<"8: Success="<<b<<" !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
1425// Duration e1(0, 2, 0); // 2 hours
1426// Duration e2 = t->effort(before, after);
1427// b = e1==e2;
1428// kdDebug()<<"9: Success="<<b<<" effort "<<e1.toString()<<"=="<<e2.toString()<<endl;
1429//
1430// delete t;
1431// delete p;
1432// }// end test 3
1433// kdDebug()<<endl;
1434// kdDebug()<<"------------Test 4 Parent calendar/weekdays-------------"<<endl;
1435// {
1436// TQTime t1(8,0,0);
1437// TQTime t2(10,0,0);
1438// Calendar *p = new Calendar("Test 4 parent");
1439// CalendarDay *wd1 = p->weekday(0); // monday
1440// if (wd1 == 0) {
1441// kdDebug()<<"Failed to get weekday"<<endl;
1442// }
1443// wd1->setState(Map::NonWorking);
1444//
1445// CalendarDay *wd2 = p->weekday(2); // wednesday
1446// if (wd2 == 0) {
1447// kdDebug()<<"Failed to get weekday"<<endl;
1448// }
1449// wd2->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1450// wd2->setState(Map::Working);
1451//
1452// Calendar *t = new Calendar("Test 4");
1453// t->setParent(p);
1454// TQDate wdate(2006,1,2); // monday jan 2
1455// DateTime before = DateTime(wdate.addDays(-4)); //Thursday dec 29
1456// DateTime after = DateTime(wdate.addDays(4)); // Friday jan 6
1457// DateTime wdt1(wdate, t1);
1458// DateTime wdt2(TQDate(2006, 1, 4), t2); // Wednesday
1459// CalendarDay *day = new CalendarDay(TQDate(2006,1,2), Map::Working);
1460// day->addInterval(TQPair<TQTime, TQTime>(t1, t2));
1461// if (!p->addDay(day)) {
1462// kdDebug()<<"Failed to add day"<<endl;
1463// delete day;
1464// delete t;
1465// return;
1466// }
1467// kdDebug()<<"Added date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1468// kdDebug()<<"Found date="<<day->date().toString()<<" "<<day->startOfDay().toString()<<" - "<<day->endOfDay().toString()<<endl;
1469//
1470// CalendarDay *d = p->findDay(wdate);
1471// bool b = (day == d);
1472// kdDebug()<<"1: Success="<<b<<" Find same day"<<endl;
1473//
1474// DateTime dt = t->firstAvailableAfter(after, after.addDays(10));
1475// b = (dt.isValid() && dt == DateTime(TQDate(2006,1,11), t1));
1476// kdDebug()<<"2: Success="<<b<<" firstAvailableAfter("<<after<<"): ="<<dt<<endl;
1477//
1478// dt = t->firstAvailableBefore(before, before.addDays(-10));
1479// b = (dt.isValid() && dt == DateTime(TQDate(2005, 12, 28), t2));
1480// kdDebug()<<"3: Success="<<b<<" firstAvailableBefore("<<before.toString()<<"): ="<<dt<<endl;
1481//
1482// dt = t->firstAvailableAfter(before, after);
1483// b = dt == wdt1; // We find the day jan 2
1484// kdDebug()<<"4: Success="<<b<<" firstAvailableAfter("<<before.toString()<<"): ="<<dt.toString()<<endl;
1485//
1486// dt = t->firstAvailableBefore(after, before);
1487// b = dt == wdt2; // We find the weekday (wednesday)
1488// kdDebug()<<"5: Success="<<b<<" firstAvailableBefore("<<after.toString()<<"): ="<<dt.toString()<<endl;
1489//
1490// b = t->hasInterval(before, after);
1491// kdDebug()<<"6: Success="<<b<<" hasInterval("<<before.toString()<<", "<<after<<")"<<endl;
1492//
1493// b = !t->hasInterval(after, after.addDays(1));
1494// kdDebug()<<"7: Success="<<b<<" !hasInterval("<<after.toString()<<", "<<after.addDays(1)<<")"<<endl;
1495//
1496// b = !t->hasInterval(before, before.addDays(-1));
1497// kdDebug()<<"8: Success="<<b<<" !hasInterval("<<before.toString()<<", "<<before.addDays(-1)<<")"<<endl;
1498// Duration e1(0, 4, 0); // 2 hours
1499// Duration e2 = t->effort(before, after);
1500// b = e1==e2;
1501// kdDebug()<<"9: Success="<<b<<" effort "<<e1.toString()<<"="<<e2.toString()<<endl;
1502//
1503// TQPair<DateTime, DateTime> r = t->firstInterval(before, after);
1504// b = r.first == wdt1; // We find the monday jan 2
1505// kdDebug()<<"10: Success="<<b<<" firstInterval("<<before<<"): ="<<r.first<<", "<<r.second<<endl;
1506// r = t->firstInterval(r.second, after);
1507// b = r.first == DateTime(TQDate(2006, 1, 4),t1); // We find the wednesday jan 4
1508// kdDebug()<<"11: Success="<<b<<" firstInterval("<<r.second<<"): ="<<r.first<<", "<<r.second<<endl;
1509//
1510// delete t;
1511// delete p;
1512// }// end test 4
1513}
1514#endif
1515
1516} //KPlato namespace
1517
1518#include "kptview.moc"
Any Node will store how much time it takes to complete the node (typically a Task) in the traditional...
Definition kptnode.h:556