Back to index

fet  5.18.0
activityplanningform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                 FET
00003                           -------------------
00004    copyright            : (C) by Lalescu Liviu
00005     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00006  ***************************************************************************
00007                       activityplanning.cpp  -  description
00008                              -------------------
00009     begin                : Dec 2009
00010     copyright            : (C) by Volker Dirr
00011                          : http://www.timetabling.de/
00012  ***************************************************************************
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  ***************************************************************************/
00020 
00021 // Code contributed by Volker Dirr ( http://www.timetabling.de/ )
00022 // Many thanks to Liviu Lalescu. He told me some speed optimizations.
00023 
00024 #include "activityplanningform.h"
00025 
00026 #include "timetable.h"
00027 #include "timetable_defs.h"
00028 
00029 // BE CAREFUL: DON'T USE INTERNAL VARIABLES HERE, because maybe computeInternalStructure() is not done!
00030 
00031 #include <QtGui>
00032 
00033 #include <QInputDialog>
00034 
00035 #include <QToolButton>
00036 
00037 #include <QTableWidget>
00038 #include <QHeaderView>
00039 
00040 #include <QKeySequence>
00041 
00042 #include "activitiesform.h"
00043 #include "addactivityform.h"
00044 #include "subactivitiesform.h"
00045 #include "modifyactivityform.h"
00046 #include "modifysubactivityform.h"
00047 #include "longtextmessagebox.h"
00048 
00049 #include "sparseitemmodel.h"
00050 
00051 #include <QString>
00052 #include <QStringList>
00053 #include <QHash>
00054 #include <QMultiHash>
00055 #include <QMap>
00056 #include <QSet>
00057 
00058 #include <QRadioButton>
00059 #include <QCheckBox>
00060 
00061 #include <QList>
00062 
00063 #include <QSplitter>
00064 #include <QSettings>
00065 #include <QObject>
00066 #include <QMetaObject>
00067 
00068 extern const QString COMPANY;
00069 extern const QString PROGRAM;
00070 
00071 const QString RBActivityState="/activity-radio-button-state";
00072 const QString RBSubactivityState="/subactivity-radio-button-state";
00073 const QString RBAddState="/add-activity-radio-button-state";
00074 const QString RBModifyState="/modify-activity-radio-button-state";
00075 const QString RBDeleteState="/delete-activities-radio-button-state";
00077 const QString CBActiveState="/active-combo-box-state";
00079 const QString showYearsState="/show-years-check-box-state";
00080 const QString showGroupsState="/show-groups-check-box-state";
00081 const QString showSubgroupsState="/show-subgroups-check-box-state";
00082 const QString showTeachersState="/show-teachers-check-box-state";
00083 const QString showActivityTagsState="/show-activity-tags-check-box-state";
00084 const QString showDuplicatesState="/show-duplicates-check-box-state";
00085 const QString hideEmptyLinesState="/hide-empty-lines-check-box-state";
00086 const QString swapAxisState="/swap-axes-check-box-state";
00087 
00088 //maybe put following in timetable_defs.h? (start)
00089 const int IS_YEAR = 1;
00090 const int IS_GROUP = 2;
00091 const int IS_SUBGROUP = 3;
00092 
00093 const int ACTIVE_ONLY = 0;
00094 const int INACTIVE_ONLY = 1;
00095 const int ACTIVE_OR_INACTIVE = 2;
00096 //maybe put following in timetable_defs.h? (end)
00097 
00098 extern Timetable gt;
00099 
00100 extern QStringList allStudentsNames;                           //NOT QSet <QString>!!! Because that do an incorrect order of the lists!
00101 
00102 static QList<bool> studentsDuplicates;
00103 static QList<int> yearORgroupORsubgroup;
00104 
00105 extern QStringList allTeachersNames;                           //NOT QSet <QString>!!! Because that do an incorrect order of the lists!
00106 extern QStringList allSubjectsNames;                           //NOT QSet <QString>!!! Because that do an incorrect order of the lists!
00107 
00108 extern QHash <QString, int> teachersTotalNumberOfHours;
00109 extern QHash <QString, int> teachersTotalNumberOfHours2;
00110 extern QHash <QString, int> studentsTotalNumberOfHours;
00111 extern QHash <QString, int> studentsTotalNumberOfHours2;
00112 extern QHash <QString, int> subjectsTotalNumberOfHours;
00113 extern QHash <QString, int> subjectsTotalNumberOfHours4;
00114 
00115 //TODO: activate teachersTargetNumberOfHours again! it is usefull! seach teachersTargetNumberOfHours. Just 2 lines to delete!
00116 //TODO: need to setDefaultValue for the QHashs ? (sum/number of hours) (also in statisticsexport?) look like it is unneeded.
00117 //TODO: check with toggled
00118 //TODO: retry mouseTracking (still in source. search "mouseTracking"). check: move mouse one last visibile line. is header always highlighted, under all operating systems?!
00119 //TODO: update if a new teacher, subject or year/group/subgroup is added - or better: just disalow that?!
00120 //      write a "updateBasic"-function with source from constructor if you want to update/care about teacher, subject and students
00121 //TODO: add a new row in teachers table with "comments" - of course saving data is needed to be useful
00122 //MAYBE TODO: display "related" activities. so display all activities of a subgroup also in its related year and group. Problem: Memory and speed!
00123 //            ! i don't like this feature, because using this activitiestable will be much more difficult, because it mean each cell contains (normaly) more then 1 activity!
00124 //            ! So all shortcuts (especialy delete, add and modify) will be useless!
00125 //            ! The table will be very full, so you will loose clear view!
00126 
00127 static QList<int> teachersTargetNumberOfHours;          //TODO: do this global, this must/should be saved in fet file! Do it in teachers.h ?!
00128 
00129 PlanningCommunicationSpinBox planningCommunicationSpinBox;
00130 
00131 
00132 StartActivityPlanning::StartActivityPlanning()
00133 {
00134 }
00135 
00136 StartActivityPlanning::~StartActivityPlanning()
00137 {
00138 }
00139 
00140 void StartActivityPlanning::startActivityPlanning(QWidget* parent){
00141        assert(gt.rules.initialized);
00142        teachersTargetNumberOfHours.clear();
00143        
00144        allStudentsNames.clear();
00145        studentsDuplicates.clear();
00146        yearORgroupORsubgroup.clear();
00147        foreach(StudentsYear* sty, gt.rules.yearsList){
00148               if(allStudentsNames.contains(sty->name)){
00149                      studentsDuplicates<<true;
00150               } else {
00151                      studentsDuplicates<<false;
00152               }
00153               allStudentsNames<<sty->name;
00154               yearORgroupORsubgroup<<IS_YEAR;
00155               foreach(StudentsGroup* stg, sty->groupsList){
00156                      if(allStudentsNames.contains(stg->name)){
00157                             studentsDuplicates<<true;
00158                      } else {
00159                             studentsDuplicates<<false;
00160                      }
00161                      allStudentsNames<<stg->name;
00162                      yearORgroupORsubgroup<<IS_GROUP;
00163                      foreach(StudentsSubgroup* sts, stg->subgroupsList){
00164                             if(allStudentsNames.contains(sts->name)){
00165                                    studentsDuplicates<<true;
00166                             } else {
00167                                    studentsDuplicates<<false;
00168                             }
00169                             allStudentsNames<<sts->name;
00170                             yearORgroupORsubgroup<<IS_SUBGROUP;
00171                      }
00172               }
00173        }
00174        
00175        allTeachersNames.clear();                        // just needed, because i don't need to care about correct iTeacherList if i do it this way.
00176        foreach(Teacher* t, gt.rules.teachersList){             //  So i don't need gt.rules.computeInternalStructure();
00177               allTeachersNames<<t->name;
00178               teachersTargetNumberOfHours<<0;
00179        }
00180 
00181        allSubjectsNames.clear();                        // just done, because i always want to do it the same way + it is faster
00182        foreach(Subject* s, gt.rules.subjectsList){             // Also don't display empty subjects is easier
00183               allSubjectsNames<<s->name;
00184        }
00185        
00186        ActivityPlanningForm apfd(parent);
00187        setParentAndOtherThings(&apfd, parent);
00188        apfd.exec();
00189        
00190        allStudentsNames.clear();
00191        allTeachersNames.clear();
00192        allSubjectsNames.clear();
00193        
00194        studentsDuplicates.clear();
00195        yearORgroupORsubgroup.clear();
00196 
00197        teachersTotalNumberOfHours.clear();
00198        teachersTotalNumberOfHours2.clear();
00199        studentsTotalNumberOfHours.clear();
00200        studentsTotalNumberOfHours2.clear();
00201        subjectsTotalNumberOfHours.clear();
00202        subjectsTotalNumberOfHours4.clear();
00203 }
00204 
00205 
00206 // this is very similar to statisticsexport.cpp. so please also check there if you change something here!
00207 ActivityPlanningForm::ActivityPlanningForm(QWidget *parent): QDialog(parent)
00208 {
00209        this->setWindowTitle(tr("Activity Planning Dialog"));
00210        
00211        QHBoxLayout* wholeDialog=new QHBoxLayout(this);
00212        
00213        leftSplitter=new QSplitter(Qt::Vertical);
00214        //leftSplitter->setMinimumSize(650, 600);
00215        
00216        activitiesTableView= new SparseTableView;
00217 
00218        teachersTableView= new SparseTableView;
00219        
00220        leftSplitter->addWidget(activitiesTableView);
00221        leftSplitter->addWidget(teachersTableView);
00222        
00223        //begin added by Liviu
00224        QList<int> list;
00225        list<<10000<<4100;
00226        leftSplitter->setSizes(list);
00227        //end added by Liviu
00228        
00229        leftSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00230        
00231        QVBoxLayout* rightDialog=new QVBoxLayout();
00232        
00233        /*QGroupBox**/ actionsBox=new QGroupBox(tr("Action", "It means the kind of action the user selects"));
00234        QVBoxLayout* actionsBoxVertical=new QVBoxLayout();
00235        RBActivity= new QRadioButton(tr("Activities", "Please keep translation short"));
00236        RBSubactivity= new QRadioButton(tr("Subactivities", "Please keep translation short"));
00237        RBAdd= new QRadioButton(tr("Add activity", "Please keep translation short"));
00238        RBModify= new QRadioButton(tr("Modify activity", "Please keep translation short"));
00239        RBDelete= new QRadioButton(tr("Delete activities", "Please keep translation short"));
00240 
00241        actionsBoxVertical->addWidget(RBActivity);
00242        actionsBoxVertical->addWidget(RBSubactivity);
00243        actionsBoxVertical->addWidget(RBAdd);
00244        actionsBoxVertical->addWidget(RBModify);
00245        actionsBoxVertical->addWidget(RBDelete);
00246        RBActivity->setChecked(true);
00247        actionsBox->setLayout(actionsBoxVertical);
00248        
00249        /*QGroupBox**/ optionsBox=new QGroupBox(tr("Options"));
00250        QVBoxLayout* optionsBoxVertical=new QVBoxLayout();
00251        QStringList activeStrings;
00252        //please do not modify order for these below, as the current combobox index is saved in settings and restored
00253        activeStrings<<tr("Active", "It refers to active activities. Please keep translation short")
00254               <<tr("Inactive", "It refers to inactive activities. Please keep translation short")
00255               <<tr("All", "It refers to all activities. Please keep translation short");
00256        CBActive=new QComboBox();
00257        CBActive->addItems(activeStrings);
00258        CBActive->setCurrentIndex(ACTIVE_ONLY);
00259        showYears=new QCheckBox(tr("Show years", "Please keep translation short"));
00260        showYears->setChecked(true);
00261        showGroups=new QCheckBox(tr("Show groups", "Please keep translation short"));
00262        showGroups->setChecked(true);
00263        showSubgroups=new QCheckBox(tr("Show subgroups", "Please keep translation short"));
00264        showSubgroups->setChecked(false);
00265        showTeachers=new QCheckBox(tr("Show teachers", "Please keep translation short"));
00266        showTeachers->setChecked(true);
00267        //showActivityTags=new QCheckBox(tr("Show activity tags", "Please keep translation short"));
00268        showActivityTags=new QCheckBox(tr("Show tags", "Please keep translation short. It refers to activity tags, but I want to keep it shorter, because there is not enough space."));
00269        showActivityTags->setChecked(false);
00270        showDuplicates=new QCheckBox(tr("Show duplicates", "Please keep translation short"));
00271        showDuplicates->setChecked(false);
00272        hideEmptyLines=new QCheckBox(tr("Hide empty lines", "Please keep translation short"));
00273        hideEmptyLines->setChecked(false);
00274        hideUsedTeachers=new QCheckBox(tr("Hide full teachers", "This field is for the moment not shown in FET, but we translate it for maybe future versions. "
00275               "It refers to teachers who have their number of hours fulfilled. Please keep translation short"));
00276        hideUsedTeachers->setChecked(false); //important to not hide teachers without activities, if target number of hours is deactivated
00277        swapAxis=new QCheckBox(tr("Swap axes", "Please keep translation short"));
00278        swapAxis->setChecked(false);
00279        pbPseudoActivities=new QPushButton(tr("Pseudo activities", "Please keep translation short. It means activities without teachers and/or students sets"));
00280        //set auto default all buttons, so that the user can press Enter on a cell and have the action for the cell, not the auto default button
00281        pbPseudoActivities->setAutoDefault(false);
00282        pbDeleteAll=new QPushButton(tr("Delete all", "Refers to activities. Please keep translation short"));
00283        pbDeleteAll->setAutoDefault(false);
00284        //pbHelp=new QPushButton(tr("Help", "Please keep translation short"));
00285        //pbHelp->setAutoDefault(false);
00286        
00287        showHideButton=new QToolButton;
00288        showHideButton->setText(tr("Hide buttons", "Please keep translation short. This is an option to hide some buttons in the planning activity dialog, so that the tables are more visible."));
00289        showHideButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
00290        origShowHideSizePolicy=showHideButton->sizePolicy();
00291        /*cout<<"hpol=="<<showHidePushButton->sizePolicy().horizontalPolicy()<<" ";
00292        cout<<"vpol=="<<showHidePushButton->sizePolicy().verticalPolicy()<<endl;*/
00293        showHideButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
00294        
00295        pbClose=new QPushButton(tr("Close", "Please keep translation short"));
00296        pbClose->setAutoDefault(false);
00297        
00298        optionsBoxVertical->addWidget(CBActive);
00299        optionsBoxVertical->addWidget(showYears);
00300        optionsBoxVertical->addWidget(showGroups);
00301        optionsBoxVertical->addWidget(showSubgroups);
00302        optionsBoxVertical->addWidget(showTeachers);
00303        optionsBoxVertical->addWidget(showActivityTags);
00304        optionsBoxVertical->addWidget(showDuplicates);
00305        optionsBoxVertical->addWidget(hideEmptyLines);
00306        optionsBoxVertical->addWidget(hideUsedTeachers);
00307        optionsBoxVertical->addWidget(swapAxis);
00308        //optionsBoxVertical->addWidget(pbPseudoActivities);
00309        optionsBox->setLayout(optionsBoxVertical);
00310        
00311        rightDialog->addWidget(actionsBox);
00312        rightDialog->addWidget(optionsBox);
00313        rightDialog->addWidget(pbPseudoActivities);
00314        rightDialog->addStretch();
00315        rightDialog->addWidget(pbDeleteAll);
00316        rightDialog->addStretch();
00317        //rightDialog->addWidget(pbHelp);
00318        rightDialog->addWidget(showHideButton);
00319        rightDialog->addStretch();
00320        rightDialog->addWidget(pbClose);
00321        
00322        wholeDialog->addWidget(leftSplitter);
00323        wholeDialog->addLayout(rightDialog);
00324        
00325        teachersTableView->setSelectionMode(QAbstractItemView::SingleSelection);
00326 
00327        activitiesTableView->setSelectionMode(QAbstractItemView::SingleSelection);
00328        
00329        //maybe disable AlternatingColors as soon as mouseTracking work correct?!
00330        activitiesTableView->setAlternatingRowColors(true);
00331 
00332        teachersTableView->setAlternatingRowColors(true); //by Liviu
00333        //mouseTracking (start 1/3)
00334        /*
00335        activitiesTable->setMouseTracking(true);
00336        teachersTable->setMouseTracking(true);
00337        */
00338        //mouseTracking (end 1/3)
00339        
00340        updateTables(0);
00341        
00342        //connect(activitiesTableView, SIGNAL(cellClicked(int, int)), this, SLOT(activitiesCellSelected(int, int)));
00343        connect(activitiesTableView, SIGNAL(activated(const QModelIndex&)), this, SLOT(activitiesCellSelected(const QModelIndex&)));
00344        
00345        //connect(activitiesTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(ActivtiesCellSelected(int, int)));
00346 
00347        //connect(teachersTable, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(teachersCellSelected(QTableWidgetItem*)));
00348        connect(teachersTableView, SIGNAL(activated(const QModelIndex&)), this, SLOT(teachersCellSelected(const QModelIndex&)));
00349 
00350        //mouseTracking (start 2/3)
00351        /*
00352        connect(activitiesTable, SIGNAL(cellEntered(int, int)), this, SLOT(ActivtiesCellEntered(int, int)));
00353        connect(teachersTable, SIGNAL(cellEntered(int, int)), this, SLOT(TeachersCellEntered(int, int)));
00354        */
00355        //mouseTracking (end 2/3)
00356        
00357        connect(activitiesTableView->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(activitiesTableHorizontalHeaderClicked(int)));
00358        connect(activitiesTableView->verticalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(activitiesTableVerticalHeaderClicked(int)));
00359 
00360        connect(teachersTableView->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(teachersTableHorizontalHeaderClicked(int)));
00361        
00362        connect(CBActive, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTables(int)));
00363        connect(showDuplicates, SIGNAL(stateChanged(int)), this, SLOT(updateTablesVisual(int)));
00364        connect(showYears, SIGNAL(stateChanged(int)), this, SLOT(updateTablesVisual(int)));
00365        connect(showGroups, SIGNAL(stateChanged(int)), this, SLOT(updateTablesVisual(int)));
00366        connect(showSubgroups, SIGNAL(stateChanged(int)), this, SLOT(updateTablesVisual(int)));
00367        connect(showTeachers, SIGNAL(stateChanged(int)), this, SLOT(updateTables(int)));
00368        connect(showActivityTags, SIGNAL(stateChanged(int)), this, SLOT(updateTables(int)));
00369        connect(hideEmptyLines, SIGNAL(stateChanged(int)), this, SLOT(updateTablesVisual(int)));
00370        connect(hideUsedTeachers, SIGNAL(stateChanged(int)), this, SLOT(updateTablesVisual(int)));
00371        connect(swapAxis, SIGNAL(stateChanged(int)), this, SLOT(updateTables(int)));
00372        connect(pbDeleteAll, SIGNAL(clicked()), this, SLOT(deleteAll()));
00373        connect(pbPseudoActivities, SIGNAL(clicked()), this, SLOT(pseudoActivities()));
00374        //connect(pbHelp, SIGNAL(clicked()), this, SLOT(help()));
00375        connect(showHideButton, SIGNAL(clicked()), this, SLOT(showHide()));
00376        connect(pbClose, SIGNAL(clicked()), this, SLOT(close()));
00377        
00378        connect(&planningCommunicationSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateTables(int)));
00379 
00380        int hh=560;
00381        if(hh<this->minimumSizeHint().height())
00382               hh=this->minimumSizeHint().height();
00383        this->resize(840, hh);
00384        
00385        buttonsVisible=true;
00386 
00387        centerWidgetOnScreen(this);
00388        restoreFETDialogGeometry(this);
00389        //restore splitter state
00390        QSettings settings(COMPANY, PROGRAM);
00391        if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
00392               leftSplitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
00394        if(settings.contains(this->metaObject()->className()+QString("/buttons-visible"))){
00395               bool bv=settings.value(this->metaObject()->className()+QString("/buttons-visible")).toBool();
00396               if(bv==false){
00397                      showHide();
00398               }
00399        }
00400        //restore other settings
00401        if(settings.contains(this->metaObject()->className()+RBActivityState))
00402               RBActivity->setChecked(settings.value(this->metaObject()->className()+RBActivityState).toBool());
00403        if(settings.contains(this->metaObject()->className()+RBSubactivityState))
00404               RBSubactivity->setChecked(settings.value(this->metaObject()->className()+RBSubactivityState).toBool());
00405        if(settings.contains(this->metaObject()->className()+RBAddState))
00406               RBAdd->setChecked(settings.value(this->metaObject()->className()+RBAddState).toBool());
00407        if(settings.contains(this->metaObject()->className()+RBModifyState))
00408               RBModify->setChecked(settings.value(this->metaObject()->className()+RBModifyState).toBool());
00409        if(settings.contains(this->metaObject()->className()+RBDeleteState))
00410               RBDelete->setChecked(settings.value(this->metaObject()->className()+RBDeleteState).toBool());
00411        //
00412        if(settings.contains(this->metaObject()->className()+CBActiveState))
00413               CBActive->setCurrentIndex(settings.value(this->metaObject()->className()+CBActiveState).toInt());
00414        //
00415        if(settings.contains(this->metaObject()->className()+showYearsState))
00416               showYears->setChecked(settings.value(this->metaObject()->className()+showYearsState).toBool());
00417        if(settings.contains(this->metaObject()->className()+showGroupsState))
00418               showGroups->setChecked(settings.value(this->metaObject()->className()+showGroupsState).toBool());
00419        if(settings.contains(this->metaObject()->className()+showSubgroupsState))
00420               showSubgroups->setChecked(settings.value(this->metaObject()->className()+showSubgroupsState).toBool());
00421        if(settings.contains(this->metaObject()->className()+showTeachersState))
00422               showTeachers->setChecked(settings.value(this->metaObject()->className()+showTeachersState).toBool());
00423        if(settings.contains(this->metaObject()->className()+showActivityTagsState))
00424               showActivityTags->setChecked(settings.value(this->metaObject()->className()+showActivityTagsState).toBool());
00425        if(settings.contains(this->metaObject()->className()+showDuplicatesState))
00426               showDuplicates->setChecked(settings.value(this->metaObject()->className()+showDuplicatesState).toBool());
00427        if(settings.contains(this->metaObject()->className()+hideEmptyLinesState))
00428               hideEmptyLines->setChecked(settings.value(this->metaObject()->className()+hideEmptyLinesState).toBool());
00429        if(settings.contains(this->metaObject()->className()+swapAxisState))
00430               swapAxis->setChecked(settings.value(this->metaObject()->className()+swapAxisState).toBool());
00431 }
00432 
00433 ActivityPlanningForm::~ActivityPlanningForm()
00434 {
00435        saveFETDialogGeometry(this);
00436 
00437        //save splitter state
00438        QSettings settings(COMPANY, PROGRAM);
00439        settings.setValue(this->metaObject()->className()+QString("/splitter-state"), leftSplitter->saveState());
00440 
00441        settings.setValue(this->metaObject()->className()+QString("/buttons-visible"), buttonsVisible);
00442 
00443        //save other settings
00444        settings.setValue(this->metaObject()->className()+RBActivityState, RBActivity->isChecked());
00445        settings.setValue(this->metaObject()->className()+RBSubactivityState, RBSubactivity->isChecked());
00446        settings.setValue(this->metaObject()->className()+RBAddState, RBAdd->isChecked());
00447        settings.setValue(this->metaObject()->className()+RBModifyState, RBModify->isChecked());
00448        settings.setValue(this->metaObject()->className()+RBDeleteState, RBDelete->isChecked());
00449        //
00450        settings.setValue(this->metaObject()->className()+CBActiveState, CBActive->currentIndex());
00451        //
00452        settings.setValue(this->metaObject()->className()+showYearsState, showYears->isChecked());
00453        settings.setValue(this->metaObject()->className()+showGroupsState, showGroups->isChecked());
00454        settings.setValue(this->metaObject()->className()+showSubgroupsState, showSubgroups->isChecked());
00455        settings.setValue(this->metaObject()->className()+showTeachersState, showTeachers->isChecked());
00456        settings.setValue(this->metaObject()->className()+showActivityTagsState, showActivityTags->isChecked());
00457        settings.setValue(this->metaObject()->className()+showDuplicatesState, showDuplicates->isChecked());
00458        settings.setValue(this->metaObject()->className()+hideEmptyLinesState, hideEmptyLines->isChecked());
00459        settings.setValue(this->metaObject()->className()+swapAxisState, swapAxis->isChecked());
00460 }
00461 
00462 void ActivityPlanningForm::showHide()
00463 {
00464        /*cout<<"hpol=="<<showHidePushButton->sizePolicy().horizontalPolicy()<<" ";
00465        cout<<"vpol=="<<showHidePushButton->sizePolicy().verticalPolicy()<<endl;*/
00466 
00467        if(buttonsVisible){
00468               pbPseudoActivities->hide();
00469               pbDeleteAll->hide();
00470               showHideButton->setText(tr("B", "Abbreviation for 'Buttons'. Please keep translation very short (probably only one letter)."
00471                      " There is an option to hide the buttons in the planning activity dialog, so that the tables can have larger visible parts."
00472                      " This button (B) will remain there after the user hides the other buttons. The user then can press this button to show again all the buttons."
00473                      " We need this 'B' button to be very small, so keep translation abbreviated to the initial only"));
00474               pbClose->hide();
00475               
00476               optionsBox->hide();
00477               actionsBox->hide();
00478 
00479               showHideButton->setSizePolicy(origShowHideSizePolicy);
00480               
00481               buttonsVisible=false;
00482        }
00483        else{
00484               pbPseudoActivities->show();
00485               pbDeleteAll->show();
00486               showHideButton->setText(tr("Hide buttons", "Please keep translation short. This is an option to hide some buttons in the planning activity dialog, so that the tables are more visible."));
00487               pbClose->show();
00488 
00489               optionsBox->show();
00490               actionsBox->show();
00491 
00492               showHideButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
00493 
00494               buttonsVisible=true;
00495        }
00496 }
00497 
00498 void ActivityPlanningForm::computeActivitiesForDeletion(const QString& teacherName, const QString& studentsSetName, const QString& subjectName,
00499        const QList<int>& tmpID, const QList<int>& tmpGroupID,
00500        int& nTotalActsDeleted,
00501        QList<int>& _idsToBeRemoved, QList<int>& _agidsToBeRemoved,
00502        QList<bool>& _affectOtherTeachersToBeRemoved, bool& _affectOtherTeachersOverall,
00503        QList<bool>& _affectOtherStudentsSetsToBeRemoved, bool& _affectOtherStudentsSetsOverall,
00504        QList<bool>& _affectOtherSubjectsToBeRemoved, bool& _affectOtherSubjectsOverall)
00505 {
00506        QHash<int, int> representantForId;
00507        QHash<int, int> numberOfSubactivitiesForRepresentant;
00508        QSet<int> affectStatusForRepresentantTeacher; //if in set, it affects
00509        QSet<int> affectStatusForRepresentantStudent; //if in set, it affects
00510        QSet<int> affectStatusForRepresentantSubject; //if in set, it affects
00511        foreach(Activity* act, gt.rules.activitiesList){
00512               int id=act->id;
00513               
00514               int agid=act->activityGroupId;
00515               if(agid==0)
00516                      agid=id;
00517               
00518               assert(!representantForId.contains(id));
00519               representantForId.insert(id, agid);
00520               
00521               int c=numberOfSubactivitiesForRepresentant.value(agid, 0);
00522               c++;
00523               numberOfSubactivitiesForRepresentant.insert(agid, c);
00524               
00525               if(teacherName!=""){
00526                      bool af=true;
00527                      if(act->teachersNames.count()==1)
00528                             if(act->teachersNames.at(0)==teacherName)
00529                                    af=false;
00530                                    
00531                      if( af && !affectStatusForRepresentantTeacher.contains(agid) )
00532                             affectStatusForRepresentantTeacher.insert(agid);
00533               }
00534               if(studentsSetName!=""){
00535                      bool af=true;
00536                      if(act->studentsNames.count()==1)
00537                             if(act->studentsNames.at(0)==studentsSetName)
00538                                    af=false;
00539                                    
00540                      if( af && !affectStatusForRepresentantStudent.contains(agid) )
00541                             affectStatusForRepresentantStudent.insert(agid);
00542               }
00543               if(subjectName!=""){
00544                      bool af=true;
00545                      if(act->subjectName==subjectName)
00546                             af=false;
00547                             
00548                      if( af && !affectStatusForRepresentantSubject.contains(agid) )
00549                             affectStatusForRepresentantSubject.insert(agid);
00550               }
00551        }
00552        
00553        QSet<int> representantCounted;
00554 
00555        nTotalActsDeleted=0;
00556        
00557        _idsToBeRemoved.clear();
00558        _agidsToBeRemoved.clear();
00559        
00560        _affectOtherTeachersToBeRemoved.clear();
00561        _affectOtherTeachersOverall=false;
00562        
00563        _affectOtherStudentsSetsToBeRemoved.clear();
00564        _affectOtherStudentsSetsOverall=false;
00565        
00566        _affectOtherSubjectsToBeRemoved.clear();
00567        _affectOtherSubjectsOverall=false;
00568 
00569        assert(tmpID.count()==tmpGroupID.count());
00570        
00571        for(int i=0; i<tmpID.count(); i++){
00572               int id=tmpID.at(i);
00573               assert(representantForId.contains(id));
00574               int repr=representantForId.value(id);
00575               
00576               if(!representantCounted.contains(repr)){
00577                      representantCounted.insert(repr);
00578                      
00579                      assert(numberOfSubactivitiesForRepresentant.contains(repr));
00580                      int n=numberOfSubactivitiesForRepresentant.value(repr);
00581                      assert(n>0);
00582                      nTotalActsDeleted+=n;
00583                      
00584                      _idsToBeRemoved.append(id);
00585                      _agidsToBeRemoved.append(tmpGroupID.at(i));
00586                      
00587                      if(affectStatusForRepresentantTeacher.contains(repr)){
00588                             _affectOtherTeachersToBeRemoved.append(true);
00589                             _affectOtherTeachersOverall=true;
00590                      }
00591                      else{
00592                             _affectOtherTeachersToBeRemoved.append(false);
00593                      }
00594                      
00595                      if(affectStatusForRepresentantStudent.contains(repr)){
00596                             _affectOtherStudentsSetsToBeRemoved.append(true);
00597                             _affectOtherStudentsSetsOverall=true;
00598                      }
00599                      else{
00600                             _affectOtherStudentsSetsToBeRemoved.append(false);
00601                      }
00602                      
00603                      if(affectStatusForRepresentantSubject.contains(repr)){
00604                             _affectOtherSubjectsToBeRemoved.append(true);
00605                             _affectOtherSubjectsOverall=true;
00606                      }
00607                      else{
00608                             _affectOtherSubjectsToBeRemoved.append(false);
00609                      }
00610               }
00611        }
00612 
00613        assert(_idsToBeRemoved.count()==_agidsToBeRemoved.count());
00614        assert(_idsToBeRemoved.count()==_affectOtherTeachersToBeRemoved.count());
00615        assert(_idsToBeRemoved.count()==_affectOtherStudentsSetsToBeRemoved.count());
00616        assert(_idsToBeRemoved.count()==_affectOtherSubjectsToBeRemoved.count());
00617 }
00618 
00619 void ActivityPlanningForm::activitiesTableHorizontalHeaderClicked(int column){
00620        if(RBActivity->isChecked()){
00621               if(swapAxis->checkState()==Qt::Checked){
00622                      ActivitiesForm form(this, "", allStudentsNames[column], "", "");
00623                      setParentAndOtherThings(&form, this);
00624                      form.exec();
00625               } else {
00626                      ActivitiesForm form(this, "", "", allSubjectsNames[column], "");
00627                      setParentAndOtherThings(&form, this);
00628                      form.exec();
00629               }
00630        } else if(RBSubactivity->isChecked()) {
00631               if(swapAxis->checkState()==Qt::Checked){
00632                      SubactivitiesForm form(this, "", allStudentsNames[column], "", "");
00633                      setParentAndOtherThings(&form, this);
00634                      form.exec();
00635               } else {
00636                      SubactivitiesForm form(this, "", "", allSubjectsNames[column], "");
00637                      setParentAndOtherThings(&form, this);
00638                      form.exec();
00639               }
00640        } else if(RBAdd->isChecked()) {
00641               if(swapAxis->checkState()==Qt::Checked){
00642                      AddActivityForm addActivityForm(this, "", allStudentsNames[column], "", "");
00643                      setParentAndOtherThings(&addActivityForm, this);
00644                      addActivityForm.exec();
00645               } else {
00646                      AddActivityForm addActivityForm(this, "", "", allSubjectsNames[column], "");
00647                      setParentAndOtherThings(&addActivityForm, this);
00648                      addActivityForm.exec();     
00649               }
00650        } else if(RBModify->isChecked()) {
00651               //Normaly there are to many activities. So just entering the activity form
00652               if(swapAxis->checkState()==Qt::Checked){
00653                      ActivitiesForm form(this, "", allStudentsNames[column], "", "");
00654                      setParentAndOtherThings(&form, this);
00655                      form.exec();
00656               } else {
00657                      ActivitiesForm form(this, "", "", allSubjectsNames[column], "");
00658                      setParentAndOtherThings(&form, this);
00659                      form.exec();
00660               }
00661        } else if(RBDelete->isChecked()) {
00662               int students=-1;
00663               int subject=column;
00664               if(swapAxis->checkState()==Qt::Checked){
00665                      students=column;
00666                      subject=-1;
00667               }
00668               //bool affectOtherStudents=false;
00669               QList<int> tmpID;
00670               QList<int> tmpGroupID;
00671               //QStringList tmpIdentify;
00672               QSet<int> tmpIdentifySet;
00673               //QList<bool> tmpAffectOtherStudents;
00674               Activity* act;
00675               for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
00676                      act=gt.rules.activitiesList[ai];
00677                      int tmpCurrentIndex=CBActive->currentIndex();
00678                      if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
00679                             || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
00680                             || (tmpCurrentIndex==ACTIVE_OR_INACTIVE) ){
00681                             if(subject==-1 || (subject>=0 && act->subjectName==allSubjectsNames[subject])){
00682                                    foreach(QString st, act->studentsNames){
00683                                           if(students==-1 || (students>=0 && st==allStudentsNames[students] )){
00684                                                  //QString tmpIdent=CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
00685                                                  //if(!tmpIdentify.contains(tmpIdent)){
00686                                                  if(!tmpIdentifySet.contains(act->id)){
00687                                                         tmpID<<act->id;
00688                                                         tmpGroupID<<act->activityGroupId;
00689                                                         //tmpIdentify<<CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
00690                                                         tmpIdentifySet.insert(act->id);
00691                                                         /*if(act->studentsNames.size()>1){
00692                                                                tmpAffectOtherStudents<<true;
00693                                                                affectOtherStudents=true;
00694                                                         } else {
00695                                                                tmpAffectOtherStudents<<false;
00696                                                         }*/
00697                                                  }
00698                                                  break;
00699                                           }
00700                                    }
00701                             }
00702                      }
00703               }
00704               
00705               assert(tmpID.count()==tmpIdentifySet.size());
00706               assert(tmpGroupID.count()==tmpIdentifySet.size());
00707               //assert(tmpAffectOtherStudents.count()==tmpIdentifySet.size());
00708               
00709               if(!tmpIdentifySet.isEmpty()){
00710                      int nTotalActsDeleted;
00711                      QList<int> _idsToBeRemoved;
00712                      QList<int> _agidsToBeRemoved;
00713 
00714                      QList<bool> _affectOtherTeachersToBeRemoved;
00715                      bool _affectOtherTeachersOverall;
00716                      QList<bool> _affectOtherStudentsToBeRemoved;
00717                      bool _affectOtherStudentsOverall;
00718                      QList<bool> _affectOtherSubjectsToBeRemoved;
00719                      bool _affectOtherSubjectsOverall;
00720 
00721                      if(swapAxis->checkState()==Qt::Checked){
00722                             computeActivitiesForDeletion("", allStudentsNames[column], "",
00723                                    tmpID, tmpGroupID,
00724                                    nTotalActsDeleted,
00725                                    _idsToBeRemoved, _agidsToBeRemoved,
00726                                    _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
00727                                    _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
00728                                    _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
00729 
00730                             QString s=tr("Delete %1 activities of students set %2?").arg(tmpIdentifySet.size()).arg(allStudentsNames[column]);
00731                             assert(nTotalActsDeleted>=tmpIdentifySet.size());
00732                             if(nTotalActsDeleted>tmpIdentifySet.size()){
00733                                    s+="\n\n";
00734                                    s+=tr("Because you have individually modified the components, there will be removed an additional number "
00735                                           "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
00736                             }
00737                             
00738                             int ret=QMessageBox::question(this, tr("Delete multiple?", "It refers to activities"), s, QMessageBox::Yes | QMessageBox::No);
00739                             
00740                             if(ret==QMessageBox::Yes){
00741                                    int ret2=QMessageBox::No;
00742                                    if(_affectOtherStudentsOverall){
00743                                           ret2=QMessageBox::question(this, tr("Delete related?", "It refers to activities"), tr("There are activities affecting other students sets. Should the related activities also be deleted?"),
00744                                                  QMessageBox::Yes | QMessageBox::No);
00745                                    }
00746                             
00747                                    for(int i=0; i<_idsToBeRemoved.count(); i++){
00748                                           if((_affectOtherStudentsToBeRemoved.at(i)==false) || (ret2==QMessageBox::Yes)){
00749                                                  gt.rules.removeActivity(_idsToBeRemoved.at(i), _agidsToBeRemoved.at(i));
00750                                           }
00751                                    }
00752                                    PlanningChanged::increasePlanningCommunicationSpinBox();
00753                             }
00754                      }
00755                      else{
00756                             computeActivitiesForDeletion("", "", allSubjectsNames[column],
00757                                    tmpID, tmpGroupID,
00758                                    nTotalActsDeleted,
00759                                    _idsToBeRemoved, _agidsToBeRemoved,
00760                                    _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
00761                                    _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
00762                                    _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
00763 
00764                             QString s=tr("Delete %1 activities of subject %2?").arg(tmpIdentifySet.size()).arg(allSubjectsNames[column]);
00765                                    //+" ("+tr("these are all the activities for this subject, possibly including activities for this subject which are not visible in the current view")+").";
00766                             assert(nTotalActsDeleted>=tmpIdentifySet.size());
00767                             if(nTotalActsDeleted>tmpIdentifySet.size()){
00768                                    s+="\n\n";
00769                                    s+=tr("Because you have individually modified the components, there will be removed an additional number "
00770                                           "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
00771                             }
00772                                    
00773                             int ret=QMessageBox::question(this, tr("Delete multiple?", "It refers to activities"), s, QMessageBox::Yes | QMessageBox::No);
00774                             
00775                             if(ret==QMessageBox::Yes){
00776                                    int ret2=QMessageBox::No;
00777                                    if(_affectOtherSubjectsOverall){
00778                                           ret2=QMessageBox::question(this, tr("Delete related?", "It refers to activities"), tr("There are activities affecting other subjects. Should the related activities also be deleted?"), QMessageBox::Yes | QMessageBox::No);
00779                                    }
00780                                    
00781                                    for(int i=0; i<_idsToBeRemoved.count(); i++){
00782                                           if((_affectOtherSubjectsToBeRemoved.at(i)==false) || (ret2==QMessageBox::Yes)){
00783                                                  gt.rules.removeActivity(_idsToBeRemoved.at(i), _agidsToBeRemoved.at(i));
00784                                           }
00785                                    }
00786                                    PlanningChanged::increasePlanningCommunicationSpinBox();
00787                             }
00788                      }
00789               }
00790        } else assert(0==1);
00791 }
00792 
00793 void ActivityPlanningForm::activitiesTableVerticalHeaderClicked(int row){
00794        if(RBActivity->isChecked()){
00795               if(swapAxis->checkState()==Qt::Checked){
00796                      ActivitiesForm form(this, "", "", allSubjectsNames[row], "");
00797                      setParentAndOtherThings(&form, this);
00798                      form.exec();
00799               } else {
00800                      ActivitiesForm form(this, "", allStudentsNames[row], "", "");
00801                      setParentAndOtherThings(&form, this);
00802                      form.exec();
00803               }
00804        } else if(RBSubactivity->isChecked()) {
00805               if(swapAxis->checkState()==Qt::Checked){
00806                      SubactivitiesForm form(this, "", "", allSubjectsNames[row], "");
00807                      setParentAndOtherThings(&form, this);
00808                      form.exec();
00809               } else {
00810                      SubactivitiesForm form(this, "", allStudentsNames[row], "", "");
00811                      setParentAndOtherThings(&form, this);
00812                      form.exec();
00813               }
00814        } else if(RBAdd->isChecked()) {
00815               if(swapAxis->checkState()==Qt::Checked){
00816                      AddActivityForm addActivityForm(this, "", "", allSubjectsNames[row], "");
00817                      setParentAndOtherThings(&addActivityForm, this);
00818                      addActivityForm.exec();
00819               } else {
00820                      AddActivityForm addActivityForm(this, "", allStudentsNames[row], "", "");
00821                      setParentAndOtherThings(&addActivityForm, this);
00822                      addActivityForm.exec();     
00823               }
00824        } else if(RBModify->isChecked()) {
00825               //Normaly there are to many activities. So just entering the activity form
00826               if(swapAxis->checkState()==Qt::Checked){
00827                      ActivitiesForm form(this, "", "", allSubjectsNames[row], "");
00828                      setParentAndOtherThings(&form, this);
00829                      form.exec();
00830               } else {
00831                      ActivitiesForm form(this, "", allStudentsNames[row], "", "");
00832                      setParentAndOtherThings(&form, this);
00833                      form.exec();
00834               }
00835        } else if(RBDelete->isChecked()) {
00836               int students=row;
00837               int subject=-1;
00838               if(swapAxis->checkState()==Qt::Checked){
00839                      students=-1;
00840                      subject=row;
00841               }
00842               //bool affectOtherStudents=false;
00843               QList<int> tmpID;
00844               QList<int> tmpGroupID;
00845               //QStringList tmpIdentify;
00846               QSet<int> tmpIdentifySet;
00847               //QList<bool> tmpAffectOtherStudents;
00848               Activity* act;
00849               for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
00850                      act=gt.rules.activitiesList[ai];
00851                      int tmpCurrentIndex=CBActive->currentIndex();
00852                      if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
00853                             || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
00854                             || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
00855                             if(subject==-1 || (subject>=0 && act->subjectName==allSubjectsNames[subject])){
00856                                    foreach(QString st, act->studentsNames){
00857                                           if(students==-1 || (students>=0 && st==allStudentsNames[students] )){
00858                                                  //QString tmpIdent=CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
00859                                                  //if(!tmpIdentify.contains(tmpIdent)){
00860                                                  if(!tmpIdentifySet.contains(act->id)){
00861                                                         tmpID<<act->id;
00862                                                         tmpGroupID<<act->activityGroupId;
00863                                                         //tmpIdentify<<CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
00864                                                         tmpIdentifySet.insert(act->id);
00865                                                         /*if(act->studentsNames.size()>1){
00866                                                                tmpAffectOtherStudents<<true;
00867                                                                affectOtherStudents=true;
00868                                                         } else {
00869                                                                tmpAffectOtherStudents<<false;
00870                                                         }*/
00871                                                  }
00872                                                  break;
00873                                           }
00874                                    }
00875                             }
00876                      }
00877               }
00878 
00879               assert(tmpID.count()==tmpIdentifySet.size());
00880               assert(tmpGroupID.count()==tmpIdentifySet.size());
00881               //assert(tmpAffectOtherStudents.count()==tmpIdentifySet.size());
00882 
00883               if(!tmpIdentifySet.isEmpty()){
00884                      int nTotalActsDeleted;
00885                      QList<int> _idsToBeRemoved;
00886                      QList<int> _agidsToBeRemoved;
00887 
00888                      QList<bool> _affectOtherTeachersToBeRemoved;
00889                      bool _affectOtherTeachersOverall;
00890                      QList<bool> _affectOtherStudentsToBeRemoved;
00891                      bool _affectOtherStudentsOverall;
00892                      QList<bool> _affectOtherSubjectsToBeRemoved;
00893                      bool _affectOtherSubjectsOverall;
00894 
00895                      if(swapAxis->checkState()==Qt::Checked){
00896                             computeActivitiesForDeletion("", "", allSubjectsNames[row],
00897                                    tmpID, tmpGroupID,
00898                                    nTotalActsDeleted,
00899                                    _idsToBeRemoved, _agidsToBeRemoved,
00900                                    _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
00901                                    _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
00902                                    _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
00903 
00904                             QString s=tr("Delete %1 activities of subject %2?").arg(tmpIdentifySet.size()).arg(allSubjectsNames[row]);
00905                                    //+" ("+tr("these are all the activities for this subject, possibly including activities for this subject which are not visible in the current view")+").";
00906                             assert(nTotalActsDeleted>=tmpIdentifySet.size());
00907                             if(nTotalActsDeleted>tmpIdentifySet.size()){
00908                                    s+="\n\n";
00909                                    s+=tr("Because you have individually modified the components, there will be removed an additional number "
00910                                           "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
00911                             }
00912                                    
00913                             int ret=QMessageBox::question(this, tr("Delete multiple?", "It refers to activities"), s, QMessageBox::Yes | QMessageBox::No);
00914                             
00915                             if(ret==QMessageBox::Yes){
00916                                    int ret2=QMessageBox::No;
00917                                    if(_affectOtherSubjectsOverall){
00918                                           ret2=QMessageBox::question(this, tr("Delete related?", "It refers to activities"), tr("There are activities affecting other subjects. Should the related activities also be deleted?"), QMessageBox::Yes | QMessageBox::No);
00919                                    }
00920                                    
00921                                    for(int i=0; i<_idsToBeRemoved.count(); i++){
00922                                           if((_affectOtherSubjectsToBeRemoved.at(i)==false) || (ret2==QMessageBox::Yes)){
00923                                                  gt.rules.removeActivity(_idsToBeRemoved.at(i), _agidsToBeRemoved.at(i));
00924                                           }
00925                                    }
00926                                    PlanningChanged::increasePlanningCommunicationSpinBox();
00927                             }
00928                      }
00929                      else{
00930                             computeActivitiesForDeletion("", allStudentsNames[row], "",
00931                                    tmpID, tmpGroupID,
00932                                    nTotalActsDeleted,
00933                                    _idsToBeRemoved, _agidsToBeRemoved,
00934                                    _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
00935                                    _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
00936                                    _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
00937 
00938                             QString s=tr("Delete %1 activities of students set %2?").arg(tmpIdentifySet.size()).arg(allStudentsNames[row]);
00939                             assert(nTotalActsDeleted>=tmpIdentifySet.size());
00940                             if(nTotalActsDeleted>tmpIdentifySet.size()){
00941                                    s+="\n\n";
00942                                    s+=tr("Because you have individually modified the components, there will be removed an additional number "
00943                                           "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
00944                             }
00945                             
00946                             int ret=QMessageBox::question(this, tr("Delete multiple?", "It refers to activities"), s, QMessageBox::Yes | QMessageBox::No);
00947                             
00948                             if(ret==QMessageBox::Yes){
00949                                    int ret2=QMessageBox::No;
00950                                    if(_affectOtherStudentsOverall){
00951                                           ret2=QMessageBox::question(this, tr("Delete related?", "It refers to activities"), tr("There are activities affecting other students sets. Should the related activities also be deleted?"),
00952                                                  QMessageBox::Yes | QMessageBox::No);
00953                                    }
00954                             
00955                                    for(int i=0; i<_idsToBeRemoved.count(); i++){
00956                                           if((_affectOtherStudentsToBeRemoved.at(i)==false) || (ret2==QMessageBox::Yes)){
00957                                                  gt.rules.removeActivity(_idsToBeRemoved.at(i), _agidsToBeRemoved.at(i));
00958                                           }
00959                                    }
00960                                    PlanningChanged::increasePlanningCommunicationSpinBox();
00961                             }
00962                      }
00963               }
00964        } else assert(0==1);
00965 }
00966 
00967 void ActivityPlanningForm::activitiesCellSelected(const QModelIndex& index){
00968        if(!index.isValid())
00969               return;
00970 
00971        int row=index.row();
00972        int column=index.column();
00973 
00974        int students=row;
00975        int subject=column;
00976        if(swapAxis->checkState()==Qt::Checked){
00977               students=column;
00978               subject=row;
00979        }
00980        if(RBActivity->isChecked()){
00981               ActivitiesForm form(this, "", allStudentsNames[students], allSubjectsNames[subject], "");
00982               setParentAndOtherThings(&form, this);
00983               form.exec();
00984        } else if(RBSubactivity->isChecked()) {
00985               SubactivitiesForm form(this, "", allStudentsNames[students], allSubjectsNames[subject], "");
00986               setParentAndOtherThings(&form, this);
00987               form.exec();
00988        } else if(RBAdd->isChecked()) {
00989               AddActivityForm addActivityForm(this, "", allStudentsNames[students], allSubjectsNames[subject], "");
00990               setParentAndOtherThings(&addActivityForm, this);
00991               addActivityForm.exec();
00992        } else if(RBModify->isChecked()) {
00993               QList<int> tmpActivities;
00994               QList<int> tmpSubactivities;
00995               QList<int> tmpAGIds;
00996               Activity* act;
00997               for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
00998                      act=gt.rules.activitiesList[ai];
00999                      int tmpCurrentIndex=CBActive->currentIndex();
01000                      if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
01001                             || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
01002                             || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
01003                             if(act->subjectName==allSubjectsNames[subject]){
01004                                    foreach(QString st, act->studentsNames){
01005                                           if(st==allStudentsNames[students]){
01006                                                  tmpSubactivities<<ai;
01007                                                  if(act->activityGroupId==0 || act->activityGroupId==act->id)
01008                                                         tmpActivities<<ai;
01009                                                  
01010                                                  tmpAGIds<<act->activityGroupId;
01011                                                  
01012                                                  break;
01013                                           }
01014                                    }
01015                             }
01016                      }
01017               }
01018               if(tmpActivities.size()<=1 && tmpSubactivities.count()>=1){
01019                      int agid=-1;
01020                      bool sameAgid=true;
01021                      foreach(int k, tmpAGIds){
01022                             if(agid==-1)
01023                                    agid=k;
01024                             else if(agid!=k){
01025                                    sameAgid=false;
01026                                    break;
01027                             }
01028                      }
01029                      
01030                      if(!sameAgid){
01031                             ActivitiesForm form(this, "", allStudentsNames[students], allSubjectsNames[subject], "");
01032                             setParentAndOtherThings(&form, this);
01033                             form.exec();
01034                             
01035                             return;
01036                      }
01037                      
01038                      if(tmpActivities.count()==0){ //maybe representant is inactive
01039                             assert(tmpAGIds.count()>=1);
01040                      
01041                             for(int i=0; i<gt.rules.activitiesList.count(); i++){
01042                                    Activity* act=gt.rules.activitiesList.at(i);
01043                                    if(act->id==act->activityGroupId && act->activityGroupId==tmpAGIds.at(0)){
01044                                           tmpActivities.append(i);
01045                                           //tmpSubactivities.prepend(i);
01046                                           //tmpAGIds.prepend(act->activityGroupId);
01047                                           break;
01048                                    }
01049                             }
01050                      }
01051                      
01052                      assert(tmpActivities.count()==1);
01053                      
01054                      foreach(int tmpAct, tmpActivities){
01055                             Activity* act=gt.rules.activitiesList[tmpAct];
01056                             if(act->isSplit()){
01057                                    //similar to activitiesform.cpp by Liviu Lalescu(start)
01058                                    //maybe TODO: write a function int activityCheckedManualy in activity.cpp, because we use this already 3 times (me even 5 times)
01059                                    //            here, in activitiesform.cpp, in csv export and also in willi2 export and winplan export.
01060                                    QStringList _teachers=act->teachersNames;
01061                                    bool _diffTeachers=false;
01062                             
01063                                    QString _subject=act->subjectName;
01064                                    bool _diffSubject=false;
01065                                    
01066                                    QStringList _activityTags=act->activityTagsNames;
01067                                    bool _diffActivityTags=false;
01068                             
01069                                    QStringList _students=act->studentsNames;
01070                                    bool _diffStudents=false;
01071                                    
01072                                    int _nTotalStudents=act->nTotalStudents;
01073                                    bool _diffNTotalStudents=false;
01074                             
01075                                    bool _computeNTotalStudents=act->computeNTotalStudents;
01076                                    bool _diffComputeNTotalStudents=false;
01077 
01078                                    int nSplit=0;
01079                                    for(int i=0; i<gt.rules.activitiesList.size(); i++){
01080                                           Activity* act2=gt.rules.activitiesList[i];
01081                                           if(act2->activityGroupId==act->activityGroupId){
01082                                                  nSplit++;
01083                                                  
01084                                                  if(_teachers!=act2->teachersNames)
01085                                                         _diffTeachers=true;
01086                                                  if(_subject!=act2->subjectName)
01087                                                         _diffSubject=true;
01088                                                  if(_activityTags!=act2->activityTagsNames)
01089                                                         _diffActivityTags=true;
01090                                                  if(_students!=act2->studentsNames)
01091                                                         _diffStudents=true;
01092                                                  if( /* !computeNTotalStudents && !act2->computeNTotalStudents && */ _nTotalStudents!=act2->nTotalStudents )
01093                                                         _diffNTotalStudents=true;
01094                                                  if(_computeNTotalStudents!=act2->computeNTotalStudents)
01095                                                         _diffComputeNTotalStudents=true;
01096                                           }
01097                                           if(nSplit>MAX_SPLIT_OF_AN_ACTIVITY){
01098                                                  QMessageBox::warning(this, tr("FET information"),
01099                                                   tr("Cannot modify this large activity, because it contains more than %1 activities.")
01100                                                   .arg(MAX_SPLIT_OF_AN_ACTIVITY));
01101                                                  return;
01102                                           }
01103                                    }
01104                                    if(_diffTeachers || _diffSubject || _diffActivityTags || _diffStudents || _diffNTotalStudents || _diffComputeNTotalStudents){
01105                                           /*QStringList s;
01106                                           if(diffTeachers)
01107                                                  s.append(tr("different teachers"));
01108                                           if(diffSubject)
01109                                                  s.append(tr("different subject"));
01110                                           if(diffActivityTags)
01111                                                  s.append(tr("different activity tags"));
01112                                           if(diffStudents)
01113                                                  s.append(tr("different students"));
01114                                           if(diffComputeNTotalStudents)
01115                                                  s.append(tr("different boolean variable 'must compute n total students'"));
01116                                           if(diffNTotalStudents)
01117                                                  s.append(tr("different number of students"));
01118                                                  
01119                                           QString s2;
01120                                           s2+=tr("The current split activity has subactivities which were individually modified. It is recommended to abort now"
01121                                            " and modify individual subactivities from the corresponding menu. Otherwise you will modify the fields for all the subactivities"
01122                                            " from this larger split activity.");
01123                                           s2+="\n\n";
01124                                           s2+=tr("The fields which are different are: %1").arg(s.join(", "));
01125                                                  
01126                                           int t=QMessageBox::warning(this, tr("FET warning"), s2, tr("Abort"), tr("Continue"), QString(), 1, 0);
01127                                           
01128                                           if(t==0)
01129                                                  return;*/
01130                                                  
01131                                           ActivitiesForm form(this, "", allStudentsNames[students], allSubjectsNames[subject], "");
01132                                           setParentAndOtherThings(&form, this);
01133                                           form.exec();
01134                             
01135                                           return;
01136                                    }
01137                             }
01138                             ModifyActivityForm modifyActivityForm(this, act->id, act->activityGroupId);
01139                             //int t;
01140                             setParentAndOtherThings(&modifyActivityForm, this);
01141                             modifyActivityForm.exec();
01142                             //similar to activitiesform.cpp (end)
01143                             return;
01144                      }
01145               }
01146               //else if(tmpSubactivities.count()>=1){
01147               else{
01148                      ActivitiesForm form(this, "", allStudentsNames[students], allSubjectsNames[subject], "");
01149                      setParentAndOtherThings(&form, this);
01150                      form.exec();
01151               }
01152        } else if(RBDelete->isChecked()) {
01153               //bool affectOtherStudents=false;
01154               QList<int> tmpID;
01155               QList<int> tmpGroupID;
01156               //QStringList tmpIdentify;
01157               QSet<int> tmpIdentifySet;
01158               //QList<bool> tmpAffectOtherStudents;
01159               Activity* act;
01160               for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
01161                      act=gt.rules.activitiesList[ai];
01162                      int tmpCurrentIndex=CBActive->currentIndex();
01163                      if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
01164                             || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
01165                             || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
01166                             if(act->subjectName==allSubjectsNames[subject]){
01167                                    foreach(QString st, act->studentsNames){
01168                                           if(st==allStudentsNames[students]){
01169                                                  //QString tmpIdent=CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
01170                                                  //if(!tmpIdentify.contains(tmpIdent)){
01171                                                  if(!tmpIdentifySet.contains(act->id)){
01172                                                         tmpID<<act->id;
01173                                                         tmpGroupID<<act->activityGroupId;
01174                                                         //tmpIdentify<<CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
01175                                                         tmpIdentifySet.insert(act->id);
01176                                                         /*if(act->studentsNames.size()>1){
01177                                                                tmpAffectOtherStudents<<true;
01178                                                                affectOtherStudents=true;
01179                                                         } else {
01180                                                                tmpAffectOtherStudents<<false;
01181                                                         }*/
01182                                                  }
01183                                                  break;
01184                                           }
01185                                    }
01186                             }
01187                      }
01188               }
01189 
01190               assert(tmpID.count()==tmpIdentifySet.size());
01191               assert(tmpGroupID.count()==tmpIdentifySet.size());
01192               //assert(tmpAffectOtherStudents.count()==tmpIdentifySet.size());
01193               
01194               if(!tmpIdentifySet.isEmpty()){
01195                      int nTotalActsDeleted;
01196                      QList<int> _idsToBeRemoved;
01197                      QList<int> _agidsToBeRemoved;
01198 
01199                      QList<bool> _affectOtherTeachersToBeRemoved;
01200                      bool _affectOtherTeachersOverall;
01201                      QList<bool> _affectOtherStudentsToBeRemoved;
01202                      bool _affectOtherStudentsOverall;
01203                      QList<bool> _affectOtherSubjectsToBeRemoved;
01204                      bool _affectOtherSubjectsOverall;
01205 
01206                      QString s;
01207                      if(swapAxis->checkState()==Qt::Checked){
01208                             computeActivitiesForDeletion("", allStudentsNames[column], allSubjectsNames[row],
01209                                    tmpID, tmpGroupID,
01210                                    nTotalActsDeleted,
01211                                    _idsToBeRemoved, _agidsToBeRemoved,
01212                                    _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
01213                                    _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
01214                                    _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
01215 
01216                             s=tr("Delete %1 activities from selected cell?").arg(tmpIdentifySet.size());
01217                             s+=" (";
01218                             s+=tr("subject=%1").arg(allSubjectsNames[row]);
01219                             s+=", ";
01220                             s+=tr("students=%1").arg(allStudentsNames[column]);
01221                             s+=")";
01222 
01223                             assert(nTotalActsDeleted>=tmpIdentifySet.size());
01224                             if(nTotalActsDeleted>tmpIdentifySet.size()){
01225                                    s+="\n\n";
01226                                    s+=tr("Because you have individually modified the components, there will be removed an additional number "
01227                                           "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
01228                             }
01229                      }
01230                      else{
01231                             computeActivitiesForDeletion("", allStudentsNames[row], allSubjectsNames[column],
01232                                    tmpID, tmpGroupID,
01233                                    nTotalActsDeleted,
01234                                    _idsToBeRemoved, _agidsToBeRemoved,
01235                                    _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
01236                                    _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
01237                                    _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
01238 
01239 
01240                             s=tr("Delete %1 activities from selected cell?").arg(tmpIdentifySet.size());
01241                             s+=" (";
01242                             s+=tr("students=%1").arg(allStudentsNames[row]);
01243                             s+=", ";
01244                             s+=tr("subject=%1").arg(allSubjectsNames[column]);
01245                             s+=")";
01246 
01247                             assert(nTotalActsDeleted>=tmpIdentifySet.size());
01248                             if(nTotalActsDeleted>tmpIdentifySet.size()){
01249                                    s+="\n\n";
01250                                    s+=tr("Because you have individually modified the components, there will be removed an additional number "
01251                                           "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
01252                             }
01253                      }
01254 
01255                      int ret=QMessageBox::question(this, tr("Delete activities?"), s, QMessageBox::Yes | QMessageBox::No);
01256                      if(ret==QMessageBox::Yes){
01257                             int retst=QMessageBox::No;
01258                             if(_affectOtherStudentsOverall){
01259                                    retst=QMessageBox::question(this, tr("Delete related?", "It refers to activities"),
01260                                           tr("This cell contains activities that relate to other students. Should the related activities also be deleted?"), QMessageBox::Yes | QMessageBox::No);
01261                             }
01262 
01263                             int retsubj=QMessageBox::No;
01264                             if(_affectOtherSubjectsOverall){
01265                                    retsubj=QMessageBox::question(this, tr("Delete related?", "It refers to activities"),
01266                                           tr("This cell contains activities that relate to other subjects. Should the related activities also be deleted?"), QMessageBox::Yes | QMessageBox::No);
01267                             }
01268 
01269                             for(int i=0; i<_idsToBeRemoved.count(); i++){
01270                                    if( ((_affectOtherStudentsToBeRemoved.at(i)==false) || (retst==QMessageBox::Yes)) && 
01271                                           ((_affectOtherSubjectsToBeRemoved.at(i)==false) || (retsubj==QMessageBox::Yes)) ){
01272                                           gt.rules.removeActivity(_idsToBeRemoved.at(i), _agidsToBeRemoved.at(i));
01273                                    }
01274                             }
01275                             PlanningChanged::increasePlanningCommunicationSpinBox();
01276                      }
01277               }
01278        } else assert(0==1);
01279 }
01280 
01281 //mouseTracking (start 3/3)
01282 /*
01283 void ActivityPlanningForm::ActivtiesCellEntered(int row, int column){
01284        activitiesTable->setCurrentCell(row, column);
01285 }
01286 
01287 void ActivityPlanningForm::TeachersCellEntered(int row, int column){
01288        teachersTable->setCurrentCell(row, column);
01289 }*/
01290 //mouseTracking (end 3/3)
01291 
01292 void ActivityPlanningForm::teachersTableHorizontalHeaderClicked(int column){
01293        if(RBActivity->isChecked()){
01294               ActivitiesForm form(this, allTeachersNames[column], "", "", "");
01295               setParentAndOtherThings(&form, this);
01296               form.exec();
01297        } else if(RBSubactivity->isChecked()) {
01298               SubactivitiesForm form(this, allTeachersNames[column], "", "", "");
01299               setParentAndOtherThings(&form, this);
01300               form.exec();
01301        } else if(RBAdd->isChecked()) {
01302               AddActivityForm addActivityForm(this, allTeachersNames[column], "", "", "");
01303               setParentAndOtherThings(&addActivityForm, this);
01304               addActivityForm.exec();     
01305        } else if(RBModify->isChecked()) {
01306               //Just enter the activity dialog, because in normal case there are to many activities related to a teacher.
01307               ActivitiesForm form(this, allTeachersNames[column], "", "", "");
01308               setParentAndOtherThings(&form, this);
01309               form.exec();
01310        } else if(RBDelete->isChecked()) {
01311               //bool affectOtherTeachers=false;
01312               QList<int> tmpID;
01313               QList<int> tmpGroupID;
01314               //QStringList tmpIdentify;
01315               QSet<int> tmpIdentifySet;
01316               //QList<bool> tmpAffectOtherTeachers;
01317               Activity* act;
01318               for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
01319                      act=gt.rules.activitiesList[ai];
01320                      int tmpCurrentIndex=CBActive->currentIndex();
01321                      if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
01322                             || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
01323                             || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
01324                                    foreach(QString t, act->teachersNames){
01325                                           if(t==allTeachersNames[column]){
01326                                                  //QString tmpIdent=CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
01327                                                  //if(!tmpIdentify.contains(tmpIdent)){
01328                                                  if(!tmpIdentifySet.contains(act->id)){
01329                                                         tmpID<<act->id;
01330                                                         tmpGroupID<<act->activityGroupId;
01331                                                         //tmpIdentify<<CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
01332                                                         tmpIdentifySet.insert(act->id);
01333                                                         /*if(act->teachersNames.size()>1){
01334                                                                tmpAffectOtherTeachers<<true;
01335                                                                affectOtherTeachers=true;
01336                                                         } else {
01337                                                                tmpAffectOtherTeachers<<false;
01338                                                         }*/
01339                                                  }
01340                                                  break;
01341                                           }
01342                                    }
01343                      }
01344               }
01345 
01346               assert(tmpID.count()==tmpIdentifySet.size());
01347               assert(tmpGroupID.count()==tmpIdentifySet.size());
01348               //assert(tmpAffectOtherTeachers.count()==tmpIdentifySet.size());
01349 
01350               if(!tmpIdentifySet.isEmpty()){
01351                      int nTotalActsDeleted;
01352                      QList<int> _idsToBeRemoved;
01353                      QList<int> _agidsToBeRemoved;
01354 
01355                      QList<bool> _affectOtherTeachersToBeRemoved;
01356                      bool _affectOtherTeachersOverall;
01357                      QList<bool> _affectOtherStudentsToBeRemoved;
01358                      bool _affectOtherStudentsOverall;
01359                      QList<bool> _affectOtherSubjectsToBeRemoved;
01360                      bool _affectOtherSubjectsOverall;
01361 
01362                      computeActivitiesForDeletion(allTeachersNames[column], "", "",
01363                             tmpID, tmpGroupID,
01364                             nTotalActsDeleted,
01365                             _idsToBeRemoved, _agidsToBeRemoved,
01366                             _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
01367                             _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
01368                             _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
01369 
01370                      QString s=tr("Delete %1 activities of teacher %2?").arg(tmpIdentifySet.size()).arg(allTeachersNames[column]);
01371                      assert(nTotalActsDeleted>=tmpIdentifySet.size());
01372                      if(nTotalActsDeleted>tmpIdentifySet.size()){
01373                             s+="\n\n";
01374                             s+=tr("Because you have individually modified the components, there will be removed an additional number "
01375                                    "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
01376                      }
01377                      int ret=QMessageBox::question(this, tr("Delete multiple?", "It refers to activities"), s, QMessageBox::Yes | QMessageBox::No);
01378                      if(ret==QMessageBox::Yes){
01379                             int ret2=QMessageBox::No;
01380                             if(_affectOtherTeachersOverall){
01381                                    ret2=QMessageBox::question(this, tr("Delete related?", "It refers to activities"), tr("There are activities affecting other teachers. Should the related activities also be deleted?"), QMessageBox::Yes | QMessageBox::No);
01382                             }
01383                             
01384                             for(int i=0; i<_idsToBeRemoved.count(); i++){
01385                                    if((_affectOtherTeachersToBeRemoved.at(i)==false) || (ret2==QMessageBox::Yes)){
01386                                           gt.rules.removeActivity(_idsToBeRemoved.at(i), _agidsToBeRemoved.at(i));
01387                                    }
01388                             }
01389                             PlanningChanged::increasePlanningCommunicationSpinBox();
01390                      }
01391               }
01392        } else assert(0==1);
01393 }
01394 
01395 void ActivityPlanningForm::teachersCellSelected(const QModelIndex& index){
01396        /*if(item==NULL){
01397               return;
01398        }*/
01399        if(!index.isValid())
01400               return;
01401        int itrow=index.row();
01402        int itcol=index.column();
01403        if(itrow==0){
01404               bool ok=false;
01405               int targetHours=QInputDialog::getInt(this, tr("FET question"), tr("Please enter the target number of hours:",
01406                      "This field is for the moment inactive in FET, but we translate it for possible future use")+" ", teachersTargetNumberOfHours.at(itcol), 0, gt.rules.nHoursPerDay*gt.rules.nDaysPerWeek, 1, &ok);
01407               if(ok){
01408                      teachersTargetNumberOfHours[itcol]=targetHours;
01409                      /*useless, because i also need to remove the table head item and i don't know how, so i redo the whole table
01410                      teachersTable->removeCellWidget(0, itcol);
01411                      QTableWidgetItem* newItem2=new QTableWidgetItem(CustomFETString::number(teachersTargetNumberOfHours.at(itcol)));
01412                      newItem2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01413                      teachersTable->setItem(0, itcol, newItem2);*/
01414                      
01415                      /*doesn't work, but idea is maybe better/faster!
01416                      QTableWidgetItem* newItem2= teachersTable->takeItem(0, itcol);
01417                      newItem2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01418                      teachersTable->setItem(0, itcol, newItem2);
01419                      QString tmpString=allTeachersNames.at(itcol)+"\n"+CustomFETString::number(teachersTotalNumberOfHours.value(allTeachersNames.at(itcol))-teachersTargetNumberOfHours.at(itcol));
01420                      if(teachersTotalNumberOfHours.value(allTeachersNames.at(itcol))!=teachersTotalNumberOfHours2.value(allTeachersNames.at(itcol)))
01421                             tmpString+=" ("+CustomFETString::number(teachersTotalNumberOfHours2.value(allTeachersNames.at(itcol))-teachersTargetNumberOfHours.at(itcol))+")";
01422                      QTableWidgetItem* newItem3= teachersTable->takeVerticalHeaderItem(itcol);
01423                      newItem3->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01424                      teachersTable->setItem(0, itcol, newItem3);*/
01425                      
01426                      //currently using not fast, but safe calculation
01427                      updateTables_Teachers();
01428               }
01429        } else {
01430               if(RBActivity->isChecked()){
01431                      ActivitiesForm form(this, allTeachersNames[itcol], "", "", "");
01432                      setParentAndOtherThings(&form, this);
01433                      form.exec();
01434               } else if(RBSubactivity->isChecked()) {
01435                      SubactivitiesForm form(this, allTeachersNames[itcol], "", "", "");
01436                      setParentAndOtherThings(&form, this);
01437                      form.exec();
01438               } else if(RBAdd->isChecked()) {
01439                      AddActivityForm addActivityForm(this, allTeachersNames[itcol], "", "", "");
01440                      setParentAndOtherThings(&addActivityForm, this);
01441                      addActivityForm.exec();     
01442               } else if(RBModify->isChecked()) {
01443                      //Just enter the activity dialog, because in normal case there are to many activities related to a teacher.
01444                      ActivitiesForm form(this, allTeachersNames[itcol], "", "", "");
01445                      setParentAndOtherThings(&form, this);
01446                      form.exec();
01447               } else if(RBDelete->isChecked()) {
01448                      //bool affectOtherTeachers=false;
01449                      QList<int> tmpID;
01450                      QList<int> tmpGroupID;
01451                      //QStringList tmpIdentify;
01452                      QSet<int> tmpIdentifySet;
01453                      //QList<bool> tmpAffectOtherTeachers;
01454                      Activity* act;
01455                      for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
01456                             act=gt.rules.activitiesList[ai];
01457                             int tmpCurrentIndex=CBActive->currentIndex();
01458                             if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
01459                                    || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
01460                                    || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
01461                                           foreach(QString t, act->teachersNames){
01462                                                  if(t==allTeachersNames[itcol]){
01463                                                         //QString tmpIdent=CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
01464                                                         //if(!tmpIdentify.contains(tmpIdent)){
01465                                                         if(!tmpIdentifySet.contains(act->id)){
01466                                                                tmpID<<act->id;
01467                                                                tmpGroupID<<act->activityGroupId;
01468                                                                //tmpIdentify<<CustomFETString::number(act->id)+" "+CustomFETString::number(act->activityGroupId);
01469                                                                tmpIdentifySet.insert(act->id);
01470                                                                /*if(act->teachersNames.size()>1){
01471                                                                       tmpAffectOtherTeachers<<true;
01472                                                                       affectOtherTeachers=true;
01473                                                                } else {
01474                                                                       tmpAffectOtherTeachers<<false;
01475                                                                }*/
01476                                                         }
01477                                                         break;
01478                                                  }
01479                                           }
01480                             }
01481                      }
01482                      assert(tmpID.count()==tmpIdentifySet.size());
01483                      assert(tmpGroupID.count()==tmpIdentifySet.size());
01484                      //assert(tmpAffectOtherTeachers.count()==tmpIdentifySet.size());
01485        
01486                      if(!tmpIdentifySet.isEmpty()){
01487                             int nTotalActsDeleted;
01488                             QList<int> _idsToBeRemoved;
01489                             QList<int> _agidsToBeRemoved;
01490 
01491                             QList<bool> _affectOtherTeachersToBeRemoved;
01492                             bool _affectOtherTeachersOverall;
01493                             QList<bool> _affectOtherStudentsToBeRemoved;
01494                             bool _affectOtherStudentsOverall;
01495                             QList<bool> _affectOtherSubjectsToBeRemoved;
01496                             bool _affectOtherSubjectsOverall;
01497        
01498                             computeActivitiesForDeletion(allTeachersNames[itcol], "", "",
01499                                    tmpID, tmpGroupID,
01500                                    nTotalActsDeleted,
01501                                    _idsToBeRemoved, _agidsToBeRemoved,
01502                                    _affectOtherTeachersToBeRemoved, _affectOtherTeachersOverall,
01503                                    _affectOtherStudentsToBeRemoved, _affectOtherStudentsOverall,
01504                                    _affectOtherSubjectsToBeRemoved, _affectOtherSubjectsOverall);
01505 
01506                             QString s=tr("Delete %1 activities of teacher %2?").arg(tmpIdentifySet.size()).arg(allTeachersNames[itcol]);
01507                             assert(nTotalActsDeleted>=tmpIdentifySet.size());
01508                             if(nTotalActsDeleted>tmpIdentifySet.size()){
01509                                    s+="\n\n";
01510                                    s+=tr("Because you have individually modified the components, there will be removed an additional number "
01511                                           "of %1 activities (which are in the same larger split activities as the selected activities).").arg(nTotalActsDeleted-tmpIdentifySet.size());
01512                             }
01513                             int ret=QMessageBox::question(this, tr("Delete multiple?", "It refers to activities"), s, QMessageBox::Yes | QMessageBox::No);
01514                             if(ret==QMessageBox::Yes){
01515                                    int ret2=QMessageBox::No;
01516                                    if(_affectOtherTeachersOverall){
01517                                           ret2=QMessageBox::question(this, tr("Delete related?", "It refers to activities"), tr("There are activities affecting other teachers. Should the related activities also be deleted?"), QMessageBox::Yes | QMessageBox::No);
01518                                    }
01519                                    
01520                                    for(int i=0; i<_idsToBeRemoved.count(); i++){
01521                                           if((_affectOtherTeachersToBeRemoved.at(i)==false) || (ret2==QMessageBox::Yes)){
01522                                                  gt.rules.removeActivity(_idsToBeRemoved.at(i), _agidsToBeRemoved.at(i));
01523                                           }
01524                                    }
01525                                    PlanningChanged::increasePlanningCommunicationSpinBox();
01526                             }
01527                      }
01528               } else assert(0==1);
01529        }
01530 }
01531 
01532 void ActivityPlanningForm::updateTables(int unneeded){
01533        Q_UNUSED(unneeded);
01534 
01535        updateTables_Students_Subjects();
01536        updateTables_Teachers();
01537 
01538        updateTablesVisual(0);
01539 }
01540 
01541 void ActivityPlanningForm::updateTables_Students_Subjects(){   //similar to statisticsexport.cpp
01542        QMultiHash <QString, int> studentsActivities;
01543 
01544        studentsTotalNumberOfHours.clear();
01545        studentsTotalNumberOfHours2.clear();
01546        subjectsTotalNumberOfHours.clear();
01547        subjectsTotalNumberOfHours4.clear();
01548        
01549        Activity* act;
01550        int tmpCurrentIndex=CBActive->currentIndex();
01551        for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
01552               //progress.setValue(ai);
01553               act=gt.rules.activitiesList[ai];
01554               if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
01555                      || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
01556                      || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
01557                             //subjectsActivities.insert(act->subjectName, ai);
01558                             int tmp=subjectsTotalNumberOfHours.value(act->subjectName)+act->duration;
01559                             subjectsTotalNumberOfHours.insert(act->subjectName, tmp);                                         // (1) so teamlearning-teaching is not counted twice!
01560                             foreach(QString st, act->studentsNames){
01561                                    studentsActivities.insert(st, ai);
01562                                    tmp=studentsTotalNumberOfHours.value(st)+act->duration;
01563                                    studentsTotalNumberOfHours.insert(st, tmp);                                                // (2)
01564                                    //subjectstTotalNumberOfHours3[act->subjectIndex]+=duration;                        // (1) so teamlearning is counted twice!
01565                             }
01566                             foreach(QString st, act->studentsNames){
01567                                    tmp=studentsTotalNumberOfHours2.value(st);
01568                                    tmp += act->duration * act->teachersNames.count();
01569                                    studentsTotalNumberOfHours2.insert(st, tmp);                                 // (2)
01570                             }
01571                             tmp=subjectsTotalNumberOfHours4.value(act->subjectName);
01572                             tmp += act->duration * act->studentsNames.count() * act->teachersNames.count();
01573                             subjectsTotalNumberOfHours4.insert(act->subjectName, tmp);                   // (1) so teamlearning-teaching is counted twice!
01574                      }
01575        }
01576        //progress.setValue(gt.rules.activitiesList.size());
01577        QStringList studentsLabels;
01578        QStringList subjectsLabels;
01579        studentsLabels.clear();
01580        subjectsLabels.clear();
01581        
01582        activitiesTableView->model.clearDataAndHeaders();
01583 
01584        if(swapAxis->checkState()==Qt::Checked){
01585               /*activitiesTable->setRowCount(allSubjectsNames.count());
01586               activitiesTable->setColumnCount(allStudentsNames.count());*/
01587               activitiesTableView->model.resize(allSubjectsNames.count(), allStudentsNames.count());
01588        } else {
01589               /*activitiesTable->setRowCount(allStudentsNames.count());
01590               activitiesTable->setColumnCount(allSubjectsNames.count());*/
01591               activitiesTableView->model.resize(allStudentsNames.count(), allSubjectsNames.count());
01592        }
01593 
01594        for(int students=0; students<allStudentsNames.count(); students++){
01595               //progress2.setValue(students);
01596               QList<int> tmpStudents;
01597               QMultiHash<QString, int> tmpSubjects;
01598               tmpStudents.clear();
01599               tmpSubjects.clear();
01600               tmpStudents=studentsActivities.values(allStudentsNames.at(students));
01601               foreach(int aidx, tmpStudents){
01602                      Activity* act=gt.rules.activitiesList.at(aidx);
01603                      tmpSubjects.insert(act->subjectName, aidx);
01604               }
01605               
01606               QString tmpStudentsLabel="";
01607               tmpStudentsLabel=allStudentsNames.at(students);
01608               tmpStudentsLabel+="\n"+CustomFETString::number(studentsTotalNumberOfHours.value(allStudentsNames.at(students)));
01609               if(studentsTotalNumberOfHours.value(allStudentsNames.at(students))!=studentsTotalNumberOfHours2.value(allStudentsNames.at(students)))
01610                      tmpStudentsLabel+=" ("+CustomFETString::number(studentsTotalNumberOfHours2.value(allStudentsNames.at(students)))+")";
01611               studentsLabels<<tmpStudentsLabel;
01612               for(int subject=0; subject<allSubjectsNames.count(); subject++){
01613                      QList<int> tmpActivities;
01614                      tmpActivities.clear();
01615                      tmpActivities=tmpSubjects.values(allSubjectsNames.at(subject));
01616                      QString tmpString="";
01617                      if(!tmpActivities.isEmpty()){
01618                             QMap<QString, int> tmpIdentDuration;      //not QHash, because i need the correct order of the activities
01619                             foreach(int tmpAct, tmpActivities){
01620                                    Activity* act=gt.rules.activitiesList[tmpAct];
01621                                    int tmpD=act->duration;
01622                                    QString tmpIdent;
01623                                    if(showTeachers->checkState()==Qt::Checked){
01624                                           if(act->teachersNames.size()>0){
01625                                                  for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++){
01626                                                         tmpIdent+=*it;
01627                                                         if(it!=act->teachersNames.end()-1)
01628                                                                tmpIdent+=", ";
01629                                                  }
01630                                           }
01631                                    }
01632                                    tmpIdent+=" ";
01633                                    if(showActivityTags->checkState()==Qt::Checked){
01634                                           if(act->activityTagsNames.size()>0){
01635                                                  for(QStringList::Iterator it=act->activityTagsNames.begin(); it!=act->activityTagsNames.end(); it++){
01636                                                         tmpIdent+=*it;
01637                                                         if(it!=act->activityTagsNames.end()-1)
01638                                                                tmpIdent+=", ";
01639                                                  }
01640                                           }
01641                                    }
01642                                    tmpD+=tmpIdentDuration.value(tmpIdent);
01643                                    tmpIdentDuration.insert(tmpIdent, tmpD);
01644                             }
01645                             QMapIterator<QString, int> it(tmpIdentDuration);
01646                             while(it.hasNext()){
01647                                    it.next();
01648                                    tmpString+=CustomFETString::number(it.value());
01649                                    tmpString+=" "+it.key();
01650                                    if(it.hasNext())
01651                                           tmpString+="\n";
01652                             }
01653                      }
01654                      if(!tmpActivities.isEmpty()){
01655                             /*QTableWidgetItem* newItem=new QTableWidgetItem(tmpString);
01656                             newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);*/
01657                             QPair<int, int> pair;
01658                             if(swapAxis->checkState()==Qt::Checked){
01659                                    pair.first=subject;
01660                                    pair.second=students;
01661                                    //activitiesTable->setItem(subject, students, newItem);
01662                             } else {
01663                                    pair.first=students;
01664                                    pair.second=subject;
01665                                    //activitiesTable->setItem(students, subject, newItem);
01666                             }
01667                             activitiesTableView->model.items.insert(pair, tmpString);
01668                      }
01669               }
01670        }
01671        //progress2.setValue(allStudentsNames.count());
01672        foreach(QString subjects, allSubjectsNames){
01673               QString tmpSubjectLabel="";
01674               tmpSubjectLabel=subjects+"\n"+CustomFETString::number(subjectsTotalNumberOfHours.value(subjects));
01675               if(subjectsTotalNumberOfHours.value(subjects)!=subjectsTotalNumberOfHours4.value(subjects))
01676                      tmpSubjectLabel+=" ("+CustomFETString::number(subjectsTotalNumberOfHours4.value(subjects))+")";
01677               subjectsLabels<<tmpSubjectLabel;
01678        }
01679        if(swapAxis->checkState()==Qt::Checked){
01680               /*activitiesTableView->setHorizontalHeaderLabels(studentsLabels);
01681               activitiesTableView->setVerticalHeaderLabels(subjectsLabels);*/
01682               activitiesTableView->model.horizontalHeaderItems=studentsLabels;
01683               activitiesTableView->model.verticalHeaderItems=subjectsLabels;
01684        } else {
01685               /*activitiesTableView->setHorizontalHeaderLabels(subjectsLabels);
01686               activitiesTableView->setVerticalHeaderLabels(studentsLabels);*/
01687               activitiesTableView->model.horizontalHeaderItems=subjectsLabels;
01688               activitiesTableView->model.verticalHeaderItems=studentsLabels;
01689        }
01690        
01691        activitiesTableView->allTableChanged();
01692 }
01693 
01694 
01695 void ActivityPlanningForm::updateTables_Teachers(){     //similar to statisticsexport.cpp
01696        QMultiHash <QString, int> teachersActivities;
01697        
01698        teachersTotalNumberOfHours.clear();
01699        teachersTotalNumberOfHours2.clear();
01700        
01701        Activity* act;
01702        int tmpCurrentIndex=CBActive->currentIndex();
01703        for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
01704               //progress.setValue(ai);
01705               act=gt.rules.activitiesList[ai];
01706               if( ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
01707                      || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
01708                      || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
01709                             int tmp;
01710                             foreach(QString t, act->teachersNames){
01711                                    teachersActivities.insert(t, ai);
01712                                    tmp=teachersTotalNumberOfHours.value(t)+act->duration;
01713                                    teachersTotalNumberOfHours.insert(t, tmp);                                                 // (3)
01714                             }
01715                             foreach(QString t, act->teachersNames){
01716                                    tmp=teachersTotalNumberOfHours2.value(t);
01717                                    tmp += act->duration * act->studentsNames.count();
01718                                    teachersTotalNumberOfHours2.insert(t, tmp);                                         // (3)
01719                             }
01720                      }
01721        }
01722        //progress.setValue(gt.rules.activitiesList.size());
01723 
01724        QStringList teachersLabels;
01725        for(int teacher=0; teacher<allTeachersNames.count(); teacher++){
01726               QString prefixString1="";
01727               QString prefixString2="";
01728               if(teachersTargetNumberOfHours.at(teacher)!=0){
01729                      if(teachersTotalNumberOfHours.value(allTeachersNames.at(teacher))>teachersTargetNumberOfHours.at(teacher)){
01730                             prefixString1="+";
01731                      } else if(teachersTotalNumberOfHours.value(allTeachersNames.at(teacher))==teachersTargetNumberOfHours.at(teacher)){
01732                             prefixString1="=";
01733                      }
01734                      if(teachersTotalNumberOfHours2.value(allTeachersNames.at(teacher))>teachersTargetNumberOfHours.at(teacher)){
01735                             prefixString2="+";
01736                      }else if(teachersTotalNumberOfHours2.value(allTeachersNames.at(teacher))>teachersTargetNumberOfHours.at(teacher)){
01737                             prefixString2="=";
01738                      }
01739               }
01740               QString tmpString=allTeachersNames.at(teacher)+"\n"+prefixString1+CustomFETString::number(teachersTotalNumberOfHours.value(allTeachersNames.at(teacher))-teachersTargetNumberOfHours.at(teacher));
01741               if(teachersTotalNumberOfHours.value(allTeachersNames.at(teacher))!=teachersTotalNumberOfHours2.value(allTeachersNames.at(teacher)))
01742                      tmpString+=" ("+prefixString2+CustomFETString::number(teachersTotalNumberOfHours2.value(allTeachersNames.at(teacher))-teachersTargetNumberOfHours.at(teacher))+")";
01743               teachersLabels<<tmpString;
01744        }
01745        
01746        teachersTableView->model.clearDataAndHeaders();
01747 
01748        teachersTableView->model.resize(3, allTeachersNames.count());
01749        
01750        QStringList vLabels;
01751        vLabels<<tr("Target", "Please keep translation short. This field is for the moment inactive in FET, we keep it for possible future use")
01752               <<tr("Subjects", "Please keep translation short")
01753               <<tr("Students", "Please keep translation short");
01754 
01755        teachersTableView->model.verticalHeaderItems=vLabels;
01756        teachersTableView->model.horizontalHeaderItems=teachersLabels;
01757        
01758        for(int teacher=0; teacher<allTeachersNames.count(); teacher++){
01759               //QTableWidgetItem* newItem=new QTableWidgetItem(allTeachersNames[teacher]);
01760               //newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01761               /*QTableWidgetItem* newItem2=new QTableWidgetItem(CustomFETString::number(teachersTargetNumberOfHours.at(teacher)));
01762               newItem2->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01763               teachersTable->setItem(0, teacher, newItem2);*/
01764               QString str=CustomFETString::number(teachersTargetNumberOfHours.at(teacher));
01765               QPair<int, int> pair;
01766               pair.first=0;
01767               pair.second=teacher;
01768               teachersTableView->model.items.insert(pair, str);
01769               
01770               //new (start)
01771               QList<int> tmpActivities;
01772               QMap<QString, int> tmpSubjectsNumberOfHours;            //using map, because it sort alphabeticly
01773               QMap<QString, int> tmpStudentsNumberOfHours;            //using map, because it sort alphabeticly
01774               tmpActivities.clear();
01775               tmpActivities=teachersActivities.values(allTeachersNames.at(teacher));
01776               foreach(int aidx, tmpActivities){
01777                      Activity* act=gt.rules.activitiesList.at(aidx);
01778                      //students start
01779                      int tmpD=act->duration;
01780                      QString tmpIdent;
01781                      if(act->studentsNames.size()>0){
01782                             for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++){
01783                                    tmpIdent+=*it;
01784                                    if(it!=act->studentsNames.end()-1)
01785                                           tmpIdent+=", ";
01786                             }
01787                      }
01788                      tmpIdent+=" ";
01789                      if(showActivityTags->checkState()==Qt::Checked){
01790                             if(act->activityTagsNames.size()>0){
01791                                    for(QStringList::Iterator it=act->activityTagsNames.begin(); it!=act->activityTagsNames.end(); it++){
01792                                           tmpIdent+=*it;
01793                                           if(it!=act->activityTagsNames.end()-1)
01794                                                  tmpIdent+=", ";
01795                                    }
01796                             }
01797                      }
01798                      tmpD+=tmpStudentsNumberOfHours.value(tmpIdent);
01799                      tmpStudentsNumberOfHours.insert(tmpIdent, tmpD);
01800                      //students end
01801                      //subject start
01802                      tmpD=act->duration;
01803                      tmpIdent.clear();
01804                      tmpIdent=act->subjectName;
01805                      tmpIdent+=" ";
01806                      if(showActivityTags->checkState()==Qt::Checked){
01807                             if(act->activityTagsNames.size()>0){
01808                                    for(QStringList::Iterator it=act->activityTagsNames.begin(); it!=act->activityTagsNames.end(); it++){
01809                                           tmpIdent+=*it;
01810                                           if(it!=act->activityTagsNames.end()-1)
01811                                                  tmpIdent+=", ";
01812                                    }
01813                             }
01814                      }
01815                      tmpD+=tmpSubjectsNumberOfHours.value(tmpIdent);
01816                      tmpSubjectsNumberOfHours.insert(tmpIdent, tmpD);
01817                      //subject end
01818               }
01819               
01820               QString tmpItem;
01821               tmpItem.clear();
01822               QMapIterator<QString, int> it(tmpSubjectsNumberOfHours);
01823               while(it.hasNext()){
01824                      it.next();
01825                      tmpItem+=CustomFETString::number(it.value())+" "+it.key()+"\n";
01826               }
01827               //
01828               /*QTableWidgetItem* newItem3=new QTableWidgetItem(tmpItem);
01829               newItem3->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01830               teachersTable->setItem(1, teacher, newItem3);*/
01831               //
01832               pair.first=1;
01833               pair.second=teacher;
01834               teachersTableView->model.items.insert(pair, tmpItem);
01835               
01836               tmpItem.clear();
01837               QMapIterator<QString, int> it2(tmpStudentsNumberOfHours);
01838               while(it2.hasNext()){
01839                      it2.next();
01840                      tmpItem+=CustomFETString::number(it2.value())+" "+it2.key()+"\n";
01841               }
01842               //
01843               /*QTableWidgetItem* newItem4=new QTableWidgetItem(tmpItem);
01844               newItem4->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
01845               teachersTable->setItem(2, teacher, newItem4);*/
01846               //
01847               pair.first=2;
01848               pair.second=teacher;
01849               teachersTableView->model.items.insert(pair, tmpItem);
01850               //new(end)
01851        }
01852        
01853        //teachersTargetNumberOfHours; Delete this lines! (start)
01854        teachersTableView->hideRow(0);
01855        hideUsedTeachers->hide();
01856        //teachersTargetNumberOfHours; Delete this lines! (end)
01857        
01858        teachersTableView->allTableChanged();
01859 }
01860 
01861 void ActivityPlanningForm::updateTablesVisual(int unneeded){
01862        Q_UNUSED(unneeded);
01863 
01864        assert(studentsDuplicates.count()==allStudentsNames.count());
01865        assert(studentsDuplicates.count()==yearORgroupORsubgroup.count());
01866        
01867        if(swapAxis->checkState()==Qt::Checked){
01868               for(int students=0; students<allStudentsNames.count(); students++){
01869                      bool show=true;
01870                      int tmpInt=yearORgroupORsubgroup.at(students);
01871                      switch(tmpInt){
01872                             case IS_YEAR:     if(showYears->checkState()!=Qt::Checked) show=false; break;
01873                             case IS_GROUP:    if(showGroups->checkState()!=Qt::Checked) show=false; break;
01874                             case IS_SUBGROUP: if(showSubgroups->checkState()!=Qt::Checked) show=false; break;
01875                             default: assert(0==1);
01876                      }
01877                      if((studentsDuplicates.at(students)) && (showDuplicates->checkState()!=Qt::Checked)){
01878                             show=false;
01879                      }
01880                      if(studentsTotalNumberOfHours.value(allStudentsNames.at(students))==0 && studentsTotalNumberOfHours2.value(allStudentsNames.at(students))==0 && hideEmptyLines->checkState()==Qt::Checked){
01881                             show=false;
01882                      }
01883                      if(show)
01884                             activitiesTableView->showColumn(students);
01885                      else
01886                             activitiesTableView->hideColumn(students);
01887               }
01888               for(int subject=0; subject<allSubjectsNames.count(); subject++){
01889                      bool show=true;
01890                      if(subjectsTotalNumberOfHours.value(allSubjectsNames.at(subject))==0 && subjectsTotalNumberOfHours4.value(allSubjectsNames.at(subject))==0 && hideEmptyLines->checkState()==Qt::Checked){
01891                             show=false;
01892                      }
01893                      if(show)
01894                             activitiesTableView->showRow(subject);
01895                      else
01896                             activitiesTableView->hideRow(subject);
01897               }
01898        } else {
01899               for(int students=0; students<allStudentsNames.count(); students++){
01900                      bool show=true;
01901                      int tmpInt=yearORgroupORsubgroup.at(students);
01902                      switch(tmpInt){
01903                             case IS_YEAR:     if(showYears->checkState()!=Qt::Checked) show=false; break;
01904                             case IS_GROUP:    if(showGroups->checkState()!=Qt::Checked) show=false; break;
01905                             case IS_SUBGROUP: if(showSubgroups->checkState()!=Qt::Checked) show=false; break;
01906                             default: assert(0==1);
01907                      }
01908                      if((studentsDuplicates.at(students)) && (showDuplicates->checkState()!=Qt::Checked)){
01909                             show=false;
01910                      }
01911                      if(studentsTotalNumberOfHours.value(allStudentsNames.at(students))==0 && studentsTotalNumberOfHours2.value(allStudentsNames.at(students))==0 && hideEmptyLines->checkState()==Qt::Checked){
01912                             show=false;
01913                      }
01914                      
01915                      if(show)
01916                             activitiesTableView->showRow(students);
01917                      else
01918                             activitiesTableView->hideRow(students);
01919               }
01920               for(int subject=0; subject<allSubjectsNames.count(); subject++){
01921                      bool show=true;
01922                      if(subjectsTotalNumberOfHours.value(allSubjectsNames.at(subject))==0 && subjectsTotalNumberOfHours4.value(allSubjectsNames.at(subject))==0 && hideEmptyLines->checkState()==Qt::Checked){
01923                             show=false;
01924                      }
01925                      
01926                      if(show)
01927                             activitiesTableView->showColumn(subject);
01928                      else
01929                             activitiesTableView->hideColumn(subject);
01930               }
01931        }
01932        
01933        for(int teacher=0; teacher<allTeachersNames.count(); teacher++){
01934               bool show=true;
01935               if((teachersTargetNumberOfHours.at(teacher)-teachersTotalNumberOfHours.value(allTeachersNames.at(teacher)))==0 && (teachersTargetNumberOfHours.at(teacher)-teachersTotalNumberOfHours2.value(allTeachersNames.at(teacher)))==0 && hideUsedTeachers->checkState()==Qt::Checked){
01936                      show=false;
01937               }
01938               if(show)
01939                      teachersTableView->showColumn(teacher);
01940               else
01941                      teachersTableView->hideColumn(teacher);
01942        }
01943        
01944        /*activitiesTable->resizeColumnsToContents();
01945        activitiesTable->resizeRowsToContents();*/
01946        activitiesTableView->resizeToFit();
01947        
01948        /*teachersTable->resizeColumnsToContents();
01949        teachersTable->resizeRowsToContents();*/
01950        teachersTableView->resizeToFit();
01951 }
01952 
01953 void ActivityPlanningForm::deleteAll(){
01954        int ret=QMessageBox::question(this, tr("Delete all?", "It refers to activities"), tr("Are you sure you want to remove ALL the %1 activities and related constraints?", "%1 is the number of total activities")
01955               .arg(gt.rules.activitiesList.count()), QMessageBox::Yes | QMessageBox::No);
01956        if(ret==QMessageBox::Yes){
01957               ret=QMessageBox::question(this, tr("Delete all?", "It refers to activities"), tr("Are you absolutely sure you want to remove ALL activities and related constraints from your data?"), QMessageBox::Yes | QMessageBox::No);
01958               if(ret==QMessageBox::Yes){
01959                      while(!gt.rules.activitiesList.isEmpty()){
01960                             Activity* act=gt.rules.activitiesList.at(0);
01961                             gt.rules.removeActivity(act->id, act->activityGroupId);
01962                      }
01963                      PlanningChanged::increasePlanningCommunicationSpinBox();
01964               }
01965        }
01966 }
01967 
01968 void ActivityPlanningForm::pseudoActivities(){
01969        QString noTeachersAndStudents;
01970        QString noTeachers;
01971        QString noStudents;
01972        Activity* act;
01973        int tmpCurrentIndex=CBActive->currentIndex();
01974        for(int ai=0; ai<gt.rules.activitiesList.size(); ai++){
01975               act=gt.rules.activitiesList[ai];
01976               if(    ((act->active) && (tmpCurrentIndex==ACTIVE_ONLY))
01977                      || ((!act->active) && (tmpCurrentIndex==INACTIVE_ONLY))
01978                      || (tmpCurrentIndex==ACTIVE_OR_INACTIVE)){
01979                             if(act->teachersNames.isEmpty() && act->studentsNames.isEmpty()){
01980                                    noTeachersAndStudents+=act->getDescription(gt.rules)+"\n";
01981                             } else if(act->teachersNames.isEmpty()){
01982                                    noTeachers+=act->getDescription(gt.rules)+"\n";
01983                             } else if(act->studentsNames.isEmpty()){
01984                                    noStudents+=act->getDescription(gt.rules)+"\n";
01985                             }
01986                      }
01987        }
01988        if(noTeachersAndStudents.isEmpty()){
01989               noTeachersAndStudents=tr("There are no activities without teachers and without students.")+"\n";
01990        } else {
01991               noTeachersAndStudents=tr("Activities without teachers and without students:")+"\n"+noTeachersAndStudents;
01992        }
01993        if(noTeachers.isEmpty()){
01994               noTeachers="\n"+tr("There are no activities without teachers.")+"\n";
01995        } else {
01996               noTeachers="\n"+tr("Activities without teachers:")+"\n"+noTeachers;
01997        }
01998        if(noStudents.isEmpty()){
01999               noStudents="\n"+tr("There are no activities without students.")+"\n";
02000        } else {
02001               noStudents="\n"+tr("Activities without students:")+"\n"+noStudents;
02002        }
02003        LongTextMessageBox::mediumInformation(this, tr("Information about pseudo activities", "Pseudo activities means activities without teachers and/or students sets"), noTeachersAndStudents+noTeachers+noStudents);
02004 }
02005 
02006 //communication box by Liviu Lalescu
02007 
02008 PlanningCommunicationSpinBox::PlanningCommunicationSpinBox()
02009 {
02010        minValue=0;
02011        maxValue=9;
02012        value=0;
02013 }
02014 
02015 PlanningCommunicationSpinBox::~PlanningCommunicationSpinBox()
02016 {
02017 }
02018 
02019 void PlanningCommunicationSpinBox::increaseValue()
02020 {
02021        assert(maxValue>minValue);
02022        assert(value>=minValue && value<=maxValue);
02023        value++;
02024        if(value>maxValue)
02025               value=minValue;
02026               
02027        emit(valueChanged(value));
02028 }
02029 
02030 
02031 void PlanningChanged::increasePlanningCommunicationSpinBox()
02032 {
02033        planningCommunicationSpinBox.increaseValue();
02034 }