00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kptcommand.h"
00021 #include "kptaccount.h"
00022 #include "kptappointment.h"
00023 #include "kptpart.h"
00024 #include "kptproject.h"
00025 #include "kpttask.h"
00026 #include "kptcalendar.h"
00027 #include "kptrelation.h"
00028 #include "kptresource.h"
00029
00030 #include <kdebug.h>
00031 #include <klocale.h>
00032
00033 #include <qintdict.h>
00034 #include <qmap.h>
00035
00036 namespace KPlato
00037 {
00038
00039 void NamedCommand::setCommandType(int type) {
00040 if (m_part)
00041 m_part->setCommandType(type);
00042 }
00043
00044 void NamedCommand::setSchDeleted() {
00045 QMap<Schedule*, bool>::Iterator it;
00046 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
00047 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<it.data()<<endl;
00048 it.key()->setDeleted(it.data());
00049 }
00050 }
00051 void NamedCommand::setSchDeleted(bool state) {
00052 QMap<Schedule*, bool>::Iterator it;
00053 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
00054 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<state<<endl;
00055 it.key()->setDeleted(state);
00056 }
00057 }
00058 void NamedCommand::setSchScheduled() {
00059 QMap<Schedule*, bool>::Iterator it;
00060 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
00061 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<it.data()<<endl;
00062 it.key()->setScheduled(it.data());
00063 }
00064 }
00065 void NamedCommand::setSchScheduled(bool state) {
00066 QMap<Schedule*, bool>::Iterator it;
00067 for (it = m_schedules.begin(); it != m_schedules.end(); ++it) {
00068 kdDebug()<<k_funcinfo<<it.key()->id()<<": "<<state<<endl;
00069 it.key()->setScheduled(state);
00070 }
00071 }
00072 void NamedCommand::addSchScheduled(Schedule *sch) {
00073 kdDebug()<<k_funcinfo<<sch->id()<<": "<<sch->isScheduled()<<endl;
00074 m_schedules.insert(sch, sch->isScheduled());
00075 QPtrListIterator<Appointment> it = sch->appointments();
00076 for (; it.current(); ++it) {
00077 if (it.current()->node() == sch) {
00078 m_schedules.insert(it.current()->resource(), it.current()->resource()->isScheduled());
00079 } else if (it.current()->resource() == sch) {
00080 m_schedules.insert(it.current()->node(), it.current()->node()->isScheduled());
00081 }
00082 }
00083 }
00084 void NamedCommand::addSchDeleted(Schedule *sch) {
00085 kdDebug()<<k_funcinfo<<sch->id()<<": "<<sch->isDeleted()<<endl;
00086 m_schedules.insert(sch, sch->isDeleted());
00087 QPtrListIterator<Appointment> it = sch->appointments();
00088 for (; it.current(); ++it) {
00089 if (it.current()->node() == sch) {
00090 m_schedules.insert(it.current()->resource(), it.current()->resource()->isDeleted());
00091 } else if (it.current()->resource() == sch) {
00092 m_schedules.insert(it.current()->node(), it.current()->node()->isDeleted());
00093 }
00094 }
00095 }
00096
00097
00098 CalendarAddCmd::CalendarAddCmd(Part *part, Project *project,Calendar *cal, QString name)
00099 : NamedCommand(part, name),
00100 m_project(project),
00101 m_cal(cal),
00102 m_added(false) {
00103 cal->setDeleted(true);
00104
00105 }
00106
00107 void CalendarAddCmd::execute() {
00108 if (!m_added && m_project) {
00109 m_project->addCalendar(m_cal);
00110 m_added = true;
00111 }
00112 m_cal->setDeleted(false);
00113
00114 setCommandType(0);
00115
00116 }
00117
00118 void CalendarAddCmd::unexecute() {
00119 m_cal->setDeleted(true);
00120
00121 setCommandType(0);
00122
00123 }
00124
00125 CalendarDeleteCmd::CalendarDeleteCmd(Part *part, Calendar *cal, QString name)
00126 : NamedCommand(part, name),
00127 m_cal(cal) {
00128
00129
00130 if (part) {
00131 QIntDictIterator<Schedule> it = part->getProject().schedules();
00132 for (; it.current(); ++it) {
00133 addSchScheduled(it.current());
00134 }
00135 }
00136 }
00137
00138 void CalendarDeleteCmd::execute() {
00139 m_cal->setDeleted(true);
00140 setSchScheduled(false);
00141 setCommandType(1);
00142 }
00143
00144 void CalendarDeleteCmd::unexecute() {
00145 m_cal->setDeleted(false);
00146 setSchScheduled();
00147 setCommandType(0);
00148 }
00149
00150 CalendarModifyNameCmd::CalendarModifyNameCmd(Part *part, Calendar *cal, QString newvalue, QString name)
00151 : NamedCommand(part, name),
00152 m_cal(cal) {
00153
00154 m_oldvalue = cal->name();
00155 m_newvalue = newvalue;
00156
00157 }
00158 void CalendarModifyNameCmd::execute() {
00159 m_cal->setName(m_newvalue);
00160 setCommandType(0);
00161
00162 }
00163 void CalendarModifyNameCmd::unexecute() {
00164 m_cal->setName(m_oldvalue);
00165 setCommandType(0);
00166
00167 }
00168
00169 CalendarModifyParentCmd::CalendarModifyParentCmd(Part *part, Calendar *cal, Calendar *newvalue, QString name)
00170 : NamedCommand(part, name),
00171 m_cal(cal) {
00172
00173 m_oldvalue = cal->parent();
00174 m_newvalue = newvalue;
00175
00176
00177 if (part) {
00178 QIntDictIterator<Schedule> it = part->getProject().schedules();
00179 for (; it.current(); ++it) {
00180 addSchScheduled(it.current());
00181 }
00182 }
00183 }
00184 void CalendarModifyParentCmd::execute() {
00185 m_cal->setParent(m_newvalue);
00186 setSchScheduled(false);
00187 setCommandType(1);
00188 }
00189 void CalendarModifyParentCmd::unexecute() {
00190 m_cal->setParent(m_oldvalue);
00191 setSchScheduled();
00192 setCommandType(1);
00193 }
00194
00195 CalendarAddDayCmd::CalendarAddDayCmd(Part *part, Calendar *cal, CalendarDay *newvalue, QString name)
00196 : NamedCommand(part, name),
00197 m_cal(cal),
00198 m_mine(true) {
00199
00200 m_newvalue = newvalue;
00201
00202
00203 if (part) {
00204 QIntDictIterator<Schedule> it = part->getProject().schedules();
00205 for (; it.current(); ++it) {
00206 addSchScheduled(it.current());
00207 }
00208 }
00209 }
00210 CalendarAddDayCmd::~CalendarAddDayCmd() {
00211
00212 if (m_mine)
00213 delete m_newvalue;
00214 }
00215 void CalendarAddDayCmd::execute() {
00216
00217 m_cal->addDay(m_newvalue);
00218 m_mine = false;
00219 setSchScheduled(false);
00220 setCommandType(1);
00221 }
00222 void CalendarAddDayCmd::unexecute() {
00223
00224 m_cal->takeDay(m_newvalue);
00225 m_mine = true;
00226 setSchScheduled();
00227 setCommandType(1);
00228 }
00229
00230 CalendarRemoveDayCmd::CalendarRemoveDayCmd(Part *part, Calendar *cal, const QDate &day, QString name)
00231 : NamedCommand(part, name),
00232 m_cal(cal),
00233 m_mine(false) {
00234
00235 m_value = cal->findDay(day);
00236
00237
00238 if (part) {
00239 QIntDictIterator<Schedule> it = part->getProject().schedules();
00240 for (; it.current(); ++it) {
00241 addSchScheduled(it.current());
00242 }
00243 }
00244 }
00245 void CalendarRemoveDayCmd::execute() {
00246
00247 m_cal->takeDay(m_value);
00248 m_mine = true;
00249 setSchScheduled(false);
00250 setCommandType(1);
00251 }
00252 void CalendarRemoveDayCmd::unexecute() {
00253
00254 m_cal->addDay(m_value);
00255 m_mine = false;
00256 setSchScheduled();
00257 setCommandType(1);
00258 }
00259
00260 CalendarModifyDayCmd::CalendarModifyDayCmd(Part *part, Calendar *cal, CalendarDay *value, QString name)
00261 : NamedCommand(part, name),
00262 m_cal(cal),
00263 m_mine(true) {
00264
00265 m_newvalue = value;
00266 m_oldvalue = cal->findDay(value->date());
00267
00268
00269 if (part) {
00270 QIntDictIterator<Schedule> it = part->getProject().schedules();
00271 for (; it.current(); ++it) {
00272 addSchScheduled(it.current());
00273 }
00274 }
00275 }
00276 CalendarModifyDayCmd::~CalendarModifyDayCmd() {
00277
00278 if (m_mine) {
00279 delete m_newvalue;
00280 } else {
00281 delete m_oldvalue;
00282 }
00283 }
00284 void CalendarModifyDayCmd::execute() {
00285
00286 m_cal->takeDay(m_oldvalue);
00287 m_cal->addDay(m_newvalue);
00288 m_mine = false;
00289 setSchScheduled(false);
00290 setCommandType(1);
00291 }
00292 void CalendarModifyDayCmd::unexecute() {
00293
00294 m_cal->takeDay(m_newvalue);
00295 m_cal->addDay(m_oldvalue);
00296 m_mine = true;
00297 setSchScheduled();
00298 setCommandType(1);
00299 }
00300
00301 CalendarModifyWeekdayCmd::CalendarModifyWeekdayCmd(Part *part, Calendar *cal, int weekday, CalendarDay *value, QString name)
00302 : NamedCommand(part, name),
00303 m_weekday(weekday),
00304 m_cal(cal),
00305 m_mine(true) {
00306
00307 m_value = value;
00308 kdDebug()<<k_funcinfo<<cal->name()<<" ("<<value<<")"<<endl;
00309
00310 if (part) {
00311 QIntDictIterator<Schedule> it = part->getProject().schedules();
00312 for (; it.current(); ++it) {
00313 addSchScheduled(it.current());
00314 }
00315 }
00316 }
00317 CalendarModifyWeekdayCmd::~CalendarModifyWeekdayCmd() {
00318 kdDebug()<<k_funcinfo<<m_weekday<<": "<<m_value<<endl;
00319 delete m_value;
00320
00321 }
00322 void CalendarModifyWeekdayCmd::execute() {
00323 m_value = m_cal->weekdays()->replace(m_weekday, m_value);
00324 setSchScheduled(false);
00325 setCommandType(1);
00326 }
00327 void CalendarModifyWeekdayCmd::unexecute() {
00328 m_value = m_cal->weekdays()->replace(m_weekday, m_value);
00329 setSchScheduled();
00330 setCommandType(1);
00331 }
00332
00333 NodeDeleteCmd::NodeDeleteCmd(Part *part, Node *node, QString name)
00334 : NamedCommand(part, name),
00335 m_node(node),
00336 m_index(-1) {
00337
00338 m_parent = node->getParent();
00339 if (m_parent)
00340 m_index = m_parent->findChildNode(node);
00341 m_mine = false;
00342 m_appointments.setAutoDelete(true);
00343
00344 Node *p = node->projectNode();
00345 if (p) {
00346 QIntDictIterator<Schedule> it = p->schedules();
00347 for (; it.current(); ++it) {
00348 Schedule *s = node->findSchedule(it.current()->id());
00349 if (s && s->isScheduled()) {
00350
00351 addSchScheduled(it.current());
00352 }
00353 }
00354 }
00355 }
00356 NodeDeleteCmd::~NodeDeleteCmd() {
00357 if (m_mine)
00358 delete m_node;
00359 }
00360 void NodeDeleteCmd::execute() {
00361 if (m_parent) {
00362
00363 QPtrListIterator<Appointment> it = m_node->appointments();
00364 for (; it.current(); ++it) {
00365 it.current()->detach();
00366 m_appointments.append(it.current());
00367 }
00368 m_parent->delChildNode(m_node, false);
00369 m_mine = true;
00370 setSchScheduled(false);
00371 setCommandType(1);
00372 }
00373 }
00374 void NodeDeleteCmd::unexecute() {
00375 if (m_parent) {
00376
00377 m_parent->insertChildNode(m_index, m_node);
00378 Appointment *a;
00379 for (a = m_appointments.first(); a != 0; m_appointments.take()) {
00380 a->attach();
00381 }
00382 m_mine = false;
00383 setSchScheduled();
00384 setCommandType(1);
00385 }
00386 }
00387
00388 TaskAddCmd::TaskAddCmd(Part *part, Project *project, Node *node, Node *after, QString name)
00389 : NamedCommand(part, name),
00390 m_project(project),
00391 m_node(node),
00392 m_after(after),
00393 m_added(false) {
00394
00395
00396 if (after && after->getParent() && after->getParent() != project) {
00397 node->setStartTime(after->getParent()->startTime());
00398 node->setEndTime(node->startTime() + node->duration());
00399 } else {
00400 if (project->constraint() == Node::MustFinishOn) {
00401 node->setEndTime(project->endTime());
00402 node->setStartTime(node->endTime() - node->duration());
00403 } else {
00404 node->setStartTime(project->startTime());
00405 node->setEndTime(node->startTime() + node->duration());
00406 }
00407 }
00408 node->setEarliestStart(node->startTime());
00409 node->setLatestFinish(node->endTime());
00410 node->setWorkStartTime(node->startTime());
00411 node->setWorkEndTime(node->endTime());
00412 }
00413 TaskAddCmd::~TaskAddCmd() {
00414 if (!m_added)
00415 delete m_node;
00416 }
00417 void TaskAddCmd::execute() {
00418
00419 m_project->addTask(m_node, m_after);
00420 m_added = true;
00421
00422 setCommandType(1);
00423 }
00424 void TaskAddCmd::unexecute() {
00425 m_node->getParent()->delChildNode(m_node, false);
00426 m_added = false;
00427
00428 setCommandType(1);
00429 }
00430
00431 SubtaskAddCmd::SubtaskAddCmd(Part *part, Project *project, Node *node, Node *parent, QString name)
00432 : NamedCommand(part, name),
00433 m_project(project),
00434 m_node(node),
00435 m_parent(parent),
00436 m_added(false) {
00437
00438
00439 node->setStartTime(parent->startTime());
00440 node->setEndTime(node->startTime() + node->duration());
00441 node->setEarliestStart(node->startTime());
00442 node->setLatestFinish(node->endTime());
00443 node->setWorkStartTime(node->startTime());
00444 node->setWorkEndTime(node->endTime());
00445 }
00446 SubtaskAddCmd::~SubtaskAddCmd() {
00447 if (!m_added)
00448 delete m_node;
00449 }
00450 void SubtaskAddCmd::execute() {
00451 m_project->addSubTask(m_node, m_parent);
00452 m_added = true;
00453
00454 setCommandType(1);
00455 }
00456 void SubtaskAddCmd::unexecute() {
00457 m_parent->delChildNode(m_node, false);
00458 m_added = false;
00459
00460 setCommandType(1);
00461 }
00462
00463 NodeModifyNameCmd::NodeModifyNameCmd(Part *part, Node &node, QString nodename, QString name)
00464 : NamedCommand(part, name),
00465 m_node(node),
00466 newName(nodename),
00467 oldName(node.name()) {
00468
00469 }
00470 void NodeModifyNameCmd::execute() {
00471 m_node.setName(newName);
00472
00473 setCommandType(0);
00474 }
00475 void NodeModifyNameCmd::unexecute() {
00476 m_node.setName(oldName);
00477
00478 setCommandType(0);
00479 }
00480
00481 NodeModifyLeaderCmd::NodeModifyLeaderCmd(Part *part, Node &node, QString leader, QString name)
00482 : NamedCommand(part, name),
00483 m_node(node),
00484 newLeader(leader),
00485 oldLeader(node.leader()) {
00486
00487 }
00488 void NodeModifyLeaderCmd::execute() {
00489 m_node.setLeader(newLeader);
00490
00491 setCommandType(0);
00492 }
00493 void NodeModifyLeaderCmd::unexecute() {
00494 m_node.setLeader(oldLeader);
00495
00496 setCommandType(0);
00497 }
00498
00499 NodeModifyDescriptionCmd::NodeModifyDescriptionCmd(Part *part, Node &node, QString description, QString name)
00500 : NamedCommand(part, name),
00501 m_node(node),
00502 newDescription(description),
00503 oldDescription(node.description()) {
00504
00505 }
00506 void NodeModifyDescriptionCmd::execute() {
00507 m_node.setDescription(newDescription);
00508
00509 setCommandType(0);
00510 }
00511 void NodeModifyDescriptionCmd::unexecute() {
00512 m_node.setDescription(oldDescription);
00513
00514 setCommandType(0);
00515 }
00516
00517 NodeModifyConstraintCmd::NodeModifyConstraintCmd(Part *part, Node &node, Node::ConstraintType c, QString name)
00518 : NamedCommand(part, name),
00519 m_node(node),
00520 newConstraint(c),
00521 oldConstraint(static_cast<Node::ConstraintType>(node.constraint())) {
00522
00523 QIntDictIterator<Schedule> it = node.schedules();
00524 for (; it.current(); ++it) {
00525 addSchScheduled(it.current());
00526 }
00527 }
00528 void NodeModifyConstraintCmd::execute() {
00529 m_node.setConstraint(newConstraint);
00530 setSchScheduled(false);
00531 setCommandType(1);
00532 }
00533 void NodeModifyConstraintCmd::unexecute() {
00534 m_node.setConstraint(oldConstraint);
00535 setSchScheduled();
00536 setCommandType(1);
00537 }
00538
00539 NodeModifyConstraintStartTimeCmd::NodeModifyConstraintStartTimeCmd(Part *part, Node &node, QDateTime dt, QString name)
00540 : NamedCommand(part, name),
00541 m_node(node),
00542 newTime(dt),
00543 oldTime(node.constraintStartTime()) {
00544
00545 QIntDictIterator<Schedule> it = node.schedules();
00546 for (; it.current(); ++it) {
00547 addSchScheduled(it.current());
00548 }
00549 }
00550 void NodeModifyConstraintStartTimeCmd::execute() {
00551 m_node.setConstraintStartTime(newTime);
00552 setSchScheduled(false);
00553 setCommandType(1);
00554 }
00555 void NodeModifyConstraintStartTimeCmd::unexecute() {
00556 m_node.setConstraintStartTime(oldTime);
00557 setSchScheduled();
00558 setCommandType(1);
00559 }
00560
00561 NodeModifyConstraintEndTimeCmd::NodeModifyConstraintEndTimeCmd(Part *part, Node &node, QDateTime dt, QString name)
00562 : NamedCommand(part, name),
00563 m_node(node),
00564 newTime(dt),
00565 oldTime(node.constraintEndTime()) {
00566
00567 QIntDictIterator<Schedule> it = node.schedules();
00568 for (; it.current(); ++it) {
00569 addSchScheduled(it.current());
00570 }
00571 }
00572 void NodeModifyConstraintEndTimeCmd::execute() {
00573 m_node.setConstraintEndTime(newTime);
00574 setSchScheduled(false);
00575 setCommandType(1);
00576 }
00577 void NodeModifyConstraintEndTimeCmd::unexecute() {
00578 m_node.setConstraintEndTime(oldTime);
00579 setSchScheduled();
00580 setCommandType(1);
00581 }
00582
00583 NodeModifyStartTimeCmd::NodeModifyStartTimeCmd(Part *part, Node &node, QDateTime dt, QString name)
00584 : NamedCommand(part, name),
00585 m_node(node),
00586 newTime(dt),
00587 oldTime(node.startTime()) {
00588
00589 }
00590 void NodeModifyStartTimeCmd::execute() {
00591 m_node.setStartTime(newTime);
00592
00593 setCommandType(1);
00594 }
00595 void NodeModifyStartTimeCmd::unexecute() {
00596 m_node.setStartTime(oldTime);
00597
00598 setCommandType(1);
00599 }
00600
00601 NodeModifyEndTimeCmd::NodeModifyEndTimeCmd(Part *part, Node &node, QDateTime dt, QString name)
00602 : NamedCommand(part, name),
00603 m_node(node),
00604 newTime(dt),
00605 oldTime(node.endTime()) {
00606
00607 }
00608 void NodeModifyEndTimeCmd::execute() {
00609 m_node.setEndTime(newTime);
00610
00611 setCommandType(1);
00612 }
00613 void NodeModifyEndTimeCmd::unexecute() {
00614 m_node.setEndTime(oldTime);
00615
00616 setCommandType(1);
00617 }
00618
00619 NodeModifyIdCmd::NodeModifyIdCmd(Part *part, Node &node, QString id, QString name)
00620 : NamedCommand(part, name),
00621 m_node(node),
00622 newId(id),
00623 oldId(node.id()) {
00624
00625 }
00626 void NodeModifyIdCmd::execute() {
00627 m_node.setId(newId);
00628
00629 setCommandType(0);
00630 }
00631 void NodeModifyIdCmd::unexecute() {
00632 m_node.setId(oldId);
00633
00634 setCommandType(0);
00635 }
00636
00637 NodeIndentCmd::NodeIndentCmd(Part *part, Node &node, QString name)
00638 : NamedCommand(part, name),
00639 m_node(node),
00640 m_newparent(0),
00641 m_newindex(-1) {
00642
00643 }
00644 void NodeIndentCmd::execute() {
00645 m_oldparent = m_node.getParent();
00646 m_oldindex = m_oldparent->findChildNode(&m_node);
00647 Project *p = dynamic_cast<Project *>(m_node.projectNode());
00648 if (p && p->indentTask(&m_node)) {
00649 m_newparent = m_node.getParent();
00650 m_newindex = m_newparent->findChildNode(&m_node);
00651 m_node.setParent(m_newparent);
00652 }
00653
00654 setCommandType(1);
00655 }
00656 void NodeIndentCmd::unexecute() {
00657 if (m_newindex != -1) {
00658 m_newparent->delChildNode(m_newindex, false);
00659 m_oldparent->insertChildNode(m_oldindex, &m_node);
00660 m_node.setParent(m_oldparent);
00661 m_newindex = -1;
00662 }
00663
00664 setCommandType(1);
00665 }
00666
00667 NodeUnindentCmd::NodeUnindentCmd(Part *part, Node &node, QString name)
00668 : NamedCommand(part, name),
00669 m_node(node),
00670 m_newparent(0),
00671 m_newindex(-1) {
00672 }
00673 void NodeUnindentCmd::execute() {
00674 m_oldparent = m_node.getParent();
00675 m_oldindex = m_oldparent->findChildNode(&m_node);
00676 Project *p = dynamic_cast<Project *>(m_node.projectNode());
00677 if (p && p->unindentTask(&m_node)) {
00678 m_newparent = m_node.getParent();
00679 m_newindex = m_newparent->findChildNode(&m_node);
00680 m_node.setParent(m_newparent);
00681 }
00682
00683 setCommandType(1);
00684 }
00685 void NodeUnindentCmd::unexecute() {
00686 if (m_newindex != -1) {
00687 m_newparent->delChildNode(m_newindex, false);
00688 m_oldparent->insertChildNode(m_oldindex, &m_node);
00689 m_node.setParent(m_oldparent);
00690 m_newindex = -1;
00691 }
00692
00693 setCommandType(1);
00694 }
00695
00696 NodeMoveUpCmd::NodeMoveUpCmd(Part *part, Node &node, QString name)
00697 : NamedCommand(part, name),
00698 m_node(node),
00699 m_newindex(-1) {
00700 }
00701 void NodeMoveUpCmd::execute() {
00702 m_oldindex = m_node.getParent()->findChildNode(&m_node);
00703 Project *p = dynamic_cast<Project *>(m_node.projectNode());
00704 if (p && p->moveTaskUp(&m_node)) {
00705 m_newindex = m_node.getParent()->findChildNode(&m_node);
00706 }
00707
00708 setCommandType(0);
00709 }
00710 void NodeMoveUpCmd::unexecute() {
00711 if (m_newindex != -1) {
00712 m_node.getParent()->delChildNode(m_newindex, false);
00713 m_node.getParent()->insertChildNode(m_oldindex, &m_node);
00714 m_newindex = -1;
00715 }
00716
00717 setCommandType(0);
00718 }
00719
00720 NodeMoveDownCmd::NodeMoveDownCmd(Part *part, Node &node, QString name)
00721 : NamedCommand(part, name),
00722 m_node(node),
00723 m_newindex(-1) {
00724 }
00725 void NodeMoveDownCmd::execute() {
00726 m_oldindex = m_node.getParent()->findChildNode(&m_node);
00727 Project *p = dynamic_cast<Project *>(m_node.projectNode());
00728 if (p && p->moveTaskDown(&m_node)) {
00729 m_newindex = m_node.getParent()->findChildNode(&m_node);
00730 }
00731
00732 setCommandType(0);
00733 }
00734 void NodeMoveDownCmd::unexecute() {
00735 if (m_newindex != -1) {
00736 m_node.getParent()->delChildNode(m_newindex, false);
00737 m_node.getParent()->insertChildNode(m_oldindex, &m_node);
00738 m_newindex = -1;
00739 }
00740
00741 setCommandType(0);
00742 }
00743
00744 AddRelationCmd::AddRelationCmd(Part *part, Relation *rel, QString name)
00745 : NamedCommand(part, name),
00746 m_rel(rel) {
00747
00748 m_taken = true;
00749 Node *p = rel->parent()->projectNode();
00750 if (p) {
00751 QIntDictIterator<Schedule> it = p->schedules();
00752 for (; it.current(); ++it) {
00753 addSchScheduled(it.current());
00754 }
00755 }
00756 }
00757 AddRelationCmd::~AddRelationCmd() {
00758 if (m_taken)
00759 delete m_rel;
00760 }
00761 void AddRelationCmd::execute() {
00762
00763 m_taken = false;
00764 m_rel->parent()->addDependChildNode(m_rel);
00765 m_rel->child()->addDependParentNode(m_rel);
00766 setSchScheduled(false);
00767 setCommandType(1);
00768 }
00769 void AddRelationCmd::unexecute() {
00770 m_taken = true;
00771 m_rel->parent()->takeDependChildNode(m_rel);
00772 m_rel->child()->takeDependParentNode(m_rel);
00773 setSchScheduled();
00774 setCommandType(1);
00775 }
00776
00777 DeleteRelationCmd::DeleteRelationCmd(Part *part, Relation *rel, QString name)
00778 : NamedCommand(part, name),
00779 m_rel(rel) {
00780
00781 m_taken = false;
00782 Node *p = rel->parent()->projectNode();
00783 if (p) {
00784 QIntDictIterator<Schedule> it = p->schedules();
00785 for (; it.current(); ++it) {
00786 addSchScheduled(it.current());
00787 }
00788 }
00789 }
00790 DeleteRelationCmd::~DeleteRelationCmd() {
00791 if (m_taken)
00792 delete m_rel;
00793 }
00794 void DeleteRelationCmd::execute() {
00795
00796 m_taken = true;
00797 m_rel->parent()->takeDependChildNode(m_rel);
00798 m_rel->child()->takeDependParentNode(m_rel);
00799 setSchScheduled(false);
00800 setCommandType(1);
00801 }
00802 void DeleteRelationCmd::unexecute() {
00803 m_taken = false;
00804 m_rel->parent()->addDependChildNode(m_rel);
00805 m_rel->child()->addDependParentNode(m_rel);
00806 setSchScheduled();
00807 setCommandType(1);
00808 }
00809
00810 ModifyRelationTypeCmd::ModifyRelationTypeCmd(Part *part, Relation *rel, Relation::Type type, QString name)
00811 : NamedCommand(part, name),
00812 m_rel(rel),
00813 m_newtype(type) {
00814
00815 m_oldtype = rel->type();
00816 Node *p = rel->parent()->projectNode();
00817 if (p) {
00818 QIntDictIterator<Schedule> it = p->schedules();
00819 for (; it.current(); ++it) {
00820 addSchScheduled(it.current());
00821 }
00822 }
00823 }
00824 void ModifyRelationTypeCmd::execute() {
00825 m_rel->setType(m_newtype);
00826 setSchScheduled(false);
00827 setCommandType(1);
00828 }
00829 void ModifyRelationTypeCmd::unexecute() {
00830 m_rel->setType(m_oldtype);
00831 setSchScheduled();
00832 setCommandType(1);
00833 }
00834
00835 ModifyRelationLagCmd::ModifyRelationLagCmd(Part *part, Relation *rel, Duration lag, QString name)
00836 : NamedCommand(part, name),
00837 m_rel(rel),
00838 m_newlag(lag) {
00839
00840 m_oldlag = rel->lag();
00841 Node *p = rel->parent()->projectNode();
00842 if (p) {
00843 QIntDictIterator<Schedule> it = p->schedules();
00844 for (; it.current(); ++it) {
00845 addSchScheduled(it.current());
00846 }
00847 }
00848 }
00849 void ModifyRelationLagCmd::execute() {
00850 m_rel->setLag(m_newlag);
00851 setSchScheduled(false);
00852 setCommandType(1);
00853 }
00854 void ModifyRelationLagCmd::unexecute() {
00855 m_rel->setLag(m_oldlag);
00856 setSchScheduled();
00857 setCommandType(1);
00858 }
00859
00860 AddResourceRequestCmd::AddResourceRequestCmd(Part *part, ResourceGroupRequest *group, ResourceRequest *request, QString name)
00861 : NamedCommand(part, name),
00862 m_group(group),
00863 m_request(request) {
00864
00865 m_mine = true;
00866 }
00867 AddResourceRequestCmd::~AddResourceRequestCmd() {
00868 if (m_mine)
00869 delete m_request;
00870 }
00871 void AddResourceRequestCmd::execute() {
00872
00873 m_group->addResourceRequest(m_request);
00874 m_mine = false;
00875 setSchScheduled(false);
00876 setCommandType(1);
00877 }
00878 void AddResourceRequestCmd::unexecute() {
00879
00880 m_group->takeResourceRequest(m_request);
00881 m_mine = true;
00882 setSchScheduled();
00883 setCommandType(1);
00884 }
00885
00886 RemoveResourceRequestCmd::RemoveResourceRequestCmd(Part *part, ResourceGroupRequest *group, ResourceRequest *request, QString name)
00887 : NamedCommand(part, name),
00888 m_group(group),
00889 m_request(request) {
00890
00891 m_mine = false;
00892
00893 Task *t = request->task();
00894 if (t) {
00895 QIntDictIterator<Schedule> it = t->schedules();
00896 for (; it.current(); ++it) {
00897 addSchScheduled(it.current());
00898 }
00899 }
00900 }
00901 RemoveResourceRequestCmd::~RemoveResourceRequestCmd() {
00902 if (m_mine)
00903 delete m_request;
00904 }
00905 void RemoveResourceRequestCmd::execute() {
00906 m_group->takeResourceRequest(m_request);
00907 m_mine = true;
00908 setSchScheduled(false);
00909 setCommandType(1);
00910 }
00911 void RemoveResourceRequestCmd::unexecute() {
00912 m_group->addResourceRequest(m_request);
00913 m_mine = false;
00914 setSchScheduled();
00915 setCommandType(1);
00916 }
00917
00918 ModifyEffortCmd::ModifyEffortCmd(Part *part, Effort *effort, Duration oldvalue, Duration newvalue, QString name)
00919 : NamedCommand(part, name),
00920 m_effort(effort),
00921 m_oldvalue(oldvalue),
00922 m_newvalue(newvalue) {
00923 }
00924 void ModifyEffortCmd::execute() {
00925 m_effort->set(m_newvalue);
00926
00927 setCommandType(1);
00928 }
00929 void ModifyEffortCmd::unexecute() {
00930 m_effort->set(m_oldvalue);
00931
00932 setCommandType(1);
00933 }
00934
00935 EffortModifyOptimisticRatioCmd::EffortModifyOptimisticRatioCmd(Part *part, Effort *effort, int oldvalue, int newvalue, QString name)
00936 : NamedCommand(part, name),
00937 m_effort(effort),
00938 m_oldvalue(oldvalue),
00939 m_newvalue(newvalue) {
00940 }
00941 void EffortModifyOptimisticRatioCmd::execute() {
00942 m_effort->setOptimisticRatio(m_newvalue);
00943
00944 setCommandType(1);
00945 }
00946 void EffortModifyOptimisticRatioCmd::unexecute() {
00947 m_effort->setOptimisticRatio(m_oldvalue);
00948
00949 setCommandType(1);
00950 }
00951
00952 EffortModifyPessimisticRatioCmd::EffortModifyPessimisticRatioCmd(Part *part, Effort *effort, int oldvalue, int newvalue, QString name)
00953 : NamedCommand(part, name),
00954 m_effort(effort),
00955 m_oldvalue(oldvalue),
00956 m_newvalue(newvalue) {
00957 }
00958 void EffortModifyPessimisticRatioCmd::execute() {
00959 m_effort->setPessimisticRatio(m_newvalue);
00960
00961 setCommandType(1);
00962 }
00963 void EffortModifyPessimisticRatioCmd::unexecute() {
00964 m_effort->setPessimisticRatio(m_oldvalue);
00965
00966 setCommandType(1);
00967 }
00968
00969 ModifyEffortTypeCmd::ModifyEffortTypeCmd(Part *part, Effort *effort, int oldvalue, int newvalue, QString name)
00970 : NamedCommand(part, name),
00971 m_effort(effort),
00972 m_oldvalue(oldvalue),
00973 m_newvalue(newvalue) {
00974 }
00975 void ModifyEffortTypeCmd::execute() {
00976 m_effort->setType(static_cast<Effort::Type>(m_newvalue));
00977
00978 setCommandType(1);
00979 }
00980 void ModifyEffortTypeCmd::unexecute() {
00981 m_effort->setType(static_cast<Effort::Type>(m_oldvalue));
00982
00983 setCommandType(1);
00984 }
00985
00986 AddResourceGroupRequestCmd::AddResourceGroupRequestCmd(Part *part, Task &task, ResourceGroupRequest *request, QString name)
00987 : NamedCommand(part, name),
00988 m_task(task),
00989 m_request(request) {
00990
00991 m_mine = true;
00992 }
00993 void AddResourceGroupRequestCmd::execute() {
00994
00995 m_task.addRequest(m_request);
00996 m_mine = false;
00997
00998 setCommandType(1);
00999 }
01000 void AddResourceGroupRequestCmd::unexecute() {
01001
01002 m_task.takeRequest(m_request);
01003 m_mine = true;
01004
01005 setCommandType(1);
01006 }
01007
01008 RemoveResourceGroupRequestCmd::RemoveResourceGroupRequestCmd(Part *part, ResourceGroupRequest *request, QString name)
01009 : NamedCommand(part, name),
01010 m_task(request->parent()->task()),
01011 m_request(request) {
01012
01013 m_mine = false;
01014 }
01015
01016 RemoveResourceGroupRequestCmd::RemoveResourceGroupRequestCmd(Part *part, Task &task, ResourceGroupRequest *request, QString name)
01017 : NamedCommand(part, name),
01018 m_task(task),
01019 m_request(request) {
01020
01021 m_mine = false;
01022 }
01023 void RemoveResourceGroupRequestCmd::execute() {
01024
01025 m_task.takeRequest(m_request);
01026 m_mine = true;
01027
01028 setCommandType(1);
01029 }
01030 void RemoveResourceGroupRequestCmd::unexecute() {
01031
01032 m_task.addRequest(m_request);
01033 m_mine = false;
01034
01035 setCommandType(1);
01036 }
01037
01038 AddResourceCmd::AddResourceCmd(Part *part, ResourceGroup *group, Resource *resource, QString name)
01039 : NamedCommand(part, name),
01040 m_group(group),
01041 m_resource(resource) {
01042
01043 m_mine = true;
01044 }
01045 AddResourceCmd::~AddResourceCmd() {
01046 if (m_mine) {
01047
01048 delete m_resource;
01049 }
01050 }
01051 void AddResourceCmd::execute() {
01052 m_group->addResource(m_resource, 0);
01053 m_mine = false;
01054
01055 setCommandType(0);
01056 }
01057 void AddResourceCmd::unexecute() {
01058 m_group->takeResource(m_resource);
01059
01060 m_mine = true;
01061
01062 setCommandType(0);
01063 }
01064
01065 RemoveResourceCmd::RemoveResourceCmd(Part *part, ResourceGroup *group, Resource *resource, QString name)
01066 : AddResourceCmd(part, group, resource, name) {
01067
01068 m_mine = false;
01069 m_requests = m_resource->requests();
01070
01071 QIntDictIterator<Schedule> it = resource->schedules();
01072 for (; it.current(); ++it) {
01073 addSchScheduled(it.current());
01074 }
01075 }
01076 RemoveResourceCmd::~RemoveResourceCmd() {
01077 m_appointments.setAutoDelete(true);
01078 }
01079 void RemoveResourceCmd::execute() {
01080 QPtrListIterator<ResourceRequest> it = m_requests;
01081 for (; it.current(); ++it) {
01082 it.current()->parent()->takeResourceRequest(it.current());
01083
01084 }
01085 QPtrListIterator<Appointment> ait = m_resource->appointments();
01086 for (; ait.current(); ++ait) {
01087 m_appointments.append(ait.current());
01088 }
01089 QPtrListIterator<Appointment> mit = m_appointments;
01090 for (; mit.current(); ++mit) {
01091 mit.current()->detach();
01092
01093 }
01094 AddResourceCmd::unexecute();
01095 setSchScheduled(false);
01096 }
01097 void RemoveResourceCmd::unexecute() {
01098 m_appointments.first();
01099 while (m_appointments.current()) {
01100
01101 m_appointments.take()->attach();
01102 }
01103 QPtrListIterator<ResourceRequest> it = m_requests;
01104 for (; it.current(); ++it) {
01105 it.current()->parent()->addResourceRequest(it.current());
01106
01107 }
01108 AddResourceCmd::execute();
01109 setSchScheduled();
01110 }
01111
01112 ModifyResourceNameCmd::ModifyResourceNameCmd(Part *part, Resource *resource, QString value, QString name)
01113 : NamedCommand(part, name),
01114 m_resource(resource),
01115 m_newvalue(value) {
01116 m_oldvalue = resource->name();
01117 }
01118 void ModifyResourceNameCmd::execute() {
01119 m_resource->setName(m_newvalue);
01120
01121 setCommandType(0);
01122 }
01123 void ModifyResourceNameCmd::unexecute() {
01124 m_resource->setName(m_oldvalue);
01125
01126 setCommandType(0);
01127 }
01128 ModifyResourceInitialsCmd::ModifyResourceInitialsCmd(Part *part, Resource *resource, QString value, QString name)
01129 : NamedCommand(part, name),
01130 m_resource(resource),
01131 m_newvalue(value) {
01132 m_oldvalue = resource->initials();
01133 }
01134 void ModifyResourceInitialsCmd::execute() {
01135 m_resource->setInitials(m_newvalue);
01136
01137 setCommandType(0);
01138 }
01139 void ModifyResourceInitialsCmd::unexecute() {
01140 m_resource->setInitials(m_oldvalue);
01141
01142 setCommandType(0);
01143 }
01144 ModifyResourceEmailCmd::ModifyResourceEmailCmd(Part *part, Resource *resource, QString value, QString name)
01145 : NamedCommand(part, name),
01146 m_resource(resource),
01147 m_newvalue(value) {
01148 m_oldvalue = resource->email();
01149 }
01150 void ModifyResourceEmailCmd::execute() {
01151 m_resource->setEmail(m_newvalue);
01152
01153 setCommandType(0);
01154 }
01155 void ModifyResourceEmailCmd::unexecute() {
01156 m_resource->setEmail(m_oldvalue);
01157
01158 setCommandType(0);
01159 }
01160 ModifyResourceTypeCmd::ModifyResourceTypeCmd(Part *part, Resource *resource, int value, QString name)
01161 : NamedCommand(part, name),
01162 m_resource(resource),
01163 m_newvalue(value) {
01164 m_oldvalue = resource->type();
01165
01166 QIntDictIterator<Schedule> it = resource->schedules();
01167 for (; it.current(); ++it) {
01168 addSchScheduled(it.current());
01169 }
01170 }
01171 void ModifyResourceTypeCmd::execute() {
01172 m_resource->setType((Resource::Type)m_newvalue);
01173 setSchScheduled(false);
01174 setCommandType(1);
01175 }
01176 void ModifyResourceTypeCmd::unexecute() {
01177 m_resource->setType((Resource::Type)m_oldvalue);
01178 setSchScheduled();
01179 setCommandType(1);
01180 }
01181 ModifyResourceUnitsCmd::ModifyResourceUnitsCmd(Part *part, Resource *resource, int value, QString name)
01182 : NamedCommand(part, name),
01183 m_resource(resource),
01184 m_newvalue(value) {
01185 m_oldvalue = resource->units();
01186
01187 QIntDictIterator<Schedule> it = resource->schedules();
01188 for (; it.current(); ++it) {
01189 addSchScheduled(it.current());
01190 }
01191 }
01192 void ModifyResourceUnitsCmd::execute() {
01193 m_resource->setUnits(m_newvalue);
01194 setSchScheduled(false);
01195 setCommandType(1);
01196 }
01197 void ModifyResourceUnitsCmd::unexecute() {
01198 m_resource->setUnits(m_oldvalue);
01199 setSchScheduled();
01200 setCommandType(1);
01201 }
01202
01203 ModifyResourceAvailableFromCmd::ModifyResourceAvailableFromCmd(Part *part, Resource *resource, DateTime value, QString name)
01204 : NamedCommand(part, name),
01205 m_resource(resource),
01206 m_newvalue(value) {
01207 m_oldvalue = resource->availableFrom();
01208
01209 QIntDictIterator<Schedule> it = resource->schedules();
01210 if (!it.isEmpty() && resource->project()) {
01211 QDateTime s;
01212 QDateTime e;
01213 for (; it.current(); ++it) {
01214 Schedule *sch = resource->project()->findSchedule(it.current()->id());
01215 if (sch) {
01216 s = sch->start();
01217 e = sch->end();
01218 kdDebug()<<k_funcinfo<<"old="<<m_oldvalue<<" new="<<value<<" s="<<s<<" e="<<e<<endl;
01219 }
01220 if (!s.isValid() || !e.isValid() || ((m_oldvalue > s || value > s) && (m_oldvalue < e || value < e))) {
01221 addSchScheduled(it.current());
01222 }
01223 }
01224 }
01225 }
01226 void ModifyResourceAvailableFromCmd::execute() {
01227 m_resource->setAvailableFrom(m_newvalue);
01228 setSchScheduled(false);
01229 setCommandType(1);
01230 }
01231 void ModifyResourceAvailableFromCmd::unexecute() {
01232 m_resource->setAvailableFrom(m_oldvalue);
01233 setSchScheduled();
01234 setCommandType(1);
01235 }
01236
01237 ModifyResourceAvailableUntilCmd::ModifyResourceAvailableUntilCmd(Part *part, Resource *resource, DateTime value, QString name)
01238 : NamedCommand(part, name),
01239 m_resource(resource),
01240 m_newvalue(value) {
01241 m_oldvalue = resource->availableUntil();
01242
01243 QIntDictIterator<Schedule> it = resource->schedules();
01244 if (!it.isEmpty()) {
01245 QDateTime s;
01246 QDateTime e;
01247 for (; it.current(); ++it) {
01248 Schedule *sch = resource->project()->findSchedule(it.current()->id());
01249 if (sch) {
01250 s = sch->start();
01251 e = sch->end();
01252 kdDebug()<<k_funcinfo<<"old="<<m_oldvalue<<" new="<<value<<" s="<<s<<" e="<<e<<endl;
01253 }
01254 if (!s.isValid() || !e.isValid() || ((m_oldvalue > s || value > s) && (m_oldvalue < e || value < e))) {
01255 addSchScheduled(it.current());
01256 }
01257 }
01258 }
01259 }
01260 void ModifyResourceAvailableUntilCmd::execute() {
01261 m_resource->setAvailableUntil(m_newvalue);
01262 setSchScheduled(false);
01263 setCommandType(1);
01264 }
01265 void ModifyResourceAvailableUntilCmd::unexecute() {
01266 m_resource->setAvailableUntil(m_oldvalue);
01267 setSchScheduled();
01268 setCommandType(1);
01269 }
01270
01271 ModifyResourceNormalRateCmd::ModifyResourceNormalRateCmd(Part *part, Resource *resource, double value, QString name)
01272 : NamedCommand(part, name),
01273 m_resource(resource),
01274 m_newvalue(value) {
01275 m_oldvalue = resource->normalRate();
01276 }
01277 void ModifyResourceNormalRateCmd::execute() {
01278 m_resource->setNormalRate(m_newvalue);
01279
01280 setCommandType(0);
01281 }
01282 void ModifyResourceNormalRateCmd::unexecute() {
01283 m_resource->setNormalRate(m_oldvalue);
01284
01285 setCommandType(0);
01286 }
01287 ModifyResourceOvertimeRateCmd::ModifyResourceOvertimeRateCmd(Part *part, Resource *resource, double value, QString name)
01288 : NamedCommand(part, name),
01289 m_resource(resource),
01290 m_newvalue(value) {
01291 m_oldvalue = resource->overtimeRate();
01292 }
01293 void ModifyResourceOvertimeRateCmd::execute() {
01294 m_resource->setOvertimeRate(m_newvalue);
01295
01296 setCommandType(0);
01297 }
01298 void ModifyResourceOvertimeRateCmd::unexecute() {
01299 m_resource->setOvertimeRate(m_oldvalue);
01300
01301 setCommandType(0);
01302 }
01303
01304 ModifyResourceCalendarCmd::ModifyResourceCalendarCmd(Part *part, Resource *resource, Calendar *value, QString name)
01305 : NamedCommand(part, name),
01306 m_resource(resource),
01307 m_newvalue(value) {
01308 m_oldvalue = resource->calendar(true);
01309
01310 QIntDictIterator<Schedule> it = resource->schedules();
01311 for (; it.current(); ++it) {
01312 addSchScheduled(it.current());
01313 }
01314 }
01315 void ModifyResourceCalendarCmd::execute() {
01316 m_resource->setCalendar(m_newvalue);
01317 setSchScheduled(false);
01318 setCommandType(1);
01319 }
01320 void ModifyResourceCalendarCmd::unexecute() {
01321 m_resource->setCalendar(m_oldvalue);
01322 setSchScheduled();
01323 setCommandType(1);
01324 }
01325
01326 RemoveResourceGroupCmd::RemoveResourceGroupCmd(Part *part, ResourceGroup *group, QString name)
01327 : NamedCommand(part, name),
01328 m_group(group) {
01329
01330 m_mine = false;
01331 }
01332 RemoveResourceGroupCmd::~RemoveResourceGroupCmd() {
01333 if (m_mine)
01334 delete m_group;
01335 }
01336 void RemoveResourceGroupCmd::execute() {
01337
01338 int c=0;
01339 QPtrListIterator<ResourceGroupRequest> it = m_group->requests();
01340 for (; it.current(); ++it) {
01341 if (it.current()->parent()) {
01342 it.current()->parent()->takeRequest(it.current());
01343 }
01344 c = 1;
01345 }
01346 if (m_group->project())
01347 m_group->project()->takeResourceGroup(m_group);
01348 m_mine = true;
01349
01350 setCommandType(c);
01351 }
01352 void RemoveResourceGroupCmd::unexecute() {
01353
01354 int c=0;
01355 QPtrListIterator<ResourceGroupRequest> it = m_group->requests();
01356 for (; it.current(); ++it) {
01357 if (it.current()->parent()) {
01358 it.current()->parent()->addRequest(it.current());
01359 }
01360 c = 1;
01361 }
01362 if (m_group->project())
01363 m_group->project()->addResourceGroup(m_group);
01364
01365 m_mine = false;
01366
01367 setCommandType(c);
01368 }
01369
01370 AddResourceGroupCmd::AddResourceGroupCmd(Part *part, ResourceGroup *group, QString name)
01371 : RemoveResourceGroupCmd(part, group, name) {
01372
01373 m_mine = true;
01374 }
01375 void AddResourceGroupCmd::execute() {
01376 RemoveResourceGroupCmd::unexecute();
01377 }
01378 void AddResourceGroupCmd::unexecute() {
01379 RemoveResourceGroupCmd::execute();
01380 }
01381
01382 ModifyResourceGroupNameCmd::ModifyResourceGroupNameCmd(Part *part, ResourceGroup *group, QString value, QString name)
01383 : NamedCommand(part, name),
01384 m_group(group),
01385 m_newvalue(value) {
01386 m_oldvalue = group->name();
01387 }
01388 void ModifyResourceGroupNameCmd::execute() {
01389 m_group->setName(m_newvalue);
01390
01391 setCommandType(0);
01392 }
01393 void ModifyResourceGroupNameCmd::unexecute() {
01394 m_group->setName(m_oldvalue);
01395
01396 setCommandType(0);
01397 }
01398
01399 TaskModifyProgressCmd::TaskModifyProgressCmd(Part *part, Task &task, struct Task::Progress &value, QString name)
01400 : NamedCommand(part, name),
01401 m_task(task),
01402 m_newvalue(value) {
01403 m_oldvalue = task.progress();
01404 }
01405 void TaskModifyProgressCmd::execute() {
01406 m_task.progress() = m_newvalue;
01407
01408 setCommandType(0);
01409 }
01410 void TaskModifyProgressCmd::unexecute() {
01411 m_task.progress() = m_oldvalue;
01412
01413 setCommandType(0);
01414 }
01415
01416 ProjectModifyBaselineCmd::ProjectModifyBaselineCmd(Part *part, Project &project, bool value, QString name)
01417 : NamedCommand(part, name),
01418 m_project(project),
01419 m_newvalue(value) {
01420 m_oldvalue = project.isBaselined();
01421 }
01422 void ProjectModifyBaselineCmd::execute() {
01423 m_project.setBaselined(m_newvalue);
01424
01425 setCommandType(2);
01426 }
01427 void ProjectModifyBaselineCmd::unexecute() {
01428 m_project.setBaselined(m_oldvalue);
01429
01430 setCommandType(2);
01431 }
01432
01433 AddAccountCmd::AddAccountCmd(Part *part, Project &project, Account *account, QString parent, QString name)
01434 : NamedCommand(part, name),
01435 m_project(project),
01436 m_account(account),
01437 m_parent(0),
01438 m_parentName(parent) {
01439 m_mine = true;
01440 }
01441
01442 AddAccountCmd::AddAccountCmd(Part *part, Project &project, Account *account, Account *parent, QString name)
01443 : NamedCommand(part, name),
01444 m_project(project),
01445 m_account(account),
01446 m_parent(parent) {
01447 m_mine = true;
01448 }
01449
01450 AddAccountCmd::~AddAccountCmd() {
01451 if (m_mine)
01452 delete m_account;
01453 }
01454
01455 void AddAccountCmd::execute() {
01456 if (m_parent == 0 && !m_parentName.isEmpty()) {
01457 m_parent = m_project.accounts().findAccount(m_parentName);
01458 }
01459 if (m_parent)
01460 m_parent->append(m_account);
01461 else
01462 m_project.accounts().append(m_account);
01463
01464 setCommandType(0);
01465 m_mine = false;
01466 }
01467 void AddAccountCmd::unexecute() {
01468 if (m_parent)
01469 m_parent->take(m_account);
01470 else
01471 m_project.accounts().take(m_account);
01472
01473 setCommandType(0);
01474 m_mine = true;
01475 }
01476
01477 RemoveAccountCmd::RemoveAccountCmd(Part *part, Project &project, Account *account, QString name)
01478 : NamedCommand(part, name),
01479 m_project(project),
01480 m_account(account) {
01481 m_mine = false;
01482 m_isDefault = account == project.accounts().defaultAccount();
01483 }
01484
01485 RemoveAccountCmd::~RemoveAccountCmd() {
01486 if (m_mine)
01487 delete m_account;
01488 }
01489
01490 void RemoveAccountCmd::execute() {
01491 if (m_isDefault) {
01492 m_project.accounts().setDefaultAccount(0);
01493 }
01494 if (m_account->parent())
01495 m_account->parent()->take(m_account);
01496 else
01497 m_project.accounts().take(m_account);
01498
01499 setCommandType(0);
01500 m_mine = true;
01501 }
01502 void RemoveAccountCmd::unexecute() {
01503 if (m_account->parent())
01504 m_account->parent()->append(m_account);
01505 else
01506 m_project.accounts().append(m_account);
01507
01508 if (m_isDefault)
01509 m_project.accounts().setDefaultAccount(m_account);
01510
01511 setCommandType(0);
01512 m_mine = false;
01513 }
01514
01515 RenameAccountCmd::RenameAccountCmd(Part *part, Account *account, QString value, QString name)
01516 : NamedCommand(part, name),
01517 m_account(account) {
01518 m_oldvalue = account->name();
01519 m_newvalue = value;
01520 }
01521
01522 void RenameAccountCmd::execute() {
01523 m_account->setName(m_newvalue);
01524 setCommandType(0);
01525 }
01526 void RenameAccountCmd::unexecute() {
01527 m_account->setName(m_oldvalue);
01528 setCommandType(0);
01529 }
01530
01531 ModifyAccountDescriptionCmd::ModifyAccountDescriptionCmd(Part *part, Account *account, QString value, QString name)
01532 : NamedCommand(part, name),
01533 m_account(account) {
01534 m_oldvalue = account->description();
01535 m_newvalue = value;
01536 }
01537
01538 void ModifyAccountDescriptionCmd::execute() {
01539 m_account->setDescription(m_newvalue);
01540 setCommandType(0);
01541 }
01542 void ModifyAccountDescriptionCmd::unexecute() {
01543 m_account->setDescription(m_oldvalue);
01544 setCommandType(0);
01545 }
01546
01547
01548 NodeModifyStartupCostCmd::NodeModifyStartupCostCmd(Part *part, Node &node, double value, QString name)
01549 : NamedCommand(part, name),
01550 m_node(node) {
01551 m_oldvalue = node.startupCost();
01552 m_newvalue = value;
01553 }
01554
01555 void NodeModifyStartupCostCmd::execute() {
01556 m_node.setStartupCost(m_newvalue);
01557 setCommandType(0);
01558 }
01559 void NodeModifyStartupCostCmd::unexecute() {
01560 m_node.setStartupCost(m_oldvalue);
01561 setCommandType(0);
01562 }
01563
01564 NodeModifyShutdownCostCmd::NodeModifyShutdownCostCmd(Part *part, Node &node, double value, QString name)
01565 : NamedCommand(part, name),
01566 m_node(node) {
01567 m_oldvalue = node.startupCost();
01568 m_newvalue = value;
01569 }
01570
01571 void NodeModifyShutdownCostCmd::execute() {
01572 m_node.setShutdownCost(m_newvalue);
01573 setCommandType(0);
01574 }
01575 void NodeModifyShutdownCostCmd::unexecute() {
01576 m_node.setShutdownCost(m_oldvalue);
01577 setCommandType(0);
01578 }
01579
01580 NodeModifyRunningAccountCmd::NodeModifyRunningAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, QString name)
01581 : NamedCommand(part, name),
01582 m_node(node) {
01583 m_oldvalue = oldvalue;
01584 m_newvalue = newvalue;
01585
01586 }
01587 void NodeModifyRunningAccountCmd::execute() {
01588
01589 if (m_oldvalue) {
01590 m_oldvalue->removeRunning(m_node);
01591 }
01592 if (m_newvalue) {
01593 m_newvalue->addRunning(m_node);
01594 }
01595 setCommandType(0);
01596 }
01597 void NodeModifyRunningAccountCmd::unexecute() {
01598
01599 if (m_newvalue) {
01600 m_newvalue->removeRunning(m_node);
01601 }
01602 if (m_oldvalue) {
01603 m_oldvalue->addRunning(m_node);
01604 }
01605 setCommandType(0);
01606 }
01607
01608 NodeModifyStartupAccountCmd::NodeModifyStartupAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, QString name)
01609 : NamedCommand(part, name),
01610 m_node(node) {
01611 m_oldvalue = oldvalue;
01612 m_newvalue = newvalue;
01613
01614 }
01615
01616 void NodeModifyStartupAccountCmd::execute() {
01617
01618 if (m_oldvalue) {
01619 m_oldvalue->removeStartup(m_node);
01620 }
01621 if (m_newvalue) {
01622 m_newvalue->addStartup(m_node);
01623 }
01624 setCommandType(0);
01625 }
01626 void NodeModifyStartupAccountCmd::unexecute() {
01627
01628 if (m_newvalue) {
01629 m_newvalue->removeStartup(m_node);
01630 }
01631 if (m_oldvalue) {
01632 m_oldvalue->addStartup(m_node);
01633 }
01634 setCommandType(0);
01635 }
01636
01637 NodeModifyShutdownAccountCmd::NodeModifyShutdownAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, QString name)
01638 : NamedCommand(part, name),
01639 m_node(node) {
01640 m_oldvalue = oldvalue;
01641 m_newvalue = newvalue;
01642
01643 }
01644
01645 void NodeModifyShutdownAccountCmd::execute() {
01646
01647 if (m_oldvalue) {
01648 m_oldvalue->removeShutdown(m_node);
01649 }
01650 if (m_newvalue) {
01651 m_newvalue->addShutdown(m_node);
01652 }
01653 setCommandType(0);
01654 }
01655 void NodeModifyShutdownAccountCmd::unexecute() {
01656
01657 if (m_newvalue) {
01658 m_newvalue->removeShutdown(m_node);
01659 }
01660 if (m_oldvalue) {
01661 m_oldvalue->addShutdown(m_node);
01662 }
01663 setCommandType(0);
01664 }
01665
01666 ModifyDefaultAccountCmd::ModifyDefaultAccountCmd(Part *part, Accounts &acc, Account *oldvalue, Account *newvalue, QString name)
01667 : NamedCommand(part, name),
01668 m_accounts(acc) {
01669 m_oldvalue = oldvalue;
01670 m_newvalue = newvalue;
01671
01672 }
01673
01674 void ModifyDefaultAccountCmd::execute() {
01675
01676 m_accounts.setDefaultAccount(m_newvalue);
01677 setCommandType(0);
01678 }
01679 void ModifyDefaultAccountCmd::unexecute() {
01680
01681 m_accounts.setDefaultAccount(m_oldvalue);
01682 setCommandType(0);
01683 }
01684
01685 ProjectModifyConstraintCmd::ProjectModifyConstraintCmd(Part *part, Project &node, Node::ConstraintType c, QString name)
01686 : NamedCommand(part, name),
01687 m_node(node),
01688 newConstraint(c),
01689 oldConstraint(static_cast<Node::ConstraintType>(node.constraint())) {
01690
01691 QIntDictIterator<Schedule> it = node.schedules();
01692 for (; it.current(); ++it) {
01693 addSchScheduled(it.current());
01694 }
01695 }
01696 void ProjectModifyConstraintCmd::execute() {
01697 m_node.setConstraint(newConstraint);
01698 setSchScheduled(false);
01699 setCommandType(1);
01700 }
01701 void ProjectModifyConstraintCmd::unexecute() {
01702 m_node.setConstraint(oldConstraint);
01703 setSchScheduled();
01704 setCommandType(1);
01705 }
01706
01707 ProjectModifyStartTimeCmd::ProjectModifyStartTimeCmd(Part *part, Project &node, QDateTime dt, QString name)
01708 : NamedCommand(part, name),
01709 m_node(node),
01710 newTime(dt),
01711 oldTime(node.startTime()) {
01712
01713 QIntDictIterator<Schedule> it = node.schedules();
01714 for (; it.current(); ++it) {
01715 addSchScheduled(it.current());
01716 }
01717 }
01718
01719 void ProjectModifyStartTimeCmd::execute() {
01720 m_node.setConstraintStartTime(newTime);
01721 setSchScheduled(false);
01722 setCommandType(1);
01723 }
01724 void ProjectModifyStartTimeCmd::unexecute() {
01725 m_node.setConstraintStartTime(oldTime);
01726 setSchScheduled();
01727 setCommandType(1);
01728 }
01729
01730 ProjectModifyEndTimeCmd::ProjectModifyEndTimeCmd(Part *part, Project &node, QDateTime dt, QString name)
01731 : NamedCommand(part, name),
01732 m_node(node),
01733 newTime(dt),
01734 oldTime(node.endTime()) {
01735
01736 QIntDictIterator<Schedule> it = node.schedules();
01737 for (; it.current(); ++it) {
01738 addSchScheduled(it.current());
01739 }
01740 }
01741 void ProjectModifyEndTimeCmd::execute() {
01742 m_node.setEndTime(newTime);
01743 m_node.setConstraintEndTime(newTime);
01744 setSchScheduled(false);
01745 setCommandType(1);
01746 }
01747 void ProjectModifyEndTimeCmd::unexecute() {
01748 m_node.setConstraintEndTime(oldTime);
01749 setSchScheduled();
01750 setCommandType(1);
01751 }
01752
01753 CalculateProjectCmd::CalculateProjectCmd(Part *part, Project &node, QString tname, int type, QString name)
01754 : NamedCommand(part, name),
01755 m_node(node),
01756 m_typename(tname),
01757 m_type(type),
01758 newSchedule(0) {
01759
01760 oldCurrent = node.currentSchedule();
01761
01762 }
01763 void CalculateProjectCmd::execute() {
01764 if (newSchedule == 0) {
01765
01766 newSchedule = m_node.createSchedule(m_typename, (Schedule::Type)m_type);
01767 m_node.calculate(newSchedule);
01768 } else {
01769
01770 newSchedule->setDeleted(false);
01771 m_node.setCurrentSchedulePtr(newSchedule);
01772 }
01773 setCommandType(0);
01774 }
01775 void CalculateProjectCmd::unexecute() {
01776
01777 newSchedule->setDeleted(true);
01778 m_node.setCurrentSchedulePtr(oldCurrent);
01779
01780 setCommandType(0);
01781 }
01782
01783 RecalculateProjectCmd::RecalculateProjectCmd(Part *part, Project &node, Schedule &sch, QString name)
01784 : NamedCommand(part, name),
01785 m_node(node),
01786 oldSchedule(sch),
01787 newSchedule(0),
01788 oldDeleted(sch.isDeleted()) {
01789
01790 oldCurrent = node.currentSchedule();
01791
01792 }
01793 void RecalculateProjectCmd::execute() {
01794 oldSchedule.setDeleted(true);
01795 if (newSchedule == 0) {
01796 newSchedule = m_node.createSchedule(oldSchedule.name(), oldSchedule.type());
01797 m_node.calculate(newSchedule);
01798 } else {
01799 newSchedule->setDeleted(false);
01800 m_node.setCurrentSchedulePtr(newSchedule);
01801
01802 }
01803 setCommandType(0);
01804 }
01805 void RecalculateProjectCmd::unexecute() {
01806
01807 newSchedule->setDeleted(true);
01808 oldSchedule.setDeleted(oldDeleted);
01809 m_node.setCurrentSchedulePtr(oldCurrent);
01810
01811 setCommandType(0);
01812 }
01813
01814
01815 ModifyStandardWorktimeYearCmd::ModifyStandardWorktimeYearCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01816 : NamedCommand(part, name),
01817 swt(wt),
01818 m_oldvalue(oldvalue),
01819 m_newvalue(newvalue) {
01820
01821 }
01822 void ModifyStandardWorktimeYearCmd::execute() {
01823 swt->setYear(m_newvalue);
01824 setCommandType(0);
01825 }
01826 void ModifyStandardWorktimeYearCmd::unexecute() {
01827 swt->setYear(m_oldvalue);
01828 setCommandType(0);
01829 }
01830
01831 ModifyStandardWorktimeMonthCmd::ModifyStandardWorktimeMonthCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01832 : NamedCommand(part, name),
01833 swt(wt),
01834 m_oldvalue(oldvalue),
01835 m_newvalue(newvalue) {
01836
01837 }
01838 void ModifyStandardWorktimeMonthCmd::execute() {
01839 swt->setMonth(m_newvalue);
01840 setCommandType(0);
01841 }
01842 void ModifyStandardWorktimeMonthCmd::unexecute() {
01843 swt->setMonth(m_oldvalue);
01844 setCommandType(0);
01845 }
01846
01847 ModifyStandardWorktimeWeekCmd::ModifyStandardWorktimeWeekCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01848 : NamedCommand(part, name),
01849 swt(wt),
01850 m_oldvalue(oldvalue),
01851 m_newvalue(newvalue) {
01852
01853 }
01854 void ModifyStandardWorktimeWeekCmd::execute() {
01855 swt->setWeek(m_newvalue);
01856 setCommandType(0);
01857 }
01858 void ModifyStandardWorktimeWeekCmd::unexecute() {
01859 swt->setWeek(m_oldvalue);
01860 setCommandType(0);
01861 }
01862
01863 ModifyStandardWorktimeDayCmd::ModifyStandardWorktimeDayCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01864 : NamedCommand(part, name),
01865 swt(wt),
01866 m_oldvalue(oldvalue),
01867 m_newvalue(newvalue) {
01868
01869 }
01870
01871 void ModifyStandardWorktimeDayCmd::execute() {
01872 swt->setDay(m_newvalue);
01873 setCommandType(0);
01874 }
01875 void ModifyStandardWorktimeDayCmd::unexecute() {
01876 swt->setDay(m_oldvalue);
01877 setCommandType(0);
01878 }
01879
01880
01881 }