Back to index

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