Back to index

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