Back to index

fet  5.18.0
constraintbasiccompulsoryspaceform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintbasiccompulsoryspaceform.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 <QMessageBox>
00019 
00020 #include "longtextmessagebox.h"
00021 
00022 #include "constraintbasiccompulsoryspaceform.h"
00023 #include "addconstraintbasiccompulsoryspaceform.h"
00024 #include "modifyconstraintbasiccompulsoryspaceform.h"
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 ConstraintBasicCompulsorySpaceForm::ConstraintBasicCompulsorySpaceForm(QWidget* parent): QDialog(parent)
00031 {
00032        setupUi(this);
00033 
00034        currentConstraintTextEdit->setReadOnly(true);
00035        
00036        modifyConstraintPushButton->setDefault(true);
00037 
00038        connect(constraintsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(constraintChanged(int)));
00039        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
00040        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00041        connect(removeConstraintPushButton, SIGNAL(clicked()), this, SLOT(removeConstraint()));
00042        connect(modifyConstraintPushButton, SIGNAL(clicked()), this, SLOT(modifyConstraint()));
00043        connect(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
00044 
00045        centerWidgetOnScreen(this);
00046        restoreFETDialogGeometry(this);
00047        
00048        this->filterChanged();
00049 }
00050 
00051 ConstraintBasicCompulsorySpaceForm::~ConstraintBasicCompulsorySpaceForm()
00052 {
00053        saveFETDialogGeometry(this);
00054 }
00055 
00056 bool ConstraintBasicCompulsorySpaceForm::filterOk(SpaceConstraint* ctr)
00057 {
00058        if(ctr->type==CONSTRAINT_BASIC_COMPULSORY_SPACE)
00059               return true;
00060        else
00061               return false;
00062 }
00063 
00064 void ConstraintBasicCompulsorySpaceForm::filterChanged()
00065 {
00066        this->visibleConstraintsList.clear();
00067        constraintsListWidget->clear();
00068        for(int i=0; i<gt.rules.spaceConstraintsList.size(); i++){
00069               SpaceConstraint* ctr=gt.rules.spaceConstraintsList[i];
00070               if(filterOk(ctr)){
00071                      visibleConstraintsList.append(ctr);
00072                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00073               }
00074        }
00075        
00076        if(constraintsListWidget->count()>0)
00077               constraintsListWidget->setCurrentRow(0);
00078        else
00079               this->constraintChanged(-1);
00080 }
00081 
00082 void ConstraintBasicCompulsorySpaceForm::constraintChanged(int index)
00083 {
00084        if(index<0){
00085               currentConstraintTextEdit->setPlainText("");
00086               return;
00087        }
00088        assert(index<this->visibleConstraintsList.size());
00089        SpaceConstraint* ctr=this->visibleConstraintsList.at(index);
00090        assert(ctr!=NULL);
00091        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00092 }
00093 
00094 void ConstraintBasicCompulsorySpaceForm::addConstraint()
00095 {
00096        AddConstraintBasicCompulsorySpaceForm form(this);
00097        setParentAndOtherThings(&form, this);
00098        form.exec();
00099 
00100        filterChanged();
00101        
00102        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00103 }
00104 
00105 void ConstraintBasicCompulsorySpaceForm::modifyConstraint()
00106 {
00107        int valv=constraintsListWidget->verticalScrollBar()->value();
00108        int valh=constraintsListWidget->horizontalScrollBar()->value();
00109 
00110        int i=constraintsListWidget->currentRow();
00111        if(i<0){
00112               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00113               return;
00114        }
00115        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00116 
00117        ModifyConstraintBasicCompulsorySpaceForm form(this, (ConstraintBasicCompulsorySpace*)ctr);
00118        setParentAndOtherThings(&form, this);
00119        form.exec();
00120 
00121        filterChanged();
00122 
00123        constraintsListWidget->verticalScrollBar()->setValue(valv);
00124        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00125 
00126        if(i>=constraintsListWidget->count())
00127               i=constraintsListWidget->count()-1;
00128 
00129        if(i>=0)
00130               constraintsListWidget->setCurrentRow(i);
00131        else
00132               this->constraintChanged(-1);
00133 }
00134 
00135 void ConstraintBasicCompulsorySpaceForm::removeConstraint()
00136 {
00137        int i=constraintsListWidget->currentRow();
00138        if(i<0){
00139               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00140               return;
00141        }
00142        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00143        QString s;
00144        s=tr("Remove constraint?");
00145        s+="\n\n";
00146        s+=ctr->getDetailedDescription(gt.rules);
00147        
00148        QListWidgetItem* item;
00149 
00150        int lres=LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00151               s, tr("Yes"), tr("No"), 0, 0, 1 );
00152               
00153        if(lres==0){
00154               //The user clicked the OK button or pressed Enter
00155               
00156               assert(ctr->type==CONSTRAINT_BASIC_COMPULSORY_SPACE);
00157               
00158               QString s=tr("Do you really want to remove the basic compulsory space constraint?");
00159               s+=" ";
00160               s+=tr("You cannot generate a timetable without this constraint.");
00161               s+="\n\n";
00162               s+=tr("Note: you can add again a constraint of this type from the menu Data -> Space constraints -> "
00163                      "Miscellaneous -> Basic compulsory space constraints.");
00164               
00165               QMessageBox::StandardButton wr=QMessageBox::warning(this, tr("FET warning"), s,
00166                      QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
00167               
00168               if(wr==QMessageBox::Yes){
00169                      gt.rules.removeSpaceConstraint(ctr);
00170 
00171                      visibleConstraintsList.removeAt(i);
00172                      constraintsListWidget->setCurrentRow(-1);
00173                      item=constraintsListWidget->takeItem(i);
00174                      delete item;
00175               }
00176        }
00177        //else if(lres==1){
00178               //The user clicked the Cancel button or pressed Escape
00179        //}
00180        
00181        if(i>=constraintsListWidget->count())
00182               i=constraintsListWidget->count()-1;
00183        if(i>=0)
00184               constraintsListWidget->setCurrentRow(i);
00185        else
00186               this->constraintChanged(-1);
00187 }