"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.48.0/src/interface/constraintteachermingapsbetweenorderedpairofactivitytagsform.cpp" (25 Mar 2020, 7599 Bytes) of package /linux/privat/fet-5.48.0.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 "constraintteachermingapsbetweenorderedpairofactivitytagsform.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           constraintteachermingapsbetweenorderedpairofactivitytagsform.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 "constraintteachermingapsbetweenorderedpairofactivitytagsform.h"
   23 #include "addconstraintteachermingapsbetweenorderedpairofactivitytagsform.h"
   24 #include "modifyconstraintteachermingapsbetweenorderedpairofactivitytagsform.h"
   25 
   26 #include <QListWidget>
   27 #include <QScrollBar>
   28 #include <QAbstractItemView>
   29 
   30 ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm(QWidget* parent): QDialog(parent)
   31 {
   32     setupUi(this);
   33 
   34     currentConstraintTextEdit->setReadOnly(true);
   35     
   36     modifyConstraintPushButton->setDefault(true);
   37 
   38     constraintsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
   39 
   40     connect(constraintsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(constraintChanged(int)));
   41     connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
   42     connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
   43     connect(removeConstraintPushButton, SIGNAL(clicked()), this, SLOT(removeConstraint()));
   44     connect(modifyConstraintPushButton, SIGNAL(clicked()), this, SLOT(modifyConstraint()));
   45     connect(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
   46 
   47     centerWidgetOnScreen(this);
   48     restoreFETDialogGeometry(this);
   49 
   50     QSize tmp2=teacherComboBox->minimumSizeHint();
   51     Q_UNUSED(tmp2);
   52     QSize tmp4=firstActivityTagComboBox->minimumSizeHint();
   53     Q_UNUSED(tmp4);
   54     QSize tmp5=secondActivityTagComboBox->minimumSizeHint();
   55     Q_UNUSED(tmp5);
   56     
   57     teacherComboBox->clear();
   58     teacherComboBox->addItem("");
   59     for(Teacher* tch : qAsConst(gt.rules.teachersList))
   60         teacherComboBox->addItem(tch->name);
   61     
   62     firstActivityTagComboBox->clear();
   63     firstActivityTagComboBox->addItem("");
   64     for(ActivityTag* at : qAsConst(gt.rules.activityTagsList))
   65         firstActivityTagComboBox->addItem(at->name);
   66 
   67     secondActivityTagComboBox->clear();
   68     secondActivityTagComboBox->addItem("");
   69     for(ActivityTag* at : qAsConst(gt.rules.activityTagsList))
   70         secondActivityTagComboBox->addItem(at->name);
   71 
   72     this->filterChanged();
   73 
   74     connect(teacherComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
   75     connect(firstActivityTagComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
   76     connect(secondActivityTagComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged()));
   77 }
   78 
   79 ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::~ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm()
   80 {
   81     saveFETDialogGeometry(this);
   82 }
   83 
   84 bool ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::filterOk(TimeConstraint* ctr)
   85 {
   86     if(ctr->type==CONSTRAINT_TEACHER_MIN_GAPS_BETWEEN_ORDERED_PAIR_OF_ACTIVITY_TAGS){
   87         ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTags* c=(ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTags*) ctr;
   88         return (c->teacher==teacherComboBox->currentText() || teacherComboBox->currentText()=="")
   89          &&
   90          (c->firstActivityTag==firstActivityTagComboBox->currentText() || firstActivityTagComboBox->currentText()=="")
   91          &&
   92          (c->secondActivityTag==secondActivityTagComboBox->currentText() || secondActivityTagComboBox->currentText()=="");
   93     }
   94     else
   95         return false;
   96 }
   97 
   98 void ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::filterChanged()
   99 {
  100     this->visibleConstraintsList.clear();
  101     constraintsListWidget->clear();
  102     for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
  103         TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
  104         if(filterOk(ctr)){
  105             visibleConstraintsList.append(ctr);
  106             constraintsListWidget->addItem(ctr->getDescription(gt.rules));
  107         }
  108     }
  109     
  110     if(constraintsListWidget->count()>0)
  111         constraintsListWidget->setCurrentRow(0);
  112     else
  113         this->constraintChanged(-1);
  114 }
  115 
  116 void ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::constraintChanged(int index)
  117 {
  118     if(index<0){
  119         currentConstraintTextEdit->setPlainText("");
  120         return;
  121     }
  122     assert(index<this->visibleConstraintsList.size());
  123     TimeConstraint* ctr=this->visibleConstraintsList.at(index);
  124     assert(ctr!=NULL);
  125     currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
  126 }
  127 
  128 void ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::addConstraint()
  129 {
  130     AddConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm form(this);
  131     setParentAndOtherThings(&form, this);
  132     form.exec();
  133 
  134     filterChanged();
  135     
  136     constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
  137 }
  138 
  139 void ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::modifyConstraint()
  140 {
  141     int valv=constraintsListWidget->verticalScrollBar()->value();
  142     int valh=constraintsListWidget->horizontalScrollBar()->value();
  143 
  144     int i=constraintsListWidget->currentRow();
  145     if(i<0){
  146         QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
  147         return;
  148     }
  149     TimeConstraint* ctr=this->visibleConstraintsList.at(i);
  150 
  151     ModifyConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm form(this, (ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTags*)ctr);
  152     setParentAndOtherThings(&form, this);
  153     form.exec();
  154 
  155     filterChanged();
  156     
  157     constraintsListWidget->verticalScrollBar()->setValue(valv);
  158     constraintsListWidget->horizontalScrollBar()->setValue(valh);
  159 
  160     if(i>=constraintsListWidget->count())
  161         i=constraintsListWidget->count()-1;
  162 
  163     if(i>=0)
  164         constraintsListWidget->setCurrentRow(i);
  165     else
  166         this->constraintChanged(-1);
  167 }
  168 
  169 void ConstraintTeacherMinGapsBetweenOrderedPairOfActivityTagsForm::removeConstraint()
  170 {
  171     int i=constraintsListWidget->currentRow();
  172     if(i<0){
  173         QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
  174         return;
  175     }
  176     TimeConstraint* ctr=this->visibleConstraintsList.at(i);
  177     QString s;
  178     s=tr("Remove constraint?");
  179     s+="\n\n";
  180     s+=ctr->getDetailedDescription(gt.rules);
  181     
  182     QListWidgetItem* item;
  183 
  184     switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
  185         s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
  186     case 0: // The user clicked the OK button or pressed Enter
  187         gt.rules.removeTimeConstraint(ctr);
  188         
  189         visibleConstraintsList.removeAt(i);
  190         constraintsListWidget->setCurrentRow(-1);
  191         item=constraintsListWidget->takeItem(i);
  192         delete item;
  193         
  194         break;
  195     case 1: // The user clicked the Cancel button or pressed Escape
  196         break;
  197     }
  198     
  199     if(i>=constraintsListWidget->count())
  200         i=constraintsListWidget->count()-1;
  201     if(i>=0)
  202         constraintsListWidget->setCurrentRow(i);
  203     else
  204         this->constraintChanged(-1);
  205 }