Back to index

fet  5.18.0
constraintteachersintervalmaxdaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintteachersintervalmaxdaysperweekform.cpp  -  description
00003                              -------------------
00004     begin                : 2008
00005     copyright            : (C) 2008 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 "constraintteachersintervalmaxdaysperweekform.h"
00023 #include "addconstraintteachersintervalmaxdaysperweekform.h"
00024 #include "modifyconstraintteachersintervalmaxdaysperweekform.h"
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 ConstraintTeachersIntervalMaxDaysPerWeekForm::ConstraintTeachersIntervalMaxDaysPerWeekForm(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(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
00046 
00047        centerWidgetOnScreen(this);
00048        restoreFETDialogGeometry(this);
00049        
00050        this->filterChanged();
00051 }
00052 
00053 ConstraintTeachersIntervalMaxDaysPerWeekForm::~ConstraintTeachersIntervalMaxDaysPerWeekForm()
00054 {
00055        saveFETDialogGeometry(this);
00056 }
00057 
00058 bool ConstraintTeachersIntervalMaxDaysPerWeekForm::filterOk(TimeConstraint* ctr)
00059 {
00060        if(ctr->type==CONSTRAINT_TEACHERS_INTERVAL_MAX_DAYS_PER_WEEK){
00061               return true;
00062        }
00063        else{
00064               return false;
00065        }
00066 }
00067 
00068 void ConstraintTeachersIntervalMaxDaysPerWeekForm::filterChanged()
00069 {
00070        this->visibleConstraintsList.clear();
00071        constraintsListWidget->clear();
00072        for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
00073               TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
00074               if(filterOk(ctr)){
00075                      visibleConstraintsList.append(ctr);
00076                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00077               }
00078        }
00079 
00080        if(constraintsListWidget->count()>0)
00081               constraintsListWidget->setCurrentRow(0);
00082        else
00083               constraintChanged(-1);
00084 }
00085 
00086 void ConstraintTeachersIntervalMaxDaysPerWeekForm::constraintChanged(int index)
00087 {
00088        if(index<0){
00089               currentConstraintTextEdit->setPlainText("");
00090               return;
00091        }
00092        assert(index<this->visibleConstraintsList.size());
00093        TimeConstraint* ctr=this->visibleConstraintsList.at(index);
00094        assert(ctr!=NULL);
00095        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00096 }
00097 
00098 void ConstraintTeachersIntervalMaxDaysPerWeekForm::addConstraint()
00099 {
00100        AddConstraintTeachersIntervalMaxDaysPerWeekForm form(this);
00101        setParentAndOtherThings(&form, this);
00102        form.exec();
00103 
00104        filterChanged();
00105        
00106        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00107 }
00108 
00109 void ConstraintTeachersIntervalMaxDaysPerWeekForm::modifyConstraint()
00110 {
00111        int valv=constraintsListWidget->verticalScrollBar()->value();
00112        int valh=constraintsListWidget->horizontalScrollBar()->value();
00113 
00114        int i=constraintsListWidget->currentRow();
00115        if(i<0){
00116               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00117               return;
00118        }
00119        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00120 
00121        ModifyConstraintTeachersIntervalMaxDaysPerWeekForm form(this, (ConstraintTeachersIntervalMaxDaysPerWeek*)ctr);
00122        setParentAndOtherThings(&form, this);
00123        form.exec();
00124 
00125        filterChanged();
00126        
00127        constraintsListWidget->verticalScrollBar()->setValue(valv);
00128        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00129 
00130        if(i>=constraintsListWidget->count())
00131               i=constraintsListWidget->count()-1;
00132 
00133        if(i>=0)
00134               constraintsListWidget->setCurrentRow(i);
00135        else
00136               this->constraintChanged(-1);
00137 }
00138 
00139 void ConstraintTeachersIntervalMaxDaysPerWeekForm::removeConstraint()
00140 {
00141        int i=constraintsListWidget->currentRow();
00142        if(i<0){
00143               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00144               return;
00145        }
00146        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00147        QString s;
00148        s=tr("Remove constraint?");
00149        s+="\n\n";
00150        s+=ctr->getDetailedDescription(gt.rules);
00151        
00152        QListWidgetItem* item;
00153 
00154        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00155               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00156        case 0: // The user clicked the OK button or pressed Enter
00157               gt.rules.removeTimeConstraint(ctr);
00158               
00159               visibleConstraintsList.removeAt(i);
00160               constraintsListWidget->setCurrentRow(-1);
00161               item=constraintsListWidget->takeItem(i);
00162               delete item;
00163               
00164               break;
00165        case 1: // The user clicked the Cancel button or pressed Escape
00166               break;
00167        }
00168        
00169        if(i>=constraintsListWidget->count())
00170               i=constraintsListWidget->count()-1;
00171        if(i>=0)
00172               constraintsListWidget->setCurrentRow(i);
00173        else
00174               this->constraintChanged(-1);
00175 }