Back to index

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