"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.48.0/src/interface/constraintstudentsmaxhourscontinuouslyform.cpp" (9 Oct 2017, 5800 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 "constraintstudentsmaxhourscontinuouslyform.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           constraintstudentsmaxhourscontinuouslyform.cpp  -  description
    3                              -------------------
    4     begin                : July 19, 2007
    5     copyright            : (C) 2007 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 "constraintstudentsmaxhourscontinuouslyform.h"
   23 #include "addconstraintstudentsmaxhourscontinuouslyform.h"
   24 #include "modifyconstraintstudentsmaxhourscontinuouslyform.h"
   25 
   26 #include <QListWidget>
   27 #include <QScrollBar>
   28 #include <QAbstractItemView>
   29 
   30 ConstraintStudentsMaxHoursContinuouslyForm::ConstraintStudentsMaxHoursContinuouslyForm(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     this->filterChanged();
   51 }
   52 
   53 ConstraintStudentsMaxHoursContinuouslyForm::~ConstraintStudentsMaxHoursContinuouslyForm()
   54 {
   55     saveFETDialogGeometry(this);
   56 }
   57 
   58 bool ConstraintStudentsMaxHoursContinuouslyForm::filterOk(TimeConstraint* ctr)
   59 {
   60     if(ctr->type==CONSTRAINT_STUDENTS_MAX_HOURS_CONTINUOUSLY)
   61         return true;
   62     else
   63         return false;
   64 }
   65 
   66 void ConstraintStudentsMaxHoursContinuouslyForm::filterChanged()
   67 {
   68     this->visibleConstraintsList.clear();
   69     constraintsListWidget->clear();
   70     for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
   71         TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
   72         if(filterOk(ctr)){
   73             visibleConstraintsList.append(ctr);
   74             constraintsListWidget->addItem(ctr->getDescription(gt.rules));
   75         }
   76     }
   77     
   78     if(constraintsListWidget->count()>0)
   79         constraintsListWidget->setCurrentRow(0);
   80     else
   81         this->constraintChanged(-1);
   82 }
   83 
   84 void ConstraintStudentsMaxHoursContinuouslyForm::constraintChanged(int index)
   85 {
   86     if(index<0){
   87         currentConstraintTextEdit->setPlainText("");
   88         return;
   89     }
   90     assert(index<this->visibleConstraintsList.size());
   91     TimeConstraint* ctr=this->visibleConstraintsList.at(index);
   92     assert(ctr!=NULL);
   93     currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
   94 }
   95 
   96 void ConstraintStudentsMaxHoursContinuouslyForm::addConstraint()
   97 {
   98     AddConstraintStudentsMaxHoursContinuouslyForm form(this);
   99     setParentAndOtherThings(&form, this);
  100     form.exec();
  101 
  102     filterChanged();
  103     
  104     constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
  105 }
  106 
  107 void ConstraintStudentsMaxHoursContinuouslyForm::modifyConstraint()
  108 {
  109     int valv=constraintsListWidget->verticalScrollBar()->value();
  110     int valh=constraintsListWidget->horizontalScrollBar()->value();
  111 
  112     int i=constraintsListWidget->currentRow();
  113     if(i<0){
  114         QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
  115         return;
  116     }
  117     TimeConstraint* ctr=this->visibleConstraintsList.at(i);
  118 
  119     ModifyConstraintStudentsMaxHoursContinuouslyForm form(this, (ConstraintStudentsMaxHoursContinuously*)ctr);
  120     setParentAndOtherThings(&form, this);
  121     form.exec();
  122 
  123     filterChanged();
  124     
  125     constraintsListWidget->verticalScrollBar()->setValue(valv);
  126     constraintsListWidget->horizontalScrollBar()->setValue(valh);
  127 
  128     if(i>=constraintsListWidget->count())
  129         i=constraintsListWidget->count()-1;
  130 
  131     if(i>=0)
  132         constraintsListWidget->setCurrentRow(i);
  133     else
  134         this->constraintChanged(-1);
  135 }
  136 
  137 void ConstraintStudentsMaxHoursContinuouslyForm::removeConstraint()
  138 {
  139     int i=constraintsListWidget->currentRow();
  140     if(i<0){
  141         QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
  142         return;
  143     }
  144     TimeConstraint* ctr=this->visibleConstraintsList.at(i);
  145     QString s;
  146     s=tr("Remove constraint?");
  147     s+="\n\n";
  148     s+=ctr->getDetailedDescription(gt.rules);
  149     
  150     QListWidgetItem* item;
  151 
  152     switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
  153         s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
  154     case 0: // The user clicked the OK button or pressed Enter
  155         gt.rules.removeTimeConstraint(ctr);
  156         
  157         visibleConstraintsList.removeAt(i);
  158         constraintsListWidget->setCurrentRow(-1);
  159         item=constraintsListWidget->takeItem(i);
  160         delete item;
  161         
  162         break;
  163     case 1: // The user clicked the Cancel button or pressed Escape
  164         break;
  165     }
  166     
  167     if(i>=constraintsListWidget->count())
  168         i=constraintsListWidget->count()-1;
  169     if(i>=0)
  170         constraintsListWidget->setCurrentRow(i);
  171     else
  172         this->constraintChanged(-1);
  173 }