Back to index

fet  5.18.0
subgroupsform.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 "addstudentssubgroupform.h"
00019 #include "modifystudentssubgroupform.h"
00020 #include "subgroupsform.h"
00021 #include "timetable_defs.h"
00022 #include "timetable.h"
00023 #include "fet.h"
00024 
00025 #include <QMessageBox>
00026 
00027 #include <QListWidget>
00028 #include <QScrollBar>
00029 #include <QAbstractItemView>
00030 
00031 #include <QSplitter>
00032 #include <QSettings>
00033 #include <QObject>
00034 #include <QMetaObject>
00035 
00036 extern const QString COMPANY;
00037 extern const QString PROGRAM;
00038 
00039 SubgroupsForm::SubgroupsForm(QWidget* parent): QDialog(parent)
00040 {
00041        setupUi(this);
00042        
00043        subgroupTextEdit->setReadOnly(true);
00044 
00045        modifySubgroupPushButton->setDefault(true);
00046 
00047        yearsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00048        groupsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00049        subgroupsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00050 
00051        connect(yearsListWidget, SIGNAL(currentTextChanged(const QString&)), this, SLOT(yearChanged(const QString&)));
00052        connect(groupsListWidget, SIGNAL(currentTextChanged(const QString&)), this, SLOT(groupChanged(const QString&)));
00053        connect(addSubgroupPushButton, SIGNAL(clicked()), this, SLOT(addSubgroup()));
00054        connect(removeSubgroupPushButton, SIGNAL(clicked()), this, SLOT(removeSubgroup()));
00055        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00056        connect(subgroupsListWidget, SIGNAL(currentTextChanged(const QString&)), this, SLOT(subgroupChanged(const QString&)));
00057        connect(modifySubgroupPushButton, SIGNAL(clicked()), this, SLOT(modifySubgroup()));
00058        connect(removeSubgroupPushButton_2, SIGNAL(clicked()), this, SLOT(sortSubgroups()));
00059        connect(activateStudentsPushButton, SIGNAL(clicked()), this, SLOT(activateStudents()));
00060        connect(deactivateStudentsPushButton, SIGNAL(clicked()), this, SLOT(deactivateStudents()));
00061        connect(subgroupsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifySubgroup()));
00062 
00063        centerWidgetOnScreen(this);
00064        restoreFETDialogGeometry(this);
00065        //restore splitter state
00066        QSettings settings(COMPANY, PROGRAM);
00067        if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
00068               splitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
00069        
00070        yearsListWidget->clear();
00071        for(int i=0; i<gt.rules.yearsList.size(); i++){
00072               StudentsYear* year=gt.rules.yearsList[i];
00073               yearsListWidget->addItem(year->name);
00074        }
00075 
00076        if(yearsListWidget->count()>0)
00077               yearsListWidget->setCurrentRow(0);
00078        else{
00079               groupsListWidget->clear();
00080               subgroupsListWidget->clear();
00081        }
00082 }
00083 
00084 SubgroupsForm::~SubgroupsForm()
00085 {
00086        saveFETDialogGeometry(this);
00087        //save splitter state
00088        QSettings settings(COMPANY, PROGRAM);
00089        settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
00090 }
00091 
00092 void SubgroupsForm::addSubgroup()
00093 {
00094        if(yearsListWidget->currentRow()<0){
00095               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00096               return;
00097        }
00098        QString yearName=yearsListWidget->currentItem()->text();
00099        int yearIndex=gt.rules.searchYear(yearName);
00100        assert(yearIndex>=0);
00101 
00102        if(groupsListWidget->currentRow()<0){
00103               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00104               return;
00105        }
00106        QString groupName=groupsListWidget->currentItem()->text();
00107        int groupIndex=gt.rules.searchGroup(yearName, groupName);
00108        assert(groupIndex>=0);
00109 
00110        AddStudentsSubgroupForm form(this, yearName, groupName);
00111        setParentAndOtherThings(&form, this);
00112        form.exec();
00113 
00114        groupChanged(groupsListWidget->currentItem()->text());
00115        
00116        int i=subgroupsListWidget->count()-1;
00117        if(i>=0)
00118               subgroupsListWidget->setCurrentRow(i);
00119 }
00120 
00121 void SubgroupsForm::removeSubgroup()
00122 {
00123        if(yearsListWidget->currentRow()<0){
00124               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00125               return;
00126        }
00127        QString yearName=yearsListWidget->currentItem()->text();
00128        int yearIndex=gt.rules.searchYear(yearName);
00129        assert(yearIndex>=0);
00130 
00131        if(groupsListWidget->currentRow()<0){
00132               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00133               return;
00134        }
00135        QString groupName=groupsListWidget->currentItem()->text();
00136        int groupIndex=gt.rules.searchGroup(yearName, groupName);
00137        assert(groupIndex>=0);
00138 
00139        if(subgroupsListWidget->currentRow()<0){
00140               QMessageBox::information(this, tr("FET information"), tr("Invalid selected subgroup"));
00141               return;
00142        }
00143        
00144        QString subgroupName=subgroupsListWidget->currentItem()->text();
00145        int subgroupIndex=gt.rules.searchSubgroup(yearName, groupName, subgroupName);
00146        assert(subgroupIndex>=0);
00147 
00148        if(QMessageBox::warning( this, tr("FET"),
00149               tr("Are you sure you want to delete subgroup %1 and all related activities and constraints?").arg(subgroupName),
00150               tr("Yes"), tr("No"), 0, 0, 1 ) == 1)
00151               return;
00152 
00153        bool tmp=gt.rules.removeSubgroup(yearName, groupName, subgroupName);
00154        assert(tmp);
00155        if(tmp){
00156               int q=subgroupsListWidget->currentRow();
00157               
00158               subgroupsListWidget->setCurrentRow(-1);
00159               QListWidgetItem* item;
00160               item=subgroupsListWidget->takeItem(q);
00161               delete item;
00162               
00163               if(q>=subgroupsListWidget->count())
00164                      q=subgroupsListWidget->count()-1;
00165               if(q>=0)
00166                      subgroupsListWidget->setCurrentRow(q);
00167               else
00168                      subgroupTextEdit->setPlainText(QString(""));
00169        }
00170 
00171        if(gt.rules.searchStudentsSet(subgroupName)!=NULL)
00172               QMessageBox::information( this, tr("FET"), tr("This subgroup still exists into another group. "
00173               "The related activities and constraints were not removed"));
00174 }
00175 
00176 void SubgroupsForm::yearChanged(const QString &yearName)
00177 {
00178        int yearIndex=gt.rules.searchYear(yearName);
00179        if(yearIndex<0){
00180               groupsListWidget->clear();
00181               subgroupsListWidget->clear();
00182               subgroupTextEdit->setPlainText(QString(""));
00183               return;
00184        }
00185        StudentsYear* sty=gt.rules.yearsList.at(yearIndex);
00186 
00187        groupsListWidget->clear();
00188        for(int i=0; i<sty->groupsList.size(); i++){
00189               StudentsGroup* stg=sty->groupsList[i];
00190               groupsListWidget->addItem(stg->name);
00191        }
00192 
00193        if(groupsListWidget->count()>0)
00194               groupsListWidget->setCurrentRow(0);
00195        else{
00196               subgroupsListWidget->clear();
00197               subgroupTextEdit->setPlainText(QString(""));
00198        }
00199 }
00200 
00201 void SubgroupsForm::groupChanged(const QString &groupName)
00202 {
00203        QString yearName=yearsListWidget->currentItem()->text();
00204        int yearIndex=gt.rules.searchYear(yearName);
00205        if(yearIndex<0){
00206               return;
00207        }
00208        StudentsYear* sty=gt.rules.yearsList.at(yearIndex);
00209        int groupIndex=gt.rules.searchGroup(yearName, groupName);
00210        if(groupIndex<0){
00211               subgroupsListWidget->clear();
00212               subgroupTextEdit->setPlainText(QString(""));
00213               return;
00214        }
00215 
00216        StudentsGroup* stg=sty->groupsList.at(groupIndex);
00217 
00218        subgroupsListWidget->clear();
00219        for(int i=0; i<stg->subgroupsList.size(); i++){
00220               StudentsSubgroup* sts=stg->subgroupsList[i];
00221               subgroupsListWidget->addItem(sts->name);
00222        }
00223 
00224        if(subgroupsListWidget->count()>0)
00225               subgroupsListWidget->setCurrentRow(0);
00226        else
00227               subgroupTextEdit->setPlainText(QString(""));
00228 }
00229 
00230 void SubgroupsForm::subgroupChanged(const QString &subgroupName)
00231 {
00232        StudentsSet* ss=gt.rules.searchStudentsSet(subgroupName);
00233        if(ss==NULL){
00234               subgroupTextEdit->setPlainText(QString(""));
00235               return;
00236        }
00237        StudentsSubgroup* s=(StudentsSubgroup*)ss;
00238        subgroupTextEdit->setPlainText(s->getDetailedDescriptionWithConstraints(gt.rules));
00239 }
00240 
00241 void SubgroupsForm::sortSubgroups()
00242 {
00243        if(yearsListWidget->currentRow()<0){
00244               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00245               return;
00246        }
00247        QString yearName=yearsListWidget->currentItem()->text();
00248        int yearIndex=gt.rules.searchYear(yearName);
00249        assert(yearIndex>=0);
00250 
00251        if(groupsListWidget->currentRow()<0){
00252               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00253               return;
00254        }
00255        QString groupName=groupsListWidget->currentItem()->text();
00256        int groupIndex=gt.rules.searchGroup(yearName, groupName);
00257        assert(groupIndex>=0);
00258        
00259        gt.rules.sortSubgroupsAlphabetically(yearName, groupName);
00260        
00261        groupChanged(groupName);
00262 }
00263 
00264 void SubgroupsForm::modifySubgroup()
00265 {
00266        if(yearsListWidget->currentRow()<0){
00267               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00268               return;
00269        }
00270        QString yearName=yearsListWidget->currentItem()->text();
00271        int yearIndex=gt.rules.searchYear(yearName);
00272        assert(yearIndex>=0);
00273 
00274        if(groupsListWidget->currentRow()<0){
00275               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00276               return;
00277        }
00278        QString groupName=groupsListWidget->currentItem()->text();
00279        int groupIndex=gt.rules.searchGroup(yearName, groupName);
00280        assert(groupIndex>=0);
00281 
00282        int q=subgroupsListWidget->currentRow();
00283        int valv=subgroupsListWidget->verticalScrollBar()->value();
00284        int valh=subgroupsListWidget->horizontalScrollBar()->value();
00285 
00286        if(subgroupsListWidget->currentRow()<0){
00287               QMessageBox::information(this, tr("FET information"), tr("Invalid selected subgroup"));
00288               return;
00289        }
00290        QString subgroupName=subgroupsListWidget->currentItem()->text();
00291        int subgroupIndex=gt.rules.searchSubgroup(yearName, groupName, subgroupName);
00292        assert(subgroupIndex>=0);
00293        
00294        int numberOfStudents=gt.rules.searchStudentsSet(subgroupName)->numberOfStudents;
00295        
00296        ModifyStudentsSubgroupForm form(this, yearName, groupName, subgroupName, numberOfStudents);
00297        setParentAndOtherThings(&form, this);
00298        form.exec();
00299 
00300        groupChanged(groupName);
00301        
00302        subgroupsListWidget->verticalScrollBar()->setValue(valv);
00303        subgroupsListWidget->horizontalScrollBar()->setValue(valh);
00304 
00305        if(q>=subgroupsListWidget->count())
00306               q=subgroupsListWidget->count()-1;
00307        if(q>=0)
00308               subgroupsListWidget->setCurrentRow(q);
00309        else
00310               subgroupTextEdit->setPlainText(QString(""));
00311 }
00312 
00313 void SubgroupsForm::activateStudents()
00314 {
00315        if(yearsListWidget->currentRow()<0){
00316               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00317               return;
00318        }
00319        QString yearName=yearsListWidget->currentItem()->text();
00320        int yearIndex=gt.rules.searchYear(yearName);
00321        assert(yearIndex>=0);
00322 
00323        if(groupsListWidget->currentRow()<0){
00324               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00325               return;
00326        }
00327        QString groupName=groupsListWidget->currentItem()->text();
00328        int groupIndex=gt.rules.searchGroup(yearName, groupName);
00329        assert(groupIndex>=0);
00330 
00331        if(subgroupsListWidget->currentRow()<0){
00332               QMessageBox::information(this, tr("FET information"), tr("Invalid selected subgroup"));
00333               return;
00334        }
00335        
00336        QString subgroupName=subgroupsListWidget->currentItem()->text();
00337        int count=gt.rules.activateStudents(subgroupName);
00338        QMessageBox::information(this, tr("FET information"), tr("Activated a number of %1 activities").arg(count));
00339 }
00340 
00341 void SubgroupsForm::deactivateStudents()
00342 {
00343        if(yearsListWidget->currentRow()<0){
00344               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00345               return;
00346        }
00347        QString yearName=yearsListWidget->currentItem()->text();
00348        int yearIndex=gt.rules.searchYear(yearName);
00349        assert(yearIndex>=0);
00350 
00351        if(groupsListWidget->currentRow()<0){
00352               QMessageBox::information(this, tr("FET information"), tr("Invalid selected group"));
00353               return;
00354        }
00355        QString groupName=groupsListWidget->currentItem()->text();
00356        int groupIndex=gt.rules.searchGroup(yearName, groupName);
00357        assert(groupIndex>=0);
00358 
00359        if(subgroupsListWidget->currentRow()<0){
00360               QMessageBox::information(this, tr("FET information"), tr("Invalid selected subgroup"));
00361               return;
00362        }
00363        
00364        QString subgroupName=subgroupsListWidget->currentItem()->text();
00365        int count=gt.rules.deactivateStudents(subgroupName);
00366        QMessageBox::information(this, tr("FET information"), tr("De-activated a number of %1 activities").arg(count));
00367 }