Back to index

fet  5.18.0
constraintactivitytagpreferredroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintactivitytagpreferredroomform.cpp  -  description
00003                              -------------------
00004     begin                : 2009
00005     copyright            : (C) 2009 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 "constraintactivitytagpreferredroomform.h"
00023 #include "addconstraintactivitytagpreferredroomform.h"
00024 #include "modifyconstraintactivitytagpreferredroomform.h"
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 ConstraintActivityTagPreferredRoomForm::ConstraintActivityTagPreferredRoomForm(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(roomsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00046        connect(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
00047        connect(activityTagsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00048 
00049        centerWidgetOnScreen(this);
00050        restoreFETDialogGeometry(this);
00051 
00052        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00053        Q_UNUSED(tmp4);
00054        
00055        QSize tmp5=roomsComboBox->minimumSizeHint();
00056        Q_UNUSED(tmp5);
00057        
00058        roomsComboBox->addItem("");
00059        for(int i=0; i<gt.rules.roomsList.size(); i++){
00060               Room* rm=gt.rules.roomsList[i];
00061               roomsComboBox->addItem(rm->name);
00062        }
00063 
00064        activityTagsComboBox->addItem("");
00065        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00066               ActivityTag* sb=gt.rules.activityTagsList[i];
00067               activityTagsComboBox->addItem(sb->name);
00068        }
00069 
00070        this->filterChanged();
00071 }
00072 
00073 ConstraintActivityTagPreferredRoomForm::~ConstraintActivityTagPreferredRoomForm()
00074 {
00075        saveFETDialogGeometry(this);
00076 }
00077 
00078 bool ConstraintActivityTagPreferredRoomForm::filterOk(SpaceConstraint* ctr)
00079 {
00080        if(ctr->type==CONSTRAINT_ACTIVITY_TAG_PREFERRED_ROOM){
00081               ConstraintActivityTagPreferredRoom* c=(ConstraintActivityTagPreferredRoom*) ctr;
00082               return (c->roomName==roomsComboBox->currentText() || roomsComboBox->currentText()=="")
00083                && (c->activityTagName==activityTagsComboBox->currentText() || activityTagsComboBox->currentText()=="");
00084        }
00085        else
00086               return false;
00087 }
00088 
00089 void ConstraintActivityTagPreferredRoomForm::filterChanged()
00090 {
00091        this->visibleConstraintsList.clear();
00092        constraintsListWidget->clear();
00093        for(int i=0; i<gt.rules.spaceConstraintsList.size(); i++){
00094               SpaceConstraint* ctr=gt.rules.spaceConstraintsList[i];
00095               if(filterOk(ctr)){
00096                      visibleConstraintsList.append(ctr);
00097                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00098               }
00099        }
00100        
00101        if(constraintsListWidget->count()>0)
00102               constraintsListWidget->setCurrentRow(0);
00103        else
00104               this->constraintChanged(-1);
00105 }
00106 
00107 void ConstraintActivityTagPreferredRoomForm::constraintChanged(int index)
00108 {
00109        if(index<0){
00110               currentConstraintTextEdit->setPlainText("");
00111               return;
00112        }
00113        assert(index<this->visibleConstraintsList.size());
00114        SpaceConstraint* ctr=this->visibleConstraintsList.at(index);
00115        assert(ctr!=NULL);
00116        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00117 }
00118 
00119 void ConstraintActivityTagPreferredRoomForm::addConstraint()
00120 {
00121        AddConstraintActivityTagPreferredRoomForm form(this);
00122        setParentAndOtherThings(&form, this);
00123        form.exec();
00124 
00125        filterChanged();
00126        
00127        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00128 }
00129 
00130 void ConstraintActivityTagPreferredRoomForm::modifyConstraint()
00131 {
00132        int valv=constraintsListWidget->verticalScrollBar()->value();
00133        int valh=constraintsListWidget->horizontalScrollBar()->value();
00134 
00135        int i=constraintsListWidget->currentRow();
00136        if(i<0){
00137               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00138               return;
00139        }
00140        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00141 
00142        ModifyConstraintActivityTagPreferredRoomForm form(this, (ConstraintActivityTagPreferredRoom*)ctr);
00143        setParentAndOtherThings(&form, this);
00144        form.exec();
00145 
00146        filterChanged();
00147 
00148        constraintsListWidget->verticalScrollBar()->setValue(valv);
00149        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00150 
00151        if(i>=constraintsListWidget->count())
00152               i=constraintsListWidget->count()-1;
00153 
00154        if(i>=0)
00155               constraintsListWidget->setCurrentRow(i);
00156        else
00157               this->constraintChanged(-1);
00158 }
00159 
00160 void ConstraintActivityTagPreferredRoomForm::removeConstraint()
00161 {
00162        int i=constraintsListWidget->currentRow();
00163        if(i<0){
00164               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00165               return;
00166        }
00167        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00168        QString s;
00169        s=tr("Remove constraint?");
00170        s+="\n\n";
00171        s+=ctr->getDetailedDescription(gt.rules);
00172        
00173        QListWidgetItem* item;
00174 
00175        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00176               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00177        case 0: // The user clicked the OK button or pressed Enter
00178               gt.rules.removeSpaceConstraint(ctr);
00179 
00180               visibleConstraintsList.removeAt(i);
00181               constraintsListWidget->setCurrentRow(-1);
00182               item=constraintsListWidget->takeItem(i);
00183               delete item;
00184 
00185               break;
00186        case 1: // The user clicked the Cancel button or pressed Escape
00187               break;
00188        }
00189        
00190        if(i>=constraintsListWidget->count())
00191               i=constraintsListWidget->count()-1;
00192        if(i>=0)
00193               constraintsListWidget->setCurrentRow(i);
00194        else
00195               this->constraintChanged(-1);
00196 }