"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.47.1/src/interface/modifyconstraintactivitiessameroomifconsecutiveform.cpp" (28 Apr 2020, 8662 Bytes) of package /linux/privat/fet-5.47.1.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "modifyconstraintactivitiessameroomifconsecutiveform.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           modifyconstraintactivitiessameroomifconsecutiveform.cpp  -  description
    3                              -------------------
    4     begin                : Sept 14, 2013
    5     copyright            : (C) 2013 by Lalescu Liviu
    6     email                : Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
    7  ***************************************************************************/
    8 
    9 /***************************************************************************
   10  *                                                                         *
   11  *   This program is free software: you can redistribute it and/or modify  *
   12  *   it under the terms of the GNU Affero General Public License as        *
   13  *   published by the Free Software Foundation, either version 3 of the    *
   14  *   License, or (at your option) any later version.                       *
   15  *                                                                         *
   16  ***************************************************************************/
   17 
   18 #include <QMessageBox>
   19 
   20 #include "longtextmessagebox.h"
   21 
   22 #include "modifyconstraintactivitiessameroomifconsecutiveform.h"
   23 #include "spaceconstraint.h"
   24 
   25 #include <QListWidget>
   26 #include <QAbstractItemView>
   27 #include <QScrollBar>
   28 
   29 ModifyConstraintActivitiesSameRoomIfConsecutiveForm::ModifyConstraintActivitiesSameRoomIfConsecutiveForm(QWidget* parent, ConstraintActivitiesSameRoomIfConsecutive* ctr): QDialog(parent)
   30 {
   31     setupUi(this);
   32 
   33     okPushButton->setDefault(true);
   34     
   35     allActivitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
   36     selectedActivitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
   37     
   38     connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
   39     connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
   40     connect(allActivitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addActivity()));
   41     connect(addAllActivitiesPushButton, SIGNAL(clicked()), this, SLOT(addAllActivities()));
   42     connect(selectedActivitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeActivity()));
   43     connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clear()));
   44     
   45     centerWidgetOnScreen(this);
   46     restoreFETDialogGeometry(this);
   47     
   48     this->_ctr=ctr;
   49     
   50     weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
   51 
   52     //activities
   53     QSize tmp1=teachersComboBox->minimumSizeHint();
   54     Q_UNUSED(tmp1);
   55     QSize tmp2=studentsComboBox->minimumSizeHint();
   56     Q_UNUSED(tmp2);
   57     QSize tmp3=subjectsComboBox->minimumSizeHint();
   58     Q_UNUSED(tmp3);
   59     QSize tmp4=activityTagsComboBox->minimumSizeHint();
   60     Q_UNUSED(tmp4);
   61     
   62     selectedActivitiesList.clear();
   63     selectedActivitiesListWidget->clear();
   64     for(int i=0; i<ctr->activitiesIds.count(); i++){
   65         int actId=ctr->activitiesIds.at(i);
   66         this->selectedActivitiesList.append(actId);
   67         Activity* act=NULL;
   68         for(int k=0; k<gt.rules.activitiesList.size(); k++){
   69             act=gt.rules.activitiesList[k];
   70             if(act->id==actId)
   71                 break;
   72         }
   73         assert(act);
   74         this->selectedActivitiesListWidget->addItem(act->getDescription(gt.rules));
   75     }
   76 
   77     teachersComboBox->addItem("");
   78     for(int i=0; i<gt.rules.teachersList.size(); i++){
   79         Teacher* tch=gt.rules.teachersList[i];
   80         teachersComboBox->addItem(tch->name);
   81     }
   82     teachersComboBox->setCurrentIndex(0);
   83 
   84     subjectsComboBox->addItem("");
   85     for(int i=0; i<gt.rules.subjectsList.size(); i++){
   86         Subject* sb=gt.rules.subjectsList[i];
   87         subjectsComboBox->addItem(sb->name);
   88     }
   89     subjectsComboBox->setCurrentIndex(0);
   90 
   91     activityTagsComboBox->addItem("");
   92     for(int i=0; i<gt.rules.activityTagsList.size(); i++){
   93         ActivityTag* st=gt.rules.activityTagsList[i];
   94         activityTagsComboBox->addItem(st->name);
   95     }
   96     activityTagsComboBox->setCurrentIndex(0);
   97 
   98     populateStudentsComboBox(studentsComboBox, QString(""), true);
   99     studentsComboBox->setCurrentIndex(0);
  100 
  101     filterChanged();
  102 
  103     connect(teachersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
  104     connect(studentsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
  105     connect(subjectsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
  106     connect(activityTagsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
  107 }
  108 
  109 ModifyConstraintActivitiesSameRoomIfConsecutiveForm::~ModifyConstraintActivitiesSameRoomIfConsecutiveForm()
  110 {
  111     saveFETDialogGeometry(this);
  112 }
  113 
  114 void ModifyConstraintActivitiesSameRoomIfConsecutiveForm::ok()
  115 {
  116     double weight;
  117     QString tmp=weightLineEdit->text();
  118     weight_sscanf(tmp, "%lf", &weight);
  119     if(weight<100.0 || weight>100.0){
  120         QMessageBox::warning(this, tr("FET information"),
  121             tr("Invalid weight (percentage). It has to be 100"));
  122         return;
  123     }
  124     
  125     this->_ctr->weightPercentage=weight;
  126 
  127     if(this->selectedActivitiesList.count()==0){
  128         QMessageBox::warning(this, tr("FET information"),
  129          tr("Empty list of activities"));
  130         return;
  131     }
  132     if(this->selectedActivitiesList.count()==1){
  133         QMessageBox::warning(this, tr("FET information"),
  134          tr("Only one selected activity"));
  135         return;
  136     }
  137     
  138     this->_ctr->activitiesIds=selectedActivitiesList;
  139     
  140     gt.rules.internalStructureComputed=false;
  141     setRulesModifiedAndOtherThings(&gt.rules);
  142     
  143     this->close();
  144 }
  145 
  146 void ModifyConstraintActivitiesSameRoomIfConsecutiveForm::cancel()
  147 {
  148     this->close();
  149 }
  150 
  151 //activities
  152 bool ModifyConstraintActivitiesSameRoomIfConsecutiveForm::filterOk(Activity* act)
  153 {
  154     QString tn=teachersComboBox->currentText();
  155     QString stn=studentsComboBox->currentText();
  156     QString sbn=subjectsComboBox->currentText();
  157     QString atn=activityTagsComboBox->currentText();
  158     int ok=true;
  159 
  160     //teacher
  161     if(tn!=""){
  162         bool ok2=false;
  163         for(QStringList::const_iterator it=act->teachersNames.constBegin(); it!=act->teachersNames.constEnd(); it++)
  164             if(*it == tn){
  165                 ok2=true;
  166                 break;
  167             }
  168         if(!ok2)
  169             ok=false;
  170     }
  171 
  172     //subject
  173     if(sbn!="" && sbn!=act->subjectName)
  174         ok=false;
  175         
  176     //activity tag
  177     if(atn!="" && !act->activityTagsNames.contains(atn))
  178         ok=false;
  179         
  180     //students
  181     if(stn!=""){
  182         bool ok2=false;
  183         for(QStringList::const_iterator it=act->studentsNames.constBegin(); it!=act->studentsNames.constEnd(); it++)
  184             if(*it == stn){
  185                 ok2=true;
  186                 break;
  187             }
  188         if(!ok2)
  189             ok=false;
  190     }
  191     
  192     return ok;
  193 }
  194 
  195 void ModifyConstraintActivitiesSameRoomIfConsecutiveForm::filterChanged()
  196 {
  197     allActivitiesListWidget->clear();
  198     this->activitiesList.clear();
  199     
  200     for(int i=0; i<gt.rules.activitiesList.size(); i++){
  201         Activity* ac=gt.rules.activitiesList[i];
  202         if(filterOk(ac)){
  203             allActivitiesListWidget->addItem(ac->getDescription(gt.rules));
  204             this->activitiesList.append(ac->id);
  205         }
  206     }
  207     
  208     int q=allActivitiesListWidget->verticalScrollBar()->minimum();
  209     allActivitiesListWidget->verticalScrollBar()->setValue(q);
  210 }
  211 
  212 void ModifyConstraintActivitiesSameRoomIfConsecutiveForm::addActivity()
  213 {
  214     if(allActivitiesListWidget->currentRow()<0)
  215         return;
  216     int tmp=allActivitiesListWidget->currentRow();
  217     int _id=this->activitiesList.at(tmp);
  218     
  219     QString actName=allActivitiesListWidget->currentItem()->text();
  220     assert(actName!="");
  221     
  222     //duplicate?
  223     if(this->selectedActivitiesList.contains(_id))
  224         return;
  225     
  226     selectedActivitiesListWidget->addItem(actName);
  227     selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
  228 
  229     this->selectedActivitiesList.append(_id);
  230 }
  231 
  232 void ModifyConstraintActivitiesSameRoomIfConsecutiveForm::addAllActivities()
  233 {
  234     for(int tmp=0; tmp<allActivitiesListWidget->count(); tmp++){
  235         int _id=this->activitiesList.at(tmp);
  236     
  237         QString actName=allActivitiesListWidget->item(tmp)->text();
  238         assert(actName!="");
  239         
  240         if(this->selectedActivitiesList.contains(_id))
  241             continue;
  242         
  243         selectedActivitiesListWidget->addItem(actName);
  244         this->selectedActivitiesList.append(_id);
  245     }
  246     
  247     selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
  248 }
  249 
  250 void ModifyConstraintActivitiesSameRoomIfConsecutiveForm::removeActivity()
  251 {
  252     if(selectedActivitiesListWidget->currentRow()<0 || selectedActivitiesListWidget->count()<=0)
  253         return;
  254     int tmp=selectedActivitiesListWidget->currentRow();
  255     
  256     selectedActivitiesList.removeAt(tmp);
  257 
  258     selectedActivitiesListWidget->setCurrentRow(-1);
  259     QListWidgetItem* item=selectedActivitiesListWidget->takeItem(tmp);
  260     delete item;
  261     if(tmp<selectedActivitiesListWidget->count())
  262         selectedActivitiesListWidget->setCurrentRow(tmp);
  263     else
  264         selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
  265 }
  266 
  267 void ModifyConstraintActivitiesSameRoomIfConsecutiveForm::clear()
  268 {
  269     selectedActivitiesListWidget->clear();
  270     selectedActivitiesList.clear();
  271 }