1 /***************************************************************************
2 changemindaysselectivelyform.cpp - description
3 -------------------
4 begin : July 30, 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 "changemindaysselectivelyform.h"
19
20 #include "fet.h"
21
22 #include <QMessageBox>
23
ChangeMinDaysSelectivelyForm(QWidget * parent)24 ChangeMinDaysSelectivelyForm::ChangeMinDaysSelectivelyForm(QWidget* parent): QDialog(parent)
25 {
26 setupUi(this);
27
28 okPushButton->setDefault(true);
29
30 connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
31 connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
32
33 centerWidgetOnScreen(this);
34 restoreFETDialogGeometry(this);
35
36 QSize tmp5=oldConsecutiveComboBox->minimumSizeHint();
37 Q_UNUSED(tmp5);
38 QSize tmp6=newConsecutiveComboBox->minimumSizeHint();
39 Q_UNUSED(tmp6);
40
41 oldConsecutiveComboBox->clear();
42 oldConsecutiveComboBox->addItem(tr("Any"));
43 oldConsecutiveComboBox->addItem(tr("Yes"));
44 oldConsecutiveComboBox->addItem(tr("No"));
45 oldConsecutiveComboBox->setCurrentIndex(0);
46
47 oldDaysSpinBox->setMinimum(-1);
48 oldDaysSpinBox->setMaximum(gt.rules.mode==MORNINGS_AFTERNOONS?gt.rules.nDaysPerWeek/2:gt.rules.nDaysPerWeek);
49 oldDaysSpinBox->setValue(-1);
50
51 newConsecutiveComboBox->clear();
52 newConsecutiveComboBox->addItem(tr("No change"));
53 newConsecutiveComboBox->addItem(tr("Yes"));
54 newConsecutiveComboBox->addItem(tr("No"));
55 newConsecutiveComboBox->setCurrentIndex(0);
56
57 newDaysSpinBox->setMinimum(-1);
58 newDaysSpinBox->setMaximum(gt.rules.mode==MORNINGS_AFTERNOONS?gt.rules.nDaysPerWeek/2:gt.rules.nDaysPerWeek);
59 newDaysSpinBox->setValue(-1);
60
61 oldNActsSpinBox->setMinimum(-1);
62 oldNActsSpinBox->setMaximum(MAX_SPLIT_OF_AN_ACTIVITY);
63 oldNActsSpinBox->setValue(-1);
64 }
65
~ChangeMinDaysSelectivelyForm()66 ChangeMinDaysSelectivelyForm::~ChangeMinDaysSelectivelyForm()
67 {
68 saveFETDialogGeometry(this);
69
70 }
71
ok()72 void ChangeMinDaysSelectivelyForm::ok()
73 {
74 enum {ANY=0, YES=1, NO=2};
75 enum {NOCHANGE=0};
76
77 oldWeight=oldDays=oldConsecutive=oldNActs=-2;
78 newWeight=newDays=newConsecutive=-2;
79
80 QString oldWeightS=oldWeightLineEdit->text();
81 weight_sscanf(oldWeightS, "%lf", &oldWeight);
82 if(!(oldWeight==-1 || (oldWeight>=0.0 && oldWeight<=100.0))){
83 QMessageBox::warning(this, tr("FET warning"), tr("Old weight must be -1 or both >=0 and <=100"));
84 return;
85 }
86
87 QString newWeightS=newWeightLineEdit->text();
88 weight_sscanf(newWeightS, "%lf", &newWeight);
89 if(!(newWeight==-1 || (newWeight>=0.0 && newWeight<=100.0))){
90 QMessageBox::warning(this, tr("FET warning"), tr("New weight must be -1 or both >=0 and <=100"));
91 return;
92 }
93
94 if(gt.rules.mode!=MORNINGS_AFTERNOONS){
95 oldDays=oldDaysSpinBox->value();
96 if(!(oldDays==-1 || (oldDays>=1 && oldDays<=gt.rules.nDaysPerWeek))){
97 QMessageBox::warning(this, tr("FET warning"), tr("Old min days must be -1 or both >=1 and <=n_days_per_week"));
98 return;
99 }
100
101 newDays=newDaysSpinBox->value();
102 if(!(newDays==-1 || (newDays>=1 && newDays<=gt.rules.nDaysPerWeek))){
103 QMessageBox::warning(this, tr("FET warning"), tr("New min days must be -1 or both >=1 and <=n_days_per_week"));
104 return;
105 }
106 }
107 else{
108 oldDays=oldDaysSpinBox->value();
109 if(!(oldDays==-1 || (oldDays>=1 && oldDays<=gt.rules.nDaysPerWeek/2))){
110 QMessageBox::warning(this, tr("FET warning"), tr("Old min days must be -1 or both >=1 and <=n_real_days_per_week"));
111 return;
112 }
113
114 newDays=newDaysSpinBox->value();
115 if(!(newDays==-1 || (newDays>=1 && newDays<=gt.rules.nDaysPerWeek/2))){
116 QMessageBox::warning(this, tr("FET warning"), tr("New min days must be -1 or both >=1 and <=n_real_days_per_week"));
117 return;
118 }
119 }
120
121 oldConsecutive=oldConsecutiveComboBox->currentIndex();
122 assert(oldConsecutive>=0 && oldConsecutive<=2);
123
124 newConsecutive=newConsecutiveComboBox->currentIndex();
125 assert(newConsecutive>=0 && newConsecutive<=2);
126
127 oldNActs=oldNActsSpinBox->value();
128 if(!(oldNActs==-1 || oldNActs>=1)){
129 QMessageBox::warning(this, tr("FET warning"), tr("Old n_acts must be -1 or >=1"));
130 return;
131 }
132
133 this->accept();
134 }
135
cancel()136 void ChangeMinDaysSelectivelyForm::cancel()
137 {
138 this->reject();
139 }
140