Back to index

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