Back to index

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