Back to index

fet  5.18.0
constraintstudentsmaxbuildingchangesperdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintstudentsmaxbuildingchangesperdayform.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 "constraintstudentsmaxbuildingchangesperdayform.h"
00023 #include "addconstraintstudentsmaxbuildingchangesperdayform.h"
00024 #include "modifyconstraintstudentsmaxbuildingchangesperdayform.h"
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 ConstraintStudentsMaxBuildingChangesPerDayForm::ConstraintStudentsMaxBuildingChangesPerDayForm(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 
00047        centerWidgetOnScreen(this);
00048        restoreFETDialogGeometry(this);
00049        
00050        this->filterChanged();
00051 }
00052 
00053 ConstraintStudentsMaxBuildingChangesPerDayForm::~ConstraintStudentsMaxBuildingChangesPerDayForm()
00054 {
00055        saveFETDialogGeometry(this);
00056 }
00057 
00058 bool ConstraintStudentsMaxBuildingChangesPerDayForm::filterOk(SpaceConstraint* ctr)
00059 {
00060        if(ctr->type==CONSTRAINT_STUDENTS_MAX_BUILDING_CHANGES_PER_DAY){
00061               return true;
00062        }
00063        else
00064               return false;
00065 }
00066 
00067 void ConstraintStudentsMaxBuildingChangesPerDayForm::filterChanged()
00068 {
00069        this->visibleConstraintsList.clear();
00070        constraintsListWidget->clear();
00071        for(int i=0; i<gt.rules.spaceConstraintsList.size(); i++){
00072               SpaceConstraint* ctr=gt.rules.spaceConstraintsList[i];
00073               if(filterOk(ctr)){
00074                      visibleConstraintsList.append(ctr);
00075                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00076               }
00077        }
00078        
00079        if(constraintsListWidget->count()>0)
00080               constraintsListWidget->setCurrentRow(0);
00081        else
00082               this->constraintChanged(-1);
00083 }
00084 
00085 void ConstraintStudentsMaxBuildingChangesPerDayForm::constraintChanged(int index)
00086 {
00087        if(index<0){
00088               currentConstraintTextEdit->setPlainText("");
00089               return;
00090        }
00091        assert(index<this->visibleConstraintsList.size());
00092        SpaceConstraint* ctr=this->visibleConstraintsList.at(index);
00093        assert(ctr!=NULL);
00094        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00095 }
00096 
00097 void ConstraintStudentsMaxBuildingChangesPerDayForm::addConstraint()
00098 {
00099        AddConstraintStudentsMaxBuildingChangesPerDayForm form(this);
00100        setParentAndOtherThings(&form, this);
00101        form.exec();
00102 
00103        filterChanged();
00104        
00105        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00106 }
00107 
00108 void ConstraintStudentsMaxBuildingChangesPerDayForm::modifyConstraint()
00109 {
00110        int valv=constraintsListWidget->verticalScrollBar()->value();
00111        int valh=constraintsListWidget->horizontalScrollBar()->value();
00112 
00113        int i=constraintsListWidget->currentRow();
00114        if(i<0){
00115               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00116               return;
00117        }
00118        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00119 
00120        ModifyConstraintStudentsMaxBuildingChangesPerDayForm form(this, (ConstraintStudentsMaxBuildingChangesPerDay*)ctr);
00121        setParentAndOtherThings(&form, this);
00122        form.exec();
00123 
00124        filterChanged();
00125        
00126        constraintsListWidget->verticalScrollBar()->setValue(valv);
00127        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00128 
00129        if(i>=constraintsListWidget->count())
00130               i=constraintsListWidget->count()-1;
00131 
00132        if(i>=0)
00133               constraintsListWidget->setCurrentRow(i);
00134        else
00135               this->constraintChanged(-1);
00136 }
00137 
00138 void ConstraintStudentsMaxBuildingChangesPerDayForm::removeConstraint()
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        QString s;
00147        s=tr("Remove constraint?");
00148        s+="\n\n";
00149        s+=ctr->getDetailedDescription(gt.rules);
00150        
00151        QListWidgetItem* item;
00152 
00153        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00154               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00155        case 0: // The user clicked the OK button or pressed Enter
00156               gt.rules.removeSpaceConstraint(ctr);
00157               
00158               visibleConstraintsList.removeAt(i);
00159               constraintsListWidget->setCurrentRow(-1);
00160               item=constraintsListWidget->takeItem(i);
00161               delete item;
00162               
00163               break;
00164        case 1: // The user clicked the Cancel button or pressed Escape
00165               break;
00166        }
00167        
00168        if(i>=constraintsListWidget->count())
00169               i=constraintsListWidget->count()-1;
00170        if(i>=0)
00171               constraintsListWidget->setCurrentRow(i);
00172        else
00173               this->constraintChanged(-1);
00174 }