Back to index

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