"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.47.1/src/interface/addconstraintstudentssetactivitytagminhoursdailyform.cpp" (12 Feb 2020, 4157 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 "addconstraintstudentssetactivitytagminhoursdailyform.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           addconstraintstudentssetactivitytagminhoursdailyform.cpp  -  description
    3                              -------------------
    4     begin                : 2019
    5     copyright            : (C) 2019 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 "addconstraintstudentssetactivitytagminhoursdailyform.h"
   23 #include "timeconstraint.h"
   24 
   25 AddConstraintStudentsSetActivityTagMinHoursDailyForm::AddConstraintStudentsSetActivityTagMinHoursDailyForm(QWidget* parent): QDialog(parent)
   26 {
   27     setupUi(this);
   28 
   29     addConstraintPushButton->setDefault(true);
   30 
   31     connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
   32     connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
   33 
   34     centerWidgetOnScreen(this);
   35     restoreFETDialogGeometry(this);
   36     
   37     QSize tmp2=studentsComboBox->minimumSizeHint();
   38     Q_UNUSED(tmp2);
   39     QSize tmp4=activityTagsComboBox->minimumSizeHint();
   40     Q_UNUSED(tmp4);
   41     
   42     minHoursSpinBox->setMinimum(1);
   43     minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
   44     minHoursSpinBox->setValue(1);
   45     
   46     allowEmptyDaysCheckBox->setChecked(false);
   47 
   48     updateStudentsSetComboBox();
   49     
   50     updateActivityTagsComboBox();
   51 }
   52 
   53 AddConstraintStudentsSetActivityTagMinHoursDailyForm::~AddConstraintStudentsSetActivityTagMinHoursDailyForm()
   54 {
   55     saveFETDialogGeometry(this);
   56 }
   57 
   58 void AddConstraintStudentsSetActivityTagMinHoursDailyForm::updateStudentsSetComboBox()
   59 {
   60     populateStudentsComboBox(studentsComboBox);
   61 }
   62 
   63 void AddConstraintStudentsSetActivityTagMinHoursDailyForm::updateActivityTagsComboBox()
   64 {
   65     for(ActivityTag* at : qAsConst(gt.rules.activityTagsList))
   66         activityTagsComboBox->addItem(at->name);
   67 }
   68 
   69 void AddConstraintStudentsSetActivityTagMinHoursDailyForm::addCurrentConstraint()
   70 {
   71     TimeConstraint *ctr=NULL;
   72 
   73     double weight;
   74     QString tmp=weightLineEdit->text();
   75     weight_sscanf(tmp, "%lf", &weight);
   76     if(weight<100.0 || weight>100.0){
   77         QMessageBox::warning(this, tr("FET information"),
   78             tr("Invalid weight (percentage). It has to be 100"));
   79         return;
   80     }
   81 
   82     int minHours=minHoursSpinBox->value();
   83 
   84     QString students_name=studentsComboBox->currentText();
   85     StudentsSet* s=gt.rules.searchStudentsSet(students_name);
   86     if(s==NULL){
   87         QMessageBox::warning(this, tr("FET warning"),
   88             tr("Invalid students set"));
   89         return;
   90     }
   91     
   92     QString activityTagName=activityTagsComboBox->currentText();
   93     int acttagindex=gt.rules.searchActivityTag(activityTagName);
   94     if(acttagindex<0){
   95         QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
   96         return;
   97     }
   98 
   99     if(allowEmptyDaysCheckBox->isChecked() && minHoursSpinBox->value()==1){
  100         QMessageBox::warning(this, tr("FET warning"), tr("Allow empty days is selected and min hours daily is 1, so this would be a useless constraint."));
  101         return;
  102     }
  103 
  104     ctr=new ConstraintStudentsSetActivityTagMinHoursDaily(weight, minHours, allowEmptyDaysCheckBox->isChecked(), students_name, activityTagName);
  105 
  106     bool tmp2=gt.rules.addTimeConstraint(ctr);
  107     if(tmp2)
  108         LongTextMessageBox::information(this, tr("FET information"),
  109             tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
  110     else{
  111         QMessageBox::warning(this, tr("FET information"),
  112             tr("Constraint NOT added - please report error"));
  113         delete ctr;
  114     }
  115 }