Back to index

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