Back to index

fet  5.18.0
constraintstudentssethomeroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintstudentssethomeroomform.cpp  -  description
00003                              -------------------
00004     begin                : Apr 8, 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 "constraintstudentssethomeroomform.h"
00023 #include "addconstraintstudentssethomeroomform.h"
00024 #include "modifyconstraintstudentssethomeroomform.h"
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 ConstraintStudentsSetHomeRoomForm::ConstraintStudentsSetHomeRoomForm(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(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->filterChanged();
00078 }
00079 
00080 ConstraintStudentsSetHomeRoomForm::~ConstraintStudentsSetHomeRoomForm()
00081 {
00082        saveFETDialogGeometry(this);
00083 }
00084 
00085 bool ConstraintStudentsSetHomeRoomForm::filterOk(SpaceConstraint* ctr)
00086 {
00087        if(ctr->type==CONSTRAINT_STUDENTS_SET_HOME_ROOM){
00088               ConstraintStudentsSetHomeRoom* c=(ConstraintStudentsSetHomeRoom*) ctr;
00089               return (c->roomName==roomsComboBox->currentText() || roomsComboBox->currentText()=="")
00090                && (c->studentsName==studentsComboBox->currentText() || studentsComboBox->currentText()=="");
00091        }
00092        else
00093               return false;
00094 }
00095 
00096 void ConstraintStudentsSetHomeRoomForm::filterChanged()
00097 {
00098        this->visibleConstraintsList.clear();
00099        constraintsListWidget->clear();
00100        for(int i=0; i<gt.rules.spaceConstraintsList.size(); i++){
00101               SpaceConstraint* ctr=gt.rules.spaceConstraintsList[i];
00102               if(filterOk(ctr)){
00103                      visibleConstraintsList.append(ctr);
00104                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00105               }
00106        }
00107 
00108        if(constraintsListWidget->count()>0)
00109               constraintsListWidget->setCurrentRow(0);
00110        else
00111               this->constraintChanged(-1);
00112 }
00113 
00114 void ConstraintStudentsSetHomeRoomForm::constraintChanged(int index)
00115 {
00116        if(index<0){
00117               currentConstraintTextEdit->setPlainText("");
00118               return;
00119        }
00120        assert(index<this->visibleConstraintsList.size());
00121        SpaceConstraint* ctr=this->visibleConstraintsList.at(index);
00122        assert(ctr!=NULL);
00123        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00124 }
00125 
00126 void ConstraintStudentsSetHomeRoomForm::addConstraint()
00127 {
00128        AddConstraintStudentsSetHomeRoomForm form(this);
00129        setParentAndOtherThings(&form, this);
00130        form.exec();
00131 
00132        filterChanged();
00133        
00134        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00135 }
00136 
00137 void ConstraintStudentsSetHomeRoomForm::modifyConstraint()
00138 {
00139        int valv=constraintsListWidget->verticalScrollBar()->value();
00140        int valh=constraintsListWidget->horizontalScrollBar()->value();
00141 
00142        int i=constraintsListWidget->currentRow();
00143        if(i<0){
00144               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00145               return;
00146        }
00147        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00148 
00149        ModifyConstraintStudentsSetHomeRoomForm form(this, (ConstraintStudentsSetHomeRoom*)ctr);
00150        setParentAndOtherThings(&form, this);
00151        form.exec();
00152 
00153        filterChanged();
00154        
00155        constraintsListWidget->verticalScrollBar()->setValue(valv);
00156        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00157 
00158        if(i>=constraintsListWidget->count())
00159               i=constraintsListWidget->count()-1;
00160 
00161        if(i>=0)
00162               constraintsListWidget->setCurrentRow(i);
00163        else
00164               this->constraintChanged(-1);
00165 }
00166 
00167 void ConstraintStudentsSetHomeRoomForm::removeConstraint()
00168 {
00169        int i=constraintsListWidget->currentRow();
00170        if(i<0){
00171               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00172               return;
00173        }
00174        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00175        QString s;
00176        s=tr("Remove constraint?");
00177        s+="\n\n";
00178        s+=ctr->getDetailedDescription(gt.rules);
00179        
00180        QListWidgetItem* item;
00181 
00182        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00183               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00184        case 0: // The user clicked the OK button or pressed Enter
00185               gt.rules.removeSpaceConstraint(ctr);
00186               
00187               visibleConstraintsList.removeAt(i);
00188               constraintsListWidget->setCurrentRow(-1);
00189               item=constraintsListWidget->takeItem(i);
00190               delete item;
00191               
00192               break;
00193        case 1: // The user clicked the Cancel button or pressed Escape
00194               break;
00195        }
00196        
00197        if(i>=constraintsListWidget->count())
00198               i=constraintsListWidget->count()-1;
00199        if(i>=0)
00200               constraintsListWidget->setCurrentRow(i);
00201        else
00202               this->constraintChanged(-1);
00203 }