Back to index

fet  5.18.0
modifysubactivityform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifysubactivityform.cpp  -  description
00003                              -------------------
00004     begin                : Feb 9, 2005
00005     copyright            : (C) 2005 by Lalescu Liviu
00006     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "modifysubactivityform.h"
00019 #include "teacher.h"
00020 #include "subject.h"
00021 #include "studentsset.h"
00022 
00023 #include "activityplanningform.h"
00024 
00025 #include <QMessageBox>
00026 
00027 #include <QListWidget>
00028 #include <QAbstractItemView>
00029 #include <QScrollBar>
00030 
00031 #include <QPlainTextEdit>
00032 
00033 ModifySubactivityForm::ModifySubactivityForm(QWidget* parent, int id, int activityGroupId): QDialog(parent)
00034 {
00035        setupUi(this);
00036 
00037        allTeachersListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00038        selectedTeachersListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00039        allStudentsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00040        selectedStudentsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00041        allActivityTagsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00042        selectedActivityTagsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00043 
00044        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00045        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00046        connect(clearTeacherPushButton, SIGNAL(clicked()), this, SLOT(clearTeachers()));
00047        connect(clearStudentsPushButton, SIGNAL(clicked()), this, SLOT(clearStudents()));
00048        connect(allTeachersListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addTeacher()));
00049        connect(selectedTeachersListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeTeacher()));
00050        connect(allStudentsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addStudents()));
00051        connect(selectedStudentsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeStudents()));
00052        connect(clearActivityTagPushButton, SIGNAL(clicked()), this, SLOT(clearActivityTags()));
00053        connect(allActivityTagsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addActivityTag()));
00054        connect(selectedActivityTagsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeActivityTag()));
00055        connect(showYearsCheckBox, SIGNAL(toggled(bool)), this, SLOT(showYearsChanged()));
00056        connect(showGroupsCheckBox, SIGNAL(toggled(bool)), this, SLOT(showGroupsChanged()));
00057        connect(showSubgroupsCheckBox, SIGNAL(toggled(bool)), this, SLOT(showSubgroupsChanged()));
00058        connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
00059 
00060        centerWidgetOnScreen(this);
00061        restoreFETDialogGeometry(this);
00062 
00063        QSize tmp3=subjectsComboBox->minimumSizeHint();
00064        Q_UNUSED(tmp3);
00065        
00066        int splitIndex=0;
00067        int nSplit=0;
00068        bool found=false;
00069        
00070        this->_id=id;
00071        this->_activityGroupId=activityGroupId;
00072        for(int i=0; i<gt.rules.activitiesList.size(); i++){
00073               Activity* act=gt.rules.activitiesList[i];
00074               if(act->activityGroupId==this->_activityGroupId && act->id==this->_id){
00075                      this->_activity=act;
00076                      splitIndex++;
00077                      nSplit++;
00078                      found=true;
00079               }
00080               else if(this->_activityGroupId!=0 && act->activityGroupId!=0 && act->activityGroupId==this->_activityGroupId){
00081                      if(!found)
00082                             splitIndex++;
00083                      nSplit++;
00084               }
00085        }
00086        
00087        crtTextLabel->setText(tr("Current subactivity has split index %1 out of %2").arg(splitIndex).arg(nSplit)+
00088         "<br />"+tr("The current data applies only to this subactivity"));
00089 
00090        this->_teachers=this->_activity->teachersNames;
00091        this->_subject = this->_activity->subjectName;
00092        this->_activityTags = this->_activity->activityTagsNames;
00093        this->_students=this->_activity->studentsNames;
00094        
00095        durationSpinBox->setMaximum(gt.rules.nHoursPerDay);
00096        durationSpinBox->setValue(this->_activity->duration);
00097        activeCheckBox->setChecked(this->_activity->active);
00098 
00099        nStudentsSpinBox->setMinimum(-1);
00100        nStudentsSpinBox->setMaximum(MAX_ROOM_CAPACITY);
00101        nStudentsSpinBox->setValue(-1);
00102        
00103        if(this->_activity->computeNTotalStudents==false)
00104               nStudentsSpinBox->setValue(this->_activity->nTotalStudents);
00105        
00106        updateStudentsListWidget();
00107        updateTeachersListWidget();
00108        updateSubjectsComboBox();
00109        updateActivityTagsListWidget();
00110 
00111        selectedStudentsListWidget->clear();
00112        for(QStringList::Iterator it=this->_students.begin(); it!=this->_students.end(); it++)
00113               selectedStudentsListWidget->addItem(*it);
00114        
00115        okPushButton->setDefault(true);
00116        okPushButton->setFocus();
00117 }
00118 
00119 ModifySubactivityForm::~ModifySubactivityForm()
00120 {
00121        saveFETDialogGeometry(this);
00122 }
00123 
00124 void ModifySubactivityForm::updateTeachersListWidget()
00125 {
00126        allTeachersListWidget->clear();
00127        for(int i=0; i<gt.rules.teachersList.size(); i++){
00128               Teacher* tch=gt.rules.teachersList[i];
00129               allTeachersListWidget->addItem(tch->name);
00130        }
00131               
00132        selectedTeachersListWidget->clear();
00133        for(QStringList::Iterator it=this->_teachers.begin(); it!=this->_teachers.end(); it++)
00134               selectedTeachersListWidget->addItem(*it);
00135 }
00136 
00137 void ModifySubactivityForm::addTeacher()
00138 {
00139        if(allTeachersListWidget->currentRow()<0 || allTeachersListWidget->currentRow()>=allTeachersListWidget->count())
00140               return;
00141 
00142        for(int i=0; i<selectedTeachersListWidget->count(); i++)
00143               if(selectedTeachersListWidget->item(i)->text()==allTeachersListWidget->currentItem()->text())
00144                      return;
00145 
00146        selectedTeachersListWidget->addItem(allTeachersListWidget->currentItem()->text());
00147        selectedTeachersListWidget->setCurrentRow(selectedTeachersListWidget->count()-1);
00148 }
00149 
00150 void ModifySubactivityForm::removeTeacher()
00151 {
00152        if(selectedTeachersListWidget->count()<=0 || selectedTeachersListWidget->currentRow()<0 ||
00153         selectedTeachersListWidget->currentRow()>=selectedTeachersListWidget->count())
00154               return;
00155 
00156        int i=selectedTeachersListWidget->currentRow();
00157        selectedTeachersListWidget->setCurrentRow(-1);
00158        QListWidgetItem* item=selectedTeachersListWidget->takeItem(i);
00159        delete item;
00160        if(i<selectedTeachersListWidget->count())
00161               selectedTeachersListWidget->setCurrentRow(i);
00162        else
00163               selectedTeachersListWidget->setCurrentRow(selectedTeachersListWidget->count()-1);
00164 }
00165 
00166 void ModifySubactivityForm::addStudents()
00167 {
00168        if(allStudentsListWidget->currentRow()<0 || allStudentsListWidget->currentRow()>=allStudentsListWidget->count())
00169               return;
00170 
00171        assert(canonicalStudentsSetsNames.count()==allStudentsListWidget->count());
00172        QString sn=canonicalStudentsSetsNames.at(allStudentsListWidget->currentRow());
00173 
00174        for(int i=0; i<selectedStudentsListWidget->count(); i++)
00175               if(selectedStudentsListWidget->item(i)->text()==sn)
00176                      return;
00177 
00178        selectedStudentsListWidget->addItem(sn);
00179        selectedStudentsListWidget->setCurrentRow(selectedStudentsListWidget->count()-1);
00180 }
00181 
00182 void ModifySubactivityForm::removeStudents()
00183 {
00184        if(selectedStudentsListWidget->count()<=0 || selectedStudentsListWidget->currentRow()<0 ||
00185         selectedStudentsListWidget->currentRow()>=selectedStudentsListWidget->count())
00186               return;
00187 
00188        int i=selectedStudentsListWidget->currentRow();
00189        selectedStudentsListWidget->setCurrentRow(-1);
00190        QListWidgetItem* item=selectedStudentsListWidget->takeItem(i);
00191        delete item;
00192        if(i<selectedStudentsListWidget->count())
00193               selectedStudentsListWidget->setCurrentRow(i);
00194        else
00195               selectedStudentsListWidget->setCurrentRow(selectedStudentsListWidget->count()-1);
00196 }
00197 
00198 void ModifySubactivityForm::addActivityTag()
00199 {
00200        if(allActivityTagsListWidget->currentRow()<0 || allActivityTagsListWidget->currentRow()>=allActivityTagsListWidget->count())
00201               return;
00202 
00203        for(int i=0; i<selectedActivityTagsListWidget->count(); i++)
00204               if(selectedActivityTagsListWidget->item(i)->text()==allActivityTagsListWidget->currentItem()->text())
00205                      return;
00206 
00207        selectedActivityTagsListWidget->addItem(allActivityTagsListWidget->currentItem()->text());
00208        selectedActivityTagsListWidget->setCurrentRow(selectedActivityTagsListWidget->count()-1);
00209 }
00210 
00211 void ModifySubactivityForm::removeActivityTag()
00212 {
00213        if(selectedActivityTagsListWidget->count()<=0 || selectedActivityTagsListWidget->currentRow()<0 ||
00214         selectedActivityTagsListWidget->currentRow()>=selectedActivityTagsListWidget->count())
00215               return;
00216 
00217        int i=selectedActivityTagsListWidget->currentRow();
00218        selectedActivityTagsListWidget->setCurrentRow(-1);
00219        QListWidgetItem* item=selectedActivityTagsListWidget->takeItem(i);
00220        delete item;
00221        if(i<selectedActivityTagsListWidget->count())
00222               selectedActivityTagsListWidget->setCurrentRow(i);
00223        else
00224               selectedActivityTagsListWidget->setCurrentRow(selectedActivityTagsListWidget->count()-1);
00225 }
00226 
00227 void ModifySubactivityForm::updateSubjectsComboBox()
00228 {
00229        int i=0, j=-1;
00230        subjectsComboBox->clear();
00231        for(int k=0; k<gt.rules.subjectsList.size(); k++, i++){
00232               Subject* sbj=gt.rules.subjectsList[k];
00233               subjectsComboBox->addItem(sbj->name);
00234               if(sbj->name==this->_subject)
00235                      j=i;
00236        }
00237        assert(j!=-1);
00238        subjectsComboBox->setCurrentIndex(j);
00239 }
00240 
00241 void ModifySubactivityForm::updateActivityTagsListWidget()
00242 {
00243        allActivityTagsListWidget->clear();
00244        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00245               ActivityTag* at=gt.rules.activityTagsList[i];
00246               allActivityTagsListWidget->addItem(at->name);
00247        }
00248               
00249        selectedActivityTagsListWidget->clear();
00250        for(QStringList::Iterator it=this->_activityTags.begin(); it!=this->_activityTags.end(); it++)
00251               selectedActivityTagsListWidget->addItem(*it);
00252 }
00253 
00254 void ModifySubactivityForm::showYearsChanged()
00255 {
00256        updateStudentsListWidget();
00257 }
00258 
00259 void ModifySubactivityForm::showGroupsChanged()
00260 {
00261        updateStudentsListWidget();
00262 }
00263 
00264 void ModifySubactivityForm::showSubgroupsChanged()
00265 {
00266        updateStudentsListWidget();
00267 }
00268 
00269 void ModifySubactivityForm::updateStudentsListWidget()
00270 {
00271        const int INDENT=2;
00272 
00273        bool showYears=showYearsCheckBox->isChecked();
00274        bool showGroups=showGroupsCheckBox->isChecked();
00275        bool showSubgroups=showSubgroupsCheckBox->isChecked();
00276 
00277        allStudentsListWidget->clear();
00278        canonicalStudentsSetsNames.clear();
00279        for(int i=0; i<gt.rules.yearsList.size(); i++){
00280               StudentsYear* sty=gt.rules.yearsList[i];
00281               if(showYears){
00282                      allStudentsListWidget->addItem(sty->name);
00283                      canonicalStudentsSetsNames.append(sty->name);
00284               }
00285               for(int j=0; j<sty->groupsList.size(); j++){
00286                      StudentsGroup* stg=sty->groupsList[j];
00287                      if(showGroups){
00288                             QString begin=QString("");
00289                             QString end=QString("");
00290                             begin=QString(INDENT, ' ');
00291                             allStudentsListWidget->addItem(begin+stg->name+end);
00292                             canonicalStudentsSetsNames.append(stg->name);
00293                      }
00294                      for(int k=0; k<stg->subgroupsList.size(); k++){
00295                             StudentsSubgroup* sts=stg->subgroupsList[k];
00296                             if(showSubgroups){
00297                                    QString begin=QString("");
00298                                    QString end=QString("");
00299                                    begin=QString(2*INDENT, ' ');
00300                                    allStudentsListWidget->addItem(begin+sts->name+end);
00301                                    canonicalStudentsSetsNames.append(sts->name);
00302                             }
00303                      }
00304               }
00305        }
00306 
00307        int q=allStudentsListWidget->verticalScrollBar()->minimum();
00308        allStudentsListWidget->verticalScrollBar()->setValue(q);
00309 }
00310 
00311 void ModifySubactivityForm::cancel()
00312 {
00313        this->reject();
00314 }
00315 
00316 void ModifySubactivityForm::ok()
00317 {
00318        //teachers
00319        QStringList teachers_names;
00320        if(selectedTeachersListWidget->count()<=0){
00321               int t=QMessageBox::question(this, tr("FET question"),
00322                tr("Do you really want to have the subactivity without teacher(s)?"),
00323                QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
00324 
00325               if(t==QMessageBox::No)
00326                      return;
00327        }
00328        else{
00329               for(int i=0; i<selectedTeachersListWidget->count(); i++){
00330                      assert(gt.rules.searchTeacher(selectedTeachersListWidget->item(i)->text())>=0);
00331                      teachers_names.append(selectedTeachersListWidget->item(i)->text());
00332               }
00333        }
00334 
00335        //subject
00336        QString subject_name=subjectsComboBox->currentText();
00337        int subject_index=gt.rules.searchSubject(subject_name);
00338        if(subject_index<0){
00339               QMessageBox::warning(this, tr("FET information"),
00340                      tr("Invalid subject"));
00341               return;
00342        }
00343 
00344        //activity tag
00345        QStringList activity_tags_names;
00346        for(int i=0; i<selectedActivityTagsListWidget->count(); i++){
00347               assert(gt.rules.searchActivityTag(selectedActivityTagsListWidget->item(i)->text())>=0);
00348               activity_tags_names.append(selectedActivityTagsListWidget->item(i)->text());
00349        }
00350 
00351        //students
00352        QStringList students_names;
00353        if(selectedStudentsListWidget->count()<=0){
00354               int t=QMessageBox::question(this, tr("FET question"),
00355                tr("Do you really want to have the subactivity without student set(s)?"),
00356                 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
00357 
00358               if(t==QMessageBox::No)
00359                      return;
00360        }
00361        else{
00362               for(int i=0; i<selectedStudentsListWidget->count(); i++){
00363                      assert(gt.rules.searchStudentsSet(selectedStudentsListWidget->item(i)->text())!=NULL);
00364                      students_names.append(selectedStudentsListWidget->item(i)->text());
00365               }
00366        }
00367 
00368        int total_number_of_students=0;
00369        for(QStringList::Iterator it=students_names.begin(); it!=students_names.end(); it++){
00370               StudentsSet* ss=gt.rules.searchStudentsSet(*it);
00371               total_number_of_students+=ss->numberOfStudents;
00372        }
00373 
00374        if(nStudentsSpinBox->value()==-1){
00375               gt.rules.modifySubactivity(this->_id, this->_activityGroupId, teachers_names, subject_name,
00376                activity_tags_names,students_names, durationSpinBox->value(), activeCheckBox->isChecked(),
00377                (nStudentsSpinBox->value()==-1), total_number_of_students);
00378        }
00379        else{
00380               gt.rules.modifySubactivity(this->_id, this->_activityGroupId, teachers_names, subject_name,
00381                activity_tags_names,students_names, durationSpinBox->value(), activeCheckBox->isChecked(),
00382                (nStudentsSpinBox->value()==-1), nStudentsSpinBox->value());
00383        }
00384        
00385        PlanningChanged::increasePlanningCommunicationSpinBox();
00386        
00387        this->accept();
00388 }
00389 
00390 void ModifySubactivityForm::clearTeachers()
00391 {
00392        selectedTeachersListWidget->clear();
00393 }
00394 
00395 void ModifySubactivityForm::clearStudents()
00396 {
00397        selectedStudentsListWidget->clear();
00398 }
00399 
00400 void ModifySubactivityForm::clearActivityTags()
00401 {
00402        selectedActivityTagsListWidget->clear();
00403 }
00404 
00405 void ModifySubactivityForm::help()
00406 {
00407        QString s;
00408        
00409        s+=tr("Abbreviations in this dialog:");
00410        s+="\n\n";
00411        s+=tr("'Students' (the text near the spin box), means 'Number of students (-1 for automatic)'");
00412        s+="\n";
00413        
00414        //show the message in a dialog
00415        QDialog dialog(this);
00416        
00417        dialog.setWindowTitle(tr("FET - help on modifying subactivity(ies)"));
00418 
00419        QVBoxLayout* vl=new QVBoxLayout(&dialog);
00420        QPlainTextEdit* te=new QPlainTextEdit();
00421        te->setPlainText(s);
00422        te->setReadOnly(true);
00423        QPushButton* pb=new QPushButton(tr("OK"));
00424 
00425        QHBoxLayout* hl=new QHBoxLayout(0);
00426        hl->addStretch(1);
00427        hl->addWidget(pb);
00428 
00429        vl->addWidget(te);
00430        vl->addLayout(hl);
00431        connect(pb, SIGNAL(clicked()), &dialog, SLOT(close()));
00432 
00433        dialog.resize(600,470);
00434        centerWidgetOnScreen(&dialog);
00435 
00436        setParentAndOtherThings(&dialog, this);
00437        dialog.exec();
00438 }