Back to index

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