Back to index

fet  5.18.0
constraintsubactivitiespreferredtimeslotsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintsubactivitiespreferredtimeslotsform.cpp  -  description
00003                              -------------------
00004     begin                : 2008
00005     copyright            : (C) 2008 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 "constraintsubactivitiespreferredtimeslotsform.h"
00023 #include "addconstraintsubactivitiespreferredtimeslotsform.h"
00024 #include "modifyconstraintsubactivitiespreferredtimeslotsform.h"
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 ConstraintSubactivitiesPreferredTimeSlotsForm::ConstraintSubactivitiesPreferredTimeSlotsForm(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(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
00047 
00048        centerWidgetOnScreen(this);
00049        restoreFETDialogGeometry(this);
00050        
00051        this->refreshConstraintsListWidget();
00052 }
00053 
00054 ConstraintSubactivitiesPreferredTimeSlotsForm::~ConstraintSubactivitiesPreferredTimeSlotsForm()
00055 {
00056        saveFETDialogGeometry(this);
00057 }
00058 
00059 void ConstraintSubactivitiesPreferredTimeSlotsForm::refreshConstraintsListWidget()
00060 {
00061        this->visibleConstraintsList.clear();
00062        constraintsListWidget->clear();
00063        for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
00064               TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
00065               if(filterOk(ctr)){
00066                      QString s;
00067                      s=ctr->getDescription(gt.rules);
00068                      visibleConstraintsList.append(ctr);
00069                      constraintsListWidget->addItem(s);
00070               }
00071        }
00072 
00073        if(constraintsListWidget->count()>0)
00074               constraintsListWidget->setCurrentRow(0);
00075        else
00076               this->constraintChanged(-1);
00077 }
00078 
00079 bool ConstraintSubactivitiesPreferredTimeSlotsForm::filterOk(TimeConstraint* ctr)
00080 {
00081        if(ctr->type==CONSTRAINT_SUBACTIVITIES_PREFERRED_TIME_SLOTS)
00082               return true;
00083        else
00084               return false;
00085 }
00086 
00087 void ConstraintSubactivitiesPreferredTimeSlotsForm::constraintChanged(int index)
00088 {
00089        if(index<0){
00090               currentConstraintTextEdit->setPlainText("");
00091               return;
00092        }
00093        QString s;
00094        assert(index<this->visibleConstraintsList.size());
00095        TimeConstraint* ctr=this->visibleConstraintsList.at(index);
00096        assert(ctr!=NULL);
00097        s=ctr->getDetailedDescription(gt.rules);
00098        currentConstraintTextEdit->setPlainText(s);
00099 }
00100 
00101 void ConstraintSubactivitiesPreferredTimeSlotsForm::addConstraint()
00102 {
00103        AddConstraintSubactivitiesPreferredTimeSlotsForm form(this);
00104        setParentAndOtherThings(&form, this);
00105        form.exec();
00106 
00107        this->refreshConstraintsListWidget();
00108        
00109        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00110 }
00111 
00112 void ConstraintSubactivitiesPreferredTimeSlotsForm::modifyConstraint()
00113 {
00114        int valv=constraintsListWidget->verticalScrollBar()->value();
00115        int valh=constraintsListWidget->horizontalScrollBar()->value();
00116 
00117        int i=constraintsListWidget->currentRow();
00118        if(i<0){
00119               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00120               return;
00121        }
00122        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00123 
00124        ModifyConstraintSubactivitiesPreferredTimeSlotsForm form(this, (ConstraintSubactivitiesPreferredTimeSlots*)ctr);
00125        setParentAndOtherThings(&form, this);
00126        form.exec();
00127 
00128        this->refreshConstraintsListWidget();
00129        
00130        constraintsListWidget->verticalScrollBar()->setValue(valv);
00131        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00132 
00133        if(i>=constraintsListWidget->count())
00134               i=constraintsListWidget->count()-1;
00135 
00136        if(i>=0)
00137               constraintsListWidget->setCurrentRow(i);
00138        else
00139               this->constraintChanged(-1);
00140 }
00141 
00142 void ConstraintSubactivitiesPreferredTimeSlotsForm::removeConstraint()
00143 {
00144        int i=constraintsListWidget->currentRow();
00145        if(i<0){
00146               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00147               return;
00148        }
00149        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00150        QString s;
00151        s=tr("Remove constraint?");
00152        s+="\n\n";
00153        s+=ctr->getDetailedDescription(gt.rules);
00154        
00155        QListWidgetItem* item;
00156 
00157        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00158               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00159        case 0: // The user clicked the OK button or pressed Enter
00160               gt.rules.removeTimeConstraint(ctr);
00161               
00162               visibleConstraintsList.removeAt(i);
00163               constraintsListWidget->setCurrentRow(-1);
00164               item=constraintsListWidget->takeItem(i);
00165               delete item;
00166               
00167               break;
00168        case 1: // The user clicked the Cancel button or pressed Escape
00169               break;
00170        }
00171 
00172        if(i>=constraintsListWidget->count())
00173               i=constraintsListWidget->count()-1;
00174        if(i>=0)
00175               constraintsListWidget->setCurrentRow(i);
00176        else
00177               this->constraintChanged(-1);
00178 }
00179 
00180 void ConstraintSubactivitiesPreferredTimeSlotsForm::help()
00181 {
00182        LongTextMessageBox::largeInformation(this, tr("FET help"), tr(
00183         "This constraint is used to specify that for some components of a type of"
00184        " activities, for instance for Mathematics activities, you need that from say 4-5"
00185        " per week, at least the first 2 to be early (say in the first 4 hours).")
00186        +"\n\n"+
00187        tr(
00188        "This is simple: just add 2 constraints of this type, with the component"
00189        " number 1, (then 2) and the corresponding subject (you can also"
00190        " define teacher, students set and activity tag, of course)."
00191         )
00192         +"\n\n"+
00193         tr("Note: if you have Maths with 4 and 5 splits and want to constrain 2 subactivities for those with 4 per week and 3 subactivities"
00194         " for those with 5 per week, you can add constraints only for Maths with components 3, 4 and 5 (nice trick)")
00195         +"\n\n"+
00196         tr("Note: if an activity does not belong to a larger group (is a single activity),"
00197         " it is considered to have component number 1. As an advice, if you have activities of say Biology splitted into 1"
00198         " or 2 per week and want to constrain only one component if there are 2 per week, add a constraint for Biology with component number=2")
00199         +"\n\n"+
00200         tr("Note: if a teacher or a students set cannot have lessons in some slots because of this constraint, gaps will be counted (if you have max gaps constraints)"
00201          ". So be careful if you add this constraint for all sub-activities, for only a teacher or for only a students set"));
00202 }