Back to index

fet  5.18.0
yearsform.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 "addstudentsyearform.h"
00019 #include "modifystudentsyearform.h"
00020 #include "timetable_defs.h"
00021 #include "timetable.h"
00022 #include "fet.h"
00023 #include "yearsform.h"
00024 #include "studentsset.h"
00025 
00026 #include "splityearform.h"
00027 
00028 #include <QMessageBox>
00029 
00030 #include <QListWidget>
00031 #include <QScrollBar>
00032 #include <QAbstractItemView>
00033 
00034 #include <QSplitter>
00035 #include <QSettings>
00036 #include <QObject>
00037 #include <QMetaObject>
00038 
00039 extern const QString COMPANY;
00040 extern const QString PROGRAM;
00041 
00042 YearsForm::YearsForm(QWidget* parent): QDialog(parent)
00043 {
00044        setupUi(this);
00045        
00046        detailsTextEdit->setReadOnly(true);
00047        
00048        modifyYearPushButton->setDefault(true);
00049 
00050        yearsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00051 
00052        connect(addYearPushButton, SIGNAL(clicked()), this, SLOT(addYear()));
00053        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00054        connect(removeYearPushButton, SIGNAL(clicked()), this, SLOT(removeYear()));
00055        connect(yearsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(yearChanged()));
00056        connect(modifyYearPushButton, SIGNAL(clicked()), this, SLOT(modifyYear()));
00057        connect(sortYearsPushButton, SIGNAL(clicked()), this, SLOT(sortYears()));
00058        connect(activateStudentsPushButton, SIGNAL(clicked()), this, SLOT(activateStudents()));
00059        connect(deactivateStudentsPushButton, SIGNAL(clicked()), this, SLOT(deactivateStudents()));
00060        connect(divisionsPushButton, SIGNAL(clicked()), this, SLOT(divideYear()));
00061        connect(yearsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyYear()));
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 }
00079 
00080 YearsForm::~YearsForm()
00081 {
00082        saveFETDialogGeometry(this);
00083        //save splitter state
00084        QSettings settings(COMPANY, PROGRAM);
00085        settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
00086 }
00087 
00088 void YearsForm::addYear()
00089 {
00090        AddStudentsYearForm form(this);
00091        setParentAndOtherThings(&form, this);
00092        form.exec();
00093 
00094        yearsListWidget->clear();
00095        for(int i=0; i<gt.rules.yearsList.size(); i++){
00096               StudentsYear* year=gt.rules.yearsList[i];
00097               yearsListWidget->addItem(year->name);
00098        }
00099        
00100        int i=yearsListWidget->count()-1;
00101        if(i>=0)
00102               yearsListWidget->setCurrentRow(i);
00103 }
00104 
00105 void YearsForm::removeYear()
00106 {
00107        if(yearsListWidget->currentRow()<0){
00108               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00109               return;
00110        }
00111        QString yearName=yearsListWidget->currentItem()->text();
00112        int yearIndex=gt.rules.searchYear(yearName);
00113        assert(yearIndex>=0);
00114 
00115        if(QMessageBox::warning( this, tr("FET"),
00116               tr("Are you sure you want to delete year %1 and all related groups, subgroups, activities and constraints?").arg(yearName),
00117               tr("Yes"), tr("No"), 0, 0, 1 ) == 1)
00118               return;
00119 
00120        bool tmp=gt.rules.removeYear(yearName);
00121        assert(tmp);
00122        if(tmp){
00123               int q=yearsListWidget->currentRow();
00124 
00125               yearsListWidget->setCurrentRow(-1);
00126               QListWidgetItem* item;
00127               item=yearsListWidget->takeItem(q);
00128               delete item;
00129 
00130               if(q>=yearsListWidget->count())
00131                      q=yearsListWidget->count()-1;
00132               if(q>=0)
00133                      yearsListWidget->setCurrentRow(q);
00134               else
00135                      detailsTextEdit->setPlainText(QString(""));
00136        }
00137 }
00138 
00139 void YearsForm::yearChanged()
00140 {
00141        if(yearsListWidget->currentRow()<0){
00142               detailsTextEdit->setPlainText("");
00143               return;
00144        }
00145        StudentsYear* sty=gt.rules.yearsList.at(yearsListWidget->currentRow());
00146        detailsTextEdit->setPlainText(sty->getDetailedDescriptionWithConstraints(gt.rules));
00147 }
00148 
00149 void YearsForm::sortYears()
00150 {
00151        gt.rules.sortYearsAlphabetically();
00152 
00153        yearsListWidget->clear();
00154        for(int i=0; i<gt.rules.yearsList.size(); i++){
00155               StudentsYear* year=gt.rules.yearsList[i];
00156               yearsListWidget->addItem(year->name);
00157        }
00158 
00159        if(yearsListWidget->count()>0)
00160               yearsListWidget->setCurrentRow(0);
00161 }
00162 
00163 void YearsForm::modifyYear()
00164 {
00165        int q=yearsListWidget->currentRow();
00166        int valv=yearsListWidget->verticalScrollBar()->value();
00167        int valh=yearsListWidget->horizontalScrollBar()->value();
00168 
00169        if(yearsListWidget->currentRow()<0){
00170               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00171               return;
00172        }
00173        QString yearName=yearsListWidget->currentItem()->text();
00174        int numberOfStudents=gt.rules.searchStudentsSet(yearName)->numberOfStudents;
00175 
00176        ModifyStudentsYearForm form(this, yearName, numberOfStudents);
00177        setParentAndOtherThings(&form, this);
00178        form.exec();
00179 
00180        yearsListWidget->clear();
00181        for(int i=0; i<gt.rules.yearsList.size(); i++){
00182               StudentsYear* year=gt.rules.yearsList[i];
00183               yearsListWidget->addItem(year->name);
00184        }
00185        
00186        yearsListWidget->verticalScrollBar()->setValue(valv);
00187        yearsListWidget->horizontalScrollBar()->setValue(valh);
00188 
00189        if(q>=yearsListWidget->count())
00190               q=yearsListWidget->count()-1;
00191        if(q>=0)
00192               yearsListWidget->setCurrentRow(q);
00193        else
00194               detailsTextEdit->setPlainText(QString(""));
00195 }
00196 
00197 void YearsForm::activateStudents()
00198 {
00199        if(yearsListWidget->currentRow()<0){
00200               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00201               return;
00202        }
00203        
00204        QString yearName=yearsListWidget->currentItem()->text();
00205        int count=gt.rules.activateStudents(yearName);
00206        QMessageBox::information(this, tr("FET information"), tr("Activated a number of %1 activities").arg(count));
00207 }
00208 
00209 void YearsForm::deactivateStudents()
00210 {
00211        if(yearsListWidget->currentRow()<0){
00212               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00213               return;
00214        }
00215        
00216        QString yearName=yearsListWidget->currentItem()->text();
00217        int count=gt.rules.deactivateStudents(yearName);
00218        QMessageBox::information(this, tr("FET information"), tr("De-activated a number of %1 activities").arg(count));
00219 }
00220 
00221 void YearsForm::divideYear()
00222 {
00223        if(yearsListWidget->currentRow()<0){
00224               QMessageBox::information(this, tr("FET information"), tr("Invalid selected year"));
00225               return;
00226        }
00227        
00228        QString yearName=yearsListWidget->currentItem()->text();
00229        
00230        SplitYearForm form(this, yearName);
00231        setParentAndOtherThings(&form, this);
00232        form.exec();
00233 }