Back to index

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