Back to index

fet  5.18.0
constraintstudentssetactivitytagmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintstudentssetactivitytagmaxhoursdailyform.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 "helponimperfectconstraints.h"
00023 
00024 #include "constraintstudentssetactivitytagmaxhoursdailyform.h"
00025 #include "addconstraintstudentssetactivitytagmaxhoursdailyform.h"
00026 #include "modifyconstraintstudentssetactivitytagmaxhoursdailyform.h"
00027 
00028 #include <QListWidget>
00029 #include <QScrollBar>
00030 #include <QAbstractItemView>
00031 
00032 ConstraintStudentsSetActivityTagMaxHoursDailyForm::ConstraintStudentsSetActivityTagMaxHoursDailyForm(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(studentsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00048        connect(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
00049        connect(activityTagsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00050        connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
00051 
00052        centerWidgetOnScreen(this);
00053        restoreFETDialogGeometry(this);
00054 
00055        QSize tmp2=studentsComboBox->minimumSizeHint();
00056        Q_UNUSED(tmp2);
00057        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00058        Q_UNUSED(tmp4);
00059        
00060        studentsComboBox->addItem("");
00061 
00062        for(int i=0; i<gt.rules.yearsList.size(); i++){
00063               StudentsYear* sty=gt.rules.yearsList[i];
00064               studentsComboBox->addItem(sty->name);
00065               for(int j=0; j<sty->groupsList.size(); j++){
00066                      StudentsGroup* stg=sty->groupsList[j];
00067                      studentsComboBox->addItem(stg->name);
00068                      for(int k=0; k<stg->subgroupsList.size(); k++){
00069                             StudentsSubgroup* sts=stg->subgroupsList[k];
00070                             studentsComboBox->addItem(sts->name);
00071                      }
00072               }
00073        }
00074        
00075        activityTagsComboBox->clear();
00076        activityTagsComboBox->addItem("");
00077        foreach(ActivityTag* at, gt.rules.activityTagsList)
00078               activityTagsComboBox->addItem(at->name);
00079 
00080        this->filterChanged();
00081 }
00082 
00083 ConstraintStudentsSetActivityTagMaxHoursDailyForm::~ConstraintStudentsSetActivityTagMaxHoursDailyForm()
00084 {
00085        saveFETDialogGeometry(this);
00086 }
00087 
00088 bool ConstraintStudentsSetActivityTagMaxHoursDailyForm::filterOk(TimeConstraint* ctr)
00089 {
00090        if(ctr->type==CONSTRAINT_STUDENTS_SET_ACTIVITY_TAG_MAX_HOURS_DAILY){
00091               ConstraintStudentsSetActivityTagMaxHoursDaily* c=(ConstraintStudentsSetActivityTagMaxHoursDaily*) ctr;
00092               return (c->students==studentsComboBox->currentText() || studentsComboBox->currentText()=="") 
00093                &&
00094                (c->activityTagName==activityTagsComboBox->currentText() || activityTagsComboBox->currentText()=="");
00095        }
00096        else
00097               return false;
00098 }
00099 
00100 void ConstraintStudentsSetActivityTagMaxHoursDailyForm::filterChanged()
00101 {
00102        this->visibleConstraintsList.clear();
00103        constraintsListWidget->clear();
00104        for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
00105               TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
00106               if(filterOk(ctr)){
00107                      visibleConstraintsList.append(ctr);
00108                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00109               }
00110        }
00111        
00112        if(constraintsListWidget->count()>0)
00113               constraintsListWidget->setCurrentRow(0);
00114        else
00115               this->constraintChanged(-1);
00116 }
00117 
00118 void ConstraintStudentsSetActivityTagMaxHoursDailyForm::constraintChanged(int index)
00119 {
00120        if(index<0){
00121               currentConstraintTextEdit->setPlainText("");
00122               return;
00123        }
00124        assert(index<this->visibleConstraintsList.size());
00125        TimeConstraint* ctr=this->visibleConstraintsList.at(index);
00126        assert(ctr!=NULL);
00127        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00128 }
00129 
00130 void ConstraintStudentsSetActivityTagMaxHoursDailyForm::addConstraint()
00131 {
00132        AddConstraintStudentsSetActivityTagMaxHoursDailyForm form(this);
00133        setParentAndOtherThings(&form, this);
00134        form.exec();
00135 
00136        filterChanged();
00137        
00138        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00139 }
00140 
00141 void ConstraintStudentsSetActivityTagMaxHoursDailyForm::modifyConstraint()
00142 {
00143        int valv=constraintsListWidget->verticalScrollBar()->value();
00144        int valh=constraintsListWidget->horizontalScrollBar()->value();
00145 
00146        int i=constraintsListWidget->currentRow();
00147        if(i<0){
00148               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00149               return;
00150        }
00151        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00152 
00153        ModifyConstraintStudentsSetActivityTagMaxHoursDailyForm form(this, (ConstraintStudentsSetActivityTagMaxHoursDaily*)ctr);
00154        setParentAndOtherThings(&form, this);
00155        form.exec();
00156 
00157        filterChanged();
00158        
00159        constraintsListWidget->verticalScrollBar()->setValue(valv);
00160        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00161 
00162        if(i>=constraintsListWidget->count())
00163               i=constraintsListWidget->count()-1;
00164 
00165        if(i>=0)
00166               constraintsListWidget->setCurrentRow(i);
00167        else
00168               this->constraintChanged(-1);
00169 }
00170 
00171 void ConstraintStudentsSetActivityTagMaxHoursDailyForm::removeConstraint()
00172 {
00173        int i=constraintsListWidget->currentRow();
00174        if(i<0){
00175               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00176               return;
00177        }
00178        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00179        QString s;
00180        s=tr("Remove constraint?");
00181        s+="\n\n";
00182        s+=ctr->getDetailedDescription(gt.rules);
00183        
00184        QListWidgetItem* item;
00185 
00186        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00187               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00188        case 0: // The user clicked the OK button or pressed Enter
00189               gt.rules.removeTimeConstraint(ctr);
00190               
00191               visibleConstraintsList.removeAt(i);
00192               constraintsListWidget->setCurrentRow(-1);
00193               item=constraintsListWidget->takeItem(i);
00194               delete item;
00195               
00196               break;
00197        case 1: // The user clicked the Cancel button or pressed Escape
00198               break;
00199        }
00200        
00201        if(i>=constraintsListWidget->count())
00202               i=constraintsListWidget->count()-1;
00203        if(i>=0)
00204               constraintsListWidget->setCurrentRow(i);
00205        else
00206               this->constraintChanged(-1);
00207 }
00208 
00209 void ConstraintStudentsSetActivityTagMaxHoursDailyForm::help()
00210 {
00211        HelpOnImperfectConstraints::help(this);
00212 }