kplato

kptcommand.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004, 2005 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kptcommand.h"
21#include "kptaccount.h"
22#include "kptappointment.h"
23#include "kptpart.h"
24#include "kptproject.h"
25#include "kpttask.h"
26#include "kptcalendar.h"
27#include "kptrelation.h"
28#include "kptresource.h"
29
30#include <kdebug.h>
31#include <tdelocale.h>
32
33#include <tqintdict.h>
34#include <tqmap.h>
35
36namespace KPlato
37{
38
39void NamedCommand::setCommandType(int type) {
40 if (m_part)
41 m_part->setCommandType(type);
42}
43
44void NamedCommand::setSchDeleted() {
45 TQMap<Schedule*, bool>::Iterator it;
46 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
47 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<it.data()<<endl;
48 it.key()->setDeleted(it.data());
49 }
50}
51void NamedCommand::setSchDeleted(bool state) {
52 TQMap<Schedule*, bool>::Iterator it;
53 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
54 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<state<<endl;
55 it.key()->setDeleted(state);
56 }
57}
58void NamedCommand::setSchScheduled() {
59TQMap<Schedule*, bool>::Iterator it;
60 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
61 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<it.data()<<endl;
62 it.key()->setScheduled(it.data());
63 }
64}
65void NamedCommand::setSchScheduled(bool state) {
66 TQMap<Schedule*, bool>::Iterator it;
67 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
68 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<state<<endl;
69 it.key()->setScheduled(state);
70 }
71}
72void NamedCommand::addSchScheduled(Schedule *sch) {
73 kdDebug()<<k_funcinfo<<sch->id()<<": "<<sch->isScheduled()<<endl;
74 m_schedules.insert(sch, sch->isScheduled());
75 TQPtrListIterator<Appointment> it = sch->appointments();
76 for (; it.current(); ++it) {
77 if (it.current()->node() == sch) {
78 m_schedules.insert(it.current()->resource(), it.current()->resource()->isScheduled());
79 } else if (it.current()->resource() == sch) {
80 m_schedules.insert(it.current()->node(), it.current()->node()->isScheduled());
81 }
82 }
83}
84void NamedCommand::addSchDeleted(Schedule *sch) {
85 kdDebug()<<k_funcinfo<<sch->id()<<": "<<sch->isDeleted()<<endl;
86 m_schedules.insert(sch, sch->isDeleted());
87 TQPtrListIterator<Appointment> it = sch->appointments();
88 for (; it.current(); ++it) {
89 if (it.current()->node() == sch) {
90 m_schedules.insert(it.current()->resource(), it.current()->resource()->isDeleted());
91 } else if (it.current()->resource() == sch) {
92 m_schedules.insert(it.current()->node(), it.current()->node()->isDeleted());
93 }
94 }
95}
96
97//-------------------------------------------------
98CalendarAddCmd::CalendarAddCmd(Part *part, Project *project,Calendar *cal, TQString name)
99 : NamedCommand(part, name),
100 m_project(project),
101 m_cal(cal),
102 m_added(false) {
103 cal->setDeleted(true);
104 //kdDebug()<<k_funcinfo<<cal->name()<<endl;
105}
106
107void CalendarAddCmd::execute() {
108 if (!m_added && m_project) {
109 m_project->addCalendar(m_cal);
110 m_added = true;
111 }
112 m_cal->setDeleted(false);
113
114 setCommandType(0);
115 //kdDebug()<<k_funcinfo<<m_cal->name()<<" added to: "<<m_project->name()<<endl;
116}
117
118void CalendarAddCmd::unexecute() {
119 m_cal->setDeleted(true);
120
121 setCommandType(0);
122 //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
123}
124
125CalendarDeleteCmd::CalendarDeleteCmd(Part *part, Calendar *cal, TQString name)
126 : NamedCommand(part, name),
127 m_cal(cal) {
128
129 // TODO check if any resources uses this calendar
130 if (part) {
131 TQIntDictIterator<Schedule> it = part->getProject().schedules();
132 for (; it.current(); ++it) {
133 addSchScheduled(it.current());
134 }
135 }
136}
137
138void CalendarDeleteCmd::execute() {
139 m_cal->setDeleted(true);
140 setSchScheduled(false);
141 setCommandType(1);
142}
143
144void CalendarDeleteCmd::unexecute() {
145 m_cal->setDeleted(false);
146 setSchScheduled();
147 setCommandType(0);
148}
149
150CalendarModifyNameCmd::CalendarModifyNameCmd(Part *part, Calendar *cal, TQString newvalue, TQString name)
151 : NamedCommand(part, name),
152 m_cal(cal) {
153
154 m_oldvalue = cal->name();
155 m_newvalue = newvalue;
156 //kdDebug()<<k_funcinfo<<cal->name()<<endl;
157}
158void CalendarModifyNameCmd::execute() {
159 m_cal->setName(m_newvalue);
160 setCommandType(0);
161 //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
162}
163void CalendarModifyNameCmd::unexecute() {
164 m_cal->setName(m_oldvalue);
165 setCommandType(0);
166 //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
167}
168
169CalendarModifyParentCmd::CalendarModifyParentCmd(Part *part, Calendar *cal, Calendar *newvalue, TQString name)
170 : NamedCommand(part, name),
171 m_cal(cal) {
172
173 m_oldvalue = cal->parent();
174 m_newvalue = newvalue;
175 //kdDebug()<<k_funcinfo<<cal->name()<<endl;
176 // TODO check if any resources uses this calendar
177 if (part) {
178 TQIntDictIterator<Schedule> it = part->getProject().schedules();
179 for (; it.current(); ++it) {
180 addSchScheduled(it.current());
181 }
182 }
183}
184void CalendarModifyParentCmd::execute() {
185 m_cal->setParent(m_newvalue);
186 setSchScheduled(false);
187 setCommandType(1);
188}
189void CalendarModifyParentCmd::unexecute() {
190 m_cal->setParent(m_oldvalue);
191 setSchScheduled();
192 setCommandType(1);
193}
194
195CalendarAddDayCmd::CalendarAddDayCmd(Part *part, Calendar *cal, CalendarDay *newvalue, TQString name)
196 : NamedCommand(part, name),
197 m_cal(cal),
198 m_mine(true) {
199
200 m_newvalue = newvalue;
201 //kdDebug()<<k_funcinfo<<cal->name()<<endl;
202 // TODO check if any resources uses this calendar
203 if (part) {
204 TQIntDictIterator<Schedule> it = part->getProject().schedules();
205 for (; it.current(); ++it) {
206 addSchScheduled(it.current());
207 }
208 }
209}
210CalendarAddDayCmd::~CalendarAddDayCmd() {
211 //kdDebug()<<k_funcinfo<<endl;
212 if (m_mine)
213 delete m_newvalue;
214}
215void CalendarAddDayCmd::execute() {
216 //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
217 m_cal->addDay(m_newvalue);
218 m_mine = false;
219 setSchScheduled(false);
220 setCommandType(1);
221}
222void CalendarAddDayCmd::unexecute() {
223 //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
224 m_cal->takeDay(m_newvalue);
225 m_mine = true;
226 setSchScheduled();
227 setCommandType(1);
228}
229
230CalendarRemoveDayCmd::CalendarRemoveDayCmd(Part *part, Calendar *cal, const TQDate &day, TQString name)
231 : NamedCommand(part, name),
232 m_cal(cal),
233 m_mine(false) {
234
235 m_value = cal->findDay(day);
236 //kdDebug()<<k_funcinfo<<cal->name()<<endl;
237 // TODO check if any resources uses this calendar
238 if (part) {
239 TQIntDictIterator<Schedule> it = part->getProject().schedules();
240 for (; it.current(); ++it) {
241 addSchScheduled(it.current());
242 }
243 }
244}
245void CalendarRemoveDayCmd::execute() {
246 //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
247 m_cal->takeDay(m_value);
248 m_mine = true;
249 setSchScheduled(false);
250 setCommandType(1);
251}
252void CalendarRemoveDayCmd::unexecute() {
253 //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
254 m_cal->addDay(m_value);
255 m_mine = false;
256 setSchScheduled();
257 setCommandType(1);
258}
259
260CalendarModifyDayCmd::CalendarModifyDayCmd(Part *part, Calendar *cal, CalendarDay *value, TQString name)
261 : NamedCommand(part, name),
262 m_cal(cal),
263 m_mine(true) {
264
265 m_newvalue = value;
266 m_oldvalue = cal->findDay(value->date());
267 //kdDebug()<<k_funcinfo<<cal->name()<<" old:("<<m_oldvalue<<") new:("<<m_newvalue<<")"<<endl;
268 // TODO check if any resources uses this calendar
269 if (part) {
270 TQIntDictIterator<Schedule> it = part->getProject().schedules();
271 for (; it.current(); ++it) {
272 addSchScheduled(it.current());
273 }
274 }
275}
276CalendarModifyDayCmd::~CalendarModifyDayCmd() {
277 //kdDebug()<<k_funcinfo<<endl;
278 if (m_mine) {
279 delete m_newvalue;
280 } else {
281 delete m_oldvalue;
282 }
283}
284void CalendarModifyDayCmd::execute() {
285 //kdDebug()<<k_funcinfo<<endl;
286 m_cal->takeDay(m_oldvalue);
287 m_cal->addDay(m_newvalue);
288 m_mine = false;
289 setSchScheduled(false);
290 setCommandType(1);
291}
292void CalendarModifyDayCmd::unexecute() {
293 //kdDebug()<<k_funcinfo<<endl;
294 m_cal->takeDay(m_newvalue);
295 m_cal->addDay(m_oldvalue);
296 m_mine = true;
297 setSchScheduled();
298 setCommandType(1);
299}
300
301CalendarModifyWeekdayCmd::CalendarModifyWeekdayCmd(Part *part, Calendar *cal, int weekday, CalendarDay *value, TQString name)
302 : NamedCommand(part, name),
303 m_weekday(weekday),
304 m_cal(cal),
305 m_mine(true) {
306
307 m_value = value;
308 kdDebug()<<k_funcinfo<<cal->name()<<" ("<<value<<")"<<endl;
309 // TODO check if any resources uses this calendar
310 if (part) {
311 TQIntDictIterator<Schedule> it = part->getProject().schedules();
312 for (; it.current(); ++it) {
313 addSchScheduled(it.current());
314 }
315 }
316}
317CalendarModifyWeekdayCmd::~CalendarModifyWeekdayCmd() {
318 kdDebug()<<k_funcinfo<<m_weekday<<": "<<m_value<<endl;
319 delete m_value;
320
321}
322void CalendarModifyWeekdayCmd::execute() {
323 m_value = m_cal->weekdays()->replace(m_weekday, m_value);
324 setSchScheduled(false);
325 setCommandType(1);
326}
327void CalendarModifyWeekdayCmd::unexecute() {
328 m_value = m_cal->weekdays()->replace(m_weekday, m_value);
329 setSchScheduled();
330 setCommandType(1);
331}
332
333NodeDeleteCmd::NodeDeleteCmd(Part *part, Node *node, TQString name)
334 : NamedCommand(part, name),
335 m_node(node),
336 m_index(-1) {
337
338 m_parent = node->getParent();
339 if (m_parent)
340 m_index = m_parent->findChildNode(node);
341 m_mine = false;
342 m_appointments.setAutoDelete(true);
343
344 m_project = static_cast<Project*>(node->projectNode());
345 if (m_project) {
346 TQIntDictIterator<Schedule> it = m_project->schedules();
347 for (; it.current(); ++it) {
348 Schedule *s = node->findSchedule(it.current()->id());
349 if (s && s->isScheduled()) {
350 // Only invalidate schedules this node is part of
351 addSchScheduled(it.current());
352 }
353 }
354 }
355}
356NodeDeleteCmd::~NodeDeleteCmd() {
357 if (m_mine)
358 delete m_node;
359}
360void NodeDeleteCmd::execute() {
361 if (m_parent && m_project) {
362 //kdDebug()<<k_funcinfo<<m_node->name()<<" "<<m_index<<endl;
363 TQPtrListIterator<Appointment> it = m_node->appointments();
364 for (; it.current(); ++it) {
365 it.current()->detach();
366 m_appointments.append(it.current());
367 }
368 m_project->delTask(m_node);
369 m_mine = true;
370 setSchScheduled(false);
371 setCommandType(1);
372 }
373}
374void NodeDeleteCmd::unexecute() {
375 if (m_parent && m_project) {
376 //kdDebug()<<k_funcinfo<<m_node->name()<<" "<<m_index<<endl;
377 m_project->addSubTask(m_node, m_index, m_parent);
378 Appointment *a;
379 for (a = m_appointments.first(); a != 0; m_appointments.take()) {
380 a->attach();
381 }
382 m_mine = false;
383 setSchScheduled();
384 setCommandType(1);
385 }
386}
387
388TaskAddCmd::TaskAddCmd(Part *part, Project *project, Node *node, Node *after, TQString name)
389 : NamedCommand(part, name),
390 m_project(project),
391 m_node(node),
392 m_after(after),
393 m_added(false) {
394
395 // set some reasonable defaults for normally calculated values
396 if (after && after->getParent() && after->getParent() != project) {
397 node->setStartTime(after->getParent()->startTime());
398 node->setEndTime(node->startTime() + node->duration());
399 } else {
400 if (project->constraint() == Node::MustFinishOn) {
401 node->setEndTime(project->endTime());
402 node->setStartTime(node->endTime() - node->duration());
403 } else {
404 node->setStartTime(project->startTime());
405 node->setEndTime(node->startTime() + node->duration());
406 }
407 }
408 node->setEarliestStart(node->startTime());
409 node->setLatestFinish(node->endTime());
410 node->setWorkStartTime(node->startTime());
411 node->setWorkEndTime(node->endTime());
412}
413TaskAddCmd::~TaskAddCmd() {
414 if (!m_added)
415 delete m_node;
416}
417void TaskAddCmd::execute() {
418 //kdDebug()<<k_funcinfo<<m_node->name()<<endl;
419 m_project->addTask(m_node, m_after);
420 m_added = true;
421
422 setCommandType(1);
423}
424void TaskAddCmd::unexecute() {
425 m_project->delTask(m_node);
426 m_added = false;
427
428 setCommandType(1);
429}
430
431SubtaskAddCmd::SubtaskAddCmd(Part *part, Project *project, Node *node, Node *parent, TQString name)
432 : NamedCommand(part, name),
433 m_project(project),
434 m_node(node),
435 m_parent(parent),
436 m_added(false) {
437
438 // set some reasonable defaults for normally calculated values
439 node->setStartTime(parent->startTime());
440 node->setEndTime(node->startTime() + node->duration());
441 node->setEarliestStart(node->startTime());
442 node->setLatestFinish(node->endTime());
443 node->setWorkStartTime(node->startTime());
444 node->setWorkEndTime(node->endTime());
445}
446SubtaskAddCmd::~SubtaskAddCmd() {
447 if (!m_added)
448 delete m_node;
449}
450void SubtaskAddCmd::execute() {
451 m_project->addSubTask(m_node, m_parent);
452 m_added = true;
453
454 setCommandType(1);
455}
456void SubtaskAddCmd::unexecute() {
457 m_project->delTask(m_node);
458 m_added = false;
459
460 setCommandType(1);
461}
462
463NodeModifyNameCmd::NodeModifyNameCmd(Part *part, Node &node, TQString nodename, TQString name)
464 : NamedCommand(part, name),
465 m_node(node),
466 newName(nodename),
467 oldName(node.name()) {
468
469}
470void NodeModifyNameCmd::execute() {
471 m_node.setName(newName);
472
473 setCommandType(0);
474}
475void NodeModifyNameCmd::unexecute() {
476 m_node.setName(oldName);
477
478 setCommandType(0);
479}
480
481NodeModifyLeaderCmd::NodeModifyLeaderCmd(Part *part, Node &node, TQString leader, TQString name)
482 : NamedCommand(part, name),
483 m_node(node),
484 newLeader(leader),
485 oldLeader(node.leader()) {
486
487}
488void NodeModifyLeaderCmd::execute() {
489 m_node.setLeader(newLeader);
490
491 setCommandType(0);
492}
493void NodeModifyLeaderCmd::unexecute() {
494 m_node.setLeader(oldLeader);
495
496 setCommandType(0);
497}
498
499NodeModifyDescriptionCmd::NodeModifyDescriptionCmd(Part *part, Node &node, TQString description, TQString name)
500 : NamedCommand(part, name),
501 m_node(node),
502 newDescription(description),
503 oldDescription(node.description()) {
504
505}
506void NodeModifyDescriptionCmd::execute() {
507 m_node.setDescription(newDescription);
508
509 setCommandType(0);
510}
511void NodeModifyDescriptionCmd::unexecute() {
512 m_node.setDescription(oldDescription);
513
514 setCommandType(0);
515}
516
517NodeModifyConstraintCmd::NodeModifyConstraintCmd(Part *part, Node &node, Node::ConstraintType c, TQString name)
518 : NamedCommand(part, name),
519 m_node(node),
520 newConstraint(c),
521 oldConstraint(static_cast<Node::ConstraintType>(node.constraint())) {
522
523 TQIntDictIterator<Schedule> it = node.schedules();
524 for (; it.current(); ++it) {
525 addSchScheduled(it.current());
526 }
527}
528void NodeModifyConstraintCmd::execute() {
529 m_node.setConstraint(newConstraint);
530 setSchScheduled(false);
531 setCommandType(1);
532}
533void NodeModifyConstraintCmd::unexecute() {
534 m_node.setConstraint(oldConstraint);
535 setSchScheduled();
536 setCommandType(1);
537}
538
539NodeModifyConstraintStartTimeCmd::NodeModifyConstraintStartTimeCmd(Part *part, Node &node, TQDateTime dt, TQString name)
540 : NamedCommand(part, name),
541 m_node(node),
542 newTime(dt),
543 oldTime(node.constraintStartTime()) {
544
545 TQIntDictIterator<Schedule> it = node.schedules();
546 for (; it.current(); ++it) {
547 addSchScheduled(it.current());
548 }
549}
550void NodeModifyConstraintStartTimeCmd::execute() {
551 m_node.setConstraintStartTime(newTime);
552 setSchScheduled(false);
553 setCommandType(1);
554}
555void NodeModifyConstraintStartTimeCmd::unexecute() {
556 m_node.setConstraintStartTime(oldTime);
557 setSchScheduled();
558 setCommandType(1);
559}
560
561NodeModifyConstraintEndTimeCmd::NodeModifyConstraintEndTimeCmd(Part *part, Node &node, TQDateTime dt, TQString name)
562 : NamedCommand(part, name),
563 m_node(node),
564 newTime(dt),
565 oldTime(node.constraintEndTime()) {
566
567 TQIntDictIterator<Schedule> it = node.schedules();
568 for (; it.current(); ++it) {
569 addSchScheduled(it.current());
570 }
571}
572void NodeModifyConstraintEndTimeCmd::execute() {
573 m_node.setConstraintEndTime(newTime);
574 setSchScheduled(false);
575 setCommandType(1);
576}
577void NodeModifyConstraintEndTimeCmd::unexecute() {
578 m_node.setConstraintEndTime(oldTime);
579 setSchScheduled();
580 setCommandType(1);
581}
582
583NodeModifyStartTimeCmd::NodeModifyStartTimeCmd(Part *part, Node &node, TQDateTime dt, TQString name)
584 : NamedCommand(part, name),
585 m_node(node),
586 newTime(dt),
587 oldTime(node.startTime()) {
588
589}
590void NodeModifyStartTimeCmd::execute() {
591 m_node.setStartTime(newTime);
592
593 setCommandType(1);
594}
595void NodeModifyStartTimeCmd::unexecute() {
596 m_node.setStartTime(oldTime);
597
598 setCommandType(1);
599}
600
601NodeModifyEndTimeCmd::NodeModifyEndTimeCmd(Part *part, Node &node, TQDateTime dt, TQString name)
602 : NamedCommand(part, name),
603 m_node(node),
604 newTime(dt),
605 oldTime(node.endTime()) {
606
607}
608void NodeModifyEndTimeCmd::execute() {
609 m_node.setEndTime(newTime);
610
611 setCommandType(1);
612}
613void NodeModifyEndTimeCmd::unexecute() {
614 m_node.setEndTime(oldTime);
615
616 setCommandType(1);
617}
618
619NodeModifyIdCmd::NodeModifyIdCmd(Part *part, Node &node, TQString id, TQString name)
620 : NamedCommand(part, name),
621 m_node(node),
622 newId(id),
623 oldId(node.id()) {
624
625}
626void NodeModifyIdCmd::execute() {
627 m_node.setId(newId);
628
629 setCommandType(0);
630}
631void NodeModifyIdCmd::unexecute() {
632 m_node.setId(oldId);
633
634 setCommandType(0);
635}
636
637NodeIndentCmd::NodeIndentCmd(Part *part, Node &node, TQString name)
638 : NamedCommand(part, name),
639 m_node(node),
640 m_newparent(0),
641 m_newindex(-1) {
642
643}
644void NodeIndentCmd::execute() {
645 m_oldparent = m_node.getParent();
646 m_oldindex = m_oldparent->findChildNode(&m_node);
647 Project *p = dynamic_cast<Project *>(m_node.projectNode());
648 if (p && p->indentTask(&m_node)) {
649 m_newparent = m_node.getParent();
650 m_newindex = m_newparent->findChildNode(&m_node);
651 m_node.setParent(m_newparent);
652 }
653
654 setCommandType(1);
655}
656void NodeIndentCmd::unexecute() {
657 if (m_newindex != -1) {
658 m_newparent->delChildNode(m_newindex, false);
659 m_oldparent->insertChildNode(m_oldindex, &m_node);
660 m_node.setParent(m_oldparent);
661 m_newindex = -1;
662 }
663
664 setCommandType(1);
665}
666
667NodeUnindentCmd::NodeUnindentCmd(Part *part, Node &node, TQString name)
668 : NamedCommand(part, name),
669 m_node(node),
670 m_newparent(0),
671 m_newindex(-1) {
672}
673void NodeUnindentCmd::execute() {
674 m_oldparent = m_node.getParent();
675 m_oldindex = m_oldparent->findChildNode(&m_node);
676 Project *p = dynamic_cast<Project *>(m_node.projectNode());
677 if (p && p->unindentTask(&m_node)) {
678 m_newparent = m_node.getParent();
679 m_newindex = m_newparent->findChildNode(&m_node);
680 m_node.setParent(m_newparent);
681 }
682
683 setCommandType(1);
684}
685void NodeUnindentCmd::unexecute() {
686 if (m_newindex != -1) {
687 m_newparent->delChildNode(m_newindex, false);
688 m_oldparent->insertChildNode(m_oldindex, &m_node);
689 m_node.setParent(m_oldparent);
690 m_newindex = -1;
691 }
692
693 setCommandType(1);
694}
695
696NodeMoveUpCmd::NodeMoveUpCmd(Part *part, Node &node, TQString name)
697 : NamedCommand(part, name),
698 m_node(node),
699 m_moved(false) {
700
701 m_project = static_cast<Project *>(m_node.projectNode());
702}
703void NodeMoveUpCmd::execute() {
704 if (m_project) {
705 m_moved = m_project->moveTaskUp(&m_node);
706 }
707
708 setCommandType(0);
709}
710void NodeMoveUpCmd::unexecute() {
711 if (m_project && m_moved) {
712 m_project->moveTaskDown(&m_node);
713 }
714 m_moved = false;
715 setCommandType(0);
716}
717
718NodeMoveDownCmd::NodeMoveDownCmd(Part *part, Node &node, TQString name)
719 : NamedCommand(part, name),
720 m_node(node),
721 m_moved(false) {
722
723 m_project = static_cast<Project *>(m_node.projectNode());
724}
725void NodeMoveDownCmd::execute() {
726 if (m_project) {
727 m_moved = m_project->moveTaskDown(&m_node);
728 }
729 setCommandType(0);
730}
731void NodeMoveDownCmd::unexecute() {
732 if (m_project && m_moved) {
733 m_project->moveTaskUp(&m_node);
734 }
735 m_moved = false;
736 setCommandType(0);
737}
738
739AddRelationCmd::AddRelationCmd(Part *part, Relation *rel, TQString name)
740 : NamedCommand(part, name),
741 m_rel(rel) {
742
743 m_taken = true;
744 Node *p = rel->parent()->projectNode();
745 if (p) {
746 TQIntDictIterator<Schedule> it = p->schedules();
747 for (; it.current(); ++it) {
748 addSchScheduled(it.current());
749 }
750 }
751}
752AddRelationCmd::~AddRelationCmd() {
753 if (m_taken)
754 delete m_rel;
755}
756void AddRelationCmd::execute() {
757 //kdDebug()<<k_funcinfo<<m_rel->parent()<<" to "<<m_rel->child()<<endl;
758 m_taken = false;
759 m_rel->parent()->addDependChildNode(m_rel);
760 m_rel->child()->addDependParentNode(m_rel);
761 setSchScheduled(false);
762 setCommandType(1);
763}
764void AddRelationCmd::unexecute() {
765 m_taken = true;
766 m_rel->parent()->takeDependChildNode(m_rel);
767 m_rel->child()->takeDependParentNode(m_rel);
768 setSchScheduled();
769 setCommandType(1);
770}
771
772DeleteRelationCmd::DeleteRelationCmd(Part *part, Relation *rel, TQString name)
773 : NamedCommand(part, name),
774 m_rel(rel) {
775
776 m_taken = false;
777 Node *p = rel->parent()->projectNode();
778 if (p) {
779 TQIntDictIterator<Schedule> it = p->schedules();
780 for (; it.current(); ++it) {
781 addSchScheduled(it.current());
782 }
783 }
784}
785DeleteRelationCmd::~DeleteRelationCmd() {
786 if (m_taken)
787 delete m_rel;
788}
789void DeleteRelationCmd::execute() {
790 //kdDebug()<<k_funcinfo<<m_rel->parent()<<" to "<<m_rel->child()<<endl;
791 m_taken = true;
792 m_rel->parent()->takeDependChildNode(m_rel);
793 m_rel->child()->takeDependParentNode(m_rel);
794 setSchScheduled(false);
795 setCommandType(1);
796}
797void DeleteRelationCmd::unexecute() {
798 m_taken = false;
799 m_rel->parent()->addDependChildNode(m_rel);
800 m_rel->child()->addDependParentNode(m_rel);
801 setSchScheduled();
802 setCommandType(1);
803}
804
805ModifyRelationTypeCmd::ModifyRelationTypeCmd(Part *part, Relation *rel, Relation::Type type, TQString name)
806 : NamedCommand(part, name),
807 m_rel(rel),
808 m_newtype(type) {
809
810 m_oldtype = rel->type();
811 Node *p = rel->parent()->projectNode();
812 if (p) {
813 TQIntDictIterator<Schedule> it = p->schedules();
814 for (; it.current(); ++it) {
815 addSchScheduled(it.current());
816 }
817 }
818}
819void ModifyRelationTypeCmd::execute() {
820 m_rel->setType(m_newtype);
821 setSchScheduled(false);
822 setCommandType(1);
823}
824void ModifyRelationTypeCmd::unexecute() {
825 m_rel->setType(m_oldtype);
826 setSchScheduled();
827 setCommandType(1);
828}
829
830ModifyRelationLagCmd::ModifyRelationLagCmd(Part *part, Relation *rel, Duration lag, TQString name)
831 : NamedCommand(part, name),
832 m_rel(rel),
833 m_newlag(lag) {
834
835 m_oldlag = rel->lag();
836 Node *p = rel->parent()->projectNode();
837 if (p) {
838 TQIntDictIterator<Schedule> it = p->schedules();
839 for (; it.current(); ++it) {
840 addSchScheduled(it.current());
841 }
842 }
843}
844void ModifyRelationLagCmd::execute() {
845 m_rel->setLag(m_newlag);
846 setSchScheduled(false);
847 setCommandType(1);
848}
849void ModifyRelationLagCmd::unexecute() {
850 m_rel->setLag(m_oldlag);
851 setSchScheduled();
852 setCommandType(1);
853}
854
855AddResourceRequestCmd::AddResourceRequestCmd(Part *part, ResourceGroupRequest *group, ResourceRequest *request, TQString name)
856 : NamedCommand(part, name),
857 m_group(group),
858 m_request(request) {
859
860 m_mine = true;
861}
862AddResourceRequestCmd::~AddResourceRequestCmd() {
863 if (m_mine)
864 delete m_request;
865}
866void AddResourceRequestCmd::execute() {
867 //kdDebug()<<k_funcinfo<<"group="<<m_group<<" req="<<m_request<<endl;
868 m_group->addResourceRequest(m_request);
869 m_mine = false;
870 setSchScheduled(false);
871 setCommandType(1);
872}
873void AddResourceRequestCmd::unexecute() {
874 //kdDebug()<<k_funcinfo<<"group="<<m_group<<" req="<<m_request<<endl;
875 m_group->takeResourceRequest(m_request);
876 m_mine = true;
877 setSchScheduled();
878 setCommandType(1);
879}
880
881RemoveResourceRequestCmd::RemoveResourceRequestCmd(Part *part, ResourceGroupRequest *group, ResourceRequest *request, TQString name)
882 : NamedCommand(part, name),
883 m_group(group),
884 m_request(request) {
885
886 m_mine = false;
887 //kdDebug()<<k_funcinfo<<"group="<<group<<" req="<<request<<endl;
888 Task *t = request->task();
889 if (t) { // safety, something is seriously wrong!
890 TQIntDictIterator<Schedule> it = t->schedules();
891 for (; it.current(); ++it) {
892 addSchScheduled(it.current());
893 }
894 }
895}
896RemoveResourceRequestCmd::~RemoveResourceRequestCmd() {
897 if (m_mine)
898 delete m_request;
899}
900void RemoveResourceRequestCmd::execute() {
901 m_group->takeResourceRequest(m_request);
902 m_mine = true;
903 setSchScheduled(false);
904 setCommandType(1);
905}
906void RemoveResourceRequestCmd::unexecute() {
907 m_group->addResourceRequest(m_request);
908 m_mine = false;
909 setSchScheduled();
910 setCommandType(1);
911}
912
913ModifyEffortCmd::ModifyEffortCmd(Part *part, Node &node, Duration oldvalue, Duration newvalue, TQString name)
914 : NamedCommand(part, name),
915 m_effort(node.effort()),
916 m_oldvalue(oldvalue),
917 m_newvalue(newvalue) {
918
919 TQIntDictIterator<Schedule> it = node.schedules();
920 for (; it.current(); ++it) {
921 addSchScheduled(it.current());
922 }
923}
924void ModifyEffortCmd::execute() {
925 m_effort->set(m_newvalue);
926 setSchScheduled(false);
927 setCommandType(1);
928}
929void ModifyEffortCmd::unexecute() {
930 m_effort->set(m_oldvalue);
931 setSchScheduled();
932 setCommandType(1);
933}
934
935EffortModifyOptimisticRatioCmd::EffortModifyOptimisticRatioCmd(Part *part, Node &node, int oldvalue, int newvalue, TQString name)
936 : NamedCommand(part, name),
937 m_effort(node.effort()),
938 m_oldvalue(oldvalue),
939 m_newvalue(newvalue) {
940
941 TQIntDictIterator<Schedule> it = node.schedules();
942 for (; it.current(); ++it) {
943 addSchScheduled(it.current());
944 }
945}
946void EffortModifyOptimisticRatioCmd::execute() {
947 m_effort->setOptimisticRatio(m_newvalue);
948 setSchScheduled(false);
949 setCommandType(1);
950}
951void EffortModifyOptimisticRatioCmd::unexecute() {
952 m_effort->setOptimisticRatio(m_oldvalue);
953 setSchScheduled();
954 setCommandType(1);
955}
956
957EffortModifyPessimisticRatioCmd::EffortModifyPessimisticRatioCmd(Part *part, Node &node, int oldvalue, int newvalue, TQString name)
958 : NamedCommand(part, name),
959 m_effort(node.effort()),
960 m_oldvalue(oldvalue),
961 m_newvalue(newvalue) {
962
963 TQIntDictIterator<Schedule> it = node.schedules();
964 for (; it.current(); ++it) {
965 addSchScheduled(it.current());
966 }
967}
968void EffortModifyPessimisticRatioCmd::execute() {
969 m_effort->setPessimisticRatio(m_newvalue);
970 setSchScheduled(false);
971 setCommandType(1);
972}
973void EffortModifyPessimisticRatioCmd::unexecute() {
974 m_effort->setPessimisticRatio(m_oldvalue);
975 setSchScheduled();
976 setCommandType(1);
977}
978
979ModifyEffortTypeCmd::ModifyEffortTypeCmd(Part *part, Node &node, int oldvalue, int newvalue, TQString name)
980 : NamedCommand(part, name),
981 m_effort(node.effort()),
982 m_oldvalue(oldvalue),
983 m_newvalue(newvalue) {
984
985 TQIntDictIterator<Schedule> it = node.schedules();
986 for (; it.current(); ++it) {
987 addSchScheduled(it.current());
988 }
989}
990void ModifyEffortTypeCmd::execute() {
991 m_effort->setType(static_cast<Effort::Type>(m_newvalue));
992 setSchScheduled(false);
993 setCommandType(1);
994}
995void ModifyEffortTypeCmd::unexecute() {
996 m_effort->setType(static_cast<Effort::Type>(m_oldvalue));
997 setSchScheduled();
998 setCommandType(1);
999}
1000
1001EffortModifyRiskCmd::EffortModifyRiskCmd(Part *part, Node &node, int oldvalue, int newvalue, TQString name)
1002 : NamedCommand(part, name),
1003 m_effort(node.effort()),
1004 m_oldvalue(oldvalue),
1005 m_newvalue(newvalue) {
1006
1007 TQIntDictIterator<Schedule> it = node.schedules();
1008 for (; it.current(); ++it) {
1009 addSchScheduled(it.current());
1010 }
1011}
1012void EffortModifyRiskCmd::execute() {
1013 m_effort->setRisktype(static_cast<Effort::Risktype>(m_newvalue));
1014 setSchScheduled(false);
1015 setCommandType(1);
1016}
1017void EffortModifyRiskCmd::unexecute() {
1018 m_effort->setRisktype(static_cast<Effort::Risktype>(m_oldvalue));
1019 setSchScheduled();
1020 setCommandType(1);
1021}
1022
1023AddResourceGroupRequestCmd::AddResourceGroupRequestCmd(Part *part, Task &task, ResourceGroupRequest *request, TQString name)
1024 : NamedCommand(part, name),
1025 m_task(task),
1026 m_request(request) {
1027
1028 m_mine = true;
1029}
1030void AddResourceGroupRequestCmd::execute() {
1031 //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
1032 m_task.addRequest(m_request);
1033 m_mine = false;
1034
1035 setCommandType(1);
1036}
1037void AddResourceGroupRequestCmd::unexecute() {
1038 //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
1039 m_task.takeRequest(m_request); // group should now be empty of resourceRequests
1040 m_mine = true;
1041
1042 setCommandType(1);
1043}
1044
1045RemoveResourceGroupRequestCmd::RemoveResourceGroupRequestCmd(Part *part, ResourceGroupRequest *request, TQString name)
1046 : NamedCommand(part, name),
1047 m_task(request->parent()->task()),
1048 m_request(request) {
1049
1050 m_mine = false;
1051}
1052
1053RemoveResourceGroupRequestCmd::RemoveResourceGroupRequestCmd(Part *part, Task &task, ResourceGroupRequest *request, TQString name)
1054 : NamedCommand(part, name),
1055 m_task(task),
1056 m_request(request) {
1057
1058 m_mine = false;
1059}
1060void RemoveResourceGroupRequestCmd::execute() {
1061 //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
1062 m_task.takeRequest(m_request); // group should now be empty of resourceRequests
1063 m_mine = true;
1064
1065 setCommandType(1);
1066}
1067void RemoveResourceGroupRequestCmd::unexecute() {
1068 //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
1069 m_task.addRequest(m_request);
1070 m_mine = false;
1071
1072 setCommandType(1);
1073}
1074
1075AddResourceCmd::AddResourceCmd(Part *part, ResourceGroup *group, Resource *resource, TQString name)
1076 : NamedCommand(part, name),
1077 m_group(group),
1078 m_resource(resource) {
1079
1080 m_mine = true;
1081}
1082AddResourceCmd::~AddResourceCmd() {
1083 if (m_mine) {
1084 //kdDebug()<<k_funcinfo<<"delete: "<<m_resource<<endl;
1085 delete m_resource;
1086 }
1087}
1088void AddResourceCmd::execute() {
1089 m_group->addResource(m_resource, 0/*risk*/);
1090 m_mine = false;
1091 //kdDebug()<<k_funcinfo<<"added: "<<m_resource<<endl;
1092 setCommandType(0);
1093}
1094void AddResourceCmd::unexecute() {
1095 m_group->takeResource(m_resource);
1096 //kdDebug()<<k_funcinfo<<"removed: "<<m_resource<<endl;
1097 m_mine = true;
1098
1099 setCommandType(0);
1100}
1101
1102RemoveResourceCmd::RemoveResourceCmd(Part *part, ResourceGroup *group, Resource *resource, TQString name)
1103 : AddResourceCmd(part, group, resource, name) {
1104 //kdDebug()<<k_funcinfo<<resource<<endl;
1105 m_mine = false;
1106 m_requests = m_resource->requests();
1107
1108 TQIntDictIterator<Schedule> it = resource->schedules();
1109 for (; it.current(); ++it) {
1110 addSchScheduled(it.current());
1111 }
1112}
1113RemoveResourceCmd::~RemoveResourceCmd() {
1114 m_appointments.setAutoDelete(true);
1115}
1116void RemoveResourceCmd::execute() {
1117 TQPtrListIterator<ResourceRequest> it = m_requests;
1118 for (; it.current(); ++it) {
1119 it.current()->parent()->takeResourceRequest(it.current());
1120 //kdDebug()<<"Remove request for"<<it.current()->resource()->name()<<endl;
1121 }
1122 TQPtrListIterator<Appointment> ait = m_resource->appointments();
1123 for (; ait.current(); ++ait) {
1124 m_appointments.append(ait.current());
1125 }
1126 TQPtrListIterator<Appointment> mit = m_appointments;
1127 for (; mit.current(); ++mit) {
1128 mit.current()->detach(); //NOTE: removes from m_resource->appointments()
1129 //kdDebug()<<k_funcinfo<<"detached: "<<mit.current()<<endl;
1130 }
1131 AddResourceCmd::unexecute();
1132 setSchScheduled(false);
1133}
1134void RemoveResourceCmd::unexecute() {
1135 m_appointments.first();
1136 while (m_appointments.current()) {
1137 //kdDebug()<<k_funcinfo<<"attach: "<<m_appointments.current()<<endl;
1138 m_appointments.take()->attach();
1139 }
1140 TQPtrListIterator<ResourceRequest> it = m_requests;
1141 for (; it.current(); ++it) {
1142 it.current()->parent()->addResourceRequest(it.current());
1143 //kdDebug()<<"Add request for "<<it.current()->resource()->name()<<endl;
1144 }
1145 AddResourceCmd::execute();
1146 setSchScheduled();
1147}
1148
1149ModifyResourceNameCmd::ModifyResourceNameCmd(Part *part, Resource *resource, TQString value, TQString name)
1150 : NamedCommand(part, name),
1151 m_resource(resource),
1152 m_newvalue(value) {
1153 m_oldvalue = resource->name();
1154}
1155void ModifyResourceNameCmd::execute() {
1156 m_resource->setName(m_newvalue);
1157
1158 setCommandType(0);
1159}
1160void ModifyResourceNameCmd::unexecute() {
1161 m_resource->setName(m_oldvalue);
1162
1163 setCommandType(0);
1164}
1165ModifyResourceInitialsCmd::ModifyResourceInitialsCmd(Part *part, Resource *resource, TQString value, TQString name)
1166 : NamedCommand(part, name),
1167 m_resource(resource),
1168 m_newvalue(value) {
1169 m_oldvalue = resource->initials();
1170}
1171void ModifyResourceInitialsCmd::execute() {
1172 m_resource->setInitials(m_newvalue);
1173
1174 setCommandType(0);
1175}
1176void ModifyResourceInitialsCmd::unexecute() {
1177 m_resource->setInitials(m_oldvalue);
1178
1179 setCommandType(0);
1180}
1181ModifyResourceEmailCmd::ModifyResourceEmailCmd(Part *part, Resource *resource, TQString value, TQString name)
1182 : NamedCommand(part, name),
1183 m_resource(resource),
1184 m_newvalue(value) {
1185 m_oldvalue = resource->email();
1186}
1187void ModifyResourceEmailCmd::execute() {
1188 m_resource->setEmail(m_newvalue);
1189
1190 setCommandType(0);
1191}
1192void ModifyResourceEmailCmd::unexecute() {
1193 m_resource->setEmail(m_oldvalue);
1194
1195 setCommandType(0);
1196}
1197ModifyResourceTypeCmd::ModifyResourceTypeCmd(Part *part, Resource *resource, int value, TQString name)
1198 : NamedCommand(part, name),
1199 m_resource(resource),
1200 m_newvalue(value) {
1201 m_oldvalue = resource->type();
1202
1203 TQIntDictIterator<Schedule> it = resource->schedules();
1204 for (; it.current(); ++it) {
1205 addSchScheduled(it.current());
1206 }
1207}
1208void ModifyResourceTypeCmd::execute() {
1209 m_resource->setType((Resource::Type)m_newvalue);
1210 setSchScheduled(false);
1211 setCommandType(1);
1212}
1213void ModifyResourceTypeCmd::unexecute() {
1214 m_resource->setType((Resource::Type)m_oldvalue);
1215 setSchScheduled();
1216 setCommandType(1);
1217}
1218ModifyResourceUnitsCmd::ModifyResourceUnitsCmd(Part *part, Resource *resource, int value, TQString name)
1219 : NamedCommand(part, name),
1220 m_resource(resource),
1221 m_newvalue(value) {
1222 m_oldvalue = resource->units();
1223
1224 TQIntDictIterator<Schedule> it = resource->schedules();
1225 for (; it.current(); ++it) {
1226 addSchScheduled(it.current());
1227 }
1228}
1229void ModifyResourceUnitsCmd::execute() {
1230 m_resource->setUnits(m_newvalue);
1231 setSchScheduled(false);
1232 setCommandType(1);
1233}
1234void ModifyResourceUnitsCmd::unexecute() {
1235 m_resource->setUnits(m_oldvalue);
1236 setSchScheduled();
1237 setCommandType(1);
1238}
1239
1240ModifyResourceAvailableFromCmd::ModifyResourceAvailableFromCmd(Part *part, Resource *resource, DateTime value, TQString name)
1241 : NamedCommand(part, name),
1242 m_resource(resource),
1243 m_newvalue(value) {
1244 m_oldvalue = resource->availableFrom();
1245
1246 TQIntDictIterator<Schedule> it = resource->schedules();
1247 if (!it.isEmpty() && resource->project()) {
1248 TQDateTime s;
1249 TQDateTime e;
1250 for (; it.current(); ++it) {
1251 Schedule *sch = resource->project()->findSchedule(it.current()->id());
1252 if (sch) {
1253 s = sch->start();
1254 e = sch->end();
1255 kdDebug()<<k_funcinfo<<"old="<<m_oldvalue<<" new="<<value<<" s="<<s<<" e="<<e<<endl;
1256 }
1257 if (!s.isValid() || !e.isValid() || ((m_oldvalue > s || value > s) && (m_oldvalue < e || value < e))) {
1258 addSchScheduled(it.current());
1259 }
1260 }
1261 }
1262}
1263void ModifyResourceAvailableFromCmd::execute() {
1264 m_resource->setAvailableFrom(m_newvalue);
1265 setSchScheduled(false);
1266 setCommandType(1); //FIXME
1267}
1268void ModifyResourceAvailableFromCmd::unexecute() {
1269 m_resource->setAvailableFrom(m_oldvalue);
1270 setSchScheduled();
1271 setCommandType(1); //FIXME
1272}
1273
1274ModifyResourceAvailableUntilCmd::ModifyResourceAvailableUntilCmd(Part *part, Resource *resource, DateTime value, TQString name)
1275 : NamedCommand(part, name),
1276 m_resource(resource),
1277 m_newvalue(value) {
1278 m_oldvalue = resource->availableUntil();
1279
1280 TQIntDictIterator<Schedule> it = resource->schedules();
1281 if (!it.isEmpty()) {
1282 TQDateTime s;
1283 TQDateTime e;
1284 for (; it.current(); ++it) {
1285 Schedule *sch = resource->project()->findSchedule(it.current()->id());
1286 if (sch) {
1287 s = sch->start();
1288 e = sch->end();
1289 kdDebug()<<k_funcinfo<<"old="<<m_oldvalue<<" new="<<value<<" s="<<s<<" e="<<e<<endl;
1290 }
1291 if (!s.isValid() || !e.isValid() || ((m_oldvalue > s || value > s) && (m_oldvalue < e || value < e))) {
1292 addSchScheduled(it.current());
1293 }
1294 }
1295 }
1296}
1297void ModifyResourceAvailableUntilCmd::execute() {
1298 m_resource->setAvailableUntil(m_newvalue);
1299 setSchScheduled(false);
1300 setCommandType(1); //FIXME
1301}
1302void ModifyResourceAvailableUntilCmd::unexecute() {
1303 m_resource->setAvailableUntil(m_oldvalue);
1304 setSchScheduled();
1305 setCommandType(1); //FIXME
1306}
1307
1308ModifyResourceNormalRateCmd::ModifyResourceNormalRateCmd(Part *part, Resource *resource, double value, TQString name)
1309 : NamedCommand(part, name),
1310 m_resource(resource),
1311 m_newvalue(value) {
1312 m_oldvalue = resource->normalRate();
1313}
1314void ModifyResourceNormalRateCmd::execute() {
1315 m_resource->setNormalRate(m_newvalue);
1316
1317 setCommandType(0);
1318}
1319void ModifyResourceNormalRateCmd::unexecute() {
1320 m_resource->setNormalRate(m_oldvalue);
1321
1322 setCommandType(0);
1323}
1324ModifyResourceOvertimeRateCmd::ModifyResourceOvertimeRateCmd(Part *part, Resource *resource, double value, TQString name)
1325 : NamedCommand(part, name),
1326 m_resource(resource),
1327 m_newvalue(value) {
1328 m_oldvalue = resource->overtimeRate();
1329}
1330void ModifyResourceOvertimeRateCmd::execute() {
1331 m_resource->setOvertimeRate(m_newvalue);
1332
1333 setCommandType(0);
1334}
1335void ModifyResourceOvertimeRateCmd::unexecute() {
1336 m_resource->setOvertimeRate(m_oldvalue);
1337
1338 setCommandType(0);
1339}
1340
1341ModifyResourceCalendarCmd::ModifyResourceCalendarCmd(Part *part, Resource *resource, Calendar *value, TQString name)
1342 : NamedCommand(part, name),
1343 m_resource(resource),
1344 m_newvalue(value) {
1345 m_oldvalue = resource->calendar(true);
1346
1347 TQIntDictIterator<Schedule> it = resource->schedules();
1348 for (; it.current(); ++it) {
1349 addSchScheduled(it.current());
1350 }
1351}
1352void ModifyResourceCalendarCmd::execute() {
1353 m_resource->setCalendar(m_newvalue);
1354 setSchScheduled(false);
1355 setCommandType(1);
1356}
1357void ModifyResourceCalendarCmd::unexecute() {
1358 m_resource->setCalendar(m_oldvalue);
1359 setSchScheduled();
1360 setCommandType(1);
1361}
1362
1363RemoveResourceGroupCmd::RemoveResourceGroupCmd(Part *part, ResourceGroup *group, TQString name)
1364 : NamedCommand(part, name),
1365 m_group(group) {
1366
1367 m_mine = false;
1368}
1369RemoveResourceGroupCmd::~RemoveResourceGroupCmd() {
1370 if (m_mine)
1371 delete m_group;
1372}
1373void RemoveResourceGroupCmd::execute() {
1374 // remove all requests to this group
1375 int c=0;
1376 TQPtrListIterator<ResourceGroupRequest> it = m_group->requests();
1377 for (; it.current(); ++it) {
1378 if (it.current()->parent()) {
1379 it.current()->parent()->takeRequest(it.current());
1380 }
1381 c = 1;
1382 }
1383 if (m_group->project())
1384 m_group->project()->takeResourceGroup(m_group);
1385 m_mine = true;
1386
1387 setCommandType(c);
1388}
1389void RemoveResourceGroupCmd::unexecute() {
1390 // add all requests
1391 int c=0;
1392 TQPtrListIterator<ResourceGroupRequest> it = m_group->requests();
1393 for (; it.current(); ++it) {
1394 if (it.current()->parent()) {
1395 it.current()->parent()->addRequest(it.current());
1396 }
1397 c = 1;
1398 }
1399 if (m_group->project())
1400 m_group->project()->addResourceGroup(m_group);
1401
1402 m_mine = false;
1403
1404 setCommandType(c);
1405}
1406
1407AddResourceGroupCmd::AddResourceGroupCmd(Part *part, ResourceGroup *group, TQString name)
1408 : RemoveResourceGroupCmd(part, group, name) {
1409
1410 m_mine = true;
1411}
1412void AddResourceGroupCmd::execute() {
1413 RemoveResourceGroupCmd::unexecute();
1414}
1415void AddResourceGroupCmd::unexecute() {
1416 RemoveResourceGroupCmd::execute();
1417}
1418
1419ModifyResourceGroupNameCmd::ModifyResourceGroupNameCmd(Part *part, ResourceGroup *group, TQString value, TQString name)
1420 : NamedCommand(part, name),
1421 m_group(group),
1422 m_newvalue(value) {
1423 m_oldvalue = group->name();
1424}
1425void ModifyResourceGroupNameCmd::execute() {
1426 m_group->setName(m_newvalue);
1427
1428 setCommandType(0);
1429}
1430void ModifyResourceGroupNameCmd::unexecute() {
1431 m_group->setName(m_oldvalue);
1432
1433 setCommandType(0);
1434}
1435
1436TaskModifyProgressCmd::TaskModifyProgressCmd(Part *part, Task &task, struct Task::Progress &value, TQString name)
1437 : NamedCommand(part, name),
1438 m_task(task),
1439 m_newvalue(value) {
1440 m_oldvalue = task.progress();
1441}
1442void TaskModifyProgressCmd::execute() {
1443 m_task.progress() = m_newvalue;
1444
1445 setCommandType(0);
1446}
1447void TaskModifyProgressCmd::unexecute() {
1448 m_task.progress() = m_oldvalue;
1449
1450 setCommandType(0);
1451}
1452
1453ProjectModifyBaselineCmd::ProjectModifyBaselineCmd(Part *part, Project &project, bool value, TQString name)
1454 : NamedCommand(part, name),
1455 m_project(project),
1456 m_newvalue(value) {
1457 m_oldvalue = project.isBaselined();
1458}
1459void ProjectModifyBaselineCmd::execute() {
1460 m_project.setBaselined(m_newvalue);
1461
1462 setCommandType(2);
1463}
1464void ProjectModifyBaselineCmd::unexecute() {
1465 m_project.setBaselined(m_oldvalue);
1466
1467 setCommandType(2);
1468}
1469
1470AddAccountCmd::AddAccountCmd(Part *part, Project &project, Account *account, TQString parent, TQString name)
1471 : NamedCommand(part, name),
1472 m_project(project),
1473 m_account(account),
1474 m_parent(0),
1475 m_parentName(parent) {
1476 m_mine = true;
1477}
1478
1479AddAccountCmd::AddAccountCmd(Part *part, Project &project, Account *account, Account *parent, TQString name)
1480 : NamedCommand(part, name),
1481 m_project(project),
1482 m_account(account),
1483 m_parent(parent) {
1484 m_mine = true;
1485}
1486
1487AddAccountCmd::~AddAccountCmd() {
1488 if (m_mine)
1489 delete m_account;
1490}
1491
1492void AddAccountCmd::execute() {
1493 if (m_parent == 0 && !m_parentName.isEmpty()) {
1494 m_parent = m_project.accounts().findAccount(m_parentName);
1495 }
1496 if (m_parent)
1497 m_parent->append(m_account);
1498 else
1499 m_project.accounts().append(m_account);
1500
1501 setCommandType(0);
1502 m_mine = false;
1503}
1504void AddAccountCmd::unexecute() {
1505 if (m_parent)
1506 m_parent->take(m_account);
1507 else
1508 m_project.accounts().take(m_account);
1509
1510 setCommandType(0);
1511 m_mine = true;
1512}
1513
1514RemoveAccountCmd::RemoveAccountCmd(Part *part, Project &project, Account *account, TQString name)
1515 : NamedCommand(part, name),
1516 m_project(project),
1517 m_account(account) {
1518 m_mine = false;
1519 m_isDefault = account == project.accounts().defaultAccount();
1520}
1521
1522RemoveAccountCmd::~RemoveAccountCmd() {
1523 if (m_mine)
1524 delete m_account;
1525}
1526
1527void RemoveAccountCmd::execute() {
1528 if (m_isDefault) {
1529 m_project.accounts().setDefaultAccount(0);
1530 }
1531 if (m_account->parent())
1532 m_account->parent()->take(m_account);
1533 else
1534 m_project.accounts().take(m_account);
1535
1536 setCommandType(0);
1537 m_mine = true;
1538}
1539void RemoveAccountCmd::unexecute() {
1540 if (m_account->parent())
1541 m_account->parent()->append(m_account);
1542 else
1543 m_project.accounts().append(m_account);
1544
1545 if (m_isDefault)
1546 m_project.accounts().setDefaultAccount(m_account);
1547
1548 setCommandType(0);
1549 m_mine = false;
1550}
1551
1552RenameAccountCmd::RenameAccountCmd(Part *part, Account *account, TQString value, TQString name)
1553 : NamedCommand(part, name),
1554 m_account(account) {
1555 m_oldvalue = account->name();
1556 m_newvalue = value;
1557}
1558
1559void RenameAccountCmd::execute() {
1560 m_account->setName(m_newvalue);
1561 setCommandType(0);
1562}
1563void RenameAccountCmd::unexecute() {
1564 m_account->setName(m_oldvalue);
1565 setCommandType(0);
1566}
1567
1568ModifyAccountDescriptionCmd::ModifyAccountDescriptionCmd(Part *part, Account *account, TQString value, TQString name)
1569 : NamedCommand(part, name),
1570 m_account(account) {
1571 m_oldvalue = account->description();
1572 m_newvalue = value;
1573}
1574
1575void ModifyAccountDescriptionCmd::execute() {
1576 m_account->setDescription(m_newvalue);
1577 setCommandType(0);
1578}
1579void ModifyAccountDescriptionCmd::unexecute() {
1580 m_account->setDescription(m_oldvalue);
1581 setCommandType(0);
1582}
1583
1584
1585NodeModifyStartupCostCmd::NodeModifyStartupCostCmd(Part *part, Node &node, double value, TQString name)
1586 : NamedCommand(part, name),
1587 m_node(node) {
1588 m_oldvalue = node.startupCost();
1589 m_newvalue = value;
1590}
1591
1592void NodeModifyStartupCostCmd::execute() {
1593 m_node.setStartupCost(m_newvalue);
1594 setCommandType(0);
1595}
1596void NodeModifyStartupCostCmd::unexecute() {
1597 m_node.setStartupCost(m_oldvalue);
1598 setCommandType(0);
1599}
1600
1601NodeModifyShutdownCostCmd::NodeModifyShutdownCostCmd(Part *part, Node &node, double value, TQString name)
1602 : NamedCommand(part, name),
1603 m_node(node) {
1604 m_oldvalue = node.startupCost();
1605 m_newvalue = value;
1606}
1607
1608void NodeModifyShutdownCostCmd::execute() {
1609 m_node.setShutdownCost(m_newvalue);
1610 setCommandType(0);
1611}
1612void NodeModifyShutdownCostCmd::unexecute() {
1613 m_node.setShutdownCost(m_oldvalue);
1614 setCommandType(0);
1615}
1616
1617NodeModifyRunningAccountCmd::NodeModifyRunningAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, TQString name)
1618 : NamedCommand(part, name),
1619 m_node(node) {
1620 m_oldvalue = oldvalue;
1621 m_newvalue = newvalue;
1622 //kdDebug()<<k_funcinfo<<endl;
1623}
1624void NodeModifyRunningAccountCmd::execute() {
1625 //kdDebug()<<k_funcinfo<<endl;
1626 if (m_oldvalue) {
1627 m_oldvalue->removeRunning(m_node);
1628 }
1629 if (m_newvalue) {
1630 m_newvalue->addRunning(m_node);
1631 }
1632 setCommandType(0);
1633}
1634void NodeModifyRunningAccountCmd::unexecute() {
1635 //kdDebug()<<k_funcinfo<<endl;
1636 if (m_newvalue) {
1637 m_newvalue->removeRunning(m_node);
1638 }
1639 if (m_oldvalue) {
1640 m_oldvalue->addRunning(m_node);
1641 }
1642 setCommandType(0);
1643}
1644
1645NodeModifyStartupAccountCmd::NodeModifyStartupAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, TQString name)
1646 : NamedCommand(part, name),
1647 m_node(node) {
1648 m_oldvalue = oldvalue;
1649 m_newvalue = newvalue;
1650 //kdDebug()<<k_funcinfo<<endl;
1651}
1652
1653void NodeModifyStartupAccountCmd::execute() {
1654 //kdDebug()<<k_funcinfo<<endl;
1655 if (m_oldvalue) {
1656 m_oldvalue->removeStartup(m_node);
1657 }
1658 if (m_newvalue) {
1659 m_newvalue->addStartup(m_node);
1660 }
1661 setCommandType(0);
1662}
1663void NodeModifyStartupAccountCmd::unexecute() {
1664 //kdDebug()<<k_funcinfo<<endl;
1665 if (m_newvalue) {
1666 m_newvalue->removeStartup(m_node);
1667 }
1668 if (m_oldvalue) {
1669 m_oldvalue->addStartup(m_node);
1670 }
1671 setCommandType(0);
1672}
1673
1674NodeModifyShutdownAccountCmd::NodeModifyShutdownAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, TQString name)
1675 : NamedCommand(part, name),
1676 m_node(node) {
1677 m_oldvalue = oldvalue;
1678 m_newvalue = newvalue;
1679 //kdDebug()<<k_funcinfo<<endl;
1680}
1681
1682void NodeModifyShutdownAccountCmd::execute() {
1683 //kdDebug()<<k_funcinfo<<endl;
1684 if (m_oldvalue) {
1685 m_oldvalue->removeShutdown(m_node);
1686 }
1687 if (m_newvalue) {
1688 m_newvalue->addShutdown(m_node);
1689 }
1690 setCommandType(0);
1691}
1692void NodeModifyShutdownAccountCmd::unexecute() {
1693 //kdDebug()<<k_funcinfo<<endl;
1694 if (m_newvalue) {
1695 m_newvalue->removeShutdown(m_node);
1696 }
1697 if (m_oldvalue) {
1698 m_oldvalue->addShutdown(m_node);
1699 }
1700 setCommandType(0);
1701}
1702
1703ModifyDefaultAccountCmd::ModifyDefaultAccountCmd(Part *part, Accounts &acc, Account *oldvalue, Account *newvalue, TQString name)
1704 : NamedCommand(part, name),
1705 m_accounts(acc) {
1706 m_oldvalue = oldvalue;
1707 m_newvalue = newvalue;
1708 //kdDebug()<<k_funcinfo<<endl;
1709}
1710
1711void ModifyDefaultAccountCmd::execute() {
1712 //kdDebug()<<k_funcinfo<<endl;
1713 m_accounts.setDefaultAccount(m_newvalue);
1714 setCommandType(0);
1715}
1716void ModifyDefaultAccountCmd::unexecute() {
1717 //kdDebug()<<k_funcinfo<<endl;
1718 m_accounts.setDefaultAccount(m_oldvalue);
1719 setCommandType(0);
1720}
1721
1722ProjectModifyConstraintCmd::ProjectModifyConstraintCmd(Part *part, Project &node, Node::ConstraintType c, TQString name)
1723 : NamedCommand(part, name),
1724 m_node(node),
1725 newConstraint(c),
1726 oldConstraint(static_cast<Node::ConstraintType>(node.constraint())) {
1727
1728 TQIntDictIterator<Schedule> it = node.schedules();
1729 for (; it.current(); ++it) {
1730 addSchScheduled(it.current());
1731 }
1732}
1733void ProjectModifyConstraintCmd::execute() {
1734 m_node.setConstraint(newConstraint);
1735 setSchScheduled(false);
1736 setCommandType(1);
1737}
1738void ProjectModifyConstraintCmd::unexecute() {
1739 m_node.setConstraint(oldConstraint);
1740 setSchScheduled();
1741 setCommandType(1);
1742}
1743
1744ProjectModifyStartTimeCmd::ProjectModifyStartTimeCmd(Part *part, Project &node, TQDateTime dt, TQString name)
1745 : NamedCommand(part, name),
1746 m_node(node),
1747 newTime(dt),
1748 oldTime(node.startTime()) {
1749
1750 TQIntDictIterator<Schedule> it = node.schedules();
1751 for (; it.current(); ++it) {
1752 addSchScheduled(it.current());
1753 }
1754}
1755
1756void ProjectModifyStartTimeCmd::execute() {
1757 m_node.setConstraintStartTime(newTime);
1758 setSchScheduled(false);
1759 setCommandType(1);
1760}
1761void ProjectModifyStartTimeCmd::unexecute() {
1762 m_node.setConstraintStartTime(oldTime);
1763 setSchScheduled();
1764 setCommandType(1);
1765}
1766
1767ProjectModifyEndTimeCmd::ProjectModifyEndTimeCmd(Part *part, Project &node, TQDateTime dt, TQString name)
1768 : NamedCommand(part, name),
1769 m_node(node),
1770 newTime(dt),
1771 oldTime(node.endTime()) {
1772
1773 TQIntDictIterator<Schedule> it = node.schedules();
1774 for (; it.current(); ++it) {
1775 addSchScheduled(it.current());
1776 }
1777}
1778void ProjectModifyEndTimeCmd::execute() {
1779 m_node.setEndTime(newTime);
1780 m_node.setConstraintEndTime(newTime);
1781 setSchScheduled(false);
1782 setCommandType(1);
1783}
1784void ProjectModifyEndTimeCmd::unexecute() {
1785 m_node.setConstraintEndTime(oldTime);
1786 setSchScheduled();
1787 setCommandType(1);
1788}
1789
1790CalculateProjectCmd::CalculateProjectCmd(Part *part, Project &node, TQString tname, int type, TQString name)
1791 : NamedCommand(part, name),
1792 m_node(node),
1793 m_typename(tname),
1794 m_type(type),
1795 newSchedule(0) {
1796
1797 oldCurrent = node.currentSchedule();
1798 //kdDebug()<<k_funcinfo<<type<<endl;
1799}
1800void CalculateProjectCmd::execute() {
1801 if (newSchedule == 0) {
1802 //kdDebug()<<k_funcinfo<<" create schedule"<<endl;
1803 newSchedule = m_node.createSchedule(m_typename, (Schedule::Type)m_type);
1804 m_node.calculate(newSchedule);
1805 } else {
1806 //kdDebug()<<k_funcinfo<<" redo"<<endl;
1807 newSchedule->setDeleted(false);
1808 m_node.setCurrentSchedulePtr(newSchedule);
1809 }
1810 setCommandType(0);
1811}
1812void CalculateProjectCmd::unexecute() {
1813 //kdDebug()<<k_funcinfo<<endl;
1814 newSchedule->setDeleted(true);
1815 m_node.setCurrentSchedulePtr(oldCurrent);
1816
1817 setCommandType(0);
1818}
1819
1820RecalculateProjectCmd::RecalculateProjectCmd(Part *part, Project &node, Schedule &sch, TQString name)
1821 : NamedCommand(part, name),
1822 m_node(node),
1823 oldSchedule(sch),
1824 newSchedule(0),
1825 oldDeleted(sch.isDeleted()) {
1826
1827 oldCurrent = node.currentSchedule();
1828 //kdDebug()<<k_funcinfo<<sch.typeToString()<<" curr="<<(oldCurrent?oldCurrent->id():-1)<<endl;
1829}
1830void RecalculateProjectCmd::execute() {
1831 oldSchedule.setDeleted(true);
1832 if (newSchedule == 0) {
1833 newSchedule = m_node.createSchedule(oldSchedule.name(), oldSchedule.type());
1834 m_node.calculate(newSchedule);
1835 } else {
1836 newSchedule->setDeleted(false);
1837 m_node.setCurrentSchedulePtr(newSchedule);
1838 //kdDebug()<<k_funcinfo<<newSchedule->typeToString()<<" redo"<<endl;
1839 }
1840 setCommandType(0);
1841}
1842void RecalculateProjectCmd::unexecute() {
1843 //kdDebug()<<k_funcinfo<<newSchedule->typeToString()<<(oldCurrent ? oldCurrent->id() : -1)<<endl;
1844 newSchedule->setDeleted(true);
1845 oldSchedule.setDeleted(oldDeleted);
1846 m_node.setCurrentSchedulePtr(oldCurrent);
1847
1848 setCommandType(0);
1849}
1850
1851
1852ModifyStandardWorktimeYearCmd::ModifyStandardWorktimeYearCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, TQString name)
1853 : NamedCommand(part, name),
1854 swt(wt),
1855 m_oldvalue(oldvalue),
1856 m_newvalue(newvalue) {
1857
1858}
1859void ModifyStandardWorktimeYearCmd::execute() {
1860 swt->setYear(m_newvalue);
1861 setCommandType(0);
1862}
1863void ModifyStandardWorktimeYearCmd::unexecute() {
1864 swt->setYear(m_oldvalue);
1865 setCommandType(0);
1866}
1867
1868ModifyStandardWorktimeMonthCmd::ModifyStandardWorktimeMonthCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, TQString name)
1869 : NamedCommand(part, name),
1870 swt(wt),
1871 m_oldvalue(oldvalue),
1872 m_newvalue(newvalue) {
1873
1874}
1875void ModifyStandardWorktimeMonthCmd::execute() {
1876 swt->setMonth(m_newvalue);
1877 setCommandType(0);
1878}
1879void ModifyStandardWorktimeMonthCmd::unexecute() {
1880 swt->setMonth(m_oldvalue);
1881 setCommandType(0);
1882}
1883
1884ModifyStandardWorktimeWeekCmd::ModifyStandardWorktimeWeekCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, TQString name)
1885 : NamedCommand(part, name),
1886 swt(wt),
1887 m_oldvalue(oldvalue),
1888 m_newvalue(newvalue) {
1889
1890}
1891void ModifyStandardWorktimeWeekCmd::execute() {
1892 swt->setWeek(m_newvalue);
1893 setCommandType(0);
1894}
1895void ModifyStandardWorktimeWeekCmd::unexecute() {
1896 swt->setWeek(m_oldvalue);
1897 setCommandType(0);
1898}
1899
1900ModifyStandardWorktimeDayCmd::ModifyStandardWorktimeDayCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, TQString name)
1901 : NamedCommand(part, name),
1902 swt(wt),
1903 m_oldvalue(oldvalue),
1904 m_newvalue(newvalue) {
1905
1906}
1907
1908void ModifyStandardWorktimeDayCmd::execute() {
1909 swt->setDay(m_newvalue);
1910 setCommandType(0);
1911}
1912void ModifyStandardWorktimeDayCmd::unexecute() {
1913 swt->setDay(m_oldvalue);
1914 setCommandType(0);
1915}
1916
1917
1918} //KPlato namespace