ModifyActivityForm::ModifyActivityForm(QWidget* parent, int id, int activityGroupId): QDialog(parent) { setupUi(this); durList.clear(); durList.append(duration1SpinBox); durList.append(duration2SpinBox); durList.append(duration3SpinBox); durList.append(duration4SpinBox); durList.append(duration5SpinBox); durList.append(duration6SpinBox); durList.append(duration7SpinBox); durList.append(duration8SpinBox); durList.append(duration9SpinBox); durList.append(duration10SpinBox); durList.append(duration11SpinBox); durList.append(duration12SpinBox); durList.append(duration13SpinBox); durList.append(duration14SpinBox); durList.append(duration15SpinBox); durList.append(duration16SpinBox); durList.append(duration17SpinBox); durList.append(duration18SpinBox); durList.append(duration19SpinBox); durList.append(duration20SpinBox); durList.append(duration21SpinBox); durList.append(duration22SpinBox); durList.append(duration23SpinBox); durList.append(duration24SpinBox); durList.append(duration25SpinBox); durList.append(duration26SpinBox); durList.append(duration27SpinBox); durList.append(duration28SpinBox); durList.append(duration29SpinBox); durList.append(duration30SpinBox); durList.append(duration31SpinBox); durList.append(duration32SpinBox); durList.append(duration33SpinBox); durList.append(duration34SpinBox); durList.append(duration35SpinBox); for(int i=0; i<MAX_SPLIT_OF_AN_ACTIVITY; i++) dur(i)->setMaximum(gt.rules.nHoursPerDay); activList.clear(); activList.append(active1CheckBox); activList.append(active2CheckBox); activList.append(active3CheckBox); activList.append(active4CheckBox); activList.append(active5CheckBox); activList.append(active6CheckBox); activList.append(active7CheckBox); activList.append(active8CheckBox); activList.append(active9CheckBox); activList.append(active10CheckBox); activList.append(active11CheckBox); activList.append(active12CheckBox); activList.append(active13CheckBox); activList.append(active14CheckBox); activList.append(active15CheckBox); activList.append(active16CheckBox); activList.append(active17CheckBox); activList.append(active18CheckBox); activList.append(active19CheckBox); activList.append(active20CheckBox); activList.append(active21CheckBox); activList.append(active22CheckBox); activList.append(active23CheckBox); activList.append(active24CheckBox); activList.append(active25CheckBox); activList.append(active26CheckBox); activList.append(active27CheckBox); activList.append(active28CheckBox); activList.append(active29CheckBox); activList.append(active30CheckBox); activList.append(active31CheckBox); activList.append(active32CheckBox); activList.append(active33CheckBox); activList.append(active34CheckBox); activList.append(active35CheckBox); allTeachersListWidget->setSelectionMode(QAbstractItemView::SingleSelection); selectedTeachersListWidget->setSelectionMode(QAbstractItemView::SingleSelection); allStudentsListWidget->setSelectionMode(QAbstractItemView::SingleSelection); selectedStudentsListWidget->setSelectionMode(QAbstractItemView::SingleSelection); allActivityTagsListWidget->setSelectionMode(QAbstractItemView::SingleSelection); selectedActivityTagsListWidget->setSelectionMode(QAbstractItemView::SingleSelection); connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel())); connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok())); connect(clearTeacherPushButton, SIGNAL(clicked()), this, SLOT(clearTeachers())); connect(clearStudentsPushButton, SIGNAL(clicked()), this, SLOT(clearStudents())); connect(allTeachersListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addTeacher())); connect(selectedTeachersListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeTeacher())); connect(allStudentsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addStudents())); connect(selectedStudentsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeStudents())); connect(clearActivityTagPushButton, SIGNAL(clicked()), this, SLOT(clearActivityTags())); connect(allActivityTagsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addActivityTag())); connect(selectedActivityTagsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeActivityTag())); connect(showYearsCheckBox, SIGNAL(toggled(bool)), this, SLOT(showYearsChanged())); connect(showGroupsCheckBox, SIGNAL(toggled(bool)), this, SLOT(showGroupsChanged())); connect(showSubgroupsCheckBox, SIGNAL(toggled(bool)), this, SLOT(showSubgroupsChanged())); connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help())); centerWidgetOnScreen(this); restoreFETDialogGeometry(this); QSize tmp3=subjectsComboBox->minimumSizeHint(); Q_UNUSED(tmp3); this->_id=id; this->_activityGroupId=activityGroupId; for(int i=0; i<gt.rules.activitiesList.size(); i++){ Activity* act=gt.rules.activitiesList[i]; if(act->activityGroupId==this->_activityGroupId && act->id==this->_id) this->_activity=act; } this->_teachers=this->_activity->teachersNames; this->_subject = this->_activity->subjectName; this->_activityTags = this->_activity->activityTagsNames; this->_students=this->_activity->studentsNames; int nSplit; if(this->_activityGroupId!=0){ nSplit=0; for(int i=0; i<gt.rules.activitiesList.size(); i++){ Activity* act=gt.rules.activitiesList[i]; if(act->activityGroupId==this->_activityGroupId){ if(nSplit>=MAX_SPLIT_OF_AN_ACTIVITY){ assert(0); } else{ if(this->_id==act->id) subactivitiesTabWidget->setCurrentIndex(nSplit); dur(nSplit)->setValue(act->duration); activ(nSplit)->setChecked(act->active); nSplit++; } } } } else{ nSplit=1; dur(0)->setValue(this->_activity->duration); activ(0)->setChecked(this->_activity->active); subactivitiesTabWidget->setCurrentIndex(0); } splitSpinBox->setMinimum(nSplit); splitSpinBox->setMaximum(nSplit); splitSpinBox->setValue(nSplit); nStudentsSpinBox->setMinimum(-1); nStudentsSpinBox->setMaximum(MAX_ROOM_CAPACITY); nStudentsSpinBox->setValue(-1); if(this->_activity->computeNTotalStudents==false) nStudentsSpinBox->setValue(this->_activity->nTotalStudents); updateStudentsListWidget(); updateTeachersListWidget(); updateSubjectsComboBox(); updateActivityTagsListWidget(); selectedStudentsListWidget->clear(); for(QStringList::Iterator it=this->_students.begin(); it!=this->_students.end(); it++) selectedStudentsListWidget->addItem(*it); for(int i=0; i<MAX_SPLIT_OF_AN_ACTIVITY; i++) if(i<nSplit) subactivitiesTabWidget->setTabEnabled(i, true); else subactivitiesTabWidget->setTabEnabled(i, false); okPushButton->setDefault(true); okPushButton->setFocus(); foreach(Teacher* tch, gt.rules.teachersList) teacherNamesSet.insert(tch->name); foreach(Subject* sbj, gt.rules.subjectsList) subjectNamesSet.insert(sbj->name); foreach(ActivityTag* at, gt.rules.activityTagsList) activityTagNamesSet.insert(at->name); /*foreach(StudentsYear* year, gt.rules.yearsList){ numberOfStudentsHash.insert(year->name, year->numberOfStudents); foreach(StudentsGroup* group, year->groupsList){ numberOfStudentsHash.insert(group->name, group->numberOfStudents); foreach(StudentsSubgroup* subgroup, group->subgroupsList){ numberOfStudentsHash.insert(subgroup->name, subgroup->numberOfStudents); } } }*/ }
void AddActivityForm::addActivity() { double weight; QString tmp=percentageLineEdit->text(); weight_sscanf(tmp, "%lf", &weight); if(percentageLineEdit->isEnabled() && (weight<0.0 || weight>100.0)){ QMessageBox::warning(this, tr("FET information"), tr("Invalid weight (percentage) for added constraint min days between activities")); return; } //teachers QStringList teachers_names; if(selectedTeachersListWidget->count()<=0){ int t=QMessageBox::question(this, tr("FET question"), tr("Do you really want to add an activity without teacher(s)?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(t==QMessageBox::No) return; } else{ for(int i=0; i<selectedTeachersListWidget->count(); i++){ assert(gt.rules.searchTeacher(selectedTeachersListWidget->item(i)->text())>=0); teachers_names.append(selectedTeachersListWidget->item(i)->text()); } } //subject QString subject_name=subjectsComboBox->currentText(); int subject_index=gt.rules.searchSubject(subject_name); if(subject_index<0){ QMessageBox::warning(this, tr("FET warning"), tr("Invalid subject")); return; } QStringList activity_tags_names; for(int i=0; i<selectedActivityTagsListWidget->count(); i++){ assert(gt.rules.searchActivityTag(selectedActivityTagsListWidget->item(i)->text())>=0); activity_tags_names.append(selectedActivityTagsListWidget->item(i)->text()); } //students QStringList students_names; if(selectedStudentsListWidget->count()<=0){ int t=QMessageBox::question(this, tr("FET question"), tr("Do you really want to add an activity without student set(s)?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(t==QMessageBox::No) return; } else{ for(int i=0; i<selectedStudentsListWidget->count(); i++){ assert(gt.rules.searchStudentsSet(selectedStudentsListWidget->item(i)->text())!=NULL); students_names.append(selectedStudentsListWidget->item(i)->text()); } } if(splitSpinBox->value()==1){ //indivisible activity int duration=duration1SpinBox->value(); if(duration<0){ QMessageBox::warning(this, tr("FET information"), tr("Invalid duration")); return; } bool active=false; if(active1CheckBox->isChecked()) active=true; int activityid=0; //We set the id of this newly added activity = (the largest existing id + 1) for(int i=0; i<gt.rules.activitiesList.size(); i++){ Activity* act=gt.rules.activitiesList[i]; if(act->id > activityid) activityid = act->id; } activityid++; Activity a(gt.rules, activityid, 0, teachers_names, subject_name, activity_tags_names, students_names, duration, duration, /*parity,*/ active, (nStudentsSpinBox->value()==-1), nStudentsSpinBox->value()); bool already_existing=false; for(int i=0; i<gt.rules.activitiesList.size(); i++){ Activity* act=gt.rules.activitiesList[i]; if((*act)==a) already_existing=true; } if(already_existing){ int t=QMessageBox::question(this, tr("FET question"), //tr("This activity already exists. Insert it again?"), tr("A similar activity already exists. Do you want to insert current activity?"), tr("Yes"),tr("No")); assert(t==0 || t==1 ||t==-1); if(t==1) //no pressed return; if(t==-1) //Esc pressed return; } bool tmp=gt.rules.addSimpleActivity(this, activityid, 0, teachers_names, subject_name, activity_tags_names, students_names, duration, duration, active, (nStudentsSpinBox->value()==-1), nStudentsSpinBox->value()); if(tmp) QMessageBox::information(this, tr("FET information"), tr("Activity added")); else QMessageBox::critical(this, tr("FET information"), tr("Activity NOT added - please report error")); } else{ //split activity if(minDayDistanceSpinBox->value()>0 && splitSpinBox->value()>gt.rules.nDaysPerWeek){ int t=LongTextMessageBox::largeConfirmation(this, tr("FET confirmation"), tr("Possible incorrect setting. Are you sure you want to add current activity? See details below:")+"\n\n"+ tr("You want to add a container activity split into more than the number of days per week and also add a constraint min days between activities." " This is a very bad practice from the way the algorithm of generation works (it slows down the generation and makes it harder to find a solution).")+ "\n\n"+ tr("The best way to add the activities would be:")+ "\n\n"+ tr("1. If you add 'force consecutive if same day', then couple extra activities in pairs to obtain a number of activities equal to the number of days per week" ". Example: 7 activities with duration 1 in a 5 days week, then transform into 5 activities with durations: 2,2,1,1,1 and add a single container activity with these 5 components" " (possibly raising the weight of added constraint min days between activities up to 100%)")+ "\n\n"+ tr("2. If you don't add 'force consecutive if same day', then add a larger activity splitted into a number of" " activities equal with the number of days per week and the remaining components into other larger splitted activity." " For example, suppose you need to add 7 activities with duration 1 in a 5 days week. Add 2 larger container activities," " first one splitted into 5 activities with duration 1 and second one splitted into 2 activities with duration 1" " (possibly raising the weight of added constraints min days between activities for each of the 2 containers up to 100%)")+ "\n\n"+ tr("Do you want to add current activities as they are now (not recommended) or cancel and edit them as instructed?") , tr("Yes"), tr("No"), QString(), 0, 1); if(t==1) return; } int totalduration; int durations[MAX_SPLIT_OF_AN_ACTIVITY]; bool active[MAX_SPLIT_OF_AN_ACTIVITY]; int nsplit=splitSpinBox->value(); totalduration=0; for(int i=0; i<nsplit; i++){ durations[i]=dur(i)->value(); active[i]=false; if(activ(i)->isChecked()) active[i]=true; totalduration+=durations[i]; } //the group id of this split activity and the id of the first partial activity //it is the maximum already existing id + 1 int firstactivityid=0; for(int i=0; i<gt.rules.activitiesList.size(); i++){ Activity* act=gt.rules.activitiesList[i]; if(act->id > firstactivityid) firstactivityid = act->id; } firstactivityid++; int minD=minDayDistanceSpinBox->value(); bool tmp=gt.rules.addSplitActivity(this, firstactivityid, firstactivityid, teachers_names, subject_name, activity_tags_names, students_names, nsplit, totalduration, durations, active, minD, weight, forceConsecutiveCheckBox->isChecked(), (nStudentsSpinBox->value()==-1), nStudentsSpinBox->value()); if(tmp){ if(minD>1 && weight<100.0){ SecondMinDaysDialog second(this, minD, weight); setParentAndOtherThings(&second, this); int code=second.exec(); if(code==QDialog::Accepted){ assert(second.weight>=0 && second.weight<=100.0); QList<int> acts; for(int i=0; i<nsplit; i++){ acts.append(firstactivityid+i); } TimeConstraint* c=new ConstraintMinDaysBetweenActivities(second.weight, forceConsecutiveCheckBox->isChecked(), nsplit, acts, minD-1); bool tmp=gt.rules.addTimeConstraint(c); assert(tmp); } } QMessageBox::information(this, tr("FET information"), tr("Split activity added." " Please note that FET currently cannot check for duplicates when adding split activities" ". It is advisable to check the statistics after adding all the activities")); } else QMessageBox::critical(this, tr("FET information"), tr("Split activity NOT added - error???")); } PlanningChanged::increasePlanningCommunicationSpinBox(); }
void ModifyActivityForm::ok() { //teachers QStringList teachers_names; if(selectedTeachersListWidget->count()<=0){ int t=QMessageBox::question(this, tr("FET question"), tr("Do you really want to have the activity without teacher(s)?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); if(t==QMessageBox::No) return; } else{ for(int i=0; i<selectedTeachersListWidget->count(); i++){ //assert(gt.rules.searchTeacher(selectedTeachersListWidget->item(i)->text())>=0); assert(teacherNamesSet.contains(selectedTeachersListWidget->item(i)->text())); teachers_names.append(selectedTeachersListWidget->item(i)->text()); } } //subject QString subject_name=subjectsComboBox->currentText(); /*int subject_index=gt.rules.searchSubject(subject_name); if(subject_index<0){*/ bool found=subjectNamesSet.contains(subject_name); if(!found){ QMessageBox::warning(this, tr("FET information"), tr("Invalid subject")); return; } //activity tag QStringList activity_tags_names; for(int i=0; i<selectedActivityTagsListWidget->count(); i++){ //assert(gt.rules.searchActivityTag(selectedActivityTagsListWidget->item(i)->text())>=0); assert(activityTagNamesSet.contains(selectedActivityTagsListWidget->item(i)->text())); activity_tags_names.append(selectedActivityTagsListWidget->item(i)->text()); } //students int numberOfStudents=0; QStringList students_names; if(selectedStudentsListWidget->count()<=0){ int t=QMessageBox::question(this, tr("FET question"), tr("Do you really want to have the activity without student set(s)?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); if(t==QMessageBox::No) return; } else{ for(int i=0; i<selectedStudentsListWidget->count(); i++){ //assert(gt.rules.searchStudentsSet(selectedStudentsListWidget->item(i)->text())!=NULL); /*assert(numberOfStudentsHash.contains(selectedStudentsListWidget->item(i)->text())); numberOfStudents+=numberOfStudentsHash.value(selectedStudentsListWidget->item(i)->text());*/ assert(gt.rules.permanentStudentsHash.contains(selectedStudentsListWidget->item(i)->text())); numberOfStudents+=gt.rules.permanentStudentsHash.value(selectedStudentsListWidget->item(i)->text())->numberOfStudents; students_names.append(selectedStudentsListWidget->item(i)->text()); } } /*int total_number_of_students=0; for(QStringList::Iterator it=students_names.begin(); it!=students_names.end(); it++){ StudentsSet* ss=gt.rules.searchStudentsSet(*it); assert(ss!=NULL); total_number_of_students+=ss->numberOfStudents; }*/ int total_number_of_students=numberOfStudents; int totalduration; int durations[MAX_SPLIT_OF_AN_ACTIVITY]; bool active[MAX_SPLIT_OF_AN_ACTIVITY]; int nsplit=splitSpinBox->value(); totalduration=0; for(int i=0; i<nsplit; i++){ durations[i]=dur(i)->value(); active[i]=activ(i)->isChecked(); totalduration+=durations[i]; } if(nStudentsSpinBox->value()==-1){ gt.rules.modifyActivity(this->_id, this->_activityGroupId, teachers_names, subject_name, activity_tags_names,students_names, nsplit, totalduration, durations, active, (nStudentsSpinBox->value()==-1), total_number_of_students); } else{ gt.rules.modifyActivity(this->_id, this->_activityGroupId, teachers_names, subject_name, activity_tags_names,students_names, nsplit, totalduration, durations, active, (nStudentsSpinBox->value()==-1), nStudentsSpinBox->value()); } PlanningChanged::increasePlanningCommunicationSpinBox(); this->accept(); }