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