Back to index

fet  5.18.0
splityearform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           splityearform.cpp  -  description
00003                              -------------------
00004     begin                : 10 Aug 2007
00005     copyright            : (C) 2007 by Lalescu Liviu
00006     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "splityearform.h"
00019 
00020 #include <QtGui>
00021 
00022 #include <QMessageBox>
00023 
00024 #include <QSettings>
00025 
00026 #include "centerwidgetonscreen.h"
00027 
00028 extern const QString COMPANY;
00029 extern const QString PROGRAM;
00030 
00031 SplitYearForm::SplitYearForm(QWidget* parent, const QString _year): QDialog(parent)
00032 {
00033        setupUi(this);
00034        
00035        okPushButton->setDefault(true);
00036 
00037        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00038        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(close()));
00039        connect(categoriesSpinBox, SIGNAL(valueChanged(int)), this, SLOT(numberOfCategoriesChanged()));
00040        connect(category1SpinBox, SIGNAL(valueChanged(int)), this, SLOT(category1Changed()));
00041        connect(pushButton3, SIGNAL(clicked()), this, SLOT(help()));
00042        connect(category2SpinBox, SIGNAL(valueChanged(int)), this, SLOT(category2Changed()));
00043        connect(category3SpinBox, SIGNAL(valueChanged(int)), this, SLOT(category3Changed()));
00044        connect(pushButton4, SIGNAL(clicked()), this, SLOT(reset()));
00045 
00046        centerWidgetOnScreen(this);
00047        restoreFETDialogGeometry(this);
00048        
00049        QSettings settings(COMPANY, PROGRAM);
00050        
00051        _sep=settings.value(this->metaObject()->className()+QString("/separator-string"), QString(" ")).toString();
00052        
00053        _nCategories=settings.value(this->metaObject()->className()+QString("/number-of-categories"), 1).toInt();
00054 
00055        _nDiv1=settings.value(this->metaObject()->className()+QString("/category/1/number-of-divisions"), 2).toInt();
00056        _nDiv2=settings.value(this->metaObject()->className()+QString("/category/2/number-of-divisions"), 2).toInt();
00057        _nDiv3=settings.value(this->metaObject()->className()+QString("/category/3/number-of-divisions"), 2).toInt();
00058 
00059        _cat1div1=settings.value(this->metaObject()->className()+QString("/category/1/division/1"), QString("")).toString();
00060        _cat1div2=settings.value(this->metaObject()->className()+QString("/category/1/division/2"), QString("")).toString();
00061        _cat1div3=settings.value(this->metaObject()->className()+QString("/category/1/division/3"), QString("")).toString();
00062        _cat1div4=settings.value(this->metaObject()->className()+QString("/category/1/division/4"), QString("")).toString();
00063        _cat1div5=settings.value(this->metaObject()->className()+QString("/category/1/division/5"), QString("")).toString();
00064        _cat1div6=settings.value(this->metaObject()->className()+QString("/category/1/division/6"), QString("")).toString();
00065        _cat1div7=settings.value(this->metaObject()->className()+QString("/category/1/division/7"), QString("")).toString();
00066        _cat1div8=settings.value(this->metaObject()->className()+QString("/category/1/division/8"), QString("")).toString();
00067        _cat1div9=settings.value(this->metaObject()->className()+QString("/category/1/division/9"), QString("")).toString();
00068        _cat1div10=settings.value(this->metaObject()->className()+QString("/category/1/division/10"), QString("")).toString();
00069        _cat1div11=settings.value(this->metaObject()->className()+QString("/category/1/division/11"), QString("")).toString();
00070        _cat1div12=settings.value(this->metaObject()->className()+QString("/category/1/division/12"), QString("")).toString();
00071 
00072        _cat2div1=settings.value(this->metaObject()->className()+QString("/category/2/division/1"), QString("")).toString();
00073        _cat2div2=settings.value(this->metaObject()->className()+QString("/category/2/division/2"), QString("")).toString();
00074        _cat2div3=settings.value(this->metaObject()->className()+QString("/category/2/division/3"), QString("")).toString();
00075        _cat2div4=settings.value(this->metaObject()->className()+QString("/category/2/division/4"), QString("")).toString();
00076        _cat2div5=settings.value(this->metaObject()->className()+QString("/category/2/division/5"), QString("")).toString();
00077        _cat2div6=settings.value(this->metaObject()->className()+QString("/category/2/division/6"), QString("")).toString();
00078 
00079        _cat3div1=settings.value(this->metaObject()->className()+QString("/category/3/division/1"), QString("")).toString();
00080        _cat3div2=settings.value(this->metaObject()->className()+QString("/category/3/division/2"), QString("")).toString();
00081        _cat3div3=settings.value(this->metaObject()->className()+QString("/category/3/division/3"), QString("")).toString();
00082        _cat3div4=settings.value(this->metaObject()->className()+QString("/category/3/division/4"), QString("")).toString();
00083        _cat3div5=settings.value(this->metaObject()->className()+QString("/category/3/division/5"), QString("")).toString();
00084        _cat3div6=settings.value(this->metaObject()->className()+QString("/category/3/division/6"), QString("")).toString();
00085 
00086        year=_year;
00087 
00088        QString s=tr("Splitting year: %1").arg(year);
00089        splitYearTextLabel->setText(s);
00090        
00091        //restore last screen
00092        separatorLineEdit->setText(_sep);
00093        
00094        categoriesSpinBox->setValue(_nCategories);
00095        
00096        category1SpinBox->setValue(_nDiv1);
00097        category2SpinBox->setValue(_nDiv2);
00098        category3SpinBox->setValue(_nDiv3);
00099        
00100        category1Division1LineEdit->setText(_cat1div1);
00101        category1Division2LineEdit->setText(_cat1div2);
00102        category1Division3LineEdit->setText(_cat1div3);
00103        category1Division4LineEdit->setText(_cat1div4);
00104        category1Division5LineEdit->setText(_cat1div5);
00105        category1Division6LineEdit->setText(_cat1div6);
00106        category1Division7LineEdit->setText(_cat1div7);
00107        category1Division8LineEdit->setText(_cat1div8);
00108        category1Division9LineEdit->setText(_cat1div9);
00109        category1Division10LineEdit->setText(_cat1div10);
00110        category1Division11LineEdit->setText(_cat1div11);
00111        category1Division12LineEdit->setText(_cat1div12);
00112 
00113        category2Division1LineEdit->setText(_cat2div1);
00114        category2Division2LineEdit->setText(_cat2div2);
00115        category2Division3LineEdit->setText(_cat2div3);
00116        category2Division4LineEdit->setText(_cat2div4);
00117        category2Division5LineEdit->setText(_cat2div5);
00118        category2Division6LineEdit->setText(_cat2div6);
00119 
00120        category3Division1LineEdit->setText(_cat3div1);
00121        category3Division2LineEdit->setText(_cat3div2);
00122        category3Division3LineEdit->setText(_cat3div3);
00123        category3Division4LineEdit->setText(_cat3div4);
00124        category3Division5LineEdit->setText(_cat3div5);
00125        category3Division6LineEdit->setText(_cat3div6);
00127 
00128        numberOfCategoriesChanged();
00129        category1Changed();
00130        category2Changed();
00131        category3Changed();
00132 }
00133 
00134 SplitYearForm::~SplitYearForm()
00135 {
00136        saveFETDialogGeometry(this);
00137 
00138        QSettings settings(COMPANY, PROGRAM);
00139        
00140        settings.setValue(this->metaObject()->className()+QString("/separator-string"), _sep);
00141        
00142        settings.setValue(this->metaObject()->className()+QString("/number-of-categories"), _nCategories);
00143 
00144        settings.remove(this->metaObject()->className()+QString("/category"));
00145 
00146        if(_nCategories>=1)
00147               settings.setValue(this->metaObject()->className()+QString("/category/1/number-of-divisions"), _nDiv1);
00148        if(_nCategories>=2)
00149               settings.setValue(this->metaObject()->className()+QString("/category/2/number-of-divisions"), _nDiv2);
00150        if(_nCategories>=3)
00151               settings.setValue(this->metaObject()->className()+QString("/category/3/number-of-divisions"), _nDiv3);
00152        
00154        if(_nCategories>=1 && _nDiv1>=1)
00155               settings.setValue(this->metaObject()->className()+QString("/category/1/division/1"), _cat1div1);
00156        if(_nCategories>=1 && _nDiv1>=2)
00157               settings.setValue(this->metaObject()->className()+QString("/category/1/division/2"), _cat1div2);
00158        if(_nCategories>=1 && _nDiv1>=3)
00159               settings.setValue(this->metaObject()->className()+QString("/category/1/division/3"), _cat1div3);
00160        if(_nCategories>=1 && _nDiv1>=4)
00161               settings.setValue(this->metaObject()->className()+QString("/category/1/division/4"), _cat1div4);
00162        if(_nCategories>=1 && _nDiv1>=5)
00163               settings.setValue(this->metaObject()->className()+QString("/category/1/division/5"), _cat1div5);
00164        if(_nCategories>=1 && _nDiv1>=6)
00165               settings.setValue(this->metaObject()->className()+QString("/category/1/division/6"), _cat1div6);
00166        if(_nCategories>=1 && _nDiv1>=7)
00167               settings.setValue(this->metaObject()->className()+QString("/category/1/division/7"), _cat1div7);
00168        if(_nCategories>=1 && _nDiv1>=8)
00169               settings.setValue(this->metaObject()->className()+QString("/category/1/division/8"), _cat1div8);
00170        if(_nCategories>=1 && _nDiv1>=9)
00171               settings.setValue(this->metaObject()->className()+QString("/category/1/division/9"), _cat1div9);
00172        if(_nCategories>=1 && _nDiv1>=10)
00173               settings.setValue(this->metaObject()->className()+QString("/category/1/division/10"), _cat1div10);
00174        if(_nCategories>=1 && _nDiv1>=11)
00175               settings.setValue(this->metaObject()->className()+QString("/category/1/division/11"), _cat1div11);
00176        if(_nCategories>=1 && _nDiv1>=12)
00177               settings.setValue(this->metaObject()->className()+QString("/category/1/division/12"), _cat1div12);
00179        if(_nCategories>=2 && _nDiv2>=1)
00180               settings.setValue(this->metaObject()->className()+QString("/category/2/division/1"), _cat2div1);
00181        if(_nCategories>=2 && _nDiv2>=2)
00182               settings.setValue(this->metaObject()->className()+QString("/category/2/division/2"), _cat2div2);
00183        if(_nCategories>=2 && _nDiv2>=3)
00184               settings.setValue(this->metaObject()->className()+QString("/category/2/division/3"), _cat2div3);
00185        if(_nCategories>=2 && _nDiv2>=4)
00186               settings.setValue(this->metaObject()->className()+QString("/category/2/division/4"), _cat2div4);
00187        if(_nCategories>=2 && _nDiv2>=5)
00188               settings.setValue(this->metaObject()->className()+QString("/category/2/division/5"), _cat2div5);
00189        if(_nCategories>=2 && _nDiv2>=6)
00190               settings.setValue(this->metaObject()->className()+QString("/category/2/division/6"), _cat2div6);
00192                      
00194        if(_nCategories>=3 && _nDiv3>=1)
00195               settings.setValue(this->metaObject()->className()+QString("/category/3/division/1"), _cat3div1);
00196        if(_nCategories>=3 && _nDiv3>=2)
00197               settings.setValue(this->metaObject()->className()+QString("/category/3/division/2"), _cat3div2);
00198        if(_nCategories>=3 && _nDiv3>=3)
00199               settings.setValue(this->metaObject()->className()+QString("/category/3/division/3"), _cat3div3);
00200        if(_nCategories>=3 && _nDiv3>=4)
00201               settings.setValue(this->metaObject()->className()+QString("/category/3/division/4"), _cat3div4);
00202        if(_nCategories>=3 && _nDiv3>=5)
00203               settings.setValue(this->metaObject()->className()+QString("/category/3/division/5"), _cat3div5);
00204        if(_nCategories>=3 && _nDiv3>=6)
00205               settings.setValue(this->metaObject()->className()+QString("/category/3/division/6"), _cat3div6);
00207 }
00208 
00209 void SplitYearForm::numberOfCategoriesChanged()
00210 {
00211        if(categoriesSpinBox->value()<2)
00212               category2GroupBox->setDisabled(true);
00213        else
00214               category2GroupBox->setEnabled(true);
00215 
00216        if(categoriesSpinBox->value()<3)
00217               category3GroupBox->setDisabled(true);
00218        else
00219               category3GroupBox->setEnabled(true);
00220 }
00221 
00222 void SplitYearForm::category1Changed()
00223 {
00224        if(category1SpinBox->value()<3)
00225               category1Division3LineEdit->setHidden(true);
00226        else
00227               category1Division3LineEdit->setHidden(false);
00228 
00229        if(category1SpinBox->value()<4)
00230               category1Division4LineEdit->setHidden(true);
00231        else
00232               category1Division4LineEdit->setHidden(false);
00233 
00234        if(category1SpinBox->value()<5)
00235               category1Division5LineEdit->setHidden(true);
00236        else
00237               category1Division5LineEdit->setHidden(false);
00238 
00239        if(category1SpinBox->value()<6)
00240               category1Division6LineEdit->setHidden(true);
00241        else
00242               category1Division6LineEdit->setHidden(false);
00243 
00244        if(category1SpinBox->value()<7)
00245               category1Division7LineEdit->setHidden(true);
00246        else
00247               category1Division7LineEdit->setHidden(false);
00248 
00249        if(category1SpinBox->value()<8)
00250               category1Division8LineEdit->setHidden(true);
00251        else
00252               category1Division8LineEdit->setHidden(false);
00253 
00254        if(category1SpinBox->value()<9)
00255               category1Division9LineEdit->setHidden(true);
00256        else
00257               category1Division9LineEdit->setHidden(false);
00258 
00259        if(category1SpinBox->value()<10)
00260               category1Division10LineEdit->setHidden(true);
00261        else
00262               category1Division10LineEdit->setHidden(false);
00263 
00264        if(category1SpinBox->value()<11)
00265               category1Division11LineEdit->setHidden(true);
00266        else
00267               category1Division11LineEdit->setHidden(false);
00268 
00269        if(category1SpinBox->value()<12)
00270               category1Division12LineEdit->setHidden(true);
00271        else
00272               category1Division12LineEdit->setHidden(false);
00273 }
00274 
00275 void SplitYearForm::category2Changed()
00276 {
00277        if(category2SpinBox->value()<3)
00278               category2Division3LineEdit->setHidden(true);
00279        else
00280               category2Division3LineEdit->setHidden(false);
00281 
00282        if(category2SpinBox->value()<4)
00283               category2Division4LineEdit->setHidden(true);
00284        else
00285               category2Division4LineEdit->setHidden(false);
00286 
00287        if(category2SpinBox->value()<5)
00288               category2Division5LineEdit->setHidden(true);
00289        else
00290               category2Division5LineEdit->setHidden(false);
00291 
00292        if(category2SpinBox->value()<6)
00293               category2Division6LineEdit->setHidden(true);
00294        else
00295               category2Division6LineEdit->setHidden(false);
00296 }
00297 
00298 void SplitYearForm::category3Changed()
00299 {
00300        if(category3SpinBox->value()<3)
00301               category3Division3LineEdit->setHidden(true);
00302        else
00303               category3Division3LineEdit->setHidden(false);
00304 
00305        if(category3SpinBox->value()<4)
00306               category3Division4LineEdit->setHidden(true);
00307        else
00308               category3Division4LineEdit->setHidden(false);
00309 
00310        if(category3SpinBox->value()<5)
00311               category3Division5LineEdit->setHidden(true);
00312        else
00313               category3Division5LineEdit->setHidden(false);
00314 
00315        if(category3SpinBox->value()<6)
00316               category3Division6LineEdit->setHidden(true);
00317        else
00318               category3Division6LineEdit->setHidden(false);
00319 }
00320 
00321 void SplitYearForm::ok()
00322 {
00323        QString separator=separatorLineEdit->text();
00324 
00325        QString namesCategory1[12+1];
00326        QString namesCategory2[6+1];
00327        QString namesCategory3[6+1];
00328        
00329        //CATEGORY 1
00330        if(category1Division1LineEdit->text()==""){
00331               QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00332               return;
00333        }
00334        namesCategory1[1]=category1Division1LineEdit->text();
00335        if(category1Division2LineEdit->text()==""){
00336               QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00337               return;
00338        }
00339        namesCategory1[2]=category1Division2LineEdit->text();
00340        if(category1SpinBox->value()>=3){
00341               if(category1Division3LineEdit->text()==""){
00342                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00343                      return;
00344               }
00345               namesCategory1[3]=category1Division3LineEdit->text();
00346        }
00347        else
00348               namesCategory1[3]="";
00349 
00350        if(category1SpinBox->value()>=4){
00351               if(category1Division4LineEdit->text()==""){
00352                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00353                      return;
00354               }
00355               namesCategory1[4]=category1Division4LineEdit->text();
00356        }
00357        else
00358               namesCategory1[4]="";
00359 
00360        if(category1SpinBox->value()>=5){
00361               if(category1Division5LineEdit->text()==""){
00362                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00363                      return;
00364               }
00365               namesCategory1[5]=category1Division5LineEdit->text();
00366        }
00367        else
00368               namesCategory1[5]="";
00369 
00370        if(category1SpinBox->value()>=6){
00371               if(category1Division6LineEdit->text()==""){
00372                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00373                      return;
00374               }
00375               namesCategory1[6]=category1Division6LineEdit->text();
00376        }
00377        else
00378               namesCategory1[6]="";
00379 
00381        if(category1SpinBox->value()>=7){
00382               if(category1Division7LineEdit->text()==""){
00383                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00384                      return;
00385               }
00386               namesCategory1[7]=category1Division7LineEdit->text();
00387        }
00388        else
00389               namesCategory1[7]="";
00390 
00391        if(category1SpinBox->value()>=8){
00392               if(category1Division8LineEdit->text()==""){
00393                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00394                      return;
00395               }
00396               namesCategory1[8]=category1Division8LineEdit->text();
00397        }
00398        else
00399               namesCategory1[8]="";
00400 
00401        if(category1SpinBox->value()>=9){
00402               if(category1Division9LineEdit->text()==""){
00403                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00404                      return;
00405               }
00406               namesCategory1[9]=category1Division9LineEdit->text();
00407        }
00408        else
00409               namesCategory1[9]="";
00410 
00411        if(category1SpinBox->value()>=10){
00412               if(category1Division10LineEdit->text()==""){
00413                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00414                      return;
00415               }
00416               namesCategory1[10]=category1Division10LineEdit->text();
00417        }
00418        else
00419               namesCategory1[10]="";
00420 
00421        if(category1SpinBox->value()>=11){
00422               if(category1Division11LineEdit->text()==""){
00423                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00424                      return;
00425               }
00426               namesCategory1[11]=category1Division11LineEdit->text();
00427        }
00428        else
00429               namesCategory1[11]="";
00430 
00431        if(category1SpinBox->value()>=12){
00432               if(category1Division11LineEdit->text()==""){
00433                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00434                      return;
00435               }
00436               namesCategory1[12]=category1Division12LineEdit->text();
00437        }
00438        else
00439               namesCategory1[12]="";
00442 
00443        //CATEGORY 2
00444        if(categoriesSpinBox->value()>=2){
00445               if(category2Division1LineEdit->text()==""){
00446                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00447                      return;
00448               }
00449               namesCategory2[1]=category2Division1LineEdit->text();
00450               if(category2Division2LineEdit->text()==""){
00451                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00452                      return;
00453               }
00454               namesCategory2[2]=category2Division2LineEdit->text();
00455               if(category2SpinBox->value()>=3){
00456                      if(category2Division3LineEdit->text()==""){
00457                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00458                             return;
00459                      }
00460                      namesCategory2[3]=category2Division3LineEdit->text();
00461               }
00462               else
00463                      namesCategory2[3]="";
00464 
00465               if(category2SpinBox->value()>=4){
00466                      if(category2Division4LineEdit->text()==""){
00467                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00468                             return;
00469                      }
00470                      namesCategory2[4]=category2Division4LineEdit->text();
00471               }
00472               else
00473                      namesCategory2[4]="";
00474 
00475               if(category2SpinBox->value()>=5){
00476                      if(category2Division5LineEdit->text()==""){
00477                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00478                             return;
00479                      }
00480                      namesCategory2[5]=category2Division5LineEdit->text();
00481               }
00482               else
00483                      namesCategory2[5]="";
00484 
00485               if(category2SpinBox->value()>=6){
00486                      if(category2Division6LineEdit->text()==""){
00487                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00488                             return;
00489                      }
00490                      namesCategory2[6]=category2Division6LineEdit->text();
00491               }
00492               else
00493                      namesCategory2[6]="";
00494        }
00495        else
00496               for(int i=1; i<=6; i++)
00497                      namesCategory2[i]="";
00499               
00500        //CATEGORY 3
00501        if(categoriesSpinBox->value()>=3){
00502               if(category3Division1LineEdit->text()==""){
00503                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00504                      return;
00505               }
00506               namesCategory3[1]=category3Division1LineEdit->text();
00507               if(category3Division2LineEdit->text()==""){
00508                      QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00509                      return;
00510               }
00511               namesCategory3[2]=category3Division2LineEdit->text();
00512               if(category3SpinBox->value()>=3){
00513                      if(category3Division3LineEdit->text()==""){
00514                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00515                             return;
00516                      }
00517                      namesCategory3[3]=category3Division3LineEdit->text();
00518               }
00519               else
00520                      namesCategory3[3]="";
00521 
00522               if(category3SpinBox->value()>=4){
00523                      if(category3Division4LineEdit->text()==""){
00524                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00525                             return;
00526                      }
00527                      namesCategory3[4]=category3Division4LineEdit->text();
00528               }
00529               else
00530                      namesCategory3[4]="";
00531 
00532               if(category3SpinBox->value()>=5){
00533                      if(category3Division5LineEdit->text()==""){
00534                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00535                             return;
00536                      }
00537                      namesCategory3[5]=category3Division5LineEdit->text();
00538               }
00539               else
00540                      namesCategory3[5]="";
00541 
00542               if(category3SpinBox->value()>=6){
00543                      if(category3Division6LineEdit->text()==""){
00544                             QMessageBox::information(this, tr("FET information"), tr("Empty names not allowed"));
00545                             return;
00546                      }
00547                      namesCategory3[6]=category3Division6LineEdit->text();
00548               }
00549               else
00550                      namesCategory3[6]="";
00551        }
00552        else
00553               for(int i=1; i<=6; i++)
00554                      namesCategory3[i]="";
00556                      
00557        StudentsYear* y=(StudentsYear*)gt.rules.searchStudentsSet(year);
00558        assert(y!=NULL);
00559        
00560        if(y->groupsList.count()>0){
00561               int t=QMessageBox::question(this, tr("FET question"), tr("Year %1 is not empty and it will be emptied before adding"
00562               " the divisions you selected. This means that all the activities and constraints for"
00563               " the groups and subgroups in this year will be removed. It is strongly recommended to save your file before continuing."
00564               " You might also want, as an alternative, to modify manually the groups/subgroups from the corresponding menu, so that"
00565               " you will not lose constraints and activities referring to them."
00566               " Do you really want to empty year?").arg(year),
00567                QMessageBox::Yes, QMessageBox::Cancel);
00568                
00569               if(t==QMessageBox::Cancel)
00570                      return;
00571 
00572               t=QMessageBox::warning(this, tr("FET warning"), tr("Year %1 will be emptied."
00573                " This means that all constraints and activities referring to groups/subgroups in year %1 will be removed."
00574                " Are you absolutely sure?").arg(year),
00575                QMessageBox::Yes, QMessageBox::Cancel);
00576                
00577               if(t==QMessageBox::Cancel)
00578                      return;
00579                      
00580               while(y->groupsList.count()>0){
00581                      QString group=y->groupsList.at(0)->name;
00582                      gt.rules.removeGroup(year, group);
00583               }
00584        }
00585               
00586        QStringList tmp;
00587        for(int i=1; i<=12; i++){
00588               if(namesCategory1[i]!=""){
00589                      if(tmp.contains(namesCategory1[i])){
00590                             QMessageBox::information(this, tr("FET information"), tr("Duplicate names not allowed"));
00591                             return;
00592                      }
00593                      tmp.append(namesCategory1[i]);
00594               }
00595        }
00596        for(int j=1; j<=6; j++){
00597               if(namesCategory2[j]!=""){
00598                      if(tmp.contains(namesCategory2[j])){
00599                             QMessageBox::information(this, tr("FET information"), tr("Duplicate names not allowed"));
00600                             return;
00601                      }
00602                      tmp.append(namesCategory2[j]);
00603               }
00604        }
00605        for(int k=1; k<=6; k++){
00606               if(namesCategory3[k]!=""){
00607                      if(tmp.contains(namesCategory3[k])){
00608                             QMessageBox::information(this, tr("FET information"), tr("Duplicate names not allowed"));
00609                             return;
00610                      }
00611                      tmp.append(namesCategory3[k]);
00612               }
00613        }
00614               
00615        if(namesCategory3[1]!=""){ //3 categories
00616               for(int i=1; i<=12; i++)
00617                      if(namesCategory1[i]!="")
00618                             for(int j=1; j<=6; j++)
00619                                    if(namesCategory2[j]!="")
00620                                           for(int k=1; k<=6; k++)
00621                                                  if(namesCategory3[k]!=""){
00622                                                         QString t=year+separator+namesCategory1[i];
00623                                                         if(gt.rules.searchStudentsSet(t)!=NULL){
00624                                                                QMessageBox::information(this, tr("FET information"), tr("Cannot add group %1, because a set with same name exists. "
00625                                                                 "Please choose another name or remove old group").arg(t));
00626                                                                return;
00627                                                         }
00628                                                         t=year+separator+namesCategory2[j];
00629                                                         if(gt.rules.searchStudentsSet(t)!=NULL){
00630                                                                QMessageBox::information(this, tr("FET information"), tr("Cannot add group %1, because a set with same name exists. "
00631                                                                 "Please choose another name or remove old group").arg(t));
00632                                                                return;
00633                                                         }
00634                                                         t=year+separator+namesCategory3[k];
00635                                                         if(gt.rules.searchStudentsSet(t)!=NULL){
00636                                                                QMessageBox::information(this, tr("FET information"), tr("Cannot add group %1, because a set with same name exists. "
00637                                                                 "Please choose another name or remove old group").arg(t));
00638                                                                return;
00639                                                         }
00640                                                         t=year+separator+namesCategory1[i]+separator+namesCategory2[j]+separator+namesCategory3[k];
00641                                                         if(gt.rules.searchStudentsSet(t)!=NULL){
00642                                                                QMessageBox::information(this, tr("FET information"), tr("Cannot add subgroup %1, because a set with same name exists. "
00643                                                                 "Please choose another name or remove old subgroup").arg(t));
00644                                                                return;
00645                                                         }
00646                                                  }
00647                                                  
00648               StudentsSubgroup* subgroups[12+1][6+1][6+1];
00649               
00650               for(int i=1; i<=12; i++)
00651                      for(int j=1; j<=6; j++)
00652                             for(int k=1; k<=6; k++)
00653                                    subgroups[i][j][k]=NULL;
00654 
00655               for(int i=1; i<=12; i++)
00656                      if(namesCategory1[i]!="")
00657                             for(int j=1; j<=6; j++)
00658                                    if(namesCategory2[j]!="")
00659                                           for(int k=1; k<=6; k++)
00660                                                  if(namesCategory3[k]!=""){
00661                                                         QString t=year+separator+namesCategory1[i]+separator+namesCategory2[j]+separator+namesCategory3[k];
00662                                                         assert(gt.rules.searchStudentsSet(t)==NULL);
00663                                                         subgroups[i][j][k]=new StudentsSubgroup;
00664                                                         subgroups[i][j][k]->name=t;
00665                                                  }
00666                                                         
00667               for(int i=1; i<=12; i++)
00668                      if(namesCategory1[i]!=""){
00669                             QString t=year+separator+namesCategory1[i];
00670                             assert(gt.rules.searchStudentsSet(t)==NULL);
00671                             StudentsGroup* gr=new StudentsGroup;
00672                             gr->name=t;
00673                             gt.rules.addGroup(year, gr);
00674                             for(int j=1; j<=6; j++)
00675                                    for(int k=1; k<=6; k++)
00676                                           if(subgroups[i][j][k]!=NULL)
00677                                                  gt.rules.addSubgroup(year, t, subgroups[i][j][k]);
00678                      }
00679 
00680               for(int j=1; j<=6; j++)
00681                      if(namesCategory2[j]!=""){
00682                             QString t=year+separator+namesCategory2[j];
00683                             assert(gt.rules.searchStudentsSet(t)==NULL);
00684                             StudentsGroup* gr=new StudentsGroup;
00685                             gr->name=t;
00686                             gt.rules.addGroup(year, gr);
00687                             for(int i=1; i<=12; i++)
00688                                    for(int k=1; k<=6; k++)
00689                                           if(subgroups[i][j][k]!=NULL)
00690                                                  gt.rules.addSubgroup(year, t, subgroups[i][j][k]);
00691                      }
00692 
00693               for(int k=1; k<=6; k++)
00694                      if(namesCategory3[k]!=""){
00695                             QString t=year+separator+namesCategory3[k];
00696                             assert(gt.rules.searchStudentsSet(t)==NULL);
00697                             StudentsGroup* gr=new StudentsGroup;
00698                             gr->name=t;
00699                             gt.rules.addGroup(year, gr);
00700                             for(int i=1; i<=12; i++)
00701                                    for(int j=1; j<=6; j++)
00702                                           if(subgroups[i][j][k]!=NULL)
00703                                                  gt.rules.addSubgroup(year, t, subgroups[i][j][k]);
00704                      }
00705        }
00706        else if(namesCategory2[1]!=""){ //two categories
00707               for(int i=1; i<=12; i++)
00708                      if(namesCategory1[i]!="")
00709                             for(int j=1; j<=6; j++)
00710                                    if(namesCategory2[j]!=""){
00711                                           QString t=year+separator+namesCategory1[i];
00712                                           if(gt.rules.searchStudentsSet(t)!=NULL){
00713                                                  QMessageBox::information(this, tr("FET information"), tr("Cannot add group %1, because a set with same name exists. "
00714                                                   "Please choose another name or remove old group").arg(t));
00715                                                  return;
00716                                           }
00717                                           t=year+separator+namesCategory2[j];
00718                                           if(gt.rules.searchStudentsSet(t)!=NULL){
00719                                                  QMessageBox::information(this, tr("FET information"), tr("Cannot add group %1, because a set with same name exists. "
00720                                                   "Please choose another name or remove old group").arg(t));
00721                                                  return;
00722                                           }
00723                                           t=year+separator+namesCategory1[i]+separator+namesCategory2[j];
00724                                           if(gt.rules.searchStudentsSet(t)!=NULL){
00725                                                  QMessageBox::information(this, tr("FET information"), tr("Cannot add subgroup %1, because a set with same name exists. "
00726                                                   "Please choose another name or remove old subgroup").arg(t));
00727                                                  return;
00728                                           }
00729                                    }
00730                                           
00731               StudentsSubgroup* subgroups[12+1][6+1];
00732               
00733               for(int i=1; i<=12; i++)
00734                      for(int j=1; j<=6; j++)
00735                             subgroups[i][j]=NULL;
00736 
00737               for(int i=1; i<=12; i++)
00738                      if(namesCategory1[i]!="")
00739                             for(int j=1; j<=6; j++)
00740                                    if(namesCategory2[j]!=""){
00741                                           QString t=year+separator+namesCategory1[i]+separator+namesCategory2[j];
00742                                           assert(gt.rules.searchStudentsSet(t)==NULL);
00743                                           subgroups[i][j]=new StudentsSubgroup;
00744                                           subgroups[i][j]->name=t;
00745                                    }
00746                                                         
00747               for(int i=1; i<=12; i++)
00748                      if(namesCategory1[i]!=""){
00749                             QString t=year+separator+namesCategory1[i];
00750                             assert(gt.rules.searchStudentsSet(t)==NULL);
00751                             StudentsGroup* gr=new StudentsGroup;
00752                             gr->name=t;
00753                             gt.rules.addGroup(year, gr);
00754                             for(int j=1; j<=6; j++)
00755                                    if(subgroups[i][j]!=NULL)
00756                                           gt.rules.addSubgroup(year, t, subgroups[i][j]);
00757                      }
00758 
00759               for(int j=1; j<=6; j++)
00760                      if(namesCategory2[j]!=""){
00761                             QString t=year+separator+namesCategory2[j];
00762                             assert(gt.rules.searchStudentsSet(t)==NULL);
00763                             StudentsGroup* gr=new StudentsGroup;
00764                             gr->name=t;
00765                             gt.rules.addGroup(year, gr);
00766                             for(int i=1; i<=12; i++)
00767                                    if(subgroups[i][j]!=NULL)
00768                                           gt.rules.addSubgroup(year, t, subgroups[i][j]);
00769                      }
00770        }
00771        else{ //one categories
00772               assert(namesCategory1[1]!="");
00773               for(int i=1; i<=12; i++)
00774                      if(namesCategory1[i]!=""){
00775                             QString t=year+separator+namesCategory1[i];
00776                             if(gt.rules.searchStudentsSet(t)!=NULL){
00777                                    QMessageBox::information(this, tr("FET information"), tr("Cannot add group %1, because a set with same name exists. "
00778                                     "Please choose another name or remove old group").arg(t));
00779                                    return;
00780                             }
00781                      }
00782                                           
00783               for(int i=1; i<=12; i++)
00784                      if(namesCategory1[i]!=""){
00785                             QString t=year+separator+namesCategory1[i];
00786                             assert(gt.rules.searchStudentsSet(t)==NULL);
00787                             StudentsGroup* gr=new StudentsGroup;
00788                             gr->name=t;
00789                             gt.rules.addGroup(year, gr);
00790                      }
00791        }
00792               
00793        QMessageBox::information(this, tr("FET information"), tr("Split of year complete, please check the groups and subgroups"
00794         " of year to make sure everything is OK"));
00795         
00796        //saving page
00797        _sep=separatorLineEdit->text();
00798        
00799        _nCategories=categoriesSpinBox->value();
00800        
00801        _nDiv1=category1SpinBox->value();
00802        _nDiv2=category2SpinBox->value();
00803        _nDiv3=category3SpinBox->value();
00804        
00805        _cat1div1=category1Division1LineEdit->text();
00806        _cat1div2=category1Division2LineEdit->text();
00807        _cat1div3=category1Division3LineEdit->text();
00808        _cat1div4=category1Division4LineEdit->text();
00809        _cat1div5=category1Division5LineEdit->text();
00810        _cat1div6=category1Division6LineEdit->text();
00811        _cat1div7=category1Division7LineEdit->text();
00812        _cat1div8=category1Division8LineEdit->text();
00813        _cat1div9=category1Division9LineEdit->text();
00814        _cat1div10=category1Division10LineEdit->text();
00815        _cat1div11=category1Division11LineEdit->text();
00816        _cat1div12=category1Division12LineEdit->text();
00817        
00818        _cat2div1=category2Division1LineEdit->text();
00819        _cat2div2=category2Division2LineEdit->text();
00820        _cat2div3=category2Division3LineEdit->text();
00821        _cat2div4=category2Division4LineEdit->text();
00822        _cat2div5=category2Division5LineEdit->text();
00823        _cat2div6=category2Division6LineEdit->text();
00824        
00825        _cat3div1=category3Division1LineEdit->text();
00826        _cat3div2=category3Division2LineEdit->text();
00827        _cat3div3=category3Division3LineEdit->text();
00828        _cat3div4=category3Division4LineEdit->text();
00829        _cat3div5=category3Division5LineEdit->text();
00830        _cat3div6=category3Division6LineEdit->text();
00832        
00833        this->close();
00834 }
00835 
00836 void SplitYearForm::help()
00837 {
00838        QString s;
00839 
00840        s+=tr("You might first want to consider if dividing a year is necessary and on what options. Please remember"
00841         " that FET can handle activities with multiple teachers/students sets. If you have say students set 9a, which is split"
00842         " into 2 parts: English (teacher TE) and French (teacher TF), and language activities must be simultaneous, then you might not want to divide"
00843         " according to this category, but add more larger activities, with students set 9a and teachers TE+TF."
00844         " The only drawback is that each activity can take place only in one room in FET, so you might need to find a way to overcome that.");
00845        
00846        s+="\n\n";
00847        
00848        s+=tr("Please choose a number of categories and in each category the number of divisions. You can choose for instance"
00849         " 3 categories, 5 divisions for the first category: a, b, c, d and e, 2 divisions for the second category: boys and girls,"
00850         " and 3 divisions for the third: English, German and French."
00851         " You can select 1, 2 or 3 categories, first with 2 to 12 divisions and the second and third ones each with 2 to 6 divisions."
00852         " If you need 4 categories, you may apply this trick: consider 9a a year, 9b another year, ..., and divide them by 3 categories (more details below)"
00853         ". For more values (very unlikely case) you will have to manually"
00854         " add the groups and subgroups");
00855         
00856        s+="\n\n";
00857        
00858        s+=tr("If you need to make a division of say year 9 in 4 categories (category1: a, b,c, d, category2: language,"
00859         " category3: religion, category4: boys/girls), you might want to use this trick: consider first category to"
00860         " define years: year 9a, year 9b, year 9c, year 9d, and divide each year by 3 categories: language, religion and boys/girls."
00861         " For activities with year 9 - language 1 for instance, you need to add to these activities the groups 9a_language1+9b_language1+"
00862         "9c_language1+9d_language1. For activities with year 9a, just add year 9a to the corresponding activities.");
00863        
00864        s+="\n\n";
00865        
00866        s+=tr("Please input from the beginning the correct divisions. After you inputted activities and constraints"
00867         " for this year's groups and subgroups, dividing it again will remove the activities and constraints referring"
00868         " to these groups/subgroups. I know this is not elegant, I hope I'll solve that in the future."
00869         " You might want to use the alternative of manually adding/editing/removing groups/subgroups"
00870         " in the groups/subgroups menu, though removing a group/subgroup will also remove the activities");
00871         
00872        s+="\n\n";
00873 
00874        s+=tr("Probably you don't need to worry about empty subgroups (no significant speed changes), although I didn't test "
00875               "enough such situations."
00876               " You just need to know that for the moment the maximum total number of subgroups is %1 (which can be changed"
00877               ", but nobody needed larger values)").arg(MAX_TOTAL_SUBGROUPS);
00878         
00879        s+="\n\n";
00880 
00881        s+=tr("Please note that the dialog here will keep the last configuration of the last "
00882                "divided year, it will not remember the values for a specific year you need to modify.");
00883                
00884        s+="\n\n";
00885 
00886        s+=tr("Separator character(s) is of your choice (default is space)");
00887         
00888        //show the message in a dialog
00889        QDialog dialog(this);
00890        
00891        dialog.setWindowTitle(tr("FET - help on dividing a year"));
00892 
00893        QVBoxLayout* vl=new QVBoxLayout(&dialog);
00894        QPlainTextEdit* te=new QPlainTextEdit();
00895        te->setPlainText(s);
00896        te->setReadOnly(true);
00897        QPushButton* pb=new QPushButton(tr("OK"));
00898 
00899        QHBoxLayout* hl=new QHBoxLayout(0);
00900        hl->addStretch(1);
00901        hl->addWidget(pb);
00902 
00903        vl->addWidget(te);
00904        vl->addLayout(hl);
00905        connect(pb, SIGNAL(clicked()), &dialog, SLOT(close()));
00906 
00907        dialog.resize(700,500);
00908        centerWidgetOnScreen(&dialog);
00909 
00910        setParentAndOtherThings(&dialog, this);
00911        dialog.exec();
00912 }
00913 
00914 void SplitYearForm::reset() //reset to defaults
00915 {
00916        separatorLineEdit->setText(" ");
00917        
00918        categoriesSpinBox->setValue(1);
00919        
00920        category1SpinBox->setValue(2);
00921        category2SpinBox->setValue(2);
00922        category3SpinBox->setValue(2);
00923        
00924        category1Division1LineEdit->setText("");
00925        category1Division2LineEdit->setText("");
00926        category1Division3LineEdit->setText("");
00927        category1Division4LineEdit->setText("");
00928        category1Division5LineEdit->setText("");
00929        category1Division6LineEdit->setText("");
00930        category1Division7LineEdit->setText("");
00931        category1Division8LineEdit->setText("");
00932        category1Division9LineEdit->setText("");
00933        category1Division10LineEdit->setText("");
00934        category1Division11LineEdit->setText("");
00935        category1Division12LineEdit->setText("");
00936 
00937        category2Division1LineEdit->setText("");
00938        category2Division2LineEdit->setText("");
00939        category2Division3LineEdit->setText("");
00940        category2Division4LineEdit->setText("");
00941        category2Division5LineEdit->setText("");
00942        category2Division6LineEdit->setText("");
00943 
00944        category3Division1LineEdit->setText("");
00945        category3Division2LineEdit->setText("");
00946        category3Division3LineEdit->setText("");
00947        category3Division4LineEdit->setText("");
00948        category3Division5LineEdit->setText("");
00949        category3Division6LineEdit->setText("");
00950        
00952        
00953        /*
00954        _sep=separatorLineEdit->text();
00955        
00956        _nCategories=categoriesSpinBox->value();
00957        
00958        _nDiv1=category1SpinBox->value();
00959        _nDiv2=category2SpinBox->value();
00960        _nDiv3=category3SpinBox->value();
00961        
00962        _cat1div1=category1Division1LineEdit->text();
00963        _cat1div2=category1Division2LineEdit->text();
00964        _cat1div3=category1Division3LineEdit->text();
00965        _cat1div4=category1Division4LineEdit->text();
00966        _cat1div5=category1Division5LineEdit->text();
00967        _cat1div6=category1Division6LineEdit->text();
00968        _cat1div7=category1Division7LineEdit->text();
00969        _cat1div8=category1Division8LineEdit->text();
00970        _cat1div9=category1Division9LineEdit->text();
00971        _cat1div10=category1Division10LineEdit->text();
00972        _cat1div11=category1Division11LineEdit->text();
00973        _cat1div12=category1Division12LineEdit->text();
00974        
00975        _cat2div1=category2Division1LineEdit->text();
00976        _cat2div2=category2Division2LineEdit->text();
00977        _cat2div3=category2Division3LineEdit->text();
00978        _cat2div4=category2Division4LineEdit->text();
00979        _cat2div5=category2Division5LineEdit->text();
00980        _cat2div6=category2Division6LineEdit->text();
00981        
00982        _cat3div1=category3Division1LineEdit->text();
00983        _cat3div2=category3Division2LineEdit->text();
00984        _cat3div3=category3Division3LineEdit->text();
00985        _cat3div4=category3Division4LineEdit->text();
00986        _cat3div5=category3Division5LineEdit->text();
00987        _cat3div6=category3Division6LineEdit->text();
00988        */
00989 }