Back to index

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