Back to index

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