Back to index

fet  5.18.0
constraintactivitiessamestartingdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintactivitiessamestartingdayform.cpp  -  description
00003                              -------------------
00004     begin                : 15 Feb 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 "constraintactivitiessamestartingdayform.h"
00023 #include "addconstraintactivitiessamestartingdayform.h"
00024 #include "modifyconstraintactivitiessamestartingdayform.h"
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 ConstraintActivitiesSameStartingDayForm::ConstraintActivitiesSameStartingDayForm(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(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
00047 
00048        centerWidgetOnScreen(this);
00049        restoreFETDialogGeometry(this);
00050        
00051        this->refreshConstraintsListWidget();
00052 }
00053 
00054 ConstraintActivitiesSameStartingDayForm::~ConstraintActivitiesSameStartingDayForm()
00055 {
00056        saveFETDialogGeometry(this);
00057 }
00058 
00059 void ConstraintActivitiesSameStartingDayForm::refreshConstraintsListWidget()
00060 {
00061        this->visibleConstraintsList.clear();
00062        constraintsListWidget->clear();
00063        for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
00064               TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
00065               if(filterOk(ctr)){
00066                      QString s;
00067                      s=ctr->getDescription(gt.rules);
00068                      visibleConstraintsList.append(ctr);
00069                      constraintsListWidget->addItem(s);
00070               }
00071        }
00072 
00073        if(constraintsListWidget->count()>0)
00074               constraintsListWidget->setCurrentRow(0);
00075        else
00076               this->constraintChanged(-1);
00077 }
00078 
00079 bool ConstraintActivitiesSameStartingDayForm::filterOk(TimeConstraint* ctr)
00080 {
00081        if(ctr->type==CONSTRAINT_ACTIVITIES_SAME_STARTING_DAY)
00082               return true;
00083        else
00084               return false;
00085 }
00086 
00087 void ConstraintActivitiesSameStartingDayForm::constraintChanged(int index)
00088 {
00089        if(index<0){
00090               currentConstraintTextEdit->setPlainText("");
00091               return;
00092        }
00093        QString s;
00094        assert(index<this->visibleConstraintsList.size());
00095        TimeConstraint* ctr=this->visibleConstraintsList.at(index);
00096        assert(ctr!=NULL);
00097        s=ctr->getDetailedDescription(gt.rules);
00098        currentConstraintTextEdit->setPlainText(s);
00099 }
00100 
00101 void ConstraintActivitiesSameStartingDayForm::addConstraint()
00102 {
00103        AddConstraintActivitiesSameStartingDayForm form(this);
00104        setParentAndOtherThings(&form, this);
00105        form.exec();
00106 
00107        this->refreshConstraintsListWidget();
00108        
00109        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00110 }
00111 
00112 void ConstraintActivitiesSameStartingDayForm::modifyConstraint()
00113 {
00114        int valv=constraintsListWidget->verticalScrollBar()->value();
00115        int valh=constraintsListWidget->horizontalScrollBar()->value();
00116 
00117        int i=constraintsListWidget->currentRow();
00118        if(i<0){
00119               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00120               return;
00121        }
00122        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00123 
00124        ModifyConstraintActivitiesSameStartingDayForm form(this, (ConstraintActivitiesSameStartingDay*)ctr);
00125        setParentAndOtherThings(&form, this);
00126        form.exec();
00127 
00128        refreshConstraintsListWidget();
00129 
00130        constraintsListWidget->verticalScrollBar()->setValue(valv);
00131        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00132        
00133        if(i>=constraintsListWidget->count())
00134               i=constraintsListWidget->count()-1;
00135        
00136        if(i>=0)
00137               constraintsListWidget->setCurrentRow(i);
00138        else
00139               this->constraintChanged(-1);
00140 }
00141 
00142 void ConstraintActivitiesSameStartingDayForm::removeConstraint()
00143 {
00144        int i=constraintsListWidget->currentRow();
00145        if(i<0){
00146               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00147               return;
00148        }
00149        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
00150        QString s;
00151        s=tr("Remove constraint?");
00152        s+="\n\n";
00153        s+=ctr->getDetailedDescription(gt.rules);
00154        
00155        QListWidgetItem* item;
00156 
00157        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00158               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00159        case 0: // The user clicked the OK button or pressed Enter
00160               gt.rules.removeTimeConstraint(ctr);
00161               
00162               visibleConstraintsList.removeAt(i);
00163               constraintsListWidget->setCurrentRow(-1);
00164               item=constraintsListWidget->takeItem(i);
00165               delete item;
00166               
00167               break;
00168        case 1: // The user clicked the Cancel button or pressed Escape
00169               break;
00170        }
00171        
00172        if(i>=constraintsListWidget->count())
00173               i=constraintsListWidget->count()-1;
00174        if(i>=0)
00175               constraintsListWidget->setCurrentRow(i);
00176        else
00177               this->constraintChanged(-1);
00178 }
00179 
00180 void ConstraintActivitiesSameStartingDayForm::help()
00181 {
00182        QString s;
00183 
00184        s+=tr("IMPORTANT: after adding such constraints, it is necessary (otherwise generation might be impossible) to remove redundant constraints"
00185        " min days between activities. If you are sure that you don't have redundant constraints, you can skip this step, but it doesn't hurt to do it as a precaution."
00186        " Also, you don't have to do that after each added constraint, but only once after adding more constraints of this type."
00187        " Please read Help/Important tips - tip number 2 for details");
00188 
00189        LongTextMessageBox::largeInformation(this, tr("FET help"), s);
00190 }