kplato

kptcommand.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004, 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008    
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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     //kdDebug()<<k_funcinfo<<cal->name()<<endl;
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     //kdDebug()<<k_funcinfo<<m_cal->name()<<" added to: "<<m_project->name()<<endl;
00116 }
00117 
00118 void CalendarAddCmd::unexecute() {
00119     m_cal->setDeleted(true);
00120     
00121     setCommandType(0);
00122     //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
00123 }
00124 
00125 CalendarDeleteCmd::CalendarDeleteCmd(Part *part, Calendar *cal, QString name)
00126     : NamedCommand(part, name),
00127       m_cal(cal) {
00128 
00129     // TODO check if any resources uses this calendar
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     //kdDebug()<<k_funcinfo<<cal->name()<<endl;
00157 }
00158 void CalendarModifyNameCmd::execute() {
00159     m_cal->setName(m_newvalue);
00160     setCommandType(0);
00161     //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
00162 }
00163 void CalendarModifyNameCmd::unexecute() {
00164     m_cal->setName(m_oldvalue);
00165     setCommandType(0);
00166     //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
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     //kdDebug()<<k_funcinfo<<cal->name()<<endl;
00176     // TODO check if any resources uses this calendar
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     //kdDebug()<<k_funcinfo<<cal->name()<<endl;
00202     // TODO check if any resources uses this calendar
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     //kdDebug()<<k_funcinfo<<endl;
00212     if (m_mine)
00213         delete m_newvalue;
00214 }
00215 void CalendarAddDayCmd::execute() {
00216     //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
00217     m_cal->addDay(m_newvalue);
00218     m_mine = false;
00219     setSchScheduled(false);
00220     setCommandType(1);
00221 }
00222 void CalendarAddDayCmd::unexecute() {
00223     //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
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     //kdDebug()<<k_funcinfo<<cal->name()<<endl;
00237     // TODO check if any resources uses this calendar
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     //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
00247     m_cal->takeDay(m_value);
00248     m_mine = true;
00249     setSchScheduled(false);
00250     setCommandType(1);
00251 }
00252 void CalendarRemoveDayCmd::unexecute() {
00253     //kdDebug()<<k_funcinfo<<m_cal->name()<<endl;
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     //kdDebug()<<k_funcinfo<<cal->name()<<" old:("<<m_oldvalue<<") new:("<<m_newvalue<<")"<<endl;
00268     // TODO check if any resources uses this calendar
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     //kdDebug()<<k_funcinfo<<endl;
00278     if (m_mine) {
00279         delete m_newvalue;
00280     } else {
00281         delete m_oldvalue;
00282     }
00283 }
00284 void CalendarModifyDayCmd::execute() {
00285     //kdDebug()<<k_funcinfo<<endl;
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     //kdDebug()<<k_funcinfo<<endl;
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     // TODO check if any resources uses this calendar
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     m_project = static_cast<Project*>(node->projectNode());
00345     if (m_project) {
00346         QIntDictIterator<Schedule> it = m_project->schedules();
00347         for (; it.current(); ++it) {
00348             Schedule *s = node->findSchedule(it.current()->id());
00349             if (s && s->isScheduled()) {
00350                 // Only invalidate schedules this node is part of
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 && m_project) {
00362         //kdDebug()<<k_funcinfo<<m_node->name()<<" "<<m_index<<endl;
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_project->delTask(m_node);
00369         m_mine = true;
00370         setSchScheduled(false);
00371         setCommandType(1);
00372     }
00373 }
00374 void NodeDeleteCmd::unexecute() {
00375     if (m_parent && m_project) {
00376         //kdDebug()<<k_funcinfo<<m_node->name()<<" "<<m_index<<endl;
00377         m_project->addSubTask(m_node, m_index, m_parent);
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     // set some reasonable defaults for normally calculated values
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     //kdDebug()<<k_funcinfo<<m_node->name()<<endl;
00419     m_project->addTask(m_node, m_after);
00420     m_added = true;
00421     
00422     setCommandType(1);
00423 }
00424 void TaskAddCmd::unexecute() {
00425     m_project->delTask(m_node);
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     // set some reasonable defaults for normally calculated values
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_project->delTask(m_node);
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_moved(false) {
00700 
00701     m_project = static_cast<Project *>(m_node.projectNode());
00702 }
00703 void NodeMoveUpCmd::execute() {
00704     if (m_project) {
00705         m_moved = m_project->moveTaskUp(&m_node);
00706     }
00707     
00708     setCommandType(0);
00709 }
00710 void NodeMoveUpCmd::unexecute() {
00711     if (m_project && m_moved) {
00712         m_project->moveTaskDown(&m_node);
00713     }
00714     m_moved = false;
00715     setCommandType(0);
00716 }
00717 
00718 NodeMoveDownCmd::NodeMoveDownCmd(Part *part, Node &node, QString name)
00719     : NamedCommand(part, name),
00720       m_node(node), 
00721       m_moved(false) {
00722     
00723     m_project = static_cast<Project *>(m_node.projectNode());
00724 }
00725 void NodeMoveDownCmd::execute() {
00726     if (m_project) {
00727         m_moved = m_project->moveTaskDown(&m_node);
00728     }
00729     setCommandType(0);
00730 }
00731 void NodeMoveDownCmd::unexecute() {
00732     if (m_project && m_moved) {
00733         m_project->moveTaskUp(&m_node);
00734     }
00735     m_moved = false;
00736     setCommandType(0);
00737 }
00738 
00739 AddRelationCmd::AddRelationCmd(Part *part, Relation *rel, QString name)
00740     : NamedCommand(part, name),
00741       m_rel(rel) {
00742     
00743     m_taken = true;
00744     Node *p = rel->parent()->projectNode();
00745     if (p) {
00746         QIntDictIterator<Schedule> it = p->schedules();
00747         for (; it.current(); ++it) {
00748             addSchScheduled(it.current());
00749         }
00750     }
00751 }
00752 AddRelationCmd::~AddRelationCmd() {
00753     if (m_taken)
00754         delete m_rel;
00755 }
00756 void AddRelationCmd::execute() {
00757     //kdDebug()<<k_funcinfo<<m_rel->parent()<<" to "<<m_rel->child()<<endl;
00758     m_taken = false;
00759     m_rel->parent()->addDependChildNode(m_rel);
00760     m_rel->child()->addDependParentNode(m_rel);
00761     setSchScheduled(false);
00762     setCommandType(1);
00763 }
00764 void AddRelationCmd::unexecute() {
00765     m_taken = true;
00766     m_rel->parent()->takeDependChildNode(m_rel);
00767     m_rel->child()->takeDependParentNode(m_rel);
00768     setSchScheduled();
00769     setCommandType(1);
00770 }
00771 
00772 DeleteRelationCmd::DeleteRelationCmd(Part *part, Relation *rel, QString name)
00773     : NamedCommand(part, name),
00774       m_rel(rel) {
00775     
00776     m_taken = false;
00777     Node *p = rel->parent()->projectNode();
00778     if (p) {
00779         QIntDictIterator<Schedule> it = p->schedules();
00780         for (; it.current(); ++it) {
00781             addSchScheduled(it.current());
00782         }
00783     }
00784 }
00785 DeleteRelationCmd::~DeleteRelationCmd() {
00786     if (m_taken)
00787         delete m_rel;
00788 }
00789 void DeleteRelationCmd::execute() {
00790     //kdDebug()<<k_funcinfo<<m_rel->parent()<<" to "<<m_rel->child()<<endl;
00791     m_taken = true;
00792     m_rel->parent()->takeDependChildNode(m_rel);
00793     m_rel->child()->takeDependParentNode(m_rel);
00794     setSchScheduled(false);
00795     setCommandType(1);
00796 }
00797 void DeleteRelationCmd::unexecute() {
00798     m_taken = false;
00799     m_rel->parent()->addDependChildNode(m_rel);
00800     m_rel->child()->addDependParentNode(m_rel);
00801     setSchScheduled();
00802     setCommandType(1);
00803 }
00804 
00805 ModifyRelationTypeCmd::ModifyRelationTypeCmd(Part *part, Relation *rel, Relation::Type type, QString name)
00806     : NamedCommand(part, name),
00807       m_rel(rel),
00808       m_newtype(type) {
00809     
00810     m_oldtype = rel->type();
00811     Node *p = rel->parent()->projectNode();
00812     if (p) {
00813         QIntDictIterator<Schedule> it = p->schedules();
00814         for (; it.current(); ++it) {
00815             addSchScheduled(it.current());
00816         }
00817     }
00818 }
00819 void ModifyRelationTypeCmd::execute() {
00820     m_rel->setType(m_newtype);
00821     setSchScheduled(false);
00822     setCommandType(1);
00823 }
00824 void ModifyRelationTypeCmd::unexecute() {
00825     m_rel->setType(m_oldtype);
00826     setSchScheduled();
00827     setCommandType(1);
00828 }
00829 
00830 ModifyRelationLagCmd::ModifyRelationLagCmd(Part *part, Relation *rel, Duration lag, QString name)
00831     : NamedCommand(part, name),
00832       m_rel(rel),
00833       m_newlag(lag) {
00834     
00835     m_oldlag = rel->lag();
00836     Node *p = rel->parent()->projectNode();
00837     if (p) {
00838         QIntDictIterator<Schedule> it = p->schedules();
00839         for (; it.current(); ++it) {
00840             addSchScheduled(it.current());
00841         }
00842     }
00843 }
00844 void ModifyRelationLagCmd::execute() {
00845     m_rel->setLag(m_newlag);
00846     setSchScheduled(false);
00847     setCommandType(1);
00848 }
00849 void ModifyRelationLagCmd::unexecute() {
00850     m_rel->setLag(m_oldlag);
00851     setSchScheduled();
00852     setCommandType(1);
00853 }
00854 
00855 AddResourceRequestCmd::AddResourceRequestCmd(Part *part, ResourceGroupRequest *group, ResourceRequest *request, QString name)
00856     : NamedCommand(part, name),
00857       m_group(group),
00858       m_request(request) {
00859     
00860     m_mine = true;
00861 }
00862 AddResourceRequestCmd::~AddResourceRequestCmd() {
00863     if (m_mine)
00864         delete m_request;
00865 }
00866 void AddResourceRequestCmd::execute() {
00867     //kdDebug()<<k_funcinfo<<"group="<<m_group<<" req="<<m_request<<endl;
00868     m_group->addResourceRequest(m_request);
00869     m_mine = false;
00870     setSchScheduled(false);
00871     setCommandType(1);
00872 }
00873 void AddResourceRequestCmd::unexecute() {
00874     //kdDebug()<<k_funcinfo<<"group="<<m_group<<" req="<<m_request<<endl;
00875     m_group->takeResourceRequest(m_request);
00876     m_mine = true;
00877     setSchScheduled();
00878     setCommandType(1);
00879 }
00880 
00881 RemoveResourceRequestCmd::RemoveResourceRequestCmd(Part *part,  ResourceGroupRequest *group, ResourceRequest *request, QString name)
00882     : NamedCommand(part, name),
00883       m_group(group),
00884       m_request(request) {
00885     
00886     m_mine = false;
00887     //kdDebug()<<k_funcinfo<<"group="<<group<<" req="<<request<<endl;
00888     Task *t = request->task();
00889     if (t) { // safety, something is seriously wrong!
00890         QIntDictIterator<Schedule> it = t->schedules();
00891         for (; it.current(); ++it) {
00892             addSchScheduled(it.current());
00893         }
00894     }
00895 }
00896 RemoveResourceRequestCmd::~RemoveResourceRequestCmd() {
00897     if (m_mine)
00898         delete m_request;
00899 }
00900 void RemoveResourceRequestCmd::execute() {
00901     m_group->takeResourceRequest(m_request);
00902     m_mine = true;
00903     setSchScheduled(false);
00904     setCommandType(1);
00905 }
00906 void RemoveResourceRequestCmd::unexecute() {
00907     m_group->addResourceRequest(m_request);
00908     m_mine = false;
00909     setSchScheduled();
00910     setCommandType(1);
00911 }
00912 
00913 ModifyEffortCmd::ModifyEffortCmd(Part *part, Node &node, Duration oldvalue, Duration newvalue, QString name)
00914     : NamedCommand(part, name),
00915       m_effort(node.effort()),
00916       m_oldvalue(oldvalue),
00917       m_newvalue(newvalue) {
00918 
00919     QIntDictIterator<Schedule> it = node.schedules();
00920     for (; it.current(); ++it) {
00921         addSchScheduled(it.current());
00922     }
00923 }
00924 void ModifyEffortCmd::execute() {
00925     m_effort->set(m_newvalue);
00926     setSchScheduled(false);
00927     setCommandType(1);
00928 }
00929 void ModifyEffortCmd::unexecute() {
00930     m_effort->set(m_oldvalue);
00931     setSchScheduled();
00932     setCommandType(1);
00933 }
00934 
00935 EffortModifyOptimisticRatioCmd::EffortModifyOptimisticRatioCmd(Part *part, Node &node, int oldvalue, int newvalue, QString name)
00936     : NamedCommand(part, name),
00937       m_effort(node.effort()),
00938       m_oldvalue(oldvalue),
00939       m_newvalue(newvalue) {
00940 
00941     QIntDictIterator<Schedule> it = node.schedules();
00942     for (; it.current(); ++it) {
00943         addSchScheduled(it.current());
00944     }
00945 }
00946 void EffortModifyOptimisticRatioCmd::execute() {
00947     m_effort->setOptimisticRatio(m_newvalue);
00948     setSchScheduled(false);
00949     setCommandType(1);
00950 }
00951 void EffortModifyOptimisticRatioCmd::unexecute() {
00952     m_effort->setOptimisticRatio(m_oldvalue);
00953     setSchScheduled();
00954     setCommandType(1);
00955 }
00956 
00957 EffortModifyPessimisticRatioCmd::EffortModifyPessimisticRatioCmd(Part *part, Node &node, int oldvalue, int newvalue, QString name)
00958     : NamedCommand(part, name),
00959       m_effort(node.effort()),
00960       m_oldvalue(oldvalue),
00961       m_newvalue(newvalue) {
00962 
00963     QIntDictIterator<Schedule> it = node.schedules();
00964     for (; it.current(); ++it) {
00965         addSchScheduled(it.current());
00966     }
00967 }
00968 void EffortModifyPessimisticRatioCmd::execute() {
00969     m_effort->setPessimisticRatio(m_newvalue);
00970     setSchScheduled(false);
00971     setCommandType(1);
00972 }
00973 void EffortModifyPessimisticRatioCmd::unexecute() {
00974     m_effort->setPessimisticRatio(m_oldvalue);
00975     setSchScheduled();
00976     setCommandType(1);
00977 }
00978 
00979 ModifyEffortTypeCmd::ModifyEffortTypeCmd(Part *part, Node &node, int oldvalue, int newvalue, QString name)
00980     : NamedCommand(part, name),
00981       m_effort(node.effort()),
00982       m_oldvalue(oldvalue),
00983       m_newvalue(newvalue) {
00984     
00985     QIntDictIterator<Schedule> it = node.schedules();
00986     for (; it.current(); ++it) {
00987         addSchScheduled(it.current());
00988     }
00989 }
00990 void ModifyEffortTypeCmd::execute() {
00991     m_effort->setType(static_cast<Effort::Type>(m_newvalue));
00992     setSchScheduled(false);
00993     setCommandType(1);
00994 }
00995 void ModifyEffortTypeCmd::unexecute() {
00996     m_effort->setType(static_cast<Effort::Type>(m_oldvalue));
00997     setSchScheduled();
00998     setCommandType(1);
00999 }
01000 
01001 EffortModifyRiskCmd::EffortModifyRiskCmd(Part *part, Node &node, int oldvalue, int newvalue, QString name)
01002     : NamedCommand(part, name),
01003       m_effort(node.effort()),
01004       m_oldvalue(oldvalue),
01005       m_newvalue(newvalue) {
01006 
01007     QIntDictIterator<Schedule> it = node.schedules();
01008     for (; it.current(); ++it) {
01009         addSchScheduled(it.current());
01010     }
01011 }
01012 void EffortModifyRiskCmd::execute() {
01013     m_effort->setRisktype(static_cast<Effort::Risktype>(m_newvalue));
01014     setSchScheduled(false);
01015     setCommandType(1);
01016 }
01017 void EffortModifyRiskCmd::unexecute() {
01018     m_effort->setRisktype(static_cast<Effort::Risktype>(m_oldvalue));
01019     setSchScheduled();
01020     setCommandType(1);
01021 }
01022 
01023 AddResourceGroupRequestCmd::AddResourceGroupRequestCmd(Part *part, Task &task, ResourceGroupRequest *request, QString name)
01024     : NamedCommand(part, name),
01025       m_task(task),
01026       m_request(request) {
01027       
01028     m_mine = true;
01029 }
01030 void AddResourceGroupRequestCmd::execute() {
01031     //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
01032     m_task.addRequest(m_request);
01033     m_mine = false;
01034     
01035     setCommandType(1);
01036 }
01037 void AddResourceGroupRequestCmd::unexecute() {
01038     //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
01039     m_task.takeRequest(m_request); // group should now be empty of resourceRequests
01040     m_mine = true;
01041     
01042     setCommandType(1);
01043 }
01044 
01045 RemoveResourceGroupRequestCmd::RemoveResourceGroupRequestCmd(Part *part, ResourceGroupRequest *request, QString name)
01046     : NamedCommand(part, name),
01047       m_task(request->parent()->task()),
01048       m_request(request) {
01049       
01050     m_mine = false;
01051 }
01052 
01053 RemoveResourceGroupRequestCmd::RemoveResourceGroupRequestCmd(Part *part, Task &task, ResourceGroupRequest *request, QString name)
01054     : NamedCommand(part, name),
01055       m_task(task),
01056       m_request(request) {
01057       
01058     m_mine = false;
01059 }
01060 void RemoveResourceGroupRequestCmd::execute() {
01061     //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
01062     m_task.takeRequest(m_request); // group should now be empty of resourceRequests
01063     m_mine = true;
01064     
01065     setCommandType(1);
01066 }
01067 void RemoveResourceGroupRequestCmd::unexecute() {
01068     //kdDebug()<<k_funcinfo<<"group="<<m_request<<endl;
01069     m_task.addRequest(m_request);
01070     m_mine = false;
01071     
01072     setCommandType(1);
01073 }
01074 
01075 AddResourceCmd::AddResourceCmd(Part *part, ResourceGroup *group, Resource *resource, QString name)
01076     : NamedCommand(part, name),
01077       m_group(group),
01078       m_resource(resource) {
01079       
01080     m_mine = true;
01081 }
01082 AddResourceCmd::~AddResourceCmd() {
01083     if (m_mine) {
01084         //kdDebug()<<k_funcinfo<<"delete: "<<m_resource<<endl;
01085         delete m_resource;
01086     }
01087 }
01088 void AddResourceCmd::execute() {
01089     m_group->addResource(m_resource, 0/*risk*/); 
01090     m_mine = false;
01091     //kdDebug()<<k_funcinfo<<"added: "<<m_resource<<endl;
01092     setCommandType(0);
01093 }
01094 void AddResourceCmd::unexecute() {
01095     m_group->takeResource(m_resource);
01096     //kdDebug()<<k_funcinfo<<"removed: "<<m_resource<<endl;
01097     m_mine = true;
01098     
01099     setCommandType(0);
01100 }
01101 
01102 RemoveResourceCmd::RemoveResourceCmd(Part *part, ResourceGroup *group, Resource *resource, QString name)
01103     : AddResourceCmd(part, group, resource, name) {
01104     //kdDebug()<<k_funcinfo<<resource<<endl;
01105     m_mine = false;
01106     m_requests = m_resource->requests();
01107     
01108     QIntDictIterator<Schedule> it = resource->schedules();
01109     for (; it.current(); ++it) {
01110         addSchScheduled(it.current());
01111     }
01112 }
01113 RemoveResourceCmd::~RemoveResourceCmd() {
01114     m_appointments.setAutoDelete(true);
01115 }
01116 void RemoveResourceCmd::execute() {
01117     QPtrListIterator<ResourceRequest> it = m_requests;
01118     for (; it.current(); ++it) {
01119         it.current()->parent()->takeResourceRequest(it.current());
01120         //kdDebug()<<"Remove request for"<<it.current()->resource()->name()<<endl;
01121     }
01122     QPtrListIterator<Appointment> ait = m_resource->appointments();
01123     for (; ait.current(); ++ait) {
01124         m_appointments.append(ait.current());
01125     }
01126     QPtrListIterator<Appointment> mit = m_appointments;
01127     for (; mit.current(); ++mit) {
01128         mit.current()->detach(); //NOTE: removes from m_resource->appointments()
01129         //kdDebug()<<k_funcinfo<<"detached: "<<mit.current()<<endl;
01130     }
01131     AddResourceCmd::unexecute();
01132     setSchScheduled(false);
01133 }
01134 void RemoveResourceCmd::unexecute() {
01135     m_appointments.first();
01136     while (m_appointments.current()) {
01137         //kdDebug()<<k_funcinfo<<"attach: "<<m_appointments.current()<<endl;
01138         m_appointments.take()->attach();
01139     }
01140     QPtrListIterator<ResourceRequest> it = m_requests;
01141     for (; it.current(); ++it) {
01142         it.current()->parent()->addResourceRequest(it.current());
01143         //kdDebug()<<"Add request for "<<it.current()->resource()->name()<<endl;
01144     }
01145     AddResourceCmd::execute();
01146     setSchScheduled();
01147 }
01148 
01149 ModifyResourceNameCmd::ModifyResourceNameCmd(Part *part, Resource *resource, QString value, QString name)
01150     : NamedCommand(part, name),
01151       m_resource(resource),
01152       m_newvalue(value) {
01153     m_oldvalue = resource->name();
01154 }
01155 void ModifyResourceNameCmd::execute() {
01156     m_resource->setName(m_newvalue);
01157     
01158     setCommandType(0);
01159 }
01160 void ModifyResourceNameCmd::unexecute() {
01161     m_resource->setName(m_oldvalue);
01162     
01163     setCommandType(0);
01164 }
01165 ModifyResourceInitialsCmd::ModifyResourceInitialsCmd(Part *part, Resource *resource, QString value, QString name)
01166     : NamedCommand(part, name),
01167       m_resource(resource),
01168       m_newvalue(value) {
01169     m_oldvalue = resource->initials();
01170 }
01171 void ModifyResourceInitialsCmd::execute() {
01172     m_resource->setInitials(m_newvalue);
01173     
01174     setCommandType(0);
01175 }
01176 void ModifyResourceInitialsCmd::unexecute() {
01177     m_resource->setInitials(m_oldvalue);
01178     
01179     setCommandType(0);
01180 }
01181 ModifyResourceEmailCmd::ModifyResourceEmailCmd(Part *part, Resource *resource, QString value, QString name)
01182     : NamedCommand(part, name),
01183       m_resource(resource),
01184       m_newvalue(value) {
01185     m_oldvalue = resource->email();
01186 }
01187 void ModifyResourceEmailCmd::execute() {
01188     m_resource->setEmail(m_newvalue);
01189     
01190     setCommandType(0);
01191 }
01192 void ModifyResourceEmailCmd::unexecute() {
01193     m_resource->setEmail(m_oldvalue);
01194     
01195     setCommandType(0);
01196 }
01197 ModifyResourceTypeCmd::ModifyResourceTypeCmd(Part *part, Resource *resource, int value, QString name)
01198     : NamedCommand(part, name),
01199       m_resource(resource),
01200       m_newvalue(value) {
01201     m_oldvalue = resource->type();
01202     
01203     QIntDictIterator<Schedule> it = resource->schedules();
01204     for (; it.current(); ++it) {
01205         addSchScheduled(it.current());
01206     }
01207 }
01208 void ModifyResourceTypeCmd::execute() {
01209     m_resource->setType((Resource::Type)m_newvalue);
01210     setSchScheduled(false);
01211     setCommandType(1);
01212 }
01213 void ModifyResourceTypeCmd::unexecute() {
01214     m_resource->setType((Resource::Type)m_oldvalue);
01215     setSchScheduled();
01216     setCommandType(1);
01217 }
01218 ModifyResourceUnitsCmd::ModifyResourceUnitsCmd(Part *part, Resource *resource, int value, QString name)
01219     : NamedCommand(part, name),
01220       m_resource(resource),
01221       m_newvalue(value) {
01222     m_oldvalue = resource->units();
01223     
01224     QIntDictIterator<Schedule> it = resource->schedules();
01225     for (; it.current(); ++it) {
01226         addSchScheduled(it.current());
01227     }
01228 }
01229 void ModifyResourceUnitsCmd::execute() {
01230     m_resource->setUnits(m_newvalue);
01231     setSchScheduled(false);
01232     setCommandType(1);
01233 }
01234 void ModifyResourceUnitsCmd::unexecute() {
01235     m_resource->setUnits(m_oldvalue);
01236     setSchScheduled();
01237     setCommandType(1);
01238 }
01239 
01240 ModifyResourceAvailableFromCmd::ModifyResourceAvailableFromCmd(Part *part, Resource *resource, DateTime value, QString name)
01241     : NamedCommand(part, name),
01242       m_resource(resource),
01243       m_newvalue(value) {
01244     m_oldvalue = resource->availableFrom();
01245 
01246     QIntDictIterator<Schedule> it = resource->schedules();
01247     if (!it.isEmpty() && resource->project()) {
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 ModifyResourceAvailableFromCmd::execute() {
01264     m_resource->setAvailableFrom(m_newvalue);
01265     setSchScheduled(false);
01266     setCommandType(1); //FIXME
01267 }
01268 void ModifyResourceAvailableFromCmd::unexecute() {
01269     m_resource->setAvailableFrom(m_oldvalue);
01270     setSchScheduled();
01271     setCommandType(1); //FIXME
01272 }
01273 
01274 ModifyResourceAvailableUntilCmd::ModifyResourceAvailableUntilCmd(Part *part, Resource *resource, DateTime value, QString name)
01275     : NamedCommand(part, name),
01276       m_resource(resource),
01277       m_newvalue(value) {
01278     m_oldvalue = resource->availableUntil();
01279     
01280     QIntDictIterator<Schedule> it = resource->schedules();
01281     if (!it.isEmpty()) {
01282         QDateTime s;
01283         QDateTime e;
01284         for (; it.current(); ++it) {
01285             Schedule *sch = resource->project()->findSchedule(it.current()->id());
01286             if (sch) {
01287                 s = sch->start();
01288                 e = sch->end();
01289                 kdDebug()<<k_funcinfo<<"old="<<m_oldvalue<<" new="<<value<<" s="<<s<<" e="<<e<<endl;
01290             }
01291             if (!s.isValid() || !e.isValid() || ((m_oldvalue > s || value > s) && (m_oldvalue < e || value < e))) {
01292                 addSchScheduled(it.current());
01293             }
01294         }
01295     }
01296 }
01297 void ModifyResourceAvailableUntilCmd::execute() {
01298     m_resource->setAvailableUntil(m_newvalue);
01299     setSchScheduled(false);
01300     setCommandType(1); //FIXME
01301 }
01302 void ModifyResourceAvailableUntilCmd::unexecute() {
01303     m_resource->setAvailableUntil(m_oldvalue);
01304     setSchScheduled();
01305     setCommandType(1); //FIXME
01306 }
01307 
01308 ModifyResourceNormalRateCmd::ModifyResourceNormalRateCmd(Part *part, Resource *resource, double value, QString name)
01309     : NamedCommand(part, name),
01310       m_resource(resource),
01311       m_newvalue(value) {
01312     m_oldvalue = resource->normalRate();
01313 }
01314 void ModifyResourceNormalRateCmd::execute() {
01315     m_resource->setNormalRate(m_newvalue);
01316     
01317     setCommandType(0);
01318 }
01319 void ModifyResourceNormalRateCmd::unexecute() {
01320     m_resource->setNormalRate(m_oldvalue);
01321     
01322     setCommandType(0);
01323 }
01324 ModifyResourceOvertimeRateCmd::ModifyResourceOvertimeRateCmd(Part *part, Resource *resource, double value, QString name)
01325     : NamedCommand(part, name),
01326       m_resource(resource),
01327       m_newvalue(value) {
01328     m_oldvalue = resource->overtimeRate();
01329 }
01330 void ModifyResourceOvertimeRateCmd::execute() {
01331     m_resource->setOvertimeRate(m_newvalue);
01332     
01333     setCommandType(0);
01334 }
01335 void ModifyResourceOvertimeRateCmd::unexecute() {
01336     m_resource->setOvertimeRate(m_oldvalue);
01337     
01338     setCommandType(0);
01339 }
01340 
01341 ModifyResourceCalendarCmd::ModifyResourceCalendarCmd(Part *part, Resource *resource, Calendar *value, QString name)
01342     : NamedCommand(part, name),
01343       m_resource(resource),
01344       m_newvalue(value) {
01345     m_oldvalue = resource->calendar(true);
01346     
01347     QIntDictIterator<Schedule> it = resource->schedules();
01348     for (; it.current(); ++it) {
01349         addSchScheduled(it.current());
01350     }
01351 }
01352 void ModifyResourceCalendarCmd::execute() {
01353     m_resource->setCalendar(m_newvalue);
01354     setSchScheduled(false);
01355     setCommandType(1);
01356 }
01357 void ModifyResourceCalendarCmd::unexecute() {
01358     m_resource->setCalendar(m_oldvalue);
01359     setSchScheduled();
01360     setCommandType(1);
01361 }
01362 
01363 RemoveResourceGroupCmd::RemoveResourceGroupCmd(Part *part, ResourceGroup *group, QString name)
01364     : NamedCommand(part, name),
01365       m_group(group) {
01366             
01367     m_mine = false;
01368 }
01369 RemoveResourceGroupCmd::~RemoveResourceGroupCmd() {
01370     if (m_mine)
01371         delete m_group;
01372 }
01373 void RemoveResourceGroupCmd::execute() {
01374     // remove all requests to this group
01375     int c=0;
01376     QPtrListIterator<ResourceGroupRequest> it = m_group->requests();
01377     for (; it.current(); ++it) {
01378         if (it.current()->parent()) {
01379             it.current()->parent()->takeRequest(it.current());
01380         }
01381         c = 1;
01382     }
01383     if (m_group->project())
01384         m_group->project()->takeResourceGroup(m_group);
01385     m_mine = true;
01386     
01387     setCommandType(c);
01388 }
01389 void RemoveResourceGroupCmd::unexecute() {
01390     // add all requests
01391     int c=0;
01392     QPtrListIterator<ResourceGroupRequest> it = m_group->requests();
01393     for (; it.current(); ++it) {
01394         if (it.current()->parent()) {
01395             it.current()->parent()->addRequest(it.current());
01396         }
01397         c = 1;
01398     }
01399     if (m_group->project())
01400         m_group->project()->addResourceGroup(m_group);
01401         
01402     m_mine = false;
01403     
01404     setCommandType(c);
01405 }
01406 
01407 AddResourceGroupCmd::AddResourceGroupCmd(Part *part, ResourceGroup *group, QString name)
01408     : RemoveResourceGroupCmd(part, group, name) {
01409                 
01410     m_mine = true;
01411 }
01412 void AddResourceGroupCmd::execute() {
01413     RemoveResourceGroupCmd::unexecute();
01414 }
01415 void AddResourceGroupCmd::unexecute() {
01416     RemoveResourceGroupCmd::execute();
01417 }
01418 
01419 ModifyResourceGroupNameCmd::ModifyResourceGroupNameCmd(Part *part, ResourceGroup *group, QString value, QString name)
01420     : NamedCommand(part, name),
01421       m_group(group),
01422       m_newvalue(value) {
01423     m_oldvalue = group->name();
01424 }
01425 void ModifyResourceGroupNameCmd::execute() {
01426     m_group->setName(m_newvalue);
01427     
01428     setCommandType(0);
01429 }
01430 void ModifyResourceGroupNameCmd::unexecute() {
01431     m_group->setName(m_oldvalue);
01432     
01433     setCommandType(0);
01434 }
01435 
01436 TaskModifyProgressCmd::TaskModifyProgressCmd(Part *part, Task &task, struct Task::Progress &value, QString name)
01437     : NamedCommand(part, name),
01438       m_task(task),
01439       m_newvalue(value) {
01440     m_oldvalue = task.progress();
01441 }
01442 void TaskModifyProgressCmd::execute() {
01443     m_task.progress() = m_newvalue;
01444     
01445     setCommandType(0);
01446 }
01447 void TaskModifyProgressCmd::unexecute() {
01448     m_task.progress() = m_oldvalue;
01449     
01450     setCommandType(0);
01451 }
01452 
01453 ProjectModifyBaselineCmd::ProjectModifyBaselineCmd(Part *part, Project &project, bool value, QString name)
01454     : NamedCommand(part, name),
01455       m_project(project),
01456       m_newvalue(value) {
01457     m_oldvalue = project.isBaselined();
01458 }
01459 void ProjectModifyBaselineCmd::execute() {
01460     m_project.setBaselined(m_newvalue);
01461     
01462     setCommandType(2);
01463 }
01464 void ProjectModifyBaselineCmd::unexecute() {
01465     m_project.setBaselined(m_oldvalue);
01466     
01467     setCommandType(2);
01468 }
01469 
01470 AddAccountCmd::AddAccountCmd(Part *part, Project &project, Account *account, QString parent, QString name)
01471     : NamedCommand(part, name),
01472       m_project(project),
01473       m_account(account),
01474       m_parent(0),
01475       m_parentName(parent) {
01476     m_mine = true;
01477 }
01478 
01479 AddAccountCmd::AddAccountCmd(Part *part, Project &project, Account *account, Account *parent, QString name)
01480     : NamedCommand(part, name),
01481       m_project(project),
01482       m_account(account),
01483       m_parent(parent) {
01484     m_mine = true;
01485 }
01486 
01487 AddAccountCmd::~AddAccountCmd() {
01488     if (m_mine)
01489         delete m_account;
01490 }
01491 
01492 void AddAccountCmd::execute() {
01493     if (m_parent == 0 && !m_parentName.isEmpty()) {
01494         m_parent = m_project.accounts().findAccount(m_parentName);
01495     }
01496     if (m_parent)
01497         m_parent->append(m_account);
01498     else
01499         m_project.accounts().append(m_account);
01500     
01501     setCommandType(0);
01502     m_mine = false;
01503 }
01504 void AddAccountCmd::unexecute() {
01505     if (m_parent)
01506         m_parent->take(m_account);
01507     else
01508         m_project.accounts().take(m_account);
01509     
01510     setCommandType(0);
01511     m_mine = true;
01512 }
01513 
01514 RemoveAccountCmd::RemoveAccountCmd(Part *part, Project &project, Account *account, QString name)
01515     : NamedCommand(part, name),
01516       m_project(project),
01517       m_account(account) {
01518     m_mine = false;
01519     m_isDefault = account == project.accounts().defaultAccount();
01520 }
01521 
01522 RemoveAccountCmd::~RemoveAccountCmd() {
01523     if (m_mine)
01524         delete m_account;
01525 }
01526 
01527 void RemoveAccountCmd::execute() {
01528     if (m_isDefault) {
01529         m_project.accounts().setDefaultAccount(0);
01530     }
01531     if (m_account->parent())
01532         m_account->parent()->take(m_account);
01533     else
01534         m_project.accounts().take(m_account);
01535     
01536     setCommandType(0);
01537     m_mine = true;
01538 }
01539 void RemoveAccountCmd::unexecute() {
01540     if (m_account->parent())
01541         m_account->parent()->append(m_account);
01542     else
01543         m_project.accounts().append(m_account);
01544     
01545     if (m_isDefault)
01546         m_project.accounts().setDefaultAccount(m_account);
01547     
01548     setCommandType(0);
01549     m_mine = false;
01550 }
01551 
01552 RenameAccountCmd::RenameAccountCmd(Part *part, Account *account, QString value, QString name)
01553     : NamedCommand(part, name),
01554       m_account(account) {
01555     m_oldvalue = account->name();
01556     m_newvalue = value;
01557 }
01558 
01559 void RenameAccountCmd::execute() {
01560     m_account->setName(m_newvalue);        
01561     setCommandType(0);
01562 }
01563 void RenameAccountCmd::unexecute() {
01564     m_account->setName(m_oldvalue);
01565     setCommandType(0);
01566 }
01567 
01568 ModifyAccountDescriptionCmd::ModifyAccountDescriptionCmd(Part *part, Account *account, QString value, QString name)
01569     : NamedCommand(part, name),
01570       m_account(account) {
01571     m_oldvalue = account->description();
01572     m_newvalue = value;
01573 }
01574 
01575 void ModifyAccountDescriptionCmd::execute() {
01576     m_account->setDescription(m_newvalue);        
01577     setCommandType(0);
01578 }
01579 void ModifyAccountDescriptionCmd::unexecute() {
01580     m_account->setDescription(m_oldvalue);
01581     setCommandType(0);
01582 }
01583 
01584 
01585 NodeModifyStartupCostCmd::NodeModifyStartupCostCmd(Part *part, Node &node, double value, QString name)
01586     : NamedCommand(part, name),
01587       m_node(node) {
01588     m_oldvalue = node.startupCost();
01589     m_newvalue = value;
01590 }
01591 
01592 void NodeModifyStartupCostCmd::execute() {
01593     m_node.setStartupCost(m_newvalue);        
01594     setCommandType(0);
01595 }
01596 void NodeModifyStartupCostCmd::unexecute() {
01597     m_node.setStartupCost(m_oldvalue);
01598     setCommandType(0);
01599 }
01600 
01601 NodeModifyShutdownCostCmd::NodeModifyShutdownCostCmd(Part *part, Node &node, double value, QString name)
01602     : NamedCommand(part, name),
01603       m_node(node) {
01604     m_oldvalue = node.startupCost();
01605     m_newvalue = value;
01606 }
01607 
01608 void NodeModifyShutdownCostCmd::execute() {
01609     m_node.setShutdownCost(m_newvalue);        
01610     setCommandType(0);
01611 }
01612 void NodeModifyShutdownCostCmd::unexecute() {
01613     m_node.setShutdownCost(m_oldvalue);
01614     setCommandType(0);
01615 }
01616 
01617 NodeModifyRunningAccountCmd::NodeModifyRunningAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, QString name)
01618     : NamedCommand(part, name),
01619       m_node(node) {
01620     m_oldvalue = oldvalue;
01621     m_newvalue = newvalue;
01622     //kdDebug()<<k_funcinfo<<endl;
01623 }
01624 void NodeModifyRunningAccountCmd::execute() {
01625     //kdDebug()<<k_funcinfo<<endl;
01626     if (m_oldvalue) {
01627         m_oldvalue->removeRunning(m_node);
01628     }
01629     if (m_newvalue) {
01630         m_newvalue->addRunning(m_node);        
01631     }
01632     setCommandType(0);
01633 }
01634 void NodeModifyRunningAccountCmd::unexecute() {
01635     //kdDebug()<<k_funcinfo<<endl;
01636     if (m_newvalue) {
01637         m_newvalue->removeRunning(m_node);        
01638     }
01639     if (m_oldvalue) {
01640         m_oldvalue->addRunning(m_node);
01641     }
01642     setCommandType(0);
01643 }
01644 
01645 NodeModifyStartupAccountCmd::NodeModifyStartupAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, QString name)
01646     : NamedCommand(part, name),
01647       m_node(node) {
01648     m_oldvalue = oldvalue;
01649     m_newvalue = newvalue;
01650     //kdDebug()<<k_funcinfo<<endl;
01651 }
01652 
01653 void NodeModifyStartupAccountCmd::execute() {
01654     //kdDebug()<<k_funcinfo<<endl;
01655     if (m_oldvalue) {
01656         m_oldvalue->removeStartup(m_node);
01657     }
01658     if (m_newvalue) {
01659         m_newvalue->addStartup(m_node);        
01660     }
01661     setCommandType(0);
01662 }
01663 void NodeModifyStartupAccountCmd::unexecute() {
01664     //kdDebug()<<k_funcinfo<<endl;
01665     if (m_newvalue) {
01666         m_newvalue->removeStartup(m_node);
01667     }
01668     if (m_oldvalue) {
01669         m_oldvalue->addStartup(m_node);        
01670     }
01671     setCommandType(0);
01672 }
01673 
01674 NodeModifyShutdownAccountCmd::NodeModifyShutdownAccountCmd(Part *part, Node &node, Account *oldvalue, Account *newvalue, QString name)
01675     : NamedCommand(part, name),
01676       m_node(node) {
01677     m_oldvalue = oldvalue;
01678     m_newvalue = newvalue;
01679     //kdDebug()<<k_funcinfo<<endl;
01680 }
01681 
01682 void NodeModifyShutdownAccountCmd::execute() {
01683     //kdDebug()<<k_funcinfo<<endl;
01684     if (m_oldvalue) {
01685         m_oldvalue->removeShutdown(m_node);
01686     }
01687     if (m_newvalue) {
01688         m_newvalue->addShutdown(m_node);
01689     }
01690     setCommandType(0);
01691 }
01692 void NodeModifyShutdownAccountCmd::unexecute() {
01693     //kdDebug()<<k_funcinfo<<endl;
01694     if (m_newvalue) {
01695         m_newvalue->removeShutdown(m_node);
01696     }
01697     if (m_oldvalue) {
01698         m_oldvalue->addShutdown(m_node);
01699     }
01700     setCommandType(0);
01701 }
01702 
01703 ModifyDefaultAccountCmd::ModifyDefaultAccountCmd(Part *part, Accounts &acc, Account *oldvalue, Account *newvalue, QString name)
01704     : NamedCommand(part, name),
01705       m_accounts(acc) {
01706     m_oldvalue = oldvalue;
01707     m_newvalue = newvalue;
01708     //kdDebug()<<k_funcinfo<<endl;
01709 }
01710 
01711 void ModifyDefaultAccountCmd::execute() {
01712     //kdDebug()<<k_funcinfo<<endl;
01713     m_accounts.setDefaultAccount(m_newvalue);
01714     setCommandType(0);
01715 }
01716 void ModifyDefaultAccountCmd::unexecute() {
01717     //kdDebug()<<k_funcinfo<<endl;
01718     m_accounts.setDefaultAccount(m_oldvalue);
01719     setCommandType(0);
01720 }
01721 
01722 ProjectModifyConstraintCmd::ProjectModifyConstraintCmd(Part *part, Project &node, Node::ConstraintType c, QString name)
01723     : NamedCommand(part, name),
01724       m_node(node),
01725       newConstraint(c),
01726       oldConstraint(static_cast<Node::ConstraintType>(node.constraint())) {
01727 
01728     QIntDictIterator<Schedule> it = node.schedules();
01729     for (; it.current(); ++it) {
01730         addSchScheduled(it.current());
01731     }
01732 }
01733 void ProjectModifyConstraintCmd::execute() {
01734     m_node.setConstraint(newConstraint);
01735     setSchScheduled(false);
01736     setCommandType(1);
01737 }
01738 void ProjectModifyConstraintCmd::unexecute() {
01739     m_node.setConstraint(oldConstraint);
01740     setSchScheduled();
01741     setCommandType(1);
01742 }
01743 
01744 ProjectModifyStartTimeCmd::ProjectModifyStartTimeCmd(Part *part, Project &node, QDateTime dt, QString name)
01745     : NamedCommand(part, name),
01746       m_node(node),
01747       newTime(dt),
01748       oldTime(node.startTime()) {
01749 
01750     QIntDictIterator<Schedule> it = node.schedules();
01751     for (; it.current(); ++it) {
01752         addSchScheduled(it.current());
01753     }
01754 }
01755 
01756 void ProjectModifyStartTimeCmd::execute() {
01757     m_node.setConstraintStartTime(newTime);
01758     setSchScheduled(false);
01759     setCommandType(1);
01760 }
01761 void ProjectModifyStartTimeCmd::unexecute() {
01762     m_node.setConstraintStartTime(oldTime);
01763     setSchScheduled();
01764     setCommandType(1);
01765 }
01766 
01767 ProjectModifyEndTimeCmd::ProjectModifyEndTimeCmd(Part *part, Project &node, QDateTime dt, QString name)
01768     : NamedCommand(part, name),
01769       m_node(node),
01770       newTime(dt),
01771       oldTime(node.endTime()) {
01772 
01773     QIntDictIterator<Schedule> it = node.schedules();
01774     for (; it.current(); ++it) {
01775         addSchScheduled(it.current());
01776     }
01777 }
01778 void ProjectModifyEndTimeCmd::execute() {
01779     m_node.setEndTime(newTime);
01780     m_node.setConstraintEndTime(newTime);
01781     setSchScheduled(false);
01782     setCommandType(1);
01783 }
01784 void ProjectModifyEndTimeCmd::unexecute() {
01785     m_node.setConstraintEndTime(oldTime);
01786     setSchScheduled();
01787     setCommandType(1);
01788 }
01789 
01790 CalculateProjectCmd::CalculateProjectCmd(Part *part, Project &node, QString tname, int type, QString name)
01791     : NamedCommand(part, name),
01792       m_node(node),
01793       m_typename(tname),
01794       m_type(type),
01795       newSchedule(0) {
01796       
01797     oldCurrent = node.currentSchedule();
01798     //kdDebug()<<k_funcinfo<<type<<endl;
01799 }
01800 void CalculateProjectCmd::execute() {
01801     if (newSchedule == 0) {
01802         //kdDebug()<<k_funcinfo<<" create schedule"<<endl;
01803         newSchedule = m_node.createSchedule(m_typename, (Schedule::Type)m_type);
01804         m_node.calculate(newSchedule);
01805     } else {
01806         //kdDebug()<<k_funcinfo<<" redo"<<endl;
01807         newSchedule->setDeleted(false);
01808         m_node.setCurrentSchedulePtr(newSchedule);
01809     }
01810     setCommandType(0);
01811 }
01812 void CalculateProjectCmd::unexecute() {
01813     //kdDebug()<<k_funcinfo<<endl;
01814     newSchedule->setDeleted(true);
01815     m_node.setCurrentSchedulePtr(oldCurrent);
01816 
01817     setCommandType(0);
01818 }
01819 
01820 RecalculateProjectCmd::RecalculateProjectCmd(Part *part, Project &node, Schedule &sch, QString name)
01821     : NamedCommand(part, name),
01822       m_node(node),
01823       oldSchedule(sch),
01824       newSchedule(0),
01825       oldDeleted(sch.isDeleted()) {
01826 
01827     oldCurrent = node.currentSchedule();
01828     //kdDebug()<<k_funcinfo<<sch.typeToString()<<"  curr="<<(oldCurrent?oldCurrent->id():-1)<<endl;
01829 }
01830 void RecalculateProjectCmd::execute() {
01831     oldSchedule.setDeleted(true);
01832     if (newSchedule == 0) {
01833         newSchedule = m_node.createSchedule(oldSchedule.name(), oldSchedule.type());
01834         m_node.calculate(newSchedule);
01835     } else {
01836         newSchedule->setDeleted(false);
01837         m_node.setCurrentSchedulePtr(newSchedule);
01838         //kdDebug()<<k_funcinfo<<newSchedule->typeToString()<<" redo"<<endl;
01839     }
01840     setCommandType(0);
01841 }
01842 void RecalculateProjectCmd::unexecute() {
01843     //kdDebug()<<k_funcinfo<<newSchedule->typeToString()<<(oldCurrent ? oldCurrent->id() : -1)<<endl;
01844     newSchedule->setDeleted(true);
01845     oldSchedule.setDeleted(oldDeleted);
01846     m_node.setCurrentSchedulePtr(oldCurrent);
01847     
01848     setCommandType(0);
01849 }
01850 
01851 
01852 ModifyStandardWorktimeYearCmd::ModifyStandardWorktimeYearCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01853     : NamedCommand(part, name),
01854       swt(wt),
01855       m_oldvalue(oldvalue),
01856       m_newvalue(newvalue) {
01857 
01858 }
01859 void ModifyStandardWorktimeYearCmd::execute() {
01860     swt->setYear(m_newvalue);
01861     setCommandType(0);
01862 }
01863 void ModifyStandardWorktimeYearCmd::unexecute() {
01864     swt->setYear(m_oldvalue);
01865     setCommandType(0);
01866 }
01867 
01868 ModifyStandardWorktimeMonthCmd::ModifyStandardWorktimeMonthCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01869     : NamedCommand(part, name),
01870       swt(wt),
01871       m_oldvalue(oldvalue),
01872       m_newvalue(newvalue) {
01873 
01874 }
01875 void ModifyStandardWorktimeMonthCmd::execute() {
01876     swt->setMonth(m_newvalue);
01877     setCommandType(0);
01878 }
01879 void ModifyStandardWorktimeMonthCmd::unexecute() {
01880     swt->setMonth(m_oldvalue);
01881     setCommandType(0);
01882 }
01883 
01884 ModifyStandardWorktimeWeekCmd::ModifyStandardWorktimeWeekCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01885     : NamedCommand(part, name),
01886       swt(wt),
01887       m_oldvalue(oldvalue),
01888       m_newvalue(newvalue) {
01889 
01890 }
01891 void ModifyStandardWorktimeWeekCmd::execute() {
01892     swt->setWeek(m_newvalue);
01893     setCommandType(0);
01894 }
01895 void ModifyStandardWorktimeWeekCmd::unexecute() {
01896     swt->setWeek(m_oldvalue);
01897     setCommandType(0);
01898 }
01899 
01900 ModifyStandardWorktimeDayCmd::ModifyStandardWorktimeDayCmd(Part *part, StandardWorktime *wt, double oldvalue, double newvalue, QString name)
01901     : NamedCommand(part, name),
01902       swt(wt),
01903       m_oldvalue(oldvalue),
01904       m_newvalue(newvalue) {
01905 
01906 }
01907 
01908 void ModifyStandardWorktimeDayCmd::execute() {
01909     swt->setDay(m_newvalue);
01910     setCommandType(0);
01911 }
01912 void ModifyStandardWorktimeDayCmd::unexecute() {
01913     swt->setDay(m_oldvalue);
01914     setCommandType(0);
01915 }
01916 
01917 
01918 }  //KPlato namespace
KDE Home | KDE Accessibility Home | Description of Access Keys