00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <kprinter.h>
00022 #include <kmessagebox.h>
00023
00024 #include <KoMainWindow.h>
00025
00026 #include <qapplication.h>
00027 #include <qpainter.h>
00028 #include <qiconset.h>
00029 #include <qlayout.h>
00030 #include <qsplitter.h>
00031 #include <qcanvas.h>
00032 #include <qscrollview.h>
00033 #include <qcolor.h>
00034 #include <qlabel.h>
00035 #include <qstring.h>
00036 #include <qstringlist.h>
00037 #include <qvbox.h>
00038 #include <qgrid.h>
00039 #include <qsize.h>
00040 #include <qheader.h>
00041 #include <qtabwidget.h>
00042 #include <qwidgetstack.h>
00043 #include <qtimer.h>
00044 #include <qpopupmenu.h>
00045 #include <qpair.h>
00046
00047 #include <kiconloader.h>
00048 #include <kaction.h>
00049 #include <kstdaction.h>
00050 #include <klocale.h>
00051 #include <kdebug.h>
00052 #include <klistview.h>
00053 #include <kstdaccel.h>
00054 #include <kaccelgen.h>
00055 #include <kdeversion.h>
00056 #include <kstatusbar.h>
00057 #include <kxmlguifactory.h>
00058
00059 #include <kstandarddirs.h>
00060 #include <kdesktopfile.h>
00061 #include <kcommand.h>
00062 #include <kfiledialog.h>
00063
00064 #include "kptview.h"
00065 #include "kptaccountsview.h"
00066 #include "kptfactory.h"
00067 #include "kptmilestoneprogressdialog.h"
00068 #include "kptnode.h"
00069 #include "kptpart.h"
00070 #include "kptproject.h"
00071 #include "kptmainprojectdialog.h"
00072 #include "kptprojectdialog.h"
00073 #include "kpttask.h"
00074 #include "kptsummarytaskdialog.h"
00075 #include "kpttaskdialog.h"
00076 #include "kpttaskprogressdialog.h"
00077 #include "kptganttview.h"
00078 #include "kptpertview.h"
00079
00080 #include "kptdatetime.h"
00081 #include "kptcommand.h"
00082 #include "kptrelation.h"
00083 #include "kptrelationdialog.h"
00084 #include "kptresourceview.h"
00085 #include "kptresourcedialog.h"
00086 #include "kptresource.h"
00087 #include "kptresourcesdialog.h"
00088 #include "kptcalendarlistdialog.h"
00089 #include "kptstandardworktimedialog.h"
00090 #include "kptcanvasitem.h"
00091 #include "kptconfigdialog.h"
00092 #include "kptwbsdefinitiondialog.h"
00093 #include "kptaccountsdialog.h"
00094
00095 #include "KDGanttView.h"
00096 #include "KDGanttViewTaskItem.h"
00097 #include "KPtViewIface.h"
00098
00099 namespace KPlato
00100 {
00101
00102 View::View(Part* part, QWidget* parent, const char* )
00103 : KoView(part, parent, "Main View"),
00104 m_ganttview(0),
00105 m_ganttlayout(0),
00106 m_pertview(0),
00107 m_pertlayout(0),
00108
00109 m_baselineMode(false),
00110 m_currentEstimateType(Effort::Use_Expected)
00111 {
00112
00113 getProject().setCurrentSchedule(Schedule::Expected);
00114
00115 setInstance(Factory::global());
00116 if ( !part->isReadWrite() )
00117 setXMLFile("kplato_readonly.rc");
00118 else
00119 setXMLFile("kplato.rc");
00120 m_dcop = 0L;
00121
00122 dcopObject();
00123
00124 m_tab = new QWidgetStack(this);
00125 QVBoxLayout *layout = new QVBoxLayout(this);
00126 layout->add(m_tab);
00127
00128 m_ganttview = new GanttView(m_tab, part->isReadWrite());
00129 m_tab->addWidget(m_ganttview);
00130 m_updateGanttview = false;
00131 m_ganttview->draw(getPart()->getProject());
00132
00133 m_pertview = new PertView( this, m_tab, layout );
00134 m_tab->addWidget(m_pertview);
00135
00136 m_resourceview = new ResourceView( this, m_tab );
00137 m_updateResourceview = true;
00138 m_tab->addWidget(m_resourceview);
00139
00140 m_accountsview = new AccountsView( getProject(), this, m_tab );
00141 m_updateAccountsview = true;
00142 m_tab->addWidget(m_accountsview);
00143
00144
00145
00146
00147 connect(m_tab, SIGNAL(aboutToShow(QWidget *)), this, SLOT(slotAboutToShow(QWidget *)));
00148
00149 connect(m_pertview, SIGNAL(addRelation(Node*, Node*)), SLOT(slotAddRelation(Node*, Node*)));
00150 connect(m_pertview, SIGNAL(modifyRelation(Relation*)), SLOT(slotModifyRelation(Relation*)));
00151
00152 connect(m_ganttview, SIGNAL(enableActions(bool)), SLOT(setTaskActionsEnabled(bool)));
00153 connect(m_ganttview, SIGNAL(addRelation(Node*, Node*, int)), SLOT(slotAddRelation(Node*, Node*, int)));
00154 connect(m_ganttview, SIGNAL(modifyRelation(Relation*, int)), SLOT(slotModifyRelation(Relation*, int)));
00155 connect(m_ganttview, SIGNAL(modifyRelation(Relation*)), SLOT(slotModifyRelation(Relation*)));
00156 connect(m_ganttview, SIGNAL(itemDoubleClicked()), SLOT(slotOpenNode()));
00157 connect(m_ganttview, SIGNAL(itemRenamed(Node*, const QString&)),this,SLOT(slotRenameNode(Node*, const QString&)));
00158 connect(m_ganttview, SIGNAL(requestPopupMenu(const QString&, const QPoint &)),this,SLOT(slotPopupMenu(const QString&, const QPoint&)));
00159 connect(m_resourceview, SIGNAL(itemDoubleClicked()), SLOT(slotEditResource()));
00160
00161
00162
00163 actionCut = KStdAction::cut( this, SLOT( slotEditCut() ), actionCollection(), "edit_cut" );
00164 actionCopy = KStdAction::copy( this, SLOT( slotEditCopy() ), actionCollection(), "edit_copy" );
00165 actionPaste = KStdAction::paste( this, SLOT( slotEditPaste() ), actionCollection(), "edit_paste" );
00166
00167 actionIndentTask = new KAction(i18n("Indent Task"), "indent_task", 0, this,
00168 SLOT(slotIndentTask()), actionCollection(), "indent_task");
00169 actionUnindentTask = new KAction(i18n("Unindent Task"), "unindent_task", 0, this,
00170 SLOT(slotUnindentTask()), actionCollection(), "unindent_task");
00171 actionMoveTaskUp = new KAction(i18n("Move Up"), "move_task_up", 0, this,
00172 SLOT(slotMoveTaskUp()), actionCollection(), "move_task_up");
00173 actionMoveTaskDown = new KAction(i18n("Move Down"), "move_task_down", 0, this,
00174 SLOT(slotMoveTaskDown()), actionCollection(), "move_task_down");
00175
00176
00177 actionViewGantt = new KAction(i18n("Gantt"), "gantt_chart", 0, this, SLOT(slotViewGantt()), actionCollection(), "view_gantt");
00178
00179 QString group = "EstimationType";
00180 actionViewExpected = new KRadioAction(i18n("Expected"), 0, 0, this, SLOT(slotViewExpected()), actionCollection(), "view_expected");
00181 actionViewExpected->setExclusiveGroup(group);
00182 actionViewOptimistic = new KRadioAction(i18n("Optimistic"), 0, 0, this, SLOT(slotViewOptimistic()), actionCollection(), "view_optimistic");
00183 actionViewOptimistic->setExclusiveGroup(group);
00184 actionViewPessimistic = new KRadioAction(i18n("Pessimistic"), 0, 0, this, SLOT(slotViewPessimistic()), actionCollection(), "view_pessimistic");
00185 actionViewPessimistic->setExclusiveGroup(group);
00186
00187 actionViewGanttResources = new KToggleAction(i18n("Resources"), 0, 0, this, SLOT(slotViewGanttResources()), actionCollection(), "view_gantt_showResources");
00188 actionViewGanttTaskName = new KToggleAction(i18n("Task Name"), 0, 0, this, SLOT(slotViewGanttTaskName()), actionCollection(), "view_gantt_showTaskName");
00189 actionViewGanttTaskLinks = new KToggleAction(i18n("Task Links"), 0, 0, this, SLOT(slotViewGanttTaskLinks()), actionCollection(), "view_gantt_showTaskLinks");
00190 actionViewGanttProgress = new KToggleAction(i18n("Progress"), 0, 0, this, SLOT(slotViewGanttProgress()), actionCollection(), "view_gantt_showProgress");
00191 actionViewGanttFloat = new KToggleAction(i18n("Float"), 0, 0, this, SLOT(slotViewGanttFloat()), actionCollection(), "view_gantt_showFloat");
00192 actionViewGanttCriticalTasks = new KToggleAction(i18n("Critical Tasks"), 0, 0, this, SLOT(slotViewGanttCriticalTasks()), actionCollection(), "view_gantt_showCriticalTasks");
00193 actionViewGanttCriticalPath = new KToggleAction(i18n("Critical Path"), 0, 0, this, SLOT(slotViewGanttCriticalPath()), actionCollection(), "view_gantt_showCriticalPath");
00194
00195
00196
00197 actionViewTaskAppointments = new KToggleAction(i18n("Show allocations"), 0, 0, this, SLOT(slotViewTaskAppointments()), actionCollection(), "view_task_appointments");
00198
00199 actionViewPert = new KAction(i18n("Network"), "pert_chart", 0, this, SLOT(slotViewPert()), actionCollection(), "view_pert");
00200
00201 actionViewResources = new KAction(i18n("Resources"), "resources", 0, this, SLOT(slotViewResources()), actionCollection(), "view_resources");
00202
00203 actionViewResourceAppointments = new KToggleAction(i18n("Show allocations"), 0, 0, this, SLOT(slotViewResourceAppointments()), actionCollection(), "view_resource_appointments");
00204
00205 actionViewAccounts = new KAction(i18n("Accounts"), "accounts", 0, this, SLOT(slotViewAccounts()), actionCollection(), "view_accounts");
00206
00207
00208
00209
00210 actionAddTask = new KAction(i18n("Task..."), "add_task", 0, this,
00211 SLOT(slotAddTask()), actionCollection(), "add_task");
00212 actionAddSubtask = new KAction(i18n("Sub-Task..."), "add_sub_task", 0, this,
00213 SLOT(slotAddSubTask()), actionCollection(), "add_sub_task");
00214 actionAddMilestone = new KAction(i18n("Milestone..."), "add_milestone", 0, this,
00215 SLOT(slotAddMilestone()), actionCollection(), "add_milestone");
00216
00217
00218 actionEditMainProject = new KAction(i18n("Edit Main Project..."), "edit", 0, this, SLOT(slotProjectEdit()), actionCollection(), "project_edit");
00219 actionEditStandardWorktime = new KAction(i18n("Edit Standard Worktime..."), "edit", 0, this, SLOT(slotProjectWorktime()), actionCollection(), "project_worktime");
00220 actionEditCalendar = new KAction(i18n("Edit Calendar..."), "edit", 0, this, SLOT(slotProjectCalendar()), actionCollection(), "project_calendar");
00221 actionEditAccounts = new KAction(i18n("Edit Accounts..."), "edit", 0, this, SLOT(slotProjectAccounts()), actionCollection(), "project_accounts");
00222 actionEditResources = new KAction(i18n("Edit Resources..."), "edit", 0, this, SLOT(slotProjectResources()), actionCollection(), "project_resources");
00223
00224 actionCalculate = new KActionMenu(i18n("Calculate"), "project_calculate", actionCollection(), "project_calculate");
00225 connect(actionCalculate, SIGNAL(activated()), SLOT(slotProjectCalculate()));
00226
00227 actionCalculateExpected = new KAction(i18n("Expected"), 0, 0, this, SLOT(slotProjectCalculateExpected()), actionCollection(), "project_calculate_expected");
00228 actionCalculate->insert(actionCalculateExpected);
00229
00230 actionCalculateOptimistic = new KAction(i18n("Optimistic"), 0, 0, this, SLOT(slotProjectCalculateOptimistic()), actionCollection(), "project_calculate_optimistic");
00231 actionCalculate->insert(actionCalculateOptimistic);
00232
00233 actionCalculatePessimistic = new KAction(i18n("Pessimistic"), 0, 0, this, SLOT(slotProjectCalculatePessimistic()), actionCollection(), "project_calculate_pessimistic");
00234 actionCalculate->insert(actionCalculatePessimistic);
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 mainWindow()->toolBar("report")->hide();
00247
00248
00249
00250
00251
00252
00253 actionDefineWBS =
00254 new KAction(i18n("Define WBS Pattern..."), "tools_define_wbs", 0, this,
00255 SLOT(slotDefineWBS()), actionCollection(), "tools_generate_wbs");
00256 actionGenerateWBS =
00257 new KAction(i18n("Generate WBS Code"), "tools_generate_wbs", 0, this,
00258 SLOT(slotGenerateWBS()), actionCollection(), "tools_define_wbs");
00259
00260
00261
00262
00263
00264
00265 actionConfigure = new KAction(i18n("Configure KPlato..."), "configure", 0, this,
00266 SLOT(slotConfigure()), actionCollection(), "configure");
00267
00268
00269 actionOpenNode = new KAction(i18n("Edit..."), "edit", 0, this,
00270 SLOT(slotOpenNode()), actionCollection(), "node_properties");
00271 actionTaskProgress = new KAction(i18n("Progress..."), "edit", 0, this,
00272 SLOT(slotTaskProgress()), actionCollection(), "task_progress");
00273 actionDeleteTask = new KAction(i18n("Delete Task"), "editdelete", 0, this,
00274 SLOT(slotDeleteTask()), actionCollection(), "delete_task");
00275
00276 actionEditResource = new KAction(i18n("Edit Resource..."), "edit", 0, this,
00277 SLOT(slotEditResource()), actionCollection(), "edit_resource");
00278
00279
00280
00281 actNoInformation = new KAction("Toggle no information", CTRL+SHIFT+Key_T, this, SLOT(slotViewGanttNoInformation()), actionCollection(), "show_noinformation");
00282
00283 #ifndef NDEBUG
00284
00285 new KAction("Print Debug", CTRL+SHIFT+Key_P, this, SLOT(slotPrintSelectedDebug()), actionCollection(), "print_debug");
00286 new KAction("Print Calendar Debug", CTRL+SHIFT+Key_C, this, SLOT(slotPrintCalendarDebug()), actionCollection(), "print_calendar_debug");
00287
00288
00289 KAction* actExportGantt = new KAction( i18n( "Export Gantt" ), CTRL+SHIFT+Key_G,
00290 this, SLOT( slotExportGantt() ), actionCollection(), "export_gantt" );
00291
00292 #endif
00293
00294 #ifndef NDEBUG
00295
00296
00297 Q_UNUSED( actExportGantt );
00298 #endif
00299
00300 m_estlabel = new KStatusBarLabel("", 0);
00301 addStatusBarItem(m_estlabel, 0, true);
00302 actionViewExpected->setChecked(true);
00303 setScheduleActionsEnabled();
00304 slotViewExpected();
00305
00306 setTaskActionsEnabled(false);
00307 }
00308
00309 View::~View()
00310 {
00311 delete m_dcop;
00312 removeStatusBarItem(m_estlabel);
00313 delete m_estlabel;
00314 }
00315
00316 DCOPObject * View::dcopObject()
00317 {
00318 if ( !m_dcop )
00319 m_dcop = new ViewIface( this );
00320
00321 return m_dcop;
00322 }
00323
00324
00325 Project& View::getProject() const
00326 {
00327 return getPart()->getProject();
00328 }
00329
00330 void View::setZoom(double zoom) {
00331 m_ganttview->setZoom(zoom);
00332 m_pertview->setZoom(zoom);
00333 }
00334
00335 void View::setupPrinter(KPrinter &) {
00336
00337 }
00338
00339 void View::print(KPrinter &printer) {
00340
00341 if (printer.previewOnly()) {
00342
00343 if (!printer.setup()) {
00344 return;
00345 }
00346 }
00347 if (m_tab->visibleWidget() == m_ganttview)
00348 {
00349 m_ganttview->print(printer);
00350 }
00351 else if (m_tab->visibleWidget() == m_pertview)
00352 {
00353 m_pertview->print(printer);
00354 }
00355 else if (m_tab->visibleWidget() == m_resourceview)
00356 {
00357 m_resourceview->print(printer);
00358 }
00359 else if (m_tab->visibleWidget() == m_accountsview)
00360 {
00361 m_accountsview->print(printer);
00362 }
00363
00364
00365
00366
00367
00368 }
00369
00370 void View::slotEditCut() {
00371
00372 }
00373
00374 void View::slotEditCopy() {
00375
00376 }
00377
00378 void View::slotEditPaste() {
00379
00380 }
00381
00382 void View::slotViewExpected() {
00383
00384 m_currentEstimateType = Effort::Use_Expected;
00385 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Expected));
00386 slotUpdate(false);
00387 }
00388
00389 void View::slotViewOptimistic() {
00390
00391 m_currentEstimateType = Effort::Use_Optimistic;
00392 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Optimistic));
00393 slotUpdate(false);
00394 }
00395
00396 void View::slotViewPessimistic() {
00397
00398 m_currentEstimateType = Effort::Use_Pessimistic;
00399 getProject().setCurrentSchedulePtr(getProject().findSchedule(Schedule::Pessimistic));
00400 slotUpdate(false);
00401 }
00402
00403 void View::slotViewGanttResources() {
00404
00405 m_ganttview->setShowResources(actionViewGanttResources->isChecked());
00406 if (m_tab->visibleWidget() == m_ganttview)
00407 slotUpdate(false);
00408 }
00409
00410 void View::slotViewGanttTaskName() {
00411
00412 m_ganttview->setShowTaskName(actionViewGanttTaskName->isChecked());
00413 if (m_tab->visibleWidget() == m_ganttview)
00414 slotUpdate(false);
00415 }
00416
00417 void View::slotViewGanttTaskLinks() {
00418
00419 m_ganttview->setShowTaskLinks(actionViewGanttTaskLinks->isChecked());
00420 if (m_tab->visibleWidget() == m_ganttview)
00421 slotUpdate(false);
00422 }
00423
00424 void View::slotViewGanttProgress() {
00425
00426 m_ganttview->setShowProgress(actionViewGanttProgress->isChecked());
00427 if (m_tab->visibleWidget() == m_ganttview)
00428 slotUpdate(false);
00429 }
00430
00431 void View::slotViewGanttFloat() {
00432
00433 m_ganttview->setShowPositiveFloat(actionViewGanttFloat->isChecked());
00434 if (m_tab->visibleWidget() == m_ganttview)
00435 slotUpdate(false);
00436 }
00437
00438 void View::slotViewGanttCriticalTasks() {
00439
00440 m_ganttview->setShowCriticalTasks(actionViewGanttCriticalTasks->isChecked());
00441 if (m_tab->visibleWidget() == m_ganttview)
00442 slotUpdate(false);
00443 }
00444
00445 void View::slotViewGanttCriticalPath() {
00446
00447 m_ganttview->setShowCriticalPath(actionViewGanttCriticalPath->isChecked());
00448 if (m_tab->visibleWidget() == m_ganttview)
00449 slotUpdate(false);
00450 }
00451
00452 void View::slotViewGanttNoInformation() {
00453 kdDebug()<<k_funcinfo<<m_ganttview->showNoInformation()<<endl;
00454 m_ganttview->setShowNoInformation(!m_ganttview->showNoInformation());
00455 if (m_tab->visibleWidget() == m_ganttview)
00456 slotUpdate(false);
00457 }
00458
00459 void View::slotViewTaskAppointments() {
00460
00461 m_ganttview->setShowAppointments(actionViewTaskAppointments->isChecked());
00462 m_updateGanttview = true;
00463 if (m_tab->visibleWidget() == m_ganttview)
00464 slotUpdate(false);
00465 }
00466
00467 void View::slotViewGantt() {
00468
00469 m_tab->raiseWidget(m_ganttview);
00470 }
00471
00472 void View::slotViewPert() {
00473
00474 m_tab->raiseWidget(m_pertview);
00475 }
00476
00477 void View::slotViewResources() {
00478
00479 m_tab->raiseWidget(m_resourceview);
00480 }
00481
00482 void View::slotViewResourceAppointments() {
00483
00484 m_resourceview->setShowAppointments(actionViewResourceAppointments->isChecked());
00485 m_updateResourceview = true;
00486 if (m_tab->visibleWidget() == m_resourceview)
00487 slotUpdate(false);
00488 }
00489
00490 void View::slotViewAccounts() {
00491
00492 m_tab->raiseWidget(m_accountsview);
00493 }
00494
00495 void View::slotProjectEdit() {
00496 MainProjectDialog *dia = new MainProjectDialog(getProject());
00497 if (dia->exec()) {
00498 KCommand *cmd = dia->buildCommand(getPart());
00499 if (cmd) {
00500 getPart()->addCommand(cmd);
00501 }
00502 }
00503 delete dia;
00504 }
00505
00506 void View::slotProjectCalendar() {
00507 CalendarListDialog *dia = new CalendarListDialog(getProject());
00508 if (dia->exec()) {
00509 KCommand *cmd = dia->buildCommand(getPart());
00510 if (cmd) {
00511
00512 getPart()->addCommand(cmd);
00513 }
00514 }
00515 delete dia;
00516 }
00517
00518 void View::slotProjectAccounts() {
00519 AccountsDialog *dia = new AccountsDialog(getProject().accounts());
00520 if (dia->exec()) {
00521 KCommand *cmd = dia->buildCommand(getPart());
00522 if (cmd) {
00523
00524 getPart()->addCommand(cmd);
00525 }
00526 }
00527 delete dia;
00528 }
00529
00530 void View::slotProjectWorktime() {
00531 StandardWorktimeDialog *dia = new StandardWorktimeDialog(getProject());
00532 if (dia->exec()) {
00533 KCommand *cmd = dia->buildCommand(getPart());
00534 if (cmd) {
00535
00536 getPart()->addCommand(cmd);
00537 }
00538 }
00539 delete dia;
00540 }
00541
00542 void View::slotProjectResources() {
00543 ResourcesDialog *dia = new ResourcesDialog(getProject());
00544 if (dia->exec()) {
00545 KCommand *cmd = dia->buildCommand(getPart());
00546 if (cmd) {
00547
00548 getPart()->addCommand(cmd);
00549 }
00550 }
00551 delete dia;
00552 }
00553
00554 void View::slotProjectCalculate() {
00555
00556 slotUpdate(true);
00557 }
00558
00559 void View::slotProjectCalculateExpected() {
00560 m_currentEstimateType = Effort::Use_Expected;
00561 m_updateGanttview = true;
00562 m_updateResourceview = true;
00563 m_updateAccountsview = true;
00564 slotUpdate(true);
00565 }
00566
00567 void View::slotProjectCalculateOptimistic() {
00568 m_currentEstimateType = Effort::Use_Optimistic;
00569 m_updateGanttview = true;
00570 m_updateResourceview = true;
00571 m_updateAccountsview = true;
00572 slotUpdate(true);
00573 }
00574
00575 void View::slotProjectCalculatePessimistic() {
00576 m_currentEstimateType = Effort::Use_Pessimistic;
00577 m_updateGanttview = true;
00578 m_updateResourceview = true;
00579 m_updateAccountsview = true;
00580 slotUpdate(true);
00581 }
00582
00583 void View::projectCalculate() {
00584 if (false ) {
00585
00586 if (KMessageBox::warningContinueCancel(this, i18n("Progress information will be deleted if the project is recalculated."), i18n("Calculate"), i18n("Calculate")) == KMessageBox::Cancel) {
00587 return;
00588 }
00589 }
00590 QApplication::setOverrideCursor(Qt::waitCursor);
00591 Schedule *ns = getProject().findSchedule((Schedule::Type)m_currentEstimateType);
00592 KCommand *cmd;
00593 if (ns) {
00594 cmd = new RecalculateProjectCmd(getPart(), getProject(), *ns, i18n("Calculate"));
00595 } else {
00596 cmd = new CalculateProjectCmd(getPart(), getProject(), i18n("Standard"), (Effort::Use)m_currentEstimateType, i18n("Calculate"));
00597 }
00598 getPart()->addCommand(cmd);
00599 QApplication::restoreOverrideCursor();
00600 }
00601
00602 void View::slotViewReportDesign() {
00603
00604 }
00605
00606 void View::slotViewReports() {
00607
00608
00609 }
00610
00611 void View::slotAddSubTask() {
00612
00613
00614
00615 Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
00616 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00617 if (dia->exec()) {
00618 Node *currNode = currentTask();
00619 if (currNode)
00620 {
00621 KCommand *m = dia->buildCommand(getPart());
00622 m->execute();
00623 delete m;
00624 SubtaskAddCmd *cmd = new SubtaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Subtask"));
00625 getPart()->addCommand(cmd);
00626 return;
00627 }
00628 else
00629 kdDebug()<<k_funcinfo<<"Cannot insert new project. Hmm, no current node!?"<<endl;
00630 }
00631 delete node;
00632 delete dia;
00633 }
00634
00635
00636 void View::slotAddTask() {
00637 Task* node = getProject().createTask(getPart()->config().taskDefaults(), currentTask());
00638 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00639 if (dia->exec()) {
00640 Node* currNode = currentTask();
00641 if (currNode)
00642 {
00643 KCommand *m = dia->buildCommand(getPart());
00644 m->execute();
00645 delete m;
00646 TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Task"));
00647 getPart()->addCommand(cmd);
00648 return;
00649 }
00650 else
00651 kdDebug()<<k_funcinfo<<"Cannot insert new task. Hmm, no current node!?"<<endl;
00652 }
00653 delete node;
00654 delete dia;
00655 }
00656
00657 void View::slotAddMilestone() {
00658 Task* node = getProject().createTask(currentTask());
00659 node->effort()->set(Duration::zeroDuration);
00660
00661 TaskDialog *dia = new TaskDialog(*node, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00662 if (dia->exec()) {
00663 Node *currNode = currentTask();
00664 if (currNode)
00665 {
00666 KCommand *m = dia->buildCommand(getPart());
00667 m->execute();
00668 delete m;
00669 TaskAddCmd *cmd = new TaskAddCmd(getPart(), &(getProject()), node, currNode, i18n("Add Milestone"));
00670 getPart()->addCommand(cmd);
00671 return;
00672 }
00673 else
00674 kdDebug()<<k_funcinfo<<"Cannot insert new milestone. Hmm, no current node!?"<<endl;
00675 }
00676 delete node;
00677 delete dia;
00678 }
00679
00680 void View::slotDefineWBS() {
00681
00682 WBSDefinitionDialog *dia = new WBSDefinitionDialog(getPart()->wbsDefinition());
00683 dia->exec();
00684
00685 delete dia;
00686 }
00687
00688 void View::slotGenerateWBS() {
00689
00690 getPart()->generateWBS();
00691 slotUpdate(false);
00692 }
00693
00694 void View::slotConfigure() {
00695
00696 ConfigDialog *dia = new ConfigDialog(getPart()->config(), getProject());
00697 dia->exec();
00698 delete dia;
00699 }
00700
00701 Node *View::currentTask()
00702 {
00703 Node* task = 0;
00704 if (m_tab->visibleWidget() == m_ganttview) {
00705 task = m_ganttview->currentNode();
00706 }
00707 else if (m_tab->visibleWidget() == m_pertview) {
00708 task = m_pertview->currentNode();
00709 }
00710 else if (m_tab->visibleWidget() == m_resourceview) {
00711 task = m_resourceview->currentNode();
00712 }
00713 if ( 0 != task ) {
00714 return task;
00715 }
00716 return &(getProject());
00717 }
00718
00719 void View::slotOpenNode() {
00720
00721 Node *node = currentTask();
00722 if (!node)
00723 return;
00724
00725 switch (node->type()) {
00726 case Node::Type_Project: {
00727 Project *project = dynamic_cast<Project *>(node);
00728 MainProjectDialog *dia = new MainProjectDialog(*project);
00729 if (dia->exec()){
00730 KCommand *m = dia->buildCommand(getPart());
00731 if (m) {
00732 getPart()->addCommand(m);
00733 }
00734 }
00735 delete dia;
00736 break;
00737 }
00738 case Node::Type_Subproject:
00739
00740 break;
00741 case Node::Type_Task: {
00742 Task *task = dynamic_cast<Task *>(node);
00743 TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00744 if (dia->exec()) {
00745 KCommand *m = dia->buildCommand(getPart());
00746 if (m) {
00747 getPart()->addCommand(m);
00748 }
00749 }
00750 delete dia;
00751 break;
00752 }
00753 case Node::Type_Milestone: {
00754
00755
00756
00757
00758 Task *task = dynamic_cast<Task *>(node);
00759 TaskDialog *dia = new TaskDialog(*task, getProject().accounts(), getProject().standardWorktime(), getProject().isBaselined());
00760 if (dia->exec()) {
00761 KCommand *m = dia->buildCommand(getPart());
00762 if (m) {
00763 getPart()->addCommand(m);
00764 }
00765 }
00766 delete dia;
00767 break;
00768 }
00769 case Node::Type_Summarytask: {
00770 Task *task = dynamic_cast<Task *>(node);
00771 SummaryTaskDialog *dia = new SummaryTaskDialog(*task);
00772 if (dia->exec()) {
00773 KCommand *m = dia->buildCommand(getPart());
00774 if (m) {
00775 getPart()->addCommand(m);
00776 }
00777 }
00778 delete dia;
00779 break;
00780 }
00781 default:
00782 break;
00783 }
00784 }
00785
00786 void View::slotTaskProgress() {
00787
00788 Node *node = currentTask();
00789 if (!node)
00790 return;
00791
00792 switch (node->type()) {
00793 case Node::Type_Project: {
00794 break;
00795 }
00796 case Node::Type_Subproject:
00797
00798 break;
00799 case Node::Type_Task: {
00800 Task *task = dynamic_cast<Task *>(node);
00801 TaskProgressDialog *dia = new TaskProgressDialog(*task, getProject().standardWorktime());
00802 if (dia->exec()) {
00803 KCommand *m = dia->buildCommand(getPart());
00804 if (m) {
00805 getPart()->addCommand(m);
00806 }
00807 }
00808 delete dia;
00809 break;
00810 }
00811 case Node::Type_Milestone: {
00812 Task *task = dynamic_cast<Task *>(node);
00813 MilestoneProgressDialog *dia = new MilestoneProgressDialog(*task);
00814 if (dia->exec()) {
00815 KCommand *m = dia->buildCommand(getPart());
00816 if (m) {
00817 getPart()->addCommand(m);
00818 }
00819 }
00820 delete dia;
00821 break;
00822 }
00823 case Node::Type_Summarytask: {
00824
00825 break;
00826 }
00827 default:
00828 break;
00829 }
00830 }
00831
00832 void View::slotDeleteTask()
00833 {
00834
00835 Node *node = currentTask();
00836 if (node == 0 || node->getParent() == 0) {
00837 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
00838 return;
00839 }
00840 KMacroCommand *cmd = new KMacroCommand(i18n("Delete Task"));
00841 cmd->addCommand(new NodeDeleteCmd(getPart(), node));
00842 QPtrListIterator<Relation> it = node->dependChildNodes();
00843 for (; it.current(); ++it) {
00844 cmd->addCommand(new DeleteRelationCmd(getPart(), it.current()));
00845 }
00846 it = node->dependParentNodes();
00847 for (; it.current(); ++it) {
00848 cmd->addCommand(new DeleteRelationCmd(getPart(),it.current()));
00849 }
00850 getPart()->addCommand(cmd);
00851 }
00852
00853 void View::slotIndentTask()
00854 {
00855
00856 Node *node = currentTask();
00857 if (node == 0 || node->getParent() == 0) {
00858 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
00859 return;
00860 }
00861 if (getProject().canIndentTask(node)) {
00862 NodeIndentCmd *cmd = new NodeIndentCmd(getPart(), *node, i18n("Indent Task"));
00863 getPart()->addCommand(cmd);
00864 }
00865 }
00866
00867 void View::slotUnindentTask()
00868 {
00869
00870 Node *node = currentTask();
00871 if (node == 0 || node->getParent() == 0) {
00872 kdDebug()<<k_funcinfo<<(node ? "Task is main project" : "No current task")<<endl;
00873 return;
00874 }
00875 if (getProject().canUnindentTask(node)) {
00876 NodeUnindentCmd *cmd = new NodeUnindentCmd(getPart(), *node, i18n("Unindent Task"));
00877 getPart()->addCommand(cmd);
00878 }
00879 }
00880
00881 void View::slotMoveTaskUp()
00882 {
00883
00884
00885 Node* task = currentTask();
00886 if ( 0 == task ) {
00887
00888
00889 kdError()<<k_funcinfo<<"No current task"<<endl;
00890 return;
00891 }
00892
00893 if ( Node::Type_Project == task->type() ) {
00894 kdDebug()<<k_funcinfo<<"The root node cannot be moved up"<<endl;
00895 return;
00896 }
00897 if (getProject().canMoveTaskUp(task)) {
00898 NodeMoveUpCmd *cmd = new NodeMoveUpCmd(getPart(), *task, i18n("Move Task Up"));
00899 getPart()->addCommand(cmd);
00900 }
00901 }
00902
00903 void View::slotMoveTaskDown()
00904 {
00905
00906
00907 Node* task = currentTask();
00908 if ( 0 == task ) {
00909
00910
00911 return;
00912 }
00913
00914 if ( Node::Type_Project == task->type() ) {
00915 kdDebug()<<k_funcinfo<<"The root node cannot be moved down"<<endl;
00916 return;
00917 }
00918 if (getProject().canMoveTaskDown(task)) {
00919 NodeMoveDownCmd *cmd = new NodeMoveDownCmd(getPart(), *task, i18n("Move Task Down"));
00920 getPart()->addCommand(cmd);
00921 }
00922 }
00923
00924 void View::slotAddRelation(Node *par, Node *child) {
00925
00926 Relation *rel = new Relation(par, child);
00927 AddRelationDialog *dia = new AddRelationDialog(rel, this);
00928 if (dia->exec()) {
00929 KCommand *cmd = dia->buildCommand(getPart());
00930 if (cmd)
00931 getPart()->addCommand(cmd);
00932 } else {
00933 delete rel;
00934 }
00935 delete dia;
00936 }
00937
00938 void View::slotAddRelation(Node *par, Node *child, int linkType) {
00939
00940 if (linkType == Relation::FinishStart ||
00941 linkType == Relation::StartStart ||
00942 linkType == Relation::FinishFinish)
00943 {
00944 Relation *rel = new Relation(par, child, static_cast<Relation::Type>(linkType));
00945 getPart()->addCommand(new AddRelationCmd(getPart(), rel, i18n("Add Relation")));
00946 } else {
00947 slotAddRelation(par, child);
00948 }
00949 }
00950
00951 void View::slotModifyRelation(Relation *rel) {
00952
00953 ModifyRelationDialog *dia = new ModifyRelationDialog(rel, this);
00954 if (dia->exec()) {
00955 if (dia->relationIsDeleted()) {
00956 getPart()->addCommand(new DeleteRelationCmd(getPart(), rel, i18n("Delete Relation")));
00957 } else {
00958 KCommand *cmd = dia->buildCommand(getPart());
00959 if (cmd) {
00960 getPart()->addCommand(cmd);
00961 }
00962 }
00963 }
00964 delete dia;
00965 }
00966
00967 void View::slotModifyRelation(Relation *rel, int linkType) {
00968
00969 if (linkType == Relation::FinishStart ||
00970 linkType == Relation::StartStart ||
00971 linkType == Relation::FinishFinish)
00972 {
00973 getPart()->addCommand(new ModifyRelationTypeCmd(getPart(), rel, static_cast<Relation::Type>(linkType)));
00974 } else {
00975 slotModifyRelation(rel);
00976 }
00977 }
00978
00979
00980 void View::slotExportGantt() {
00981
00982 if (!m_ganttview) {
00983 return;
00984 }
00985 QString fn = KFileDialog::getSaveFileName( QString::null, QString::null, this );
00986 if (!fn.isEmpty()) {
00987 QFile f(fn);
00988 m_ganttview->exportGantt(&f);
00989 }
00990 }
00991
00992 void View::slotEditResource() {
00993
00994 Resource *r = m_resourceview->currentResource();
00995 if (!r)
00996 return;
00997 ResourceDialog *dia = new ResourceDialog(getProject(), r);
00998 if (dia->exec()) {
00999 KCommand *cmd = dia->buildCommand(getPart());
01000 if (cmd)
01001 getPart()->addCommand(cmd);
01002 }
01003 delete dia;
01004 }
01005
01006 void View::updateReadWrite(bool ) {
01007 }
01008
01009 Part *View::getPart()const {
01010 return (Part *)koDocument();
01011 }
01012
01013 void View::slotConnectNode() {
01014
01015
01016
01017
01018
01019 }
01020
01021 QPopupMenu * View::popupMenu( const QString& name )
01022 {
01023
01024 Q_ASSERT(factory());
01025 if ( factory() )
01026 return ((QPopupMenu*)factory()->container( name, this ));
01027 return 0L;
01028 }
01029
01030 void View::slotChanged(QWidget *)
01031 {
01032
01033 slotUpdate(false);
01034 }
01035
01036 void View::slotChanged()
01037 {
01038
01039 slotUpdate(false);
01040 }
01041
01042 void View::slotUpdate(bool calculate)
01043 {
01044
01045 if (m_currentEstimateType == Effort::Use_Expected) {
01046 m_estlabel->setText(i18n("Expected"));
01047 } else if (m_currentEstimateType == Effort::Use_Optimistic) {
01048 m_estlabel->setText(i18n("Optimistic"));
01049 } else if (m_currentEstimateType == Effort::Use_Pessimistic) {
01050 m_estlabel->setText(i18n("Pessimistic"));
01051 } else {
01052 m_estlabel->setText("");
01053 }
01054 if (calculate)
01055 projectCalculate();
01056
01057 m_updateGanttview = true;
01058 m_updateResourceview = true;
01059 m_updateAccountsview = true;
01060
01061 updateView(m_tab->visibleWidget());
01062 }
01063
01064 void View::slotAboutToShow(QWidget *widget) {
01065 updateView(widget);
01066 }
01067
01068 void View::updateView(QWidget *widget)
01069 {
01070 QApplication::setOverrideCursor(Qt::waitCursor);
01071 setScheduleActionsEnabled();
01072 setTaskActionsEnabled(false);
01073 mainWindow()->toolBar("report")->hide();
01074 if (widget == m_ganttview)
01075 {
01076
01077 m_ganttview->setShowExpected(actionViewExpected->isChecked());
01078 m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
01079 m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
01080 if (m_updateGanttview)
01081 m_ganttview->drawChanges(getProject());
01082 setTaskActionsEnabled(widget, true);
01083 m_updateGanttview = false;
01084 }
01085 else if (widget == m_pertview)
01086 {
01087
01088 m_pertview->draw();
01089 }
01090 else if (widget == m_resourceview)
01091 {
01092
01093 if (m_updateResourceview)
01094 m_resourceview->draw(getPart()->getProject());
01095 m_updateResourceview = false;
01096 }
01097 else if (widget == m_accountsview)
01098 {
01099
01100 if (m_updateAccountsview)
01101 m_accountsview->draw();
01102 m_updateAccountsview = false;
01103 }
01104
01105
01106
01107
01108
01109 QApplication::restoreOverrideCursor();
01110 }
01111
01112 void View::slotRenameNode(Node *node, const QString& name) {
01113
01114 if (node) {
01115 NodeModifyNameCmd *cmd = new NodeModifyNameCmd(getPart(), *node, name, i18n("Modify Name"));
01116 getPart()->addCommand(cmd);
01117 }
01118 }
01119
01120 void View::slotPopupMenu(const QString& menuname, const QPoint & pos)
01121 {
01122 QPopupMenu* menu = this->popupMenu(menuname);
01123 if (menu)
01124 menu->exec(pos);
01125 }
01126
01127 bool View::setContext(Context &context) {
01128
01129 m_currentEstimateType = context.currentEstimateType;
01130 getProject().setCurrentSchedule(context.currentSchedule);
01131 actionViewExpected->setChecked(context.actionViewExpected);
01132 actionViewOptimistic->setChecked(context.actionViewOptimistic);
01133 actionViewPessimistic->setChecked(context.actionViewPessimistic);
01134
01135 m_ganttview->setContext(context.ganttview, getProject());
01136
01137 actionViewGanttResources->setChecked(context.ganttview.showResources);
01138 actionViewGanttTaskName->setChecked(context.ganttview.showTaskName);
01139 actionViewGanttTaskLinks->setChecked(context.ganttview.showTaskLinks);
01140 actionViewGanttProgress->setChecked(context.ganttview.showProgress);
01141 actionViewGanttFloat->setChecked(context.ganttview.showPositiveFloat);
01142 actionViewGanttCriticalTasks->setChecked(context.ganttview.showCriticalTasks);
01143 actionViewGanttCriticalPath->setChecked(context.ganttview.showCriticalPath);
01144
01145 m_pertview->setContext(context.pertview);
01146 m_resourceview->setContext(context.resourceview);
01147 m_accountsview->setContext(context.accountsview);
01148
01149
01150 if (context.currentView == "ganttview") {
01151 m_ganttview->setShowExpected(actionViewExpected->isChecked());
01152 m_ganttview->setShowOptimistic(actionViewOptimistic->isChecked());
01153 m_ganttview->setShowPessimistic(actionViewPessimistic->isChecked());
01154 slotViewGantt();
01155 } else if (context.currentView == "pertview") {
01156 slotViewPert();
01157 } else if (context.currentView == "resourceview") {
01158 slotViewResources();
01159 } else if (context.currentView == "accountsview") {
01160 slotViewAccounts();
01161 } else if (context.currentView == "reportview") {
01162
01163 } else {
01164 slotViewGantt();
01165 }
01166 slotUpdate(false);
01167 return true;
01168 }
01169
01170 void View::getContext(Context &context) const {
01171
01172 context.currentEstimateType = m_currentEstimateType;
01173 if (getProject().currentSchedule())
01174 context.currentSchedule = getProject().currentSchedule()->id();
01175 context.actionViewExpected = actionViewExpected->isChecked();
01176 context.actionViewOptimistic = actionViewOptimistic->isChecked();
01177 context.actionViewPessimistic = actionViewPessimistic->isChecked();
01178
01179 if (m_tab->visibleWidget() == m_ganttview) {
01180 context.currentView = "ganttview";
01181 } else if (m_tab->visibleWidget() == m_pertview) {
01182 context.currentView = "pertview";
01183 } else if (m_tab->visibleWidget() == m_resourceview) {
01184 context.currentView = "resourceview";
01185 } else if (m_tab->visibleWidget() == m_accountsview) {
01186 context.currentView = "accountsview";
01187
01188
01189 }
01190 m_ganttview->getContext(context.ganttview);
01191 m_pertview->getContext(context.pertview);
01192 m_resourceview->getContext(context.resourceview);
01193 m_accountsview->getContext(context.accountsview);
01194
01195 }
01196
01197 void View::setBaselineMode(bool ) {
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223 }
01224
01225
01226 void View::setTaskActionsEnabled(QWidget *w, bool on) {
01227 Node *n = 0;
01228 if (w == m_ganttview) {
01229 n = m_ganttview->currentNode();
01230 }
01231
01232 actionAddTask->setEnabled(on);
01233 actionAddMilestone->setEnabled(on);
01234
01235 bool o = (on && n);
01236 actionAddSubtask->setEnabled(o);
01237 actionDeleteTask->setEnabled(o);
01238 actionMoveTaskUp->setEnabled(o && getProject().canMoveTaskUp(n));
01239 actionMoveTaskDown->setEnabled(o && getProject().canMoveTaskDown(n));
01240 actionIndentTask->setEnabled(o && getProject().canIndentTask(n));
01241 actionUnindentTask->setEnabled(o && getProject().canUnindentTask(n));
01242 }
01243
01244 void View::setTaskActionsEnabled(bool on) {
01245 setTaskActionsEnabled(m_ganttview, on);
01246 }
01247
01248 void View::setScheduleActionsEnabled() {
01249 actionViewExpected->setEnabled(getProject().findSchedule(Schedule::Expected));
01250 actionViewOptimistic->setEnabled(getProject().findSchedule(Schedule::Optimistic));
01251 actionViewPessimistic->setEnabled(getProject().findSchedule(Schedule::Pessimistic));
01252 Schedule *ns = getProject().currentSchedule();
01253 if (ns == 0) {
01254 return;
01255 }
01256 if (ns->type() == Schedule::Expected)
01257 actionViewExpected->setChecked(true);
01258 else if (ns->type() == Schedule::Optimistic)
01259 actionViewOptimistic->setChecked(true);
01260 else if (ns->type() == Schedule::Pessimistic)
01261 actionViewPessimistic->setChecked(true);
01262 }
01263
01264
01265 #ifndef NDEBUG
01266 void View::slotPrintDebug() {
01267 kdDebug()<<"-------- Debug printout: Node list" <<endl;
01268
01269
01270
01271
01272 getPart()->getProject().printDebug(true, "");
01273 }
01274 void View::slotPrintSelectedDebug() {
01275 Node *curr = m_ganttview->currentNode();
01276 if (curr) {
01277 kdDebug()<<"-------- Debug printout: Selected node" <<endl;
01278 curr->printDebug(true,"");
01279 } else
01280 slotPrintDebug();
01281 }
01282 void View::slotPrintCalendarDebug() {
01283 kdDebug()<<"-------- Debug printout: Node list" <<endl;
01284
01285
01286
01287
01288 getPart()->getProject().printCalendarDebug("");
01289 }
01290 void View::slotPrintTestDebug() {
01291 const QStringList &lst = getPart()->xmlLoader().log();
01292
01293 for ( QStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
01294 kdDebug()<<*it<<endl;
01295 }
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518 }
01519 #endif
01520
01521 }
01522
01523 #include "kptview.moc"