Back to index

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