Back to index

fet  5.18.0
constraintstudentssetmaxgapsperdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintstudentssetmaxgapsperdayform.cpp  -  description
00003                              -------------------
00004     begin                : 2009
00005     copyright            : (C) 2009 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 <QMessageBox>
00019 
00020 #include "helponimperfectconstraints.h"
00021 
00022 #include "longtextmessagebox.h"
00023 
00024 #include "constraintstudentssetmaxgapsperdayform.h"
00025 #include "addconstraintstudentssetmaxgapsperdayform.h"
00026 #include "modifyconstraintstudentssetmaxgapsperdayform.h"
00027 
00028 #include <QListWidget>
00029 #include <QScrollBar>
00030 #include <QAbstractItemView>
00031 
00032 ConstraintStudentsSetMaxGapsPerDayForm::ConstraintStudentsSetMaxGapsPerDayForm(QWidget* parent): QDialog(parent)
00033 {
00034        setupUi(this);
00035 
00036        currentConstraintTextEdit->setReadOnly(true);
00037 
00038        modifyConstraintPushButton->setDefault(true);
00039 
00040        constraintsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00041 
00042        connect(constraintsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(constraintChanged(int)));
00043        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
00044        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00045        connect(removeConstraintPushButton, SIGNAL(clicked()), this, SLOT(removeConstraint()));
00046        connect(modifyConstraintPushButton, SIGNAL(clicked()), this, SLOT(modifyConstraint()));
00047        connect(studentsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00048        connect(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
00049        connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
00050 
00051        centerWidgetOnScreen(this);
00052        restoreFETDialogGeometry(this);
00053 
00054        QSize tmp2=studentsComboBox->minimumSizeHint();
00055        Q_UNUSED(tmp2);
00056        
00057        studentsComboBox->addItem("");
00058 
00059        for(int i=0; i<gt.rules.yearsList.size(); i++){
00060               StudentsYear* sty=gt.rules.yearsList[i];
00061               studentsComboBox->addItem(sty->name);
00062               for(int j=0; j<sty->groupsList.size(); j++){
00063                      StudentsGroup* stg=sty->groupsList[j];
00064                      studentsComboBox->addItem(stg->name);
00065                      for(int k=0; k<stg->subgroupsList.size(); k++){
00066                             StudentsSubgroup* sts=stg->subgroupsList[k];
00067                             studentsComboBox->addItem(sts->name);
00068                      }
00069               }
00070        }
00071 
00072        this->filterChanged();
00073 }
00074 
00075 ConstraintStudentsSetMaxGapsPerDayForm::~ConstraintStudentsSetMaxGapsPerDayForm()
00076 {
00077        saveFETDialogGeometry(this);
00078 }
00079 
00080 bool ConstraintStudentsSetMaxGapsPerDayForm::filterOk(TimeConstraint* ctr)
00081 {
00082        if(ctr->type==CONSTRAINT_STUDENTS_SET_MAX_GAPS_PER_DAY){
00083               ConstraintStudentsSetMaxGapsPerDay* c=(ConstraintStudentsSetMaxGapsPerDay*) ctr;
00084               return c->students==studentsComboBox->currentText() || studentsComboBox->currentText()=="";
00085        }
00086        else
00087               return false;
00088 }
00089 
00090 void ConstraintStudentsSetMaxGapsPerDayForm::filterChanged()
00091 {
00092        this->visibleConstraintsList.clear();
00093        constraintsListWidget->clear();
00094        for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
00095               TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
00096               if(filterOk(ctr)){
00097                      visibleConstraintsList.append(ctr);
00098                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00099               }
00100        }
00101 
00102        if(constraintsListWidget->count()>0)
00103               constraintsListWidget->setCurrentRow(0);
00104        else
00105               this->constraintChanged(-1);
00106 }
00107 
00108 void ConstraintStudentsSetMaxGapsPerDayForm::constraintChanged(int index)
00109 {
00110        if(index<0){
00111               currentConstraintTextEdit->setPlainText("");
00112               return;
00113        }
00114        assert(index<this->visibleConstraintsList.size());
00115        TimeConstraint* ctr=this->visibleConstraintsList.at(index);
00116        assert(ctr!=NULL);
00117        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00118 }
00119 
00120 void ConstraintStudentsSetMaxGapsPerDayForm::addConstraint()
00121 {
00122        AddConstraintStudentsSetMaxGapsPerDayForm form(this);
00123        setParentAndOtherThings(&form, this);
00124        form.exec();
00125 
00126        filterChanged();
00127        
00128        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00129 }
00130 
00131 void ConstraintStudentsSetMaxGapsPerDayForm::modifyConstraint()
00132 {
00133        int valv=constraintsListWidget->verticalScrollBar()->value();
00134        int valh=constraintsListWidget->horizontalScrollBar()->value();
00135 
00136        int i=constraintsListWidget->currentRow();
00137        if(i<0){
00138               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00139               return;
00140        }
00141        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00142 
00143        ModifyConstraintStudentsSetMaxGapsPerDayForm form(this, (ConstraintStudentsSetMaxGapsPerDay*)ctr);
00144        setParentAndOtherThings(&form, this);
00145        form.exec();
00146 
00147        filterChanged();
00148        
00149        constraintsListWidget->verticalScrollBar()->setValue(valv);
00150        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00151 
00152        if(i>=constraintsListWidget->count())
00153               i=constraintsListWidget->count()-1;
00154 
00155        if(i>=0)
00156               constraintsListWidget->setCurrentRow(i);
00157        else
00158               this->constraintChanged(-1);
00159 }
00160 
00161 void ConstraintStudentsSetMaxGapsPerDayForm::removeConstraint()
00162 {
00163        int i=constraintsListWidget->currentRow();
00164        if(i<0){
00165               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00166               return;
00167        }
00168        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00169        QString s;
00170        s=tr("Remove constraint?");
00171        s+="\n\n";
00172        s+=ctr->getDetailedDescription(gt.rules);
00173        
00174        QListWidgetItem* item;
00175 
00176        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00177               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00178        case 0: // The user clicked the OK button or pressed Enter
00179               gt.rules.removeTimeConstraint(ctr);
00180               
00181               visibleConstraintsList.removeAt(i);
00182               constraintsListWidget->setCurrentRow(-1);
00183               item=constraintsListWidget->takeItem(i);
00184               delete item;
00185               
00186               break;
00187        case 1: // The user clicked the Cancel button or pressed Escape
00188               break;
00189        }
00190        
00191        if(i>=constraintsListWidget->count())
00192               i=constraintsListWidget->count()-1;
00193        if(i>=0)
00194               constraintsListWidget->setCurrentRow(i);
00195        else
00196               this->constraintChanged(-1);
00197 }
00198 
00199 void ConstraintStudentsSetMaxGapsPerDayForm::help()
00200 {
00201        HelpOnImperfectConstraints::help(this);
00202 }