Back to index

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