Back to index

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