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