📄 addconstraintactivitypreferredtimesform.cpp
字号:
/*************************************************************************** addconstraintactivitypreferredtimesform.cpp - description ------------------- begin : Wed Apr 23 2003 copyright : (C) 2003 by Lalescu Liviu email : liviu@lalescu.ro ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "addconstraintactivitypreferredtimesform.h"#include "timeconstraint.h"#include <qradiobutton.h>#include <qlabel.h>#include <qlineedit.h>#include <qtable.h>#define YES (QObject::tr("Yes"))#define NO (QObject::tr("No"))AddConstraintActivityPreferredTimesForm::AddConstraintActivityPreferredTimesForm(){ updateActivitiesComboBox(); preferredTimesTable->setNumRows(gt.rules.nHoursPerDay+1); preferredTimesTable->setNumCols(gt.rules.nDaysPerWeek+1); for(int j=0; j<gt.rules.nDaysPerWeek; j++) preferredTimesTable->setText(0, j+1, gt.rules.daysOfTheWeek[j]); for(int i=0; i<gt.rules.nHoursPerDay; i++) preferredTimesTable->setText(i+1, 0, gt.rules.hoursOfTheDay[i]); for(int i=0; i<gt.rules.nHoursPerDay; i++) for(int j=0; j<gt.rules.nDaysPerWeek; j++) preferredTimesTable->setText(i+1, j+1, NO);}AddConstraintActivityPreferredTimesForm::~AddConstraintActivityPreferredTimesForm(){}void AddConstraintActivityPreferredTimesForm::tableClicked(int row, int col, int button, const QPoint& mousePos){ if(&button!=NULL && &mousePos!=NULL) ; row--; col--; if(row>=0 && row<gt.rules.nHoursPerDay && col>=0 && col<gt.rules.nDaysPerWeek){ QString s=preferredTimesTable->text(row+1, col+1); if(s==YES) s=NO; else{ assert(s==NO); s=YES; } preferredTimesTable->setText(row+1, col+1, s); }}void AddConstraintActivityPreferredTimesForm::updateActivitiesComboBox(){ activitiesComboBox->clear(); for(Activity* act=gt.rules.activitiesList.first(); act; act=gt.rules.activitiesList.next()) activitiesComboBox->insertItem(act->getDescription(gt.rules));}void AddConstraintActivityPreferredTimesForm::addConstraint(){ TimeConstraint *ctr=NULL; double weight; QString tmp=weightLineEdit->text(); sscanf(tmp, "%lf", &weight); if(weight<0.0){ QMessageBox::warning(this, QObject::tr("FET information"), QObject::tr("Invalid weight")); return; } bool compulsory=false; if(compulsoryCheckBox->isChecked()) compulsory=true; int i=activitiesComboBox->currentItem(); if(i<0 || activitiesComboBox->count()<=0){ QMessageBox::warning(this, QObject::tr("FET information"), QObject::tr("Invalid activity")); return; } Activity* act=gt.rules.activitiesList.at(i); int days[MAX_N_CONSTRAINT_ACTIVITY_PREFERRED_TIMES]; int hours[MAX_N_CONSTRAINT_ACTIVITY_PREFERRED_TIMES]; int n=0; for(i=0; i<gt.rules.nHoursPerDay; i++) for(int j=0; j<gt.rules.nDaysPerWeek; j++) if(preferredTimesTable->text(i+1, j+1)==YES){ if(n>=MAX_N_CONSTRAINT_ACTIVITY_PREFERRED_TIMES){ QString s=QObject::tr("Not enough slots (too many \"Yes\" values)."); s+="\n"; s+=QObject::tr("Please increase the variable MAX_N_CONSTRAINT_ACTIVITY_PREFERRED_TIMES"); s+="\n"; s+=QObject::tr("Currently, it is %1").arg(MAX_N_CONSTRAINT_ACTIVITY_PREFERRED_TIMES); QMessageBox::warning(this, QObject::tr("FET information"), s); return; } days[n]=j; hours[n]=i; n++; } ctr=new ConstraintActivityPreferredTimes(weight, compulsory, act->id, n, days, hours); bool tmp2=gt.rules.addTimeConstraint(ctr); if(tmp2){ QString s=QObject::tr("Constraint added:"); s+="\n"; s+=ctr->getDetailedDescription(gt.rules); QMessageBox::information(this, QObject::tr("FET information"), s); } else{ QMessageBox::warning(this, QObject::tr("FET information"), QObject::tr("Constraint NOT added - duplicate?")); delete ctr; }}#undef YES#undef NO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -