Back to index

fet  5.18.0
groupsform.cpp
Go to the documentation of this file.
00001 //
00002 //
00003 // Description: This file is part of FET
00004 //
00005 //
00006 // Author: Lalescu Liviu <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 "addstudentsgroupform.h"
00019 #include "modifystudentsgroupform.h"
00020 #include "groupsform.h"
00021 #include "timetable_defs.h"
00022 #include "timetable.h"
00023 #include "fet.h"
00024 #include "studentsset.h"
00025 
00026 #include <QMessageBox>
00027 
00028 #include <QListWidget>
00029 #include <QScrollBar>
00030 #include <QAbstractItemView>
00031 
00032 #include <QSplitter>
00033 #include <QSettings>
00034 #include <QObject>
00035 #include <QMetaObject>
00036 
00037 extern const QString COMPANY;
00038 extern const QString PROGRAM;
00039 
00040 GroupsForm::GroupsForm(QWidget* parent): QDialog(parent)
00041 {
00042        setupUi(this);
00043        
00044        groupTextEdit->setReadOnly(true);
00045        
00046        modifyGroupPushButton->setDefault(true);
00047 
00048        yearsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00049        groupsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00050 
00051        connect(yearsListWidget, SIGNAL(currentTextChanged(const QString&)), this, SLOT(yearChanged(const QString&)));
00052        connect(addGroupPushButton, SIGNAL(clicked()), this, SLOT(addGroup()));
00053        connect(removeGroupPushButton, SIGNAL(clicked()), this, SLOT(removeGroup()));
00054        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00055        connect(groupsListWidget, SIGNAL(currentTextChanged(const QString&)), this, SLOT(groupChanged(const QString&)));
00056        connect(modifyGroupPushButton, SIGNAL(clicked()), this, SLOT(modifyGroup()));
00057        connect(sortGroupsPushButton, SIGNAL(clicked()), this, SLOT(sortGroups()));
00058        connect(activateStudentsPushButton, SIGNAL(clicked()), this, SLOT(activateStudents()));
00059        connect(deactivateStudentsPushButton, SIGNAL(clicked()), this, SLOT(deactivateStudents()));
00060        connect(groupsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyGroup()));
00061 
00062        centerWidgetOnScreen(this);
00063        restoreFETDialogGeometry(this);
00064        //restore splitter state
00065        QSettings settings(COMPANY, PROGRAM);
00066        if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
00067               splitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
00068        
00069        yearsListWidget->clear();
00070        for(int i=0; i<gt.rules.yearsList.size(); i++){
00071               StudentsYear* year=gt.rules.yearsList[i];
00072               yearsListWidget->addItem(year->name);
00073        }
00074 
00075        if(yearsListWidget->count()>0)
00076               yearsListWidget->setCurrentRow(0);
00077        else
00078               groupsListWidget->clear();
00079 }
00080 
00081 
00082 GroupsForm::~GroupsForm()
00083 {
00084        saveFETDialogGeometry(this);
00085        //save splitter state
00086        QSettings settings(COMPANY, PROGRAM);
00087        settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
00088 }
00089 
00090 void GroupsForm::addGroup()
00091 {
00092        if(yearsListWidget->currentRow()<0){
00093               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00094               return;
00095        }
00096        QString yearName=yearsListWidget->currentItem()->text();
00097        int yearIndex=gt.rules.searchYear(yearName);
00098        assert(yearIndex>=0);
00099 
00100        AddStudentsGroupForm form(this, yearName);
00101        setParentAndOtherThings(&form, this);
00102        form.exec();
00103 
00104        yearChanged(yearsListWidget->currentItem()->text());
00105        
00106        int i=groupsListWidget->count()-1;
00107        if(i>=0)
00108               groupsListWidget->setCurrentRow(i);
00109 }
00110 
00111 void GroupsForm::removeGroup()
00112 {
00113        if(yearsListWidget->currentRow()<0){
00114               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00115               return;
00116        }
00117        int yearIndex=gt.rules.searchYear(yearsListWidget->currentItem()->text());
00118        assert(yearIndex>=0);
00119 
00120        if(groupsListWidget->currentRow()<0){
00121               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00122               return;
00123        }
00124 
00125        QString groupName=groupsListWidget->currentItem()->text();
00126        int groupIndex=gt.rules.searchGroup(yearsListWidget->currentItem()->text(), groupName);
00127        assert(groupIndex>=0);
00128 
00129        if(QMessageBox::warning( this, tr("FET"),
00130               tr("Are you sure you want to delete group %1 and all related subgroups, activities and constraints?").arg(groupName),
00131               tr("Yes"), tr("No"), 0, 0, 1 ) == 1)
00132               return;
00133 
00134        bool tmp=gt.rules.removeGroup(yearsListWidget->currentItem()->text(), groupName);
00135        assert(tmp);
00136        if(tmp){
00137               int q=groupsListWidget->currentRow();
00138               
00139               groupsListWidget->setCurrentRow(-1);
00140               QListWidgetItem* item;
00141               item=groupsListWidget->takeItem(q);
00142               delete item;
00143               
00144               if(q>=groupsListWidget->count())
00145                      q=groupsListWidget->count()-1;
00146               if(q>=0)
00147                      groupsListWidget->setCurrentRow(q);
00148               else
00149                      groupTextEdit->setPlainText(QString(""));
00150        }
00151 
00152        if(gt.rules.searchStudentsSet(groupName)!=NULL)
00153               QMessageBox::information( this, tr("FET"), tr("This group still exists into another year. "
00154                      "The related subgroups, activities and constraints were not removed"));
00155 }
00156 
00157 void GroupsForm::yearChanged(const QString &yearName)
00158 {
00159        int yearIndex=gt.rules.searchYear(yearName);
00160        if(yearIndex<0){
00161               groupsListWidget->clear();
00162               groupTextEdit->setPlainText(QString(""));
00163               return;
00164        }
00165 
00166        groupsListWidget->clear();
00167 
00168        StudentsYear* sty=gt.rules.yearsList.at(yearIndex);
00169        for(int i=0; i<sty->groupsList.size(); i++){
00170               StudentsGroup* stg=sty->groupsList[i];
00171               groupsListWidget->addItem(stg->name);
00172        }
00173 
00174        if(groupsListWidget->count()>0)
00175               groupsListWidget->setCurrentRow(0);
00176        else
00177               groupTextEdit->setPlainText(QString(""));
00178 }
00179 
00180 void GroupsForm::groupChanged(const QString &groupName)
00181 {
00182        StudentsSet* ss=gt.rules.searchStudentsSet(groupName);
00183        if(ss==NULL){
00184               groupTextEdit->setPlainText(QString(""));
00185               return;
00186        }
00187        StudentsGroup* sg=(StudentsGroup*)ss;
00188        groupTextEdit->setPlainText(sg->getDetailedDescriptionWithConstraints(gt.rules));
00189 }
00190 
00191 void GroupsForm::sortGroups()
00192 {
00193        if(yearsListWidget->currentRow()<0){
00194               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00195               return;
00196        }
00197        int yearIndex=gt.rules.searchYear(yearsListWidget->currentItem()->text());
00198        assert(yearIndex>=0);
00199        
00200        gt.rules.sortGroupsAlphabetically(yearsListWidget->currentItem()->text());
00201 
00202        yearChanged(yearsListWidget->currentItem()->text());
00203 }
00204 
00205 void GroupsForm::modifyGroup()
00206 {
00207        if(yearsListWidget->currentRow()<0){
00208               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00209               return;
00210        }
00211        
00212        QString yearName=yearsListWidget->currentItem()->text();
00213        
00214        int yearIndex=gt.rules.searchYear(yearsListWidget->currentItem()->text());
00215        assert(yearIndex>=0);
00216        
00217        int q=groupsListWidget->currentRow();
00218        int valv=groupsListWidget->verticalScrollBar()->value();
00219        int valh=groupsListWidget->horizontalScrollBar()->value();
00220 
00221        if(groupsListWidget->currentRow()<0){
00222               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00223               return;
00224        }
00225 
00226        QString groupName=groupsListWidget->currentItem()->text();
00227        int groupIndex=gt.rules.searchGroup(yearsListWidget->currentItem()->text(), groupName);
00228        assert(groupIndex>=0);
00229 
00230        int numberOfStudents=gt.rules.searchStudentsSet(groupName)->numberOfStudents;
00231        
00232        ModifyStudentsGroupForm form(this, yearName, groupName, numberOfStudents);
00233        setParentAndOtherThings(&form, this);
00234        form.exec();
00235 
00236        yearChanged(yearsListWidget->currentItem()->text());
00237        
00238        groupsListWidget->verticalScrollBar()->setValue(valv);
00239        groupsListWidget->horizontalScrollBar()->setValue(valh);
00240        
00241        if(q>=groupsListWidget->count())
00242               q=groupsListWidget->count()-1;
00243        if(q>=0)
00244               groupsListWidget->setCurrentRow(q);
00245        else
00246               groupTextEdit->setPlainText(QString(""));
00247 }
00248 
00249 void GroupsForm::activateStudents()
00250 {
00251        if(yearsListWidget->currentRow()<0){
00252               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00253               return;
00254        }
00255        int yearIndex=gt.rules.searchYear(yearsListWidget->currentItem()->text());
00256        assert(yearIndex>=0);
00257 
00258        if(groupsListWidget->currentRow()<0){
00259               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00260               return;
00261        }
00262 
00263        QString groupName=groupsListWidget->currentItem()->text();
00264        int count=gt.rules.activateStudents(groupName);
00265        QMessageBox::information(this, tr("FET information"), tr("Activated a number of %1 activities").arg(count));
00266 }
00267 
00268 void GroupsForm::deactivateStudents()
00269 {
00270        if(yearsListWidget->currentRow()<0){
00271               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00272               return;
00273        }
00274        int yearIndex=gt.rules.searchYear(yearsListWidget->currentItem()->text());
00275        assert(yearIndex>=0);
00276 
00277        if(groupsListWidget->currentRow()<0){
00278               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00279               return;
00280        }
00281 
00282        QString groupName=groupsListWidget->currentItem()->text();
00283        int count=gt.rules.deactivateStudents(groupName);
00284        QMessageBox::information(this, tr("FET information"), tr("De-activated a number of %1 activities").arg(count));
00285 }