"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.45.1/src/interface/addconstraintmingapsbetweenactivitiesform.cpp" (21 Jun 2020, 8531 Bytes) of package /linux/privat/fet-5.45.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 "addconstraintmingapsbetweenactivitiesform.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.45.0_vs_5.45.1.

    1 /***************************************************************************
    2                           addconstraintmingapsbetweenactivitiesform.cpp  -  description
    3                              -------------------
    4     begin                : 10 July 2008
    5     copyright            : (C) 2008 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 <QList>
   21 
   22 #include "longtextmessagebox.h"
   23 
   24 #include "addconstraintmingapsbetweenactivitiesform.h"
   25 
   26 #include <QListWidget>
   27 #include <QAbstractItemView>
   28 #include <QScrollBar>
   29 
   30 AddConstraintMinGapsBetweenActivitiesForm::AddConstraintMinGapsBetweenActivitiesForm(QWidget* parent): QDialog(parent)
   31 {
   32     setupUi(this);
   33 
   34     addConstraintPushButton->setDefault(true);
   35     
   36     allActivitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
   37     selectedActivitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
   38 
   39     connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
   40     connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
   41     connect(allActivitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addActivity()));
   42     connect(addAllActivitiesPushButton, SIGNAL(clicked()), this, SLOT(addAllActivities()));
   43     connect(selectedActivitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeActivity()));
   44     connect(teachersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
   45     connect(studentsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
   46     connect(subjectsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
   47     connect(activityTagsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
   48     connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clear()));
   49 
   50     centerWidgetOnScreen(this);
   51     restoreFETDialogGeometry(this);
   52 
   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     minGapsSpinBox->setMinimum(1);
   63     minGapsSpinBox->setMaximum(gt.rules.nHoursPerDay);
   64     minGapsSpinBox->setValue(1);
   65 
   66     teachersComboBox->addItem("");
   67     for(int i=0; i<gt.rules.teachersList.size(); i++){
   68         Teacher* tch=gt.rules.teachersList[i];
   69         teachersComboBox->addItem(tch->name);
   70     }
   71     teachersComboBox->setCurrentIndex(0);
   72 
   73     subjectsComboBox->addItem("");
   74     for(int i=0; i<gt.rules.subjectsList.size(); i++){
   75         Subject* sb=gt.rules.subjectsList[i];
   76         subjectsComboBox->addItem(sb->name);
   77     }
   78     subjectsComboBox->setCurrentIndex(0);
   79 
   80     activityTagsComboBox->addItem("");
   81     for(int i=0; i<gt.rules.activityTagsList.size(); i++){
   82         ActivityTag* st=gt.rules.activityTagsList[i];
   83         activityTagsComboBox->addItem(st->name);
   84     }
   85     activityTagsComboBox->setCurrentIndex(0);
   86 
   87     populateStudentsComboBox(studentsComboBox, QString(""), true);
   88     studentsComboBox->setCurrentIndex(0);
   89 
   90     selectedActivitiesListWidget->clear();
   91     this->selectedActivitiesList.clear();
   92 
   93     filterChanged();
   94 }
   95 
   96 AddConstraintMinGapsBetweenActivitiesForm::~AddConstraintMinGapsBetweenActivitiesForm()
   97 {
   98     saveFETDialogGeometry(this);
   99 }
  100 
  101 bool AddConstraintMinGapsBetweenActivitiesForm::filterOk(Activity* act)
  102 {
  103     QString tn=teachersComboBox->currentText();
  104     QString stn=studentsComboBox->currentText();
  105     QString sbn=subjectsComboBox->currentText();
  106     QString atn=activityTagsComboBox->currentText();
  107     int ok=true;
  108 
  109     //teacher
  110     if(tn!=""){
  111         bool ok2=false;
  112         for(QStringList::const_iterator it=act->teachersNames.constBegin(); it!=act->teachersNames.constEnd(); it++)
  113             if(*it == tn){
  114                 ok2=true;
  115                 break;
  116             }
  117         if(!ok2)
  118             ok=false;
  119     }
  120 
  121     //subject
  122     if(sbn!="" && sbn!=act->subjectName)
  123         ok=false;
  124         
  125     //activity tag
  126     if(atn!="" && !act->activityTagsNames.contains(atn))
  127         ok=false;
  128         
  129     //students
  130     if(stn!=""){
  131         bool ok2=false;
  132         for(QStringList::const_iterator it=act->studentsNames.constBegin(); it!=act->studentsNames.constEnd(); it++)
  133             if(*it == stn){
  134                 ok2=true;
  135                 break;
  136             }
  137         if(!ok2)
  138             ok=false;
  139     }
  140     
  141     return ok;
  142 }
  143 
  144 void AddConstraintMinGapsBetweenActivitiesForm::filterChanged()
  145 {
  146     allActivitiesListWidget->clear();
  147     this->activitiesList.clear();
  148 
  149     for(int i=0; i<gt.rules.activitiesList.size(); i++){
  150         Activity* ac=gt.rules.activitiesList[i];
  151         if(filterOk(ac)){
  152             allActivitiesListWidget->addItem(ac->getDescription(gt.rules));
  153             this->activitiesList.append(ac->id);
  154         }
  155     }
  156     
  157     int q=allActivitiesListWidget->verticalScrollBar()->minimum();
  158     allActivitiesListWidget->verticalScrollBar()->setValue(q);
  159 }
  160 
  161 void AddConstraintMinGapsBetweenActivitiesForm::addConstraint()
  162 {
  163     TimeConstraint *ctr=NULL;
  164 
  165     double weight;
  166     QString tmp=weightLineEdit->text();
  167     weight_sscanf(tmp, "%lf", &weight);
  168     if(weight<0.0 || weight>100){
  169         QMessageBox::warning(this, tr("FET information"),
  170             tr("Invalid weight (percentage)"));
  171         return;
  172     }
  173 
  174     if(this->selectedActivitiesList.count()==0){
  175         QMessageBox::warning(this, tr("FET information"),
  176             tr("Empty list of selected activities"));
  177         return;
  178     }
  179     if(this->selectedActivitiesList.count()==1){
  180         QMessageBox::warning(this, tr("FET information"),
  181             tr("Only one selected activity"));
  182         return;
  183     }
  184 
  185     QList<int> idsList;
  186     QList<int>::const_iterator it;
  187     for(it=this->selectedActivitiesList.constBegin(); it!=this->selectedActivitiesList.constEnd(); it++)
  188         idsList.append(*it);
  189     
  190     ctr=new ConstraintMinGapsBetweenActivities(weight, this->selectedActivitiesList.count(), idsList, minGapsSpinBox->value());
  191 
  192     bool tmp2=gt.rules.addTimeConstraint(ctr);
  193     
  194     if(tmp2){
  195         QString s;
  196         
  197         s+=tr("Constraint added:");
  198         s+="\n\n";
  199         s+=ctr->getDetailedDescription(gt.rules);
  200         LongTextMessageBox::information(this, tr("FET information"), s);
  201     }
  202     else{
  203         QMessageBox::warning(this, tr("FET information"),
  204             tr("Constraint NOT added - please report error"));
  205         delete ctr;
  206     }
  207 }
  208 
  209 void AddConstraintMinGapsBetweenActivitiesForm::addActivity()
  210 {
  211     if(allActivitiesListWidget->currentRow()<0)
  212         return;
  213     int tmp=allActivitiesListWidget->currentRow();
  214     int _id=this->activitiesList.at(tmp);
  215     
  216     QString actName=allActivitiesListWidget->currentItem()->text();
  217     assert(actName!="");
  218     
  219     //duplicate?
  220     if(this->selectedActivitiesList.contains(_id))
  221         return;
  222     
  223     selectedActivitiesListWidget->addItem(actName);
  224     selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
  225 
  226     this->selectedActivitiesList.append(_id);
  227 }
  228 
  229 void AddConstraintMinGapsBetweenActivitiesForm::addAllActivities()
  230 {
  231     for(int tmp=0; tmp<allActivitiesListWidget->count(); tmp++){
  232         int _id=this->activitiesList.at(tmp);
  233     
  234         QString actName=allActivitiesListWidget->item(tmp)->text();
  235         assert(actName!="");
  236         
  237         if(this->selectedActivitiesList.contains(_id))
  238             continue;
  239         
  240         selectedActivitiesListWidget->addItem(actName);
  241         this->selectedActivitiesList.append(_id);
  242     }
  243     
  244     selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
  245 }
  246 
  247 void AddConstraintMinGapsBetweenActivitiesForm::removeActivity()
  248 {
  249     if(selectedActivitiesListWidget->currentRow()<0 || selectedActivitiesListWidget->count()<=0)
  250         return;
  251     int tmp=selectedActivitiesListWidget->currentRow();
  252     
  253     this->selectedActivitiesList.removeAt(tmp);
  254     
  255     selectedActivitiesListWidget->setCurrentRow(-1);
  256     QListWidgetItem* item=selectedActivitiesListWidget->takeItem(tmp);
  257     delete item;
  258     if(tmp<selectedActivitiesListWidget->count())
  259         selectedActivitiesListWidget->setCurrentRow(tmp);
  260     else
  261         selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
  262 }
  263 
  264 void AddConstraintMinGapsBetweenActivitiesForm::clear()
  265 {
  266     selectedActivitiesListWidget->clear();
  267     selectedActivitiesList.clear();
  268 }