Back to index

fet  5.18.0
allspaceconstraintsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           allspaceconstraintsform.cpp  -  description
00003                              -------------------
00004     begin                : Feb 13, 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 "longtextmessagebox.h"
00019 
00020 #include "allspaceconstraintsform.h"
00021 
00022 #include "modifyconstraintbasiccompulsoryspaceform.h"
00023 #include "modifyconstraintroomnotavailabletimesform.h"
00024 #include "modifyconstraintactivitypreferredroomform.h"
00025 #include "modifyconstraintactivitypreferredroomsform.h"
00026 
00027 #include "modifyconstraintstudentssethomeroomform.h"
00028 #include "modifyconstraintstudentssethomeroomsform.h"
00029 
00030 #include "modifyconstraintteacherhomeroomform.h"
00031 #include "modifyconstraintteacherhomeroomsform.h"
00032 
00033 #include "modifyconstraintstudentssetmaxbuildingchangesperdayform.h"
00034 #include "modifyconstraintstudentsmaxbuildingchangesperdayform.h"
00035 #include "modifyconstraintstudentssetmaxbuildingchangesperweekform.h"
00036 #include "modifyconstraintstudentsmaxbuildingchangesperweekform.h"
00037 #include "modifyconstraintstudentssetmingapsbetweenbuildingchangesform.h"
00038 #include "modifyconstraintstudentsmingapsbetweenbuildingchangesform.h"
00039 
00040 #include "modifyconstraintteachermaxbuildingchangesperdayform.h"
00041 #include "modifyconstraintteachersmaxbuildingchangesperdayform.h"
00042 #include "modifyconstraintteachermaxbuildingchangesperweekform.h"
00043 #include "modifyconstraintteachersmaxbuildingchangesperweekform.h"
00044 #include "modifyconstraintteachermingapsbetweenbuildingchangesform.h"
00045 #include "modifyconstraintteachersmingapsbetweenbuildingchangesform.h"
00046 
00047 #include "modifyconstraintsubjectpreferredroomform.h"
00048 #include "modifyconstraintsubjectpreferredroomsform.h"
00049 #include "modifyconstraintsubjectactivitytagpreferredroomform.h"
00050 #include "modifyconstraintsubjectactivitytagpreferredroomsform.h"
00051 
00052 #include "modifyconstraintactivitytagpreferredroomform.h"
00053 #include "modifyconstraintactivitytagpreferredroomsform.h"
00054 
00055 #include "modifyconstraintactivitiesoccupymaxdifferentroomsform.h"
00056 
00057 #include "lockunlock.h"
00058 
00059 #include "advancedfilterform.h"
00060 
00061 #include <QMessageBox>
00062 
00063 #include <QPlainTextEdit>
00064 
00065 #include <QRegExp>
00066 
00067 #include <QListWidget>
00068 #include <QScrollBar>
00069 
00070 #include <QAbstractItemView>
00071 
00072 #include <QSplitter>
00073 #include <QSettings>
00074 #include <QObject>
00075 #include <QMetaObject>
00076 
00077 #include <QBrush>
00078 #include <QPalette>
00079 
00080 #include <QtAlgorithms>
00081 
00082 extern const QString COMPANY;
00083 extern const QString PROGRAM;
00084 
00085 const int DESCRIPTION=0;
00086 const int DETDESCRIPTION=1;
00087 
00088 const int CONTAINS=0;
00089 const int DOESNOTCONTAIN=1;
00090 const int REGEXP=2;
00091 const int NOTREGEXP=3;
00092 
00093 AllSpaceConstraintsForm::AllSpaceConstraintsForm(QWidget* parent): QDialog(parent)
00094 {
00095        setupUi(this);
00096        
00097        currentConstraintTextEdit->setReadOnly(true);
00098        
00099        modifyConstraintPushButton->setDefault(true);
00100        
00101        constraintsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00102 
00103        connect(constraintsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(constraintChanged()));
00104        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00105        connect(removeConstraintPushButton, SIGNAL(clicked()), this, SLOT(removeConstraint()));
00106        connect(modifyConstraintPushButton, SIGNAL(clicked()), this, SLOT(modifyConstraint()));
00107        connect(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
00108        connect(filterCheckBox, SIGNAL(toggled(bool)), this, SLOT(filter(bool)));
00109        connect(activatePushButton, SIGNAL(clicked()), this, SLOT(activateConstraint()));
00110        connect(deactivatePushButton, SIGNAL(clicked()), this, SLOT(deactivateConstraint()));
00111        connect(sortByCommentsPushButton, SIGNAL(clicked()), this, SLOT(sortConstraintsByComments()));
00112        connect(commentsPushButton, SIGNAL(clicked()), this, SLOT(constraintComments()));
00113 
00114        centerWidgetOnScreen(this);
00115        restoreFETDialogGeometry(this);
00116        //restore splitter state
00117        QSettings settings(COMPANY, PROGRAM);
00118        if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
00119               splitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
00120 
00121        QString settingsName="AllSpaceConstraintsAdvancedFilterForm";
00122 
00123        all=settings.value(settingsName+"/all-conditions", "true").toBool();
00124 
00125        descrDetDescr.clear();
00126        int n=settings.value(settingsName+"/number-of-descriptions", "1").toInt();
00127        for(int i=0; i<n; i++)
00128               descrDetDescr.append(settings.value(settingsName+"/description/"+CustomFETString::number(i+1), CustomFETString::number(DESCRIPTION)).toInt());
00129 
00130        contains.clear();
00131        n=settings.value(settingsName+"/number-of-contains", "1").toInt();
00132        for(int i=0; i<n; i++)
00133               contains.append(settings.value(settingsName+"/contains/"+CustomFETString::number(i+1), CustomFETString::number(CONTAINS)).toInt());
00134 
00135        text.clear();
00136        n=settings.value(settingsName+"/number-of-texts", "1").toInt();
00137        for(int i=0; i<n; i++)
00138               text.append(settings.value(settingsName+"/text/"+CustomFETString::number(i+1), QString("")).toString());
00139 
00140        caseSensitive=settings.value(settingsName+"/case-sensitive", "false").toBool();
00141 
00142        useFilter=false;
00143        
00144        assert(filterCheckBox->isChecked()==false);
00145        
00146        filterChanged();
00147 }
00148 
00149 AllSpaceConstraintsForm::~AllSpaceConstraintsForm()
00150 {
00151        saveFETDialogGeometry(this);
00152        //save splitter state
00153        QSettings settings(COMPANY, PROGRAM);
00154        settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
00155 
00156        QString settingsName="AllSpaceConstraintsAdvancedFilterForm";
00157 
00158        settings.setValue(settingsName+"/all-conditions", all);
00159 
00160        settings.setValue(settingsName+"/number-of-descriptions", descrDetDescr.count());
00161        settings.remove(settingsName+"/description");
00162        for(int i=0; i<descrDetDescr.count(); i++)
00163               settings.setValue(settingsName+"/description/"+CustomFETString::number(i+1), descrDetDescr.at(i));
00164 
00165        settings.setValue(settingsName+"/number-of-contains", contains.count());
00166        settings.remove(settingsName+"/contains");
00167        for(int i=0; i<contains.count(); i++)
00168               settings.setValue(settingsName+"/contains/"+CustomFETString::number(i+1), contains.at(i));
00169 
00170        settings.setValue(settingsName+"/number-of-texts", text.count());
00171        settings.remove(settingsName+"/text");
00172        for(int i=0; i<text.count(); i++)
00173               settings.setValue(settingsName+"/text/"+CustomFETString::number(i+1), text.at(i));
00174 
00175        settings.setValue(settingsName+"/case-sensitive", caseSensitive);
00176 }
00177 
00178 bool AllSpaceConstraintsForm::filterOk(SpaceConstraint* ctr)
00179 {
00180        if(!useFilter)
00181               return true;
00182 
00183        assert(descrDetDescr.count()==contains.count());
00184        assert(contains.count()==text.count());
00185        
00186        Qt::CaseSensitivity csens=Qt::CaseSensitive;
00187        if(!caseSensitive)
00188               csens=Qt::CaseInsensitive;
00189        
00190        QList<bool> okPartial;
00191        
00192        for(int i=0; i<descrDetDescr.count(); i++){
00193               QString s;
00194               if(descrDetDescr.at(i)==DESCRIPTION)
00195                      s=ctr->getDescription(gt.rules);
00196               else
00197                      s=ctr->getDetailedDescription(gt.rules);
00198                      
00199               QString t=text.at(i);
00200               if(contains.at(i)==CONTAINS){
00201                      okPartial.append(s.contains(t, csens));
00202               }
00203               else if(contains.at(i)==DOESNOTCONTAIN){
00204                      okPartial.append(!(s.contains(t, csens)));
00205               }
00206               else if(contains.at(i)==REGEXP){
00207                      QRegExp regExp(t);
00208                      regExp.setCaseSensitivity(csens);
00209                      okPartial.append(regExp.indexIn(s)>=0);
00210               }
00211               else if(contains.at(i)==NOTREGEXP){
00212                      QRegExp regExp(t);
00213                      regExp.setCaseSensitivity(csens);
00214                      okPartial.append(regExp.indexIn(s)<0);
00215               }
00216               else
00217                      assert(0);
00218        }
00219        
00220        if(all){
00221               bool ok=true;
00222               foreach(bool b, okPartial)
00223                      ok = ok && b;
00224                      
00225               return ok;
00226        }
00227        else{ //any
00228               bool ok=false;
00229               foreach(bool b, okPartial)
00230                      ok = ok || b;
00231                      
00232               return ok;
00233        }
00234 }
00235 
00236 void AllSpaceConstraintsForm::filterChanged()
00237 {
00238        visibleSpaceConstraintsList.clear();
00239        constraintsListWidget->clear();
00240        int n_active=0;
00241        foreach(SpaceConstraint* ctr, gt.rules.spaceConstraintsList)
00242               if(filterOk(ctr)){
00243                      visibleSpaceConstraintsList.append(ctr);
00244                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00245 
00246                      if(USE_GUI_COLORS && !ctr->active)
00247                             constraintsListWidget->item(constraintsListWidget->count()-1)->setBackground(constraintsListWidget->palette().alternateBase());
00248 
00249                      if(ctr->active)
00250                             n_active++;
00251               }
00252               
00253        if(constraintsListWidget->count()<=0)
00254               currentConstraintTextEdit->setPlainText("");
00255        else
00256               constraintsListWidget->setCurrentRow(0);
00257        
00258        constraintsTextLabel->setText(tr("%1 / %2 space constraints",
00259         "%1 represents the number of visible active space constraints, %2 represents the total number of visible space constraints")
00260         .arg(n_active).arg(visibleSpaceConstraintsList.count()));
00261 }
00262 
00263 void AllSpaceConstraintsForm::constraintChanged()
00264 {
00265        int index=constraintsListWidget->currentRow();
00266 
00267        if(index<0)
00268               return;
00269 
00270        assert(index<visibleSpaceConstraintsList.count());
00271        SpaceConstraint* ctr=visibleSpaceConstraintsList.at(index);
00272        assert(ctr!=NULL);
00273        QString s=ctr->getDetailedDescription(gt.rules);
00274        currentConstraintTextEdit->setPlainText(s);
00275 }
00276 
00277 void AllSpaceConstraintsForm::modifyConstraint()
00278 {
00279        int i=constraintsListWidget->currentRow();
00280        if(i<0){
00281               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00282               return;
00283        }
00284 
00285        int valv=constraintsListWidget->verticalScrollBar()->value();
00286        int valh=constraintsListWidget->horizontalScrollBar()->value();
00287 
00288        assert(i<visibleSpaceConstraintsList.count());
00289        SpaceConstraint* ctr=visibleSpaceConstraintsList.at(i);
00290        
00291        //1
00292        if(ctr->type==CONSTRAINT_BASIC_COMPULSORY_SPACE){
00293               ModifyConstraintBasicCompulsorySpaceForm form(this, (ConstraintBasicCompulsorySpace*)ctr);
00294               setParentAndOtherThings(&form, this);
00295               form.exec();
00296        }
00297        //2
00298        else if(ctr->type==CONSTRAINT_ROOM_NOT_AVAILABLE_TIMES){
00299               ModifyConstraintRoomNotAvailableTimesForm form(this, (ConstraintRoomNotAvailableTimes*)ctr);
00300               setParentAndOtherThings(&form, this);
00301               form.exec();
00302        }
00303        //3
00304        else if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM){
00305               ModifyConstraintActivityPreferredRoomForm form(this, (ConstraintActivityPreferredRoom*)ctr);
00306               setParentAndOtherThings(&form, this);
00307               form.exec();
00308        }
00309        //4
00310        else if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOMS){
00311               ModifyConstraintActivityPreferredRoomsForm form(this, (ConstraintActivityPreferredRooms*)ctr);
00312               setParentAndOtherThings(&form, this);
00313               form.exec();
00314        }
00315        //5
00316        else if(ctr->type==CONSTRAINT_STUDENTS_SET_HOME_ROOM){
00317               ModifyConstraintStudentsSetHomeRoomForm form(this, (ConstraintStudentsSetHomeRoom*)ctr);
00318               setParentAndOtherThings(&form, this);
00319               form.exec();
00320        }
00321        //6
00322        else if(ctr->type==CONSTRAINT_STUDENTS_SET_HOME_ROOMS){
00323               ModifyConstraintStudentsSetHomeRoomsForm form(this, (ConstraintStudentsSetHomeRooms*)ctr);
00324               setParentAndOtherThings(&form, this);
00325               form.exec();
00326        }
00327        //7
00328        else if(ctr->type==CONSTRAINT_TEACHER_HOME_ROOM){
00329               ModifyConstraintTeacherHomeRoomForm form(this, (ConstraintTeacherHomeRoom*)ctr);
00330               setParentAndOtherThings(&form, this);
00331               form.exec();
00332        }
00333        //8
00334        else if(ctr->type==CONSTRAINT_TEACHER_HOME_ROOMS){
00335               ModifyConstraintTeacherHomeRoomsForm form(this, (ConstraintTeacherHomeRooms*)ctr);
00336               setParentAndOtherThings(&form, this);
00337               form.exec();
00338        }
00339        //9
00340        else if(ctr->type==CONSTRAINT_SUBJECT_PREFERRED_ROOM){
00341               ModifyConstraintSubjectPreferredRoomForm form(this, (ConstraintSubjectPreferredRoom*)ctr);
00342               setParentAndOtherThings(&form, this);
00343               form.exec();
00344        }
00345        //10
00346        else if(ctr->type==CONSTRAINT_SUBJECT_PREFERRED_ROOMS){
00347               ModifyConstraintSubjectPreferredRoomsForm form(this, (ConstraintSubjectPreferredRooms*)ctr);
00348               setParentAndOtherThings(&form, this);
00349               form.exec();
00350        }
00351        //11
00352        else if(ctr->type==CONSTRAINT_SUBJECT_ACTIVITY_TAG_PREFERRED_ROOM){
00353               ModifyConstraintSubjectActivityTagPreferredRoomForm form(this, (ConstraintSubjectActivityTagPreferredRoom*)ctr);
00354               setParentAndOtherThings(&form, this);
00355               form.exec();
00356        }
00357        //12
00358        else if(ctr->type==CONSTRAINT_SUBJECT_ACTIVITY_TAG_PREFERRED_ROOMS){
00359               ModifyConstraintSubjectActivityTagPreferredRoomsForm form(this, (ConstraintSubjectActivityTagPreferredRooms*)ctr);
00360               setParentAndOtherThings(&form, this);
00361               form.exec();
00362        }
00364        //13
00365        else if(ctr->type==CONSTRAINT_ACTIVITY_TAG_PREFERRED_ROOM){
00366               ModifyConstraintActivityTagPreferredRoomForm form(this, (ConstraintActivityTagPreferredRoom*)ctr);
00367               setParentAndOtherThings(&form, this);
00368               form.exec();
00369        }
00370        //14
00371        else if(ctr->type==CONSTRAINT_ACTIVITY_TAG_PREFERRED_ROOMS){
00372               ModifyConstraintActivityTagPreferredRoomsForm form(this, (ConstraintActivityTagPreferredRooms*)ctr);
00373               setParentAndOtherThings(&form, this);
00374               form.exec();
00375        }
00377        //15
00378        else if(ctr->type==CONSTRAINT_STUDENTS_SET_MAX_BUILDING_CHANGES_PER_DAY){
00379               ModifyConstraintStudentsSetMaxBuildingChangesPerDayForm form(this, (ConstraintStudentsSetMaxBuildingChangesPerDay*)ctr);
00380               setParentAndOtherThings(&form, this);
00381               form.exec();
00382        }
00383        //16
00384        else if(ctr->type==CONSTRAINT_STUDENTS_MAX_BUILDING_CHANGES_PER_DAY){
00385               ModifyConstraintStudentsMaxBuildingChangesPerDayForm form(this, (ConstraintStudentsMaxBuildingChangesPerDay*)ctr);
00386               setParentAndOtherThings(&form, this);
00387               form.exec();
00388        }
00389        //17
00390        else if(ctr->type==CONSTRAINT_STUDENTS_SET_MAX_BUILDING_CHANGES_PER_WEEK){
00391               ModifyConstraintStudentsSetMaxBuildingChangesPerWeekForm form(this, (ConstraintStudentsSetMaxBuildingChangesPerWeek*)ctr);
00392               setParentAndOtherThings(&form, this);
00393               form.exec();
00394        }
00395        //18
00396        else if(ctr->type==CONSTRAINT_STUDENTS_MAX_BUILDING_CHANGES_PER_WEEK){
00397               ModifyConstraintStudentsMaxBuildingChangesPerWeekForm form(this, (ConstraintStudentsMaxBuildingChangesPerWeek*)ctr);
00398               setParentAndOtherThings(&form, this);
00399               form.exec();
00400        }
00401        //19
00402        else if(ctr->type==CONSTRAINT_STUDENTS_SET_MIN_GAPS_BETWEEN_BUILDING_CHANGES){
00403               ModifyConstraintStudentsSetMinGapsBetweenBuildingChangesForm form(this, (ConstraintStudentsSetMinGapsBetweenBuildingChanges*)ctr);
00404               setParentAndOtherThings(&form, this);
00405               form.exec();
00406        }
00407        //20
00408        else if(ctr->type==CONSTRAINT_STUDENTS_MIN_GAPS_BETWEEN_BUILDING_CHANGES){
00409               ModifyConstraintStudentsMinGapsBetweenBuildingChangesForm form(this, (ConstraintStudentsMinGapsBetweenBuildingChanges*)ctr);
00410               setParentAndOtherThings(&form, this);
00411               form.exec();
00412        }
00413        //21
00414        else if(ctr->type==CONSTRAINT_TEACHER_MAX_BUILDING_CHANGES_PER_DAY){
00415               ModifyConstraintTeacherMaxBuildingChangesPerDayForm form(this, (ConstraintTeacherMaxBuildingChangesPerDay*)ctr);
00416               setParentAndOtherThings(&form, this);
00417               form.exec();
00418        }
00419        //22
00420        else if(ctr->type==CONSTRAINT_TEACHERS_MAX_BUILDING_CHANGES_PER_DAY){
00421               ModifyConstraintTeachersMaxBuildingChangesPerDayForm form(this, (ConstraintTeachersMaxBuildingChangesPerDay*)ctr);
00422               setParentAndOtherThings(&form, this);
00423               form.exec();
00424        }
00425        //23
00426        else if(ctr->type==CONSTRAINT_TEACHER_MAX_BUILDING_CHANGES_PER_WEEK){
00427               ModifyConstraintTeacherMaxBuildingChangesPerWeekForm form(this, (ConstraintTeacherMaxBuildingChangesPerWeek*)ctr);
00428               setParentAndOtherThings(&form, this);
00429               form.exec();
00430        }
00431        //24
00432        else if(ctr->type==CONSTRAINT_TEACHERS_MAX_BUILDING_CHANGES_PER_WEEK){
00433               ModifyConstraintTeachersMaxBuildingChangesPerWeekForm form(this, (ConstraintTeachersMaxBuildingChangesPerWeek*)ctr);
00434               setParentAndOtherThings(&form, this);
00435               form.exec();
00436        }
00437        //25
00438        else if(ctr->type==CONSTRAINT_TEACHER_MIN_GAPS_BETWEEN_BUILDING_CHANGES){
00439               ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm form(this, (ConstraintTeacherMinGapsBetweenBuildingChanges*)ctr);
00440               setParentAndOtherThings(&form, this);
00441               form.exec();
00442        }
00443        //26
00444        else if(ctr->type==CONSTRAINT_TEACHERS_MIN_GAPS_BETWEEN_BUILDING_CHANGES){
00445               ModifyConstraintTeachersMinGapsBetweenBuildingChangesForm form(this, (ConstraintTeachersMinGapsBetweenBuildingChanges*)ctr);
00446               setParentAndOtherThings(&form, this);
00447               form.exec();
00448        }
00449        //27
00450        else if(ctr->type==CONSTRAINT_ACTIVITIES_OCCUPY_MAX_DIFFERENT_ROOMS){
00451               ModifyConstraintActivitiesOccupyMaxDifferentRoomsForm form(this, (ConstraintActivitiesOccupyMaxDifferentRooms*)ctr);
00452               setParentAndOtherThings(&form, this);
00453               form.exec();
00454        }
00455        else{
00456               QMessageBox::critical(this, tr("FET critical"), tr("You have found a bug in FET. Please report it. This kind of constraint"
00457                " is not correctly recognized in all space constraints dialog. FET will skip this error, so that you can continue work."
00458                ". Probably the constraint can be modified from the specific constraint dialog."));
00459 //            assert(0);
00460 //            exit(1);
00461        }
00462 
00463        filterChanged();
00464        
00465        constraintsListWidget->verticalScrollBar()->setValue(valv);
00466        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00467 
00468        if(i>=constraintsListWidget->count())
00469               i=constraintsListWidget->count()-1;
00470 
00471        if(i>=0)
00472               constraintsListWidget->setCurrentRow(i);
00473 }
00474 
00475 void AllSpaceConstraintsForm::removeConstraint()
00476 {
00477        int i=constraintsListWidget->currentRow();
00478        if(i<0){
00479               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00480               return;
00481        }
00482        assert(i<visibleSpaceConstraintsList.count());
00483        SpaceConstraint* ctr=visibleSpaceConstraintsList.at(i);
00484 
00485        QString s;
00486        s=tr("Remove constraint?");
00487        s+="\n\n";
00488        s+=ctr->getDetailedDescription(gt.rules);
00489        
00490        bool recompute, t;
00491        
00492        QListWidgetItem* item;
00493        
00494        int lres=LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00495               s, tr("Yes"), tr("No"), 0, 0, 1 );
00496               
00497        if(lres==0){
00498               //The user clicked the OK button or pressed Enter
00499               
00500               QMessageBox::StandardButton wr=QMessageBox::Yes;
00501               
00502               if(ctr->type==CONSTRAINT_BASIC_COMPULSORY_SPACE){ //additional confirmation for this one
00503                      QString s=tr("Do you really want to remove the basic compulsory space constraint?");
00504                      s+=" ";
00505                      s+=tr("You cannot generate a timetable without this constraint.");
00506                      s+="\n\n";
00507                      s+=tr("Note: you can add again a constraint of this type from the menu Data -> Space constraints -> "
00508                             "Miscellaneous -> Basic compulsory space constraints.");
00509                      
00510                      wr=QMessageBox::warning(this, tr("FET warning"), s,
00511                             QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
00512               }
00513               
00514               if(wr==QMessageBox::Yes){
00515                      if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM){
00516                             recompute=true;
00517                      }
00518                      else{
00519                             recompute=false;
00520                      }
00521        
00522                      t=gt.rules.removeSpaceConstraint(ctr);
00523                      assert(t);
00524                      visibleSpaceConstraintsList.removeAt(i);
00525                      constraintsListWidget->setCurrentRow(-1);
00526                      item=constraintsListWidget->takeItem(i);
00527                      delete item;
00528                      
00529                      constraintsTextLabel->setText(tr("%1 Space Constraints", "%1 represents the number of constraints").arg(visibleSpaceConstraintsList.count()));
00530        
00531                      if(recompute){
00532                             LockUnlock::computeLockedUnlockedActivitiesOnlySpace();
00533                             LockUnlock::increaseCommunicationSpinBox();
00534                      }
00535               }
00536        }
00537        //else if(lres==1){
00538               //The user clicked the Cancel button or pressed Escape
00539        //}
00540        
00541        if(i>=constraintsListWidget->count())
00542               i=constraintsListWidget->count()-1;
00543        if(i>=0)
00544               constraintsListWidget->setCurrentRow(i);
00545        else
00546               currentConstraintTextEdit->setPlainText(QString(""));
00547 }
00548 
00549 void AllSpaceConstraintsForm::filter(bool active)
00550 {
00551        if(!active){
00552               assert(useFilter==true);
00553               useFilter=false;
00554               
00555               filterChanged();
00556        
00557               return;
00558        }
00559        
00560        assert(active);
00561        
00562        filterForm=new AdvancedFilterForm(this, all, descrDetDescr, contains, text, caseSensitive, "AllSpaceConstraintsAdvancedFilterForm");
00563 
00564        int t=filterForm->exec();
00565        
00566        if(t==QDialog::Accepted){
00567               assert(useFilter==false);
00568               useFilter=true;
00569        
00570               if(filterForm->allRadio->isChecked())
00571                      all=true;
00572               else if(filterForm->anyRadio->isChecked())
00573                      all=false;
00574               else
00575                      assert(0);
00576                      
00577               caseSensitive=filterForm->caseSensitiveCheckBox->isChecked();
00578                      
00579               descrDetDescr.clear();
00580               contains.clear();
00581               text.clear();
00582                      
00583               assert(filterForm->descrDetDescrComboBoxList.count()==filterForm->contNContReNReComboBoxList.count());
00584               assert(filterForm->descrDetDescrComboBoxList.count()==filterForm->textLineEditList.count());
00585               for(int i=0; i<filterForm->rows; i++){
00586                      QComboBox* cb1=filterForm->descrDetDescrComboBoxList.at(i);
00587                      QComboBox* cb2=filterForm->contNContReNReComboBoxList.at(i);
00588                      QLineEdit* tl=filterForm->textLineEditList.at(i);
00589                      
00590                      descrDetDescr.append(cb1->currentIndex());
00591                      contains.append(cb2->currentIndex());
00592                      text.append(tl->text());
00593               }
00594               
00595               filterChanged();
00596        }
00597        else{
00598               assert(useFilter==false);
00599               useFilter=false;
00600               
00601               disconnect(filterCheckBox, SIGNAL(toggled(bool)), this, SLOT(filter(bool)));
00602               filterCheckBox->setChecked(false);
00603               connect(filterCheckBox, SIGNAL(toggled(bool)), this, SLOT(filter(bool)));
00604        }
00605        
00606        delete filterForm;
00607 }
00608 
00609 void AllSpaceConstraintsForm::activateConstraint()
00610 {
00611        int i=constraintsListWidget->currentRow();
00612        if(i<0){
00613               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00614               return;
00615        }
00616        
00617        assert(i<visibleSpaceConstraintsList.count());
00618        SpaceConstraint* ctr=visibleSpaceConstraintsList.at(i);
00619        
00620        if(!ctr->active){
00621               ctr->active=true;
00622               
00623               gt.rules.internalStructureComputed=false;
00624               setRulesModifiedAndOtherThings(&gt.rules);
00625 
00626               constraintsListWidget->currentItem()->setText(ctr->getDescription(gt.rules));
00627               if(USE_GUI_COLORS)
00628                      constraintsListWidget->currentItem()->setBackground(constraintsListWidget->palette().base());
00629               constraintChanged();
00630               
00631               if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM){
00632                      LockUnlock::computeLockedUnlockedActivitiesOnlySpace();
00633                      LockUnlock::increaseCommunicationSpinBox();
00634               }
00635        }
00636        
00637        int n_active=0;
00638        foreach(SpaceConstraint* ctr, gt.rules.spaceConstraintsList)
00639               if(filterOk(ctr)){
00640                      if(ctr->active)
00641                             n_active++;
00642               }
00643               
00644        constraintsTextLabel->setText(tr("%1 / %2 space constraints",
00645         "%1 represents the number of visible active space constraints, %2 represents the total number of visible space constraints")
00646         .arg(n_active).arg(visibleSpaceConstraintsList.count()));
00647 }
00648 
00649 void AllSpaceConstraintsForm::deactivateConstraint()
00650 {
00651        int i=constraintsListWidget->currentRow();
00652        if(i<0){
00653               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00654               return;
00655        }
00656        
00657        assert(i<visibleSpaceConstraintsList.count());
00658        SpaceConstraint* ctr=visibleSpaceConstraintsList.at(i);
00659        
00660        if(ctr->active){
00661               if(ctr->type==CONSTRAINT_BASIC_COMPULSORY_SPACE){
00662                      QMessageBox::warning(this, tr("FET warning"), tr("You are not allowed to deactivate the basic compulsory space constraints"));
00663                      return;
00664               }
00665        
00666               ctr->active=false;
00667               
00668               gt.rules.internalStructureComputed=false;
00669               setRulesModifiedAndOtherThings(&gt.rules);
00670 
00671               constraintsListWidget->currentItem()->setText(ctr->getDescription(gt.rules));
00672               if(USE_GUI_COLORS)
00673                      constraintsListWidget->currentItem()->setBackground(constraintsListWidget->palette().alternateBase());
00674               constraintChanged();
00675               
00676               if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM){
00677                      LockUnlock::computeLockedUnlockedActivitiesOnlySpace();
00678                      LockUnlock::increaseCommunicationSpinBox();
00679               }
00680        }
00681        
00682        int n_active=0;
00683        foreach(SpaceConstraint* ctr, gt.rules.spaceConstraintsList)
00684               if(filterOk(ctr)){
00685                      if(ctr->active)
00686                             n_active++;
00687               }
00688               
00689        constraintsTextLabel->setText(tr("%1 / %2 space constraints",
00690         "%1 represents the number of visible active space constraints, %2 represents the total number of visible space constraints")
00691         .arg(n_active).arg(visibleSpaceConstraintsList.count()));
00692 }
00693 
00694 static int spaceConstraintsAscendingByComments(const SpaceConstraint* s1, const SpaceConstraint* s2)
00695 {
00696        return s1->comments < s2->comments;
00697 }
00698 
00699 void AllSpaceConstraintsForm::sortConstraintsByComments()
00700 {
00701        QMessageBox::StandardButton t=QMessageBox::question(this, tr("Sort constraints?"),
00702         tr("This will sort the space constraints list ascending according to their comments. You can obtain "
00703         "a custom ordering by adding comments to some or all space constraints, for example 'rank #1 ... other comments', "
00704         "'rank #2 ... other different comments'.")
00705         +" "+tr("Are you sure you want to continue?"),
00706         QMessageBox::Yes|QMessageBox::Cancel);
00707        
00708        if(t==QMessageBox::Cancel)
00709               return;
00710        
00711        qStableSort(gt.rules.spaceConstraintsList.begin(), gt.rules.spaceConstraintsList.end(), spaceConstraintsAscendingByComments);
00712 
00713        gt.rules.internalStructureComputed=false;
00714        setRulesModifiedAndOtherThings(&gt.rules);
00715        
00716        filterChanged();
00717 }
00718 
00719 void AllSpaceConstraintsForm::constraintComments()
00720 {
00721        int i=constraintsListWidget->currentRow();
00722        if(i<0){
00723               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00724               return;
00725        }
00726        
00727        assert(i<visibleSpaceConstraintsList.count());
00728        SpaceConstraint* ctr=visibleSpaceConstraintsList.at(i);
00729 
00730        QDialog getCommentsDialog(this);
00731        
00732        getCommentsDialog.setWindowTitle(tr("Constraint comments"));
00733        
00734        QPushButton* okPB=new QPushButton(tr("OK"));
00735        okPB->setDefault(true);
00736        QPushButton* cancelPB=new QPushButton(tr("Cancel"));
00737        
00738        connect(okPB, SIGNAL(clicked()), &getCommentsDialog, SLOT(accept()));
00739        connect(cancelPB, SIGNAL(clicked()), &getCommentsDialog, SLOT(reject()));
00740 
00741        QHBoxLayout* hl=new QHBoxLayout();
00742        hl->addStretch();
00743        hl->addWidget(okPB);
00744        hl->addWidget(cancelPB);
00745        
00746        QVBoxLayout* vl=new QVBoxLayout();
00747        
00748        QPlainTextEdit* commentsPT=new QPlainTextEdit();
00749        commentsPT->setPlainText(ctr->comments);
00750        commentsPT->selectAll();
00751        commentsPT->setFocus();
00752        
00753        vl->addWidget(commentsPT);
00754        vl->addLayout(hl);
00755        
00756        getCommentsDialog.setLayout(vl);
00757        
00758        const QString settingsName=QString("SpaceConstraintCommentsDialog");
00759        
00760        getCommentsDialog.resize(500, 320);
00761        centerWidgetOnScreen(&getCommentsDialog);
00762        restoreFETDialogGeometry(&getCommentsDialog, settingsName);
00763        
00764        int t=getCommentsDialog.exec();
00765        saveFETDialogGeometry(&getCommentsDialog, settingsName);
00766        
00767        if(t==QDialog::Accepted){
00768               ctr->comments=commentsPT->toPlainText();
00769        
00770               gt.rules.internalStructureComputed=false;
00771               setRulesModifiedAndOtherThings(&gt.rules);
00772 
00773               constraintsListWidget->currentItem()->setText(ctr->getDescription(gt.rules));
00774               constraintChanged();
00775        }
00776 }