Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::removeSubject ( const QString &  subjectName  ) 

Removes this subject and all related activities and constraints. It returns false on failure. If successful, returns true.

!! please improve this!!!

Definition at line 601 of file rules.cpp.

References activitiesList, internalStructureComputed, removeActivity(), ConstraintRoomTypeNotAllowedSubjects::removeNotAllowedSubject(), removeSpaceConstraint(), removeTimeConstraint(), spaceConstraintsList, ConstraintSubjectSubjectTagRequireEquipments::subjectName, ConstraintSubjectRequiresEquipments::subjectName, ConstraintActivitiesPreferredTimes::subjectName, ConstraintRoomTypeNotAllowedSubjects::subjects, subjectsList, and timeConstraintsList.

{
      //check the activities first
      //TODO: improve this part
      for(Activity* act=this->activitiesList.first(); act; ){
            if( act->subjectName == subjectName){
                  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();
      }
      
      //delete the time constraints related to this subject
      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ){
            if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){
                  ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;
                  if(subjectName == crt_constraint->subjectName){
                        this->removeTimeConstraint(ctr); //single constraint removal
                        ctr=this->timeConstraintsList.current();
                  }
                  else{
                        ctr=this->timeConstraintsList.next();
                  }
            }
            else
                  ctr=this->timeConstraintsList.next();
      }

      //delete the space constraints related to this subject
      for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ){
            if(ctr->type==CONSTRAINT_ROOM_TYPE_NOT_ALLOWED_SUBJECTS){
                  ConstraintRoomTypeNotAllowedSubjects* crtas=(ConstraintRoomTypeNotAllowedSubjects*)ctr;
                  QStringList::Iterator it;
                  for(it=crtas->subjects.begin(); it!=crtas->subjects.end(); it++)
                        if(*it==subjectName)
                              break;
                  if(it!=crtas->subjects.end()){
                        int tmp=crtas->removeNotAllowedSubject(subjectName);
                        assert(tmp==1);
                  }

                  //remove the constraint if subjects list empty
                  if(crtas->subjects.isEmpty()){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_SUBJECT_REQUIRES_EQUIPMENTS){
                  ConstraintSubjectRequiresEquipments* csre=(ConstraintSubjectRequiresEquipments*)ctr;

                  if(csre->subjectName == subjectName){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_REQUIRE_EQUIPMENTS){
                  ConstraintSubjectSubjectTagRequireEquipments* c=(ConstraintSubjectSubjectTagRequireEquipments*)ctr;

                  if(c->subjectName == subjectName){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else
                  ctr=this->spaceConstraintsList.next();
      }

      //remove the subject from the list
      for(Subject* sbj=this->subjectsList.first(); sbj; sbj=this->subjectsList.next())
            if(sbj->name==subjectName)
                  break;
      this->subjectsList.remove();

      this->internalStructureComputed=false;

      return true;
}


Generated by  Doxygen 1.6.0   Back to index