📄 rules.cpp
字号:
else if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){ ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr; if(initialYearName == crt_constraint->studentsName) crt_constraint->studentsName=finalYearName; } } int t=0; for(StudentsYear* sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==initialYearName){ sty->name=finalYearName; sty->numberOfStudents=finalNumberOfStudents; t++; for(StudentsGroup* stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()){ if(stg->name.right(11)==" WHOLE YEAR" && stg->name.left(stg->name.length()-11)==initialYearName) this->modifyGroup(sty->name, stg->name, sty->name+" WHOLE YEAR", stg->numberOfStudents); } } assert(t<=1); this->internalStructureComputed=false; if(t==0) return false; else return true;}void Rules::sortYearsAlphabetically(){ this->yearsList.sort(); this->internalStructureComputed=false;}bool Rules::addGroup(const QString& yearName, StudentsGroup* group){ StudentsYear* sty; for(sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==yearName) break; assert(sty); for(StudentsGroup* stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()) if(stg->name==group->name) return false; sty->groupsList.append(group); this->internalStructureComputed=false; return true;}bool Rules::removeGroup(const QString& yearName, const QString& groupName){ StudentsYear* sty; for(sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==yearName) break; assert(sty); StudentsGroup* stg; for(stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()) if(stg->name==groupName) break; assert(stg); sty->groupsList.take(); this->internalStructureComputed=false; if(this->searchStudentsSet(stg->name)!=NULL) //group still exists return true; delete stg; //TODO: improve this part for(Activity* act=this->activitiesList.first(); act; ){ act->removeStudents(groupName); if(act->studentsNames.count()==0){ this->removeActivity(act->id, act->activityGroupId); act=this->activitiesList.first(); //!!! please improve this!!! //(You have to be careful, there can be erased more activities here) } else act=this->activitiesList.next(); } for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){ bool erased=false; if(ctr->type==CONSTRAINT_STUDENTS_SET_NOT_AVAILABLE){ ConstraintStudentsSetNotAvailable* crt_constraint=(ConstraintStudentsSetNotAvailable*)ctr; if(groupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_STUDENTS_SET_N_HOURS_DAILY){ ConstraintStudentsSetNHoursDaily* crt_constraint=(ConstraintStudentsSetNHoursDaily*)ctr; if(groupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_STUDENTS_SET_NO_GAPS){ ConstraintStudentsSetNoGaps* crt_constraint=(ConstraintStudentsSetNoGaps*)ctr; if(groupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_STUDENTS_SET_INTERVAL_MAX_DAYS_PER_WEEK){ ConstraintStudentsSetIntervalMaxDaysPerWeek* crt_constraint=(ConstraintStudentsSetIntervalMaxDaysPerWeek*)ctr; if(groupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){ ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr; if(groupName == crt_constraint->studentsName){ this->removeTimeConstraint(ctr); erased=true; } } if(!erased) ctr=this->timeConstraintsList.next(); else ctr=this->timeConstraintsList.current(); } return true;}int Rules::searchGroup(const QString& yearName, const QString& groupName){ StudentsYear* sty=this->yearsList.at(this->searchYear(yearName)); assert(sty); StudentsGroup* stg; int i; for(stg=sty->groupsList.first(), i=0; stg; stg=sty->groupsList.next(), i++) if(stg->name==groupName) return i; return -1;}bool Rules::modifyGroup(const QString& yearName, const QString& initialGroupName, const QString& finalGroupName, int finalNumberOfStudents){ assert(searchGroup(yearName, initialGroupName)>=0); assert(searchStudentsSet(finalGroupName)==NULL || initialGroupName==finalGroupName); StudentsYear* sty; for(sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==yearName) break; assert(sty); StudentsGroup* stg; for(stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()) if(stg->name==initialGroupName){ stg->name=finalGroupName; stg->numberOfStudents=finalNumberOfStudents; for(StudentsSubgroup* sts=stg->subgroupsList.first(); sts; sts=stg->subgroupsList.next()){ if(sts->name.right(12)==" WHOLE GROUP" && sts->name.left(sts->name.length()-12)==initialGroupName) this->modifySubgroup(sty->name, stg->name, sts->name, stg->name+" WHOLE GROUP", sts->numberOfStudents); } break; } assert(stg); //TODO: improve this part for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next()) act->renameStudents(initialGroupName, finalGroupName); for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){ if(ctr->type==CONSTRAINT_STUDENTS_SET_NOT_AVAILABLE){ ConstraintStudentsSetNotAvailable* crt_constraint=(ConstraintStudentsSetNotAvailable*)ctr; if(initialGroupName == crt_constraint->students) crt_constraint->students=finalGroupName; } else if(ctr->type==CONSTRAINT_STUDENTS_SET_N_HOURS_DAILY){ ConstraintStudentsSetNHoursDaily* crt_constraint=(ConstraintStudentsSetNHoursDaily*)ctr; if(initialGroupName == crt_constraint->students) crt_constraint->students=finalGroupName; } else if(ctr->type==CONSTRAINT_STUDENTS_SET_NO_GAPS){ ConstraintStudentsSetNoGaps* crt_constraint=(ConstraintStudentsSetNoGaps*)ctr; if(initialGroupName == crt_constraint->students) crt_constraint->students=finalGroupName; } else if(ctr->type==CONSTRAINT_STUDENTS_SET_INTERVAL_MAX_DAYS_PER_WEEK){ ConstraintStudentsSetIntervalMaxDaysPerWeek* crt_constraint=(ConstraintStudentsSetIntervalMaxDaysPerWeek*)ctr; if(initialGroupName == crt_constraint->students) crt_constraint->students=finalGroupName; } else if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){ ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr; if(initialGroupName == crt_constraint->studentsName) crt_constraint->studentsName=finalGroupName; } } this->internalStructureComputed=false; return true;}void Rules::sortGroupsAlphabetically(const QString& yearName){ StudentsYear* sty; for(sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==yearName) break; assert(sty); sty->groupsList.sort(); this->internalStructureComputed=false;}bool Rules::addSubgroup(const QString& yearName, const QString& groupName, StudentsSubgroup* subgroup){ StudentsYear* sty; for(sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==yearName) break; assert(sty); StudentsGroup* stg; for(stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()) if(stg->name==groupName) break; assert(stg); for(StudentsSubgroup* sts=stg->subgroupsList.first(); sts; sts=stg->subgroupsList.next()) if(sts->name==subgroup->name) return false; stg->subgroupsList.append(subgroup); this->internalStructureComputed=false; return true;}bool Rules::removeSubgroup(const QString& yearName, const QString& groupName, const QString& subgroupName){ StudentsYear* sty; for(sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==yearName) break; assert(sty); StudentsGroup* stg; for(stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()) if(stg->name==groupName) break; assert(stg); StudentsSubgroup* sts; for(sts=stg->subgroupsList.first(); sts; sts=stg->subgroupsList.next()) if(sts->name==subgroupName) break; assert(sts); stg->subgroupsList.take(); if(this->searchStudentsSet(sts->name)!=NULL) //subgroup still exists, in other group return true; delete sts; this->internalStructureComputed=false; //TODO: improve this part for(Activity* act=this->activitiesList.first(); act; ){ act->removeStudents(subgroupName); if(act->studentsNames.count()==0){ this->removeActivity(act->id, act->activityGroupId); act=this->activitiesList.first(); //!!! please improve this!!! //(You have to be careful, there can be erased more activities here) } else act=this->activitiesList.next(); } for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){ bool erased=false; if(ctr->type==CONSTRAINT_STUDENTS_SET_NOT_AVAILABLE){ ConstraintStudentsSetNotAvailable* crt_constraint=(ConstraintStudentsSetNotAvailable*)ctr; if(subgroupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_STUDENTS_SET_N_HOURS_DAILY){ ConstraintStudentsSetNHoursDaily* crt_constraint=(ConstraintStudentsSetNHoursDaily*)ctr; if(subgroupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_STUDENTS_SET_NO_GAPS){ ConstraintStudentsSetNoGaps* crt_constraint=(ConstraintStudentsSetNoGaps*)ctr; if(subgroupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_STUDENTS_SET_INTERVAL_MAX_DAYS_PER_WEEK){ ConstraintStudentsSetIntervalMaxDaysPerWeek* crt_constraint=(ConstraintStudentsSetIntervalMaxDaysPerWeek*)ctr; if(subgroupName == crt_constraint->students){ this->removeTimeConstraint(ctr); erased=true; } } else if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){ ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr; if(subgroupName == crt_constraint->studentsName){ this->removeTimeConstraint(ctr); erased=true; } } if(!erased) ctr=this->timeConstraintsList.next(); else ctr=this->timeConstraintsList.current(); } return true;}int Rules::searchSubgroup(const QString& yearName, const QString& groupName, const QString& subgroupName){ StudentsYear* sty=this->yearsList.at(this->searchYear(yearName)); assert(sty); StudentsGroup* stg=sty->groupsList.at(this->searchGroup(yearName, groupName)); assert(stg); StudentsSubgroup* sts; int i; for(sts=stg->subgroupsList.first(), i=0; sts; sts=stg->subgroupsList.next(), i++) if(sts->name==subgroupName) return i; return -1;}bool Rules::modifySubgroup(const QString& yearName, const QString& groupName, const QString& initialSubgroupName, const QString& finalSubgroupName, int finalNumberOfStudents){ assert(searchSubgroup(yearName, groupName, initialSubgroupName)>=0); assert(searchStudentsSet(finalSubgroupName)==NULL || initialSubgroupName==finalSubgroupName); StudentsYear* sty; for(sty=this->yearsList.first(); sty; sty=this->yearsList.next()) if(sty->name==yearName) break; assert(sty); StudentsGroup* stg; for(stg=sty->groupsList.first(); stg; stg=sty->groupsList.next()) if(stg->name==groupName) break; assert(stg); StudentsSubgroup* sts; for(sts=stg->subgroupsList.first(); sts; sts=stg->subgroupsList.next()) if(sts->name==initialSubgroupName){ sts->name=finalSubgroupName; sts->numberOfStudents=finalNumberOfStudents; break; } assert(sts); //TODO: improve this part for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next()) act->renameStudents(initialSubgroupName, finalSubgroupName); for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){ if(ctr->type==CONSTRAINT_STUDENTS_SET_NOT_AVAILABLE){ ConstraintStudentsSetNotAvailable* crt_constraint=(ConstraintStudentsSetNotAvailable*)ctr; if(initialSubgroupName == crt_constraint->students
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -