Back to index

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