Back to index

fet  5.18.0
studentsstatisticsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           studentsstatisticform.cpp  -  description
00003                              -------------------
00004     begin                : March 25, 2006
00005     copyright            : (C) 2006 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 "studentsstatisticsform.h"
00019 
00020 #include "timetable_defs.h"
00021 #include "timetable.h"
00022 
00023 #include "fet.h"
00024 
00025 #include <QString>
00026 #include <QStringList>
00027 
00028 #include <QHash>
00029 
00030 #include <QProgressDialog>
00031 
00032 #include "longtextmessagebox.h"
00033 
00034 #include <QMessageBox>
00035 #include <QApplication>
00036 
00037 #include <QHeaderView>
00038 #include <QTableWidget>
00039 
00040 extern QApplication* pqapplication;
00041 
00042 //QHash<QString, int> onlyExactHours; //for each students set, only the hours from each activity which has exactly the same set
00043 //does not include related sets.
00044 
00045 //QHash<QString, int> onlyExactActivities;
00046 
00047 //QHash<QString, int> allStudentsSets; //int is type
00048 QSet<QString> allStudentsSets;
00049 
00050 QHash<QString, int> allHours; //for each students set, only the hours from each activity which has exactly the same set
00051 //does not include related sets.
00052 
00053 QHash<QString, int> allActivities;
00054 
00055 QSet<QString> related; //related to current set
00056 
00057 QSet<QString> relatedSubgroups;
00058 QSet<QString> relatedGroups;
00059 QSet<QString> relatedYears;
00060 
00061 StudentsStatisticsForm::StudentsStatisticsForm(QWidget* parent): QDialog(parent)
00062 {
00063        setupUi(this);
00064        
00065        closeButton->setDefault(true);
00066 
00067        connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00068 
00069        tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
00070        tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00071 
00072        centerWidgetOnScreen(this);
00073        restoreFETDialogGeometry(this);
00074        
00075        connect(showYearsCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxesModified()));
00076        connect(showGroupsCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxesModified()));
00077        connect(showSubgroupsCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxesModified()));
00078 
00079        connect(showCompleteStructureCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxesModified()));
00080 
00081        allStudentsSets.clear();
00082        foreach(StudentsYear* year, gt.rules.yearsList){
00083               allStudentsSets.insert(year->name);
00084               foreach(StudentsGroup* group, year->groupsList){
00085                      allStudentsSets.insert(group->name);
00086                      foreach(StudentsSubgroup* subgroup, group->subgroupsList){
00087                             allStudentsSets.insert(subgroup->name);
00088                      }
00089               }
00090        }
00092        
00094        allHours.clear();
00095        allActivities.clear();      
00096        
00097        QProgressDialog progress(this);
00098        progress.setWindowTitle(tr("Computing students statistics", "Title of a progress dialog"));
00099        progress.setLabelText(tr("Computing ... please wait"));
00100        progress.setRange(0, allStudentsSets.count());
00101        progress.setModal(true);
00102                                           
00103        int ttt=0;
00104                                                  
00105        foreach(QString set, allStudentsSets){
00106               progress.setValue(ttt);
00107               //pqapplication->processEvents();
00108               if(progress.wasCanceled()){
00109                      QMessageBox::information(this, tr("FET information"), tr("Canceled"));
00110                      showYearsCheckBox->setDisabled(true);
00111                      showGroupsCheckBox->setDisabled(true);
00112                      showSubgroupsCheckBox->setDisabled(true);
00113                      showCompleteStructureCheckBox->setDisabled(true);
00114                      return;
00115               }
00116               ttt++;
00117        
00118               relatedSubgroups.clear();
00119               
00120               relatedGroups.clear();
00121               
00122               relatedYears.clear();
00123               
00124               related.clear();
00125               
00126               foreach(StudentsYear* year, gt.rules.yearsList){
00127                      bool y=false;
00128                      if(year->name==set)
00129                             y=true;
00130                      if(y)
00131                             relatedYears.insert(year->name);
00132                      foreach(StudentsGroup* group, year->groupsList){
00133                             bool g=false;
00134                             if(group->name==set)
00135                                    g=true;
00136                             if(y || g)
00137                                    relatedGroups.insert(group->name);
00138                             foreach(StudentsSubgroup* subgroup, group->subgroupsList){
00139                                    if(y || g || subgroup->name==set)
00140                                           relatedSubgroups.insert(subgroup->name);
00141                             }
00142                      }
00143               }
00144               
00145               foreach(StudentsYear* year, gt.rules.yearsList){
00146                      if(relatedYears.contains(year->name))
00147                             related.insert(year->name);
00148                      foreach(StudentsGroup* group, year->groupsList){
00149                             if(relatedGroups.contains(group->name)){
00150                                    related.insert(year->name);
00151                                    related.insert(group->name);
00152                             }
00153                             foreach(StudentsSubgroup* subgroup, group->subgroupsList){
00154                                    if(relatedSubgroups.contains(subgroup->name)){
00155                                           related.insert(year->name);
00156                                           related.insert(group->name);
00157                                           related.insert(subgroup->name);
00158                                    }
00159                             }
00160                      }
00161               }
00162               
00163               int nh=0;
00164               int na=0;
00165               
00166               foreach(Activity* act, gt.rules.activitiesList) if(act->active){
00167                      foreach(QString _students, act->studentsNames){
00168                             if(related.contains(_students)){
00169                                    nh += act->duration;
00170                                    na ++;
00171                                    
00172                                    break;
00173                             }
00174                      }
00175               }
00176               
00177               allHours.insert(set, nh);
00178               allActivities.insert(set, na);
00179        }
00181 
00182        progress.setValue(allStudentsSets.count());
00183        
00184        checkBoxesModified();       
00185 }
00186 
00187 StudentsStatisticsForm::~StudentsStatisticsForm()
00188 {
00189        saveFETDialogGeometry(this);
00190 }
00191 
00192 void StudentsStatisticsForm::checkBoxesModified()
00193 {
00194        bool complete=showCompleteStructureCheckBox->isChecked();
00195        
00196        QSet<QString> studs;
00197 
00198        studs.clear();
00199        int nStudentsSets=0;
00200        foreach(StudentsYear* year, gt.rules.yearsList){
00201               bool sy=true;
00202               if(!complete){
00203                      if(studs.contains(year->name))
00204                             sy=false;
00205                      else
00206                             studs.insert(year->name);
00207               }
00208               if(showYearsCheckBox->isChecked() && sy)
00209                      nStudentsSets++;
00210               foreach(StudentsGroup* group, year->groupsList){
00211                      bool sg=true;
00212                      if(!complete){
00213                             if(studs.contains(group->name))
00214                                    sg=false;
00215                             else
00216                                    studs.insert(group->name);
00217                      }
00218                      if(showGroupsCheckBox->isChecked() && sg)
00219                             nStudentsSets++;
00220                      foreach(StudentsSubgroup* subgroup, group->subgroupsList){
00221                             bool ss=true;
00222                             if(!complete){
00223                                    if(studs.contains(subgroup->name))
00224                                           ss=false;
00225                                    else
00226                                           studs.insert(subgroup->name);
00227                             }
00228                             if(showSubgroupsCheckBox->isChecked() && ss)
00229                                    nStudentsSets++;
00230                      }
00231               }
00232        }
00233        
00234        tableWidget->clear();
00235        tableWidget->setColumnCount(3);
00236        tableWidget->setRowCount(nStudentsSets);
00237        
00238        QStringList columns;
00239        columns<<tr("Students set");
00240        columns<<tr("No. of activities");
00241        columns<<tr("Duration");
00242        
00243        tableWidget->setHorizontalHeaderLabels(columns);
00244        
00245        studs.clear();
00246        
00247        int currentStudentsSet=-1;
00248        foreach(StudentsYear* year, gt.rules.yearsList){
00249               bool sy=true;
00250               if(!complete){
00251                      if(studs.contains(year->name))
00252                             sy=false;
00253                      else
00254                             studs.insert(year->name);
00255               }
00256 
00257               if(showYearsCheckBox->isChecked() && sy){
00258                      currentStudentsSet++;              
00259                      insertStudentsSet(year, currentStudentsSet);
00260               }
00261                             
00262               foreach(StudentsGroup* group, year->groupsList){
00263                      bool sg=true;
00264                      if(!complete){
00265                             if(studs.contains(group->name))
00266                                    sg=false;
00267                             else
00268                                    studs.insert(group->name);
00269                      }
00270 
00271                      if(showGroupsCheckBox->isChecked() && sg){
00272                             currentStudentsSet++;
00273                             insertStudentsSet(group, currentStudentsSet);
00274                      }
00275                      
00276                      foreach(StudentsSubgroup* subgroup, group->subgroupsList){
00277                             bool ss=true;
00278                             if(!complete){
00279                                    if(studs.contains(subgroup->name))
00280                                           ss=false;
00281                                    else
00282                                           studs.insert(subgroup->name);
00283                             }
00284 
00285                             if(showSubgroupsCheckBox->isChecked() && ss){
00286                                    currentStudentsSet++;
00287                                    insertStudentsSet(subgroup, currentStudentsSet);
00288                             }
00289                      }      
00290               }
00291        }
00292        
00293        tableWidget->resizeColumnsToContents();
00294        tableWidget->resizeRowsToContents();
00295 }
00296 
00297 void StudentsStatisticsForm::insertStudentsSet(StudentsSet* set, int row)
00298 {
00299        QTableWidgetItem* newItem=new QTableWidgetItem(set->name);
00300        newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00301        tableWidget->setItem(row, 0, newItem);
00302 
00303        int nSubActivities=0;
00304        int nHours=0;
00305        
00306        if(allHours.contains(set->name))
00307               nHours=allHours.value(set->name);
00308        else{
00309               assert(0);
00310        }
00311               
00312        if(allActivities.contains(set->name))
00313               nSubActivities=allActivities.value(set->name);
00314        else
00315               assert(0);
00316               
00317        newItem=new QTableWidgetItem(CustomFETString::number(nSubActivities));
00318        newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00319        tableWidget->setItem(row, 1, newItem);
00320 
00321        newItem=new QTableWidgetItem(CustomFETString::number(nHours));
00322        newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00323        tableWidget->setItem(row, 2, newItem);
00324 }
00325 
00326 void StudentsStatisticsForm::on_helpPushButton_clicked()
00327 {
00328        QString s;
00329        
00330        s+=tr("The check boxes '%1', '%2' and '%3': they permit you to show/hide information related to years, groups or subgroups")
00331         .arg(tr("Show years"))
00332         .arg(tr("Show groups"))
00333         .arg(tr("Show subgroups"));
00334        
00335        s+="\n\n";
00336        
00337        s+=tr("The check box '%1': it has effect only if you have overlapping groups/years, and means that FET will show the complete tree structure"
00338         ", even if that means that some subgroups/groups will appear twice or more in the table, with the same information."
00339         " For instance, if you have year Y1, groups G1 and G2, subgroups S1, S2, S3, with structure: Y1 (G1 (S1, S2), G2 (S1, S3)),"
00340         " S1 will appear twice in the table with the same information attached").arg(tr("Show duplicates"));
00341        
00342        LongTextMessageBox::largeInformation(this, tr("FET help"), s);
00343 }