Back to index

fet  5.18.0
roomsform.cpp
Go to the documentation of this file.
00001 //
00002 //
00003 // Description: This file is part of FET
00004 //
00005 //
00006 // Author: Liviu Lalescu <Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)>
00007 // Copyright (C) 2003 Liviu Lalescu <http://lalescu.ro/liviu/>
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 "timetable_defs.h"
00019 #include "fet.h"
00020 #include "roomsform.h"
00021 #include "addroomform.h"
00022 #include "modifyroomform.h"
00023 
00024 #include <QMessageBox>
00025 
00026 #include <QListWidget>
00027 #include <QScrollBar>
00028 #include <QAbstractItemView>
00029 
00030 #include <QSplitter>
00031 #include <QSettings>
00032 #include <QObject>
00033 #include <QMetaObject>
00034 
00035 extern const QString COMPANY;
00036 extern const QString PROGRAM;
00037 
00038 RoomsForm::RoomsForm(QWidget* parent): QDialog(parent)
00039 {
00040        setupUi(this);
00041        
00042        currentRoomTextEdit->setReadOnly(true);
00043        
00044        modifyRoomPushButton->setDefault(true);
00045        
00046        roomsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00047 
00048        connect(addRoomPushButton, SIGNAL(clicked()), this, SLOT(addRoom()));
00049        connect(removeRoomPushButton, SIGNAL(clicked()), this, SLOT(removeRoom()));
00050        connect(roomsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(roomChanged(int)));
00051        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00052        connect(modifyRoomPushButton, SIGNAL(clicked()), this, SLOT(modifyRoom()));
00053        connect(sortRoomsPushButton, SIGNAL(clicked()), this, SLOT(sortRooms()));
00054        connect(roomsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyRoom()));
00055 
00056        centerWidgetOnScreen(this);
00057        restoreFETDialogGeometry(this);
00058        //restore splitter state
00059        QSettings settings(COMPANY, PROGRAM);
00060        if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
00061               splitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
00062        
00063        this->filterChanged();
00064 }
00065 
00066 
00067 RoomsForm::~RoomsForm()
00068 {
00069        saveFETDialogGeometry(this);
00070        //save splitter state
00071        QSettings settings(COMPANY, PROGRAM);
00072        settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
00073 }
00074 
00075 bool RoomsForm::filterOk(Room* rm)
00076 {
00077        Q_UNUSED(rm);
00078 
00079        bool ok=true;
00080        return ok;
00081 }
00082 
00083 void RoomsForm::filterChanged()
00084 {
00085        QString s;
00086        roomsListWidget->clear();
00087        visibleRoomsList.clear();
00088        for(int i=0; i<gt.rules.roomsList.size(); i++){
00089               Room* rm=gt.rules.roomsList[i];
00090               if(this->filterOk(rm)){
00091                      s=rm->getDescription();
00092                      visibleRoomsList.append(rm);
00093                      roomsListWidget->addItem(s);
00094               }
00095        }
00096        
00097        if(roomsListWidget->count()>0)
00098               roomsListWidget->setCurrentRow(0);
00099        else
00100               roomChanged(-1);
00101 }
00102 
00103 void RoomsForm::addRoom()
00104 {
00105        AddRoomForm addRoomForm(this);
00106        setParentAndOtherThings(&addRoomForm, this);
00107        addRoomForm.exec();
00108        
00109        filterChanged();
00110        
00111        roomsListWidget->setCurrentRow(roomsListWidget->count()-1);
00112 }
00113 
00114 void RoomsForm::removeRoom()
00115 {
00116        int ind=roomsListWidget->currentRow();
00117        if(ind<0){
00118               QMessageBox::information(this, tr("FET information"), tr("Invalid selected room"));
00119               return;
00120        }
00121        
00122        Room* rm=visibleRoomsList.at(ind);
00123        assert(rm!=NULL);
00124 
00125        if(QMessageBox::warning( this, tr("FET"),
00126               tr("Are you sure you want to delete this room and all related constraints?"),
00127               tr("Yes"), tr("No"), 0, 0, 1 ) == 1)
00128               return;
00129 
00130        bool tmp=gt.rules.removeRoom(this, rm->name);
00131        assert(tmp);
00132 
00133        visibleRoomsList.removeAt(ind);
00134        roomsListWidget->setCurrentRow(-1);
00135        QListWidgetItem* item=roomsListWidget->takeItem(ind);
00136        delete item;
00137 
00138        if(ind>=roomsListWidget->count())
00139               ind=roomsListWidget->count()-1;
00140        if(ind>=0)
00141               roomsListWidget->setCurrentRow(ind);
00142        else
00143               currentRoomTextEdit->setPlainText(QString(""));
00144 }
00145 
00146 void RoomsForm::roomChanged(int index)
00147 {
00148        if(index<0){
00149               currentRoomTextEdit->setPlainText("");
00150               return;
00151        }
00152 
00153        QString s;
00154        Room* room=visibleRoomsList.at(index);
00155 
00156        assert(room!=NULL);
00157        s=room->getDetailedDescriptionWithConstraints(gt.rules);
00158        currentRoomTextEdit->setPlainText(s);
00159 }
00160 
00161 void RoomsForm::sortRooms()
00162 {
00163        gt.rules.sortRoomsAlphabetically();
00164 
00165        filterChanged();
00166 }
00167 
00168 void RoomsForm::modifyRoom()
00169 {
00170        int valv=roomsListWidget->verticalScrollBar()->value();
00171        int valh=roomsListWidget->horizontalScrollBar()->value();
00172 
00173        int ci=roomsListWidget->currentRow();
00174        if(ci<0){
00175               QMessageBox::information(this, tr("FET information"), tr("Invalid selected room"));
00176               return;
00177        }
00178        
00179        Room* rm=visibleRoomsList.at(ci);
00180        ModifyRoomForm form(this, rm->name, rm->building, rm->capacity);
00181        setParentAndOtherThings(&form, this);
00182        form.exec();
00183 
00184        filterChanged();
00185        
00186        roomsListWidget->verticalScrollBar()->setValue(valv);
00187        roomsListWidget->horizontalScrollBar()->setValue(valh);
00188 
00189        if(ci>=roomsListWidget->count())
00190               ci=roomsListWidget->count()-1;
00191 
00192        if(ci>=0)
00193               roomsListWidget->setCurrentRow(ci);
00194 }