1 /***************************************************************************
2                           setuppageregionalawardsnew.h  -  description
3                              -------------------
4     begin                : oct 2020
5     copyright            : (C) 2020 by Jaime Robles
6     email                : jaime@robles.es
7  ***************************************************************************/
8 
9 /*****************************************************************************
10  * This file is part of KLog.                                             *
11  *                                                                           *
12  *    KLog is free software: you can redistribute it and/or modify        *
13  *    it under the terms of the GNU General Public License as published by   *
14  *    the Free Software Foundation, either version 3 of the License, or      *
15  *    (at your option) any later version.                                    *
16  *                                                                           *
17  *    KLog is distributed in the hope that it will be useful,             *
18  *    but WITHOUT ANY WARRANTY; without even the implied warranty of         *
19  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
20  *    GNU General Public License for more details.                           *
21  *                                                                           *
22  *    You should have received a copy of the GNU General Public License      *
23  *    along with KLog.  If not, see <https://www.gnu.org/licenses/>.       *
24  *                                                                           *
25  *****************************************************************************/
26 //
27 // This class implements the Dialog to add a new log
28 //
29 
30 #include "setuppages/setuppagesubdivisionnew.h"
31 
32 
SetupPageSubdivisionNew(DataProxy_SQLite * dp,QWidget * parent)33 SetupPageSubdivisionNew::SetupPageSubdivisionNew(DataProxy_SQLite *dp, QWidget *parent)
34 {
35       //qDebug() << "SetupPageSubdivisionNew::SetupPageSubdivisionNew"   << QT_ENDL;
36     dataProxy = dp;
37     editing = false;
38     checking = false;
39 
40     /*
41      * bCass = false;
42     bCOp = false;
43     bCMo = false;
44     bCPo = false;
45     bCBa = false;
46     bCOv = false;
47     bCTy = false;
48     */
49     logData.clear();
50     stationCallsignFilled = false;
51     operatorsFilled = true;
52     stationCallsign = QString();
53     operators = QString();
54     comment = QString();
55     dateString = QString();
56     //typeContest = 0;
57     //contestCatMode = 0;
58     //contestCatOperators = 0;
59     //contestCatAssisted = 0;
60     //contestCatPower = 0;
61     //contestCatBands = 0;
62     //contestBands = 0;
63     //contestCatOverlay = 0;
64     //typeContestSelected = 0;
65     //typeConteststr = QString();
66 
67 
68     stationCallsignLineEdit = new QLineEdit;
69     operatorsLineEdit = new QLineEdit;
70 
71     dateEdit = new QDateEdit;
72     dateEdit->setDate(QDate::currentDate ());
73     commentLineEdit = new QLineEdit;
74     /*
75     typeComboBox = new QComboBox;
76     contestCatModeComboBox = new QComboBox;
77     contestCatOperatorsComboBox = new QComboBox;
78     contestCatAssistedComboBox = new QComboBox;
79     contestCatPowerComboBox = new QComboBox;
80     contestCatBandsComboBox = new QComboBox;
81     contestBandsComboBox = new QComboBox;
82     contestCatOverlayComboBox = new QComboBox;
83     contestCatModeComboBox = new QComboBox;
84 
85     catAsLabel = new QLabel();
86     typeLabel = new QLabel();
87     catOpLabel = new QLabel();
88     catModeLabel = new QLabel();
89     catPowerLabel = new QLabel();
90     catBandsLabel = new QLabel();
91     overlayLabel = new QLabel();
92     validCats = new QLabel();
93     */
94     dateLabel = new QLabel(tr("&Date"));
95     stationCallsignLabel = new QLabel(tr("&Station Callsign"));
96     operatorsLabel = new QLabel(tr("&Operators"));
97     commentLabel = new QLabel(tr("Comm&ent"));
98 
99     okButton = new QPushButton(tr("&Ok"), this);
100     cancelButton = new QPushButton(tr("&Cancel"), this);
101     createWidget();
102 
103 
104     okButton->setEnabled(false);
105 
106        //qDebug() << "SetupPageSubdivisionNew::SetupPageSubdivisionNew - END"   << QT_ENDL;
107 }
108 
clear()109 void SetupPageSubdivisionNew::clear()
110 {
111       //qDebug() << "SetupPageSubdivisionNew::Clear - Start"   << QT_ENDL;
112     stationCallsignLineEdit->clear();
113     operatorsLineEdit->clear();
114     dateEdit->setDate(QDate::currentDate ());
115 /*
116     typeComboBox->setCurrentIndex(0);
117     contestCatModeComboBox->setCurrentIndex(0);
118     contestCatOperatorsComboBox->setCurrentIndex(0);
119     contestCatAssistedComboBox->setCurrentIndex(0);
120     contestCatPowerComboBox->setCurrentIndex(0);
121     contestCatBandsComboBox->setCurrentIndex(0);
122     contestBandsComboBox->setCurrentIndex(0);
123     contestCatOverlayComboBox->setCurrentIndex(0);
124     contestCatModeComboBox->setCurrentIndex(0);
125     typeContest = 0;
126     contestCatMode = 0;
127     contestCatOperators = 0;
128     contestCatAssisted = 0;
129     contestCatPower = 0;
130     contestCatBands = 0;
131     contestBands = 0;
132     contestCatOverlay = 0;
133     typeContestSelected = 0;*/
134       //qDebug() << "SetupPageSubdivisionNew::Clear - END"   << QT_ENDL;
135 }
136 
createWidget()137 void SetupPageSubdivisionNew::createWidget()
138 {
139       //qDebug() << "SetupPageSubdivisionNew::createWidget - Start" << QT_ENDL;
140 
141     stationCallsignLabel->setWordWrap(true);
142     operatorsLabel->setWordWrap(true);
143     commentLabel->setWordWrap(true);
144     dateLabel->setBuddy(dateEdit);
145 
146     stationCallsignLabel->setBuddy(stationCallsignLineEdit);
147     operatorsLabel->setBuddy(operatorsLineEdit);
148     commentLabel->setBuddy(commentLineEdit);
149     /*
150     catAsLabel->setBuddy(contestCatAssistedComboBox);
151     typeLabel->setBuddy(typeComboBox);
152     catOpLabel->setBuddy(contestCatOperatorsComboBox);
153     catModeLabel->setBuddy(contestCatModeComboBox);
154     catPowerLabel->setBuddy(contestCatPowerComboBox);
155     catBandsLabel->setBuddy(contestCatBandsComboBox);
156     overlayLabel->setBuddy(contestCatOverlayComboBox);
157 
158     validCats->setText(tr("Select categories"));
159     validCats->setWordWrap(true);
160     */
161 
162     stationCallsignLineEdit->setToolTip(tr("Callsign used for this log."));
163     operatorsLineEdit->setToolTip(tr("Comma separated list of operators: callsign1, callsign2."));
164 
165     dateEdit->setToolTip(tr("Start date of this log."));
166     commentLineEdit->setToolTip(tr("Add a comment about this log. If filled, it will be shown in the main KLog title to identify the log."));
167 
168     //typeLabel->setText(tr("&Type of Operation"));
169     //typeLabel->setWordWrap(true);
170 
171     //nameLabel->setWordWrap(true);
172     dateLabel->setWordWrap(true);
173     /*
174 
175     typeComboBox->setToolTip(tr("Select the kind of operation for this log."));
176     QStringList _qs;
177     _qs.clear();
178     _qs.append(dataProxy->getContestNames());
179     typeComboBox->addItems(_qs);
180        //qDebug() << "SetupPageSubdivisionNew::createWidget - contestNames: " << _qs.at(0) << QT_ENDL;
181 
182     catModeLabel->setText(tr("&Mode Category"));
183     catModeLabel->setWordWrap(true);
184     contestCatModeComboBox->setToolTip(tr("Select the mode category."));
185     _qs.clear();
186     _qs.append(dataProxy->getContestCat(6));
187     contestCatModeComboBox->addItems(_qs);
188 
189     //QLabel *catOpLabel = new QLabel(tr("Operators Category"));
190     catOpLabel->setText(tr("O&perators Category"));
191     catOpLabel->setWordWrap(true);
192     contestCatOperatorsComboBox->setToolTip(tr("Select the operators category."));
193     _qs.clear();
194     _qs.append(dataProxy->getContestCat(1));
195     contestCatOperatorsComboBox->addItems(_qs);
196 
197     catAsLabel->setText(tr("&Assisted Category"));
198     catOpLabel->setWordWrap(true);
199     contestCatAssistedComboBox->setToolTip(tr("Select the assisted category."));
200     _qs.clear();
201     _qs.append(dataProxy->getContestCat(2));
202     contestCatAssistedComboBox->addItems(_qs);
203 
204     //QLabel *catPowerLabel = new QLabel(tr("Power Category"));
205     catPowerLabel->setText(tr("Po&wer Category"));
206     catPowerLabel->setWordWrap(true);
207     contestCatPowerComboBox->setToolTip(tr("Select the power category."));
208     _qs.clear();
209     _qs.append(dataProxy->getContestCat(3));
210     contestCatPowerComboBox->addItems(_qs);
211 
212     //QLabel *catBandsLabel = new QLabel(tr("Bands Category"));
213     catBandsLabel->setText(tr("&Bands Category"));
214     catBandsLabel->setWordWrap(true);
215     contestCatBandsComboBox->setToolTip(tr("Select the bands category."));
216     _qs.clear();
217     _qs.append(dataProxy->getContestCat(4));
218     contestCatBandsComboBox->addItems(_qs);
219 
220     overlayLabel->setText(tr("O&verlay"));
221     overlayLabel->setWordWrap(true);
222     contestCatOverlayComboBox->setToolTip(tr("Select the Overlay category."));
223     _qs.clear();
224     _qs.append(dataProxy->getContestOverlays());
225     contestCatOverlayComboBox->addItems(_qs);
226     */
227     connect(stationCallsignLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotStationCallSignTextChanged() ) );
228     connect(operatorsLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotOperatorsTextChanged() ) );
229 
230     /*
231     connect(typeComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotTypeComboBoxChanged() ) ) ;
232     connect(contestCatModeComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatModeComboBoxChanged() ) ) ;
233     connect(contestCatAssistedComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatAssistedComboBoxChanged() ) ) ;
234     connect(contestCatOperatorsComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatOperatorsComboBoxChanged() ) ) ;
235     connect(contestCatPowerComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatPowerComboBoxChanged() ) ) ;
236     connect(contestCatBandsComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatBandsComboBoxChanged() ) ) ;
237     connect(contestCatOverlayComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatOverlayComboBoxChanged() ) ) ;
238     */
239     //connect(typeComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotTypeComboBoxChanged() ) ) ;
240     //connect(contestCatModeComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatModeComboBoxChanged() ) ) ;
241     //connect(contestCatAssistedComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatAssistedComboBoxChanged() ) ) ;
242     //connect(contestCatOperatorsComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatOperatorsComboBoxChanged() ) ) ;
243     //connect(contestCatPowerComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatPowerComboBoxChanged() ) ) ;
244     //connect(contestCatBandsComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatBandsComboBoxChanged() ) ) ;
245     //connect(contestCatOverlayComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatOverlayComboBoxChanged() ) ) ;
246 
247     //connect(contestBandsComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotBandsComboBoxChanged() ) ) ;
248     //connect(contestCatModeComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatModeComboBoxChanged() ) ) ;
249     connect(okButton,SIGNAL(clicked()), this, SLOT(slotOKButtonClicked() ) );
250     connect(cancelButton, SIGNAL(clicked()), this, SLOT(slotCancelButtonClicked() ) );
251 
252     QGridLayout *callsLayout = new QGridLayout; // Widget, row, column
253 
254     callsLayout->addWidget(stationCallsignLabel, 0, 0);
255     callsLayout->addWidget(stationCallsignLineEdit, 0, 1);
256     callsLayout->addWidget(dateLabel, 1, 0);
257     callsLayout->addWidget(dateEdit, 1, 1);
258     callsLayout->addWidget(operatorsLabel, 2, 0);
259     callsLayout->addWidget(operatorsLineEdit, 2, 1);
260     callsLayout->addWidget(commentLabel, 3, 0);
261     callsLayout->addWidget(commentLineEdit, 3, 1);
262 /*
263     callsLayout->addWidget(typeLabel, 3, 0);
264     callsLayout->addWidget(typeComboBox, 3, 1);
265 
266     callsLayout->addWidget(catModeLabel, 4, 0);
267     callsLayout->addWidget(contestCatModeComboBox, 4, 1);
268     callsLayout->addWidget(catOpLabel, 5, 0);
269     callsLayout->addWidget(contestCatOperatorsComboBox, 5, 1);
270     callsLayout->addWidget(catAsLabel, 6, 0);
271     callsLayout->addWidget(contestCatAssistedComboBox, 6, 1);
272 
273     callsLayout->addWidget(catPowerLabel, 7, 0);
274     callsLayout->addWidget(contestCatPowerComboBox, 7, 1);
275 
276     callsLayout->addWidget(catBandsLabel, 8, 0);
277     callsLayout->addWidget(contestCatBandsComboBox, 8, 1);
278     callsLayout->addWidget(contestBandsComboBox, 8, 2);
279 
280 
281     callsLayout->addWidget(overlayLabel, 10, 0);
282     callsLayout->addWidget(contestCatOverlayComboBox, 10, 1);
283 */
284 
285     QHBoxLayout *buttonsLayout = new QHBoxLayout;
286     //buttonsLayout->addWidget(validCats);
287     buttonsLayout->addSpacerItem(new QSpacerItem(10,0,QSizePolicy::Expanding,QSizePolicy::Maximum));
288     buttonsLayout->addWidget(okButton);
289     buttonsLayout->addWidget(cancelButton);
290 
291     QVBoxLayout *mainLayout = new QVBoxLayout;
292     mainLayout->addLayout(callsLayout);
293     mainLayout->addLayout(buttonsLayout);
294 
295     setLayout(mainLayout);
296     clear();
297     //page->setLayout(callsLayout);
298       //qDebug() << "SetupPageSubdivisionNew::createWidget - End" << QT_ENDL;
299 
300 }
301 
302 
slotOperatorsTextChanged()303 void SetupPageSubdivisionNew::slotOperatorsTextChanged()
304 {
305        //qDebug() << "SetupPageSubdivisionNew::slotOperatorsTextChanged - Start" << QT_ENDL;
306 //    connect(stationCallsignLineEdit, SIGNAL(textChanged(QString)), this, SLOT( ) );
307     if ((operatorsLineEdit->text()).length()<1)
308     {
309         return;
310     }
311 
312     int cursorP = operatorsLineEdit->cursorPosition();
313 
314     QString currentQrz = operatorsLineEdit->text();
315     if ((currentQrz.at(cursorP-1)).isSpace())
316     {
317         currentQrz = currentQrz.remove(cursorP-1, 1);
318         cursorP--;
319         operatorsLineEdit->setText(currentQrz);
320     }
321 
322     operatorsLineEdit->setText(((operatorsLineEdit->text())).simplified());
323     operatorsLineEdit->setText((operatorsLineEdit->text()).toUpper());
324 
325     operatorsLineEdit->setCursorPosition(cursorP);
326 
327     if (currentQrz.length()>=3)
328     {//TODO: Add a check of the format (comma separated)
329         operatorsFilled= true;
330     }
331       //qDebug() << "SetupPageSubdivisionNew::slotOperatorsTextChanged - End" << QT_ENDL;
332 }
333 
slotStationCallSignTextChanged()334 void SetupPageSubdivisionNew::slotStationCallSignTextChanged()
335 {
336        //qDebug() << "SetupPageSubdivisionNew::slotStationCallSignTextChanged" << QT_ENDL;
337 //    connect(stationCallsignLineEdit, SIGNAL(textChanged(QString)), this, SLOT( ) );
338     if ((stationCallsignLineEdit->text()).length()<1)
339     {
340         showNOK();
341         return;
342     }
343 
344     int cursorP = stationCallsignLineEdit->cursorPosition();
345 
346     QString currentQrz = stationCallsignLineEdit->text();
347     if ((currentQrz.at(cursorP-1)).isSpace())
348     {
349         currentQrz = currentQrz.remove(cursorP-1, 1);
350         cursorP--;
351         stationCallsignLineEdit->setText(currentQrz);
352     }
353 
354     stationCallsignLineEdit->setText(((stationCallsignLineEdit->text())).simplified());
355     stationCallsignLineEdit->setText((stationCallsignLineEdit->text()).toUpper());
356 
357     stationCallsignLineEdit->setCursorPosition(cursorP);
358 
359     if (currentQrz.length()>=3)
360     {
361         stationCallsignFilled = true;
362     }
363     showOK();
364       //qDebug() << "SetupPageSubdivisionNew::slotStationCallSignTextChanged - End" << QT_ENDL;
365 }
366 
367 /*
368 void SetupPageSubdivisionNew::slotTypeComboBoxChanged()
369 {
370        //qDebug() << "SetupPageSubdivisionNew::slotTypeComboBoxChanged" << QT_ENDL;
371 //    connect(typeComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotTypeComboBoxChanged() ) ) ;
372 
373 
374     contestCatMode = contestCatModeComboBox->currentIndex();
375     contestCatBands = contestCatBandsComboBox->currentIndex();
376     contestCatPower = contestCatPowerComboBox->currentIndex();
377     contestCatOperators = contestCatOperatorsComboBox->currentIndex();
378     contestCatAssisted = contestCatAssistedComboBox->currentIndex();
379     typeContestSelected = typeComboBox->currentIndex();
380     contestCatOverlay= contestCatOverlayComboBox->currentIndex();
381 
382     typeContest = getSelectedTypeContest();
383 
384     if (typeContest < 0)
385     {
386         typeLabel->setStyleSheet("QLabel {color : red; }");
387         validCats->setText(tr("Categories not OK"));
388         validCats->setStyleSheet("QLabel {color : red; }");
389         okButton->setEnabled(false);
390     }
391     else
392     {
393          typeLabel->setStyleSheet("QLabel {color : black; }");
394             showOK();
395     }
396 }
397 
398 void SetupPageSubdivisionNew::slotCatAssistedComboBoxChanged()
399 {
400       //qDebug() << "SetupPageLogs:slotCatAssistedComboBoxChanged: " << QString::number(contestCatAssistedComboBox->currentIndex())  << QT_ENDL;
401 //connect(contestCatAssistedComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatAssistedComboBoxChanged() ) ) ;
402 
403    contestCatMode = contestCatModeComboBox->currentIndex();
404    contestCatBands = contestCatBandsComboBox->currentIndex();
405    contestCatPower = contestCatPowerComboBox->currentIndex();
406    contestCatOperators = contestCatOperatorsComboBox->currentIndex();
407    contestCatAssisted = contestCatAssistedComboBox->currentIndex();
408    typeContestSelected = typeComboBox->currentIndex();
409    contestCatOverlay= contestCatOverlayComboBox->currentIndex();
410 
411    typeContest = getSelectedTypeContest();
412 
413    if (typeContest < 0)
414    {
415        catAsLabel->setStyleSheet("QLabel {color : red; }");
416        showNOK();
417    }
418    else
419    {
420         catAsLabel->setStyleSheet("QLabel {color : black; }");
421         showOK();
422    }
423 
424 }
425 
426 void SetupPageSubdivisionNew::slotCatOperatorsComboBoxChanged()
427 {
428       //qDebug() << "SetupPageSubdivisionNew::slotCatOperatorsComboBoxChanged(): " << QString::number(contestCatOperatorsComboBox->currentIndex())  << QT_ENDL;
429 
430    contestCatMode = contestCatModeComboBox->currentIndex();
431    contestCatBands = contestCatBandsComboBox->currentIndex();
432    contestCatPower = contestCatPowerComboBox->currentIndex();
433    contestCatOperators = contestCatOperatorsComboBox->currentIndex();
434    contestCatAssisted = contestCatAssistedComboBox->currentIndex();
435    typeContestSelected = typeComboBox->currentIndex();
436    contestCatOverlay= contestCatOverlayComboBox->currentIndex();
437 
438    typeContest = getSelectedTypeContest();
439 
440    if (typeContest < 0)
441    {
442        catOpLabel->setStyleSheet("QLabel {color : red; }");
443        showNOK();
444    }
445    else
446    {
447         catOpLabel->setStyleSheet("QLabel {color : black; }");
448         showOK();
449    }
450 
451 }
452 
453 void SetupPageSubdivisionNew::slotCatPowerComboBoxChanged()
454 {
455        //qDebug() << "SetupPageSubdivisionNew::slotCatPowerComboBoxChanged(): " << QString::number(contestCatPowerComboBox->currentIndex())  << QT_ENDL;
456 //connect(contestCatPowerComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatPowerComboBoxChanged() ) ) ;
457 
458     contestCatMode = contestCatModeComboBox->currentIndex();
459     contestCatBands = contestCatBandsComboBox->currentIndex();
460     contestCatPower = contestCatPowerComboBox->currentIndex();
461     contestCatOperators = contestCatOperatorsComboBox->currentIndex();
462     contestCatAssisted = contestCatAssistedComboBox->currentIndex();
463     typeContestSelected = typeComboBox->currentIndex();
464     contestCatOverlay= contestCatOverlayComboBox->currentIndex();
465 
466     typeContest = getSelectedTypeContest();
467 
468     if (typeContest < 0)
469     {
470         catPowerLabel->setStyleSheet("QLabel {color : red; }");
471         showNOK();
472     }
473     else
474     {
475          catPowerLabel->setStyleSheet("QLabel {color : black; }");
476          showOK();
477     }
478 
479 }
480 
481 void SetupPageSubdivisionNew::slotCatBandsComboBoxChanged()
482 {
483        //qDebug() << "SetupPageSubdivisionNew::slotCatBandsComboBoxChanged(): " << QString::number(contestCatBandsComboBox->currentIndex())  << QT_ENDL;
484 //connect(contestCatBandsComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotCatBandsComboBoxChanged() ) ) ;
485 
486     contestCatMode = contestCatModeComboBox->currentIndex();
487     contestCatBands = contestCatBandsComboBox->currentIndex();
488     contestCatPower = contestCatPowerComboBox->currentIndex();
489     contestCatOperators = contestCatOperatorsComboBox->currentIndex();
490     contestCatAssisted = contestCatAssistedComboBox->currentIndex();
491     typeContestSelected = typeComboBox->currentIndex();
492     contestCatOverlay= contestCatOverlayComboBox->currentIndex();
493 
494     typeContest = getSelectedTypeContest();
495 
496     if (typeContest < 0)
497     {
498         catBandsLabel->setStyleSheet("QLabel {color : red; }");
499         showNOK();
500     }
501     else
502     {
503          catBandsLabel->setStyleSheet("QLabel {color : black; }");
504          showOK();
505     }
506 
507 }
508 
509 void SetupPageSubdivisionNew::slotBandsComboBoxChanged()
510 {
511        //qDebug() << "SetupPageSubdivisionNew::slotBandsComboBoxChanged(): " << QString::number(contestBandsComboBox->currentIndex()) << QT_ENDL;
512             //connect(contestBandsComboBox, SIGNAL(currentIndexChanged ( int)), this, SLOT(slotBandsComboBoxChanged() ) ) ;
513 
514 }
515 
516 
517 void SetupPageSubdivisionNew::slotCatOverlayComboBoxChanged()
518 {
519         //qDebug() << "SetupPageSubdivisionNew::slotCatOverlayComboBoxChanged(): " << QString::number(contestCatOverlayComboBox->currentIndex())  << QT_ENDL;
520 
521      contestCatMode = contestCatModeComboBox->currentIndex();
522      contestCatBands = contestCatBandsComboBox->currentIndex();
523      contestCatPower = contestCatPowerComboBox->currentIndex();
524      contestCatOperators = contestCatOperatorsComboBox->currentIndex();
525      contestCatAssisted = contestCatAssistedComboBox->currentIndex();
526      typeContestSelected = typeComboBox->currentIndex();
527      contestCatOverlay= contestCatOverlayComboBox->currentIndex();
528 
529      typeContest = getSelectedTypeContest();
530         //qDebug() << "SetupPageSubdivisionNew::slotCatOverlayComboBoxChanged(): typeContest =  " << QString::number(typeContest)  << QT_ENDL;
531 
532      if (typeContest < 0)
533      {
534          overlayLabel->setStyleSheet("QLabel {color : red; }");
535          showNOK();
536      }
537      else
538      {
539           overlayLabel->setStyleSheet("QLabel {color : black; }");
540           showOK();
541      }
542 
543 }
544 
545 void SetupPageSubdivisionNew::slotCatModeComboBoxChanged()
546 {
547        //qDebug() << "SetupPageSubdivisionNew::slotCatModeComboBoxChanged(): " << QString::number(contestCatModeComboBox->currentIndex())  << QT_ENDL;
548 
549     contestCatMode = contestCatModeComboBox->currentIndex();
550     contestCatBands = contestCatBandsComboBox->currentIndex();
551     contestCatPower = contestCatPowerComboBox->currentIndex();
552     contestCatOperators = contestCatOperatorsComboBox->currentIndex();
553     contestCatAssisted = contestCatAssistedComboBox->currentIndex();
554     typeContestSelected = typeComboBox->currentIndex();
555     contestCatOverlay= contestCatOverlayComboBox->currentIndex();
556 
557     typeContest = getSelectedTypeContest();
558        //qDebug() << "SetupPageSubdivisionNew::slotCatModeComboBoxChanged(): " << QString::number(typeContest)  << QT_ENDL;
559 
560     if (typeContest < 0)
561     {
562         catModeLabel->setStyleSheet("QLabel {color : red; }");
563         showNOK();
564     }
565     else
566     {
567          catModeLabel->setStyleSheet("QLabel {color : black; }");
568          showOK();
569     }
570 
571 }
572 */
slotOKButtonClicked()573 void SetupPageSubdivisionNew::slotOKButtonClicked()
574 {
575 
576        //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked" << QT_ENDL;
577     stationCallsign = stationCallsignLineEdit->text();
578     if (stationCallsign.length()<3)
579     {
580         QMessageBox msgBox;
581         msgBox.setIcon(QMessageBox::Information);
582         msgBox.setText(tr("You need to enter a valid callsign in the Station Callsign box.\nThe log will not be opened."));
583         msgBox.exec();
584         return;
585     }
586 
587     operators = operatorsLineEdit->text();
588     //TODO: Check if operators is really including a comma separated list of QRZ
589     comment = commentLineEdit->text();
590     dateString = dateEdit->date().toString("yyyy-MM-dd");
591 
592     logData.clear();
593     logData << stationCallsign << operators << comment << dateString;
594     if (editing)
595     {
596         logData << "1";
597         editing = false;
598     }
599     else
600     {
601         logData << "0";
602     }
603     emit newLogData(logData);
604 
605     //gatherAndSend();
606 
607     clear();
608     accept();
609 
610     //typeContest, contestCatOperators, contestCatAssisted, contestCatPower,
611     //contestCatBands, contestCatOverlay, contestCatMode
612 /*
613     if (typeComboBox->isEnabled())
614     {
615            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: type" << QT_ENDL;
616         typeContestSelected = typeComboBox->currentIndex();
617         typeConteststr = typeComboBox->currentText();
618     }
619     else
620     {
621            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: type" << QT_ENDL;
622         typeContestSelected = 0;
623         typeConteststr = QString();
624     }
625 
626     if (contestCatModeComboBox->isEnabled())
627     {
628            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: mode" << QT_ENDL;
629         contestCatMode = contestCatModeComboBox->currentIndex();
630     }
631     else
632     {
633            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: mode" << QT_ENDL;
634         contestCatMode = 0;
635     }
636 
637     if (contestCatOperatorsComboBox->isEnabled())
638     {
639            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: oper" << QT_ENDL;
640        contestCatOperators = contestCatOperatorsComboBox->currentIndex();
641     }
642     else
643     {
644            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: oper" << QT_ENDL;
645         contestCatOperators = 0;
646     }
647 
648     if (contestCatAssistedComboBox->isEnabled())
649     {
650            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: ass" << QT_ENDL;
651         contestCatAssisted = contestCatAssistedComboBox->currentIndex();
652     }
653     else
654     {
655            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: ass" << QT_ENDL;
656         contestCatAssisted = 0;
657     }
658 
659     if (contestCatPowerComboBox->isEnabled())
660     {
661            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: pwr" << QT_ENDL;
662         contestCatPower = contestCatPowerComboBox->currentIndex();
663            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: pwr - " << contestCatPowerComboBox->currentText() << QT_ENDL;
664     }
665     else
666     {
667            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: pwr" << QT_ENDL;
668          contestCatPower = 0;
669     }
670 
671     if (contestCatBandsComboBox->isEnabled())
672     {
673            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: Cbands" << QT_ENDL;
674         contestCatBands = contestCatBandsComboBox->currentIndex();
675     }
676     else
677     {
678            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: Cbands" << QT_ENDL;
679         contestCatBands = 0;
680     }
681 
682     if (contestBandsComboBox->isEnabled())
683     {
684            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: bands" << QT_ENDL;
685         contestBands = contestBandsComboBox->currentIndex();
686     }
687     else
688     {
689            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: bands" << QT_ENDL;
690         contestBands = 0;
691     }
692 
693     if (contestCatOverlayComboBox->isEnabled())
694     {
695            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked ENA: over" << QT_ENDL;
696         contestCatOverlay = contestCatOverlayComboBox->currentIndex();
697     }
698     else
699     {
700            //qDebug() << "SetupPageSubdivisionNew::slotOkButtonClicked NOT ENA: over" << QT_ENDL;
701         contestCatOverlay = 0;
702     }
703 
704     //typeContest, contestCatOperators, contestCatAssisted, contestCatPower,
705     //contestCatBands, contestCatOverlay, contestCatMode
706    // typeContest = getSelectedTypeContest();
707     if (typeContest < 0)
708     {
709         QMessageBox msgBox;
710         msgBox.setIcon(QMessageBox::Information);
711         msgBox.setText(tr("You selected an invalid combination.\nThe log will not be opened."));
712         msgBox.exec();
713 
714     }
715     else
716     {
717 
718 
719     }
720 */
721 
722 }
723 
gatherAndSend()724 void SetupPageSubdivisionNew::gatherAndSend()
725 {
726         //qDebug() << "SetupPageSubdivisionNew::gatherAndSend: "  << QT_ENDL;
727 
728     // The following lines will be removed once more contest types have been added
729     //contestCatMode = contestCatModeComboBox->currentIndex();
730     //contestCatBands = contestCatBandsComboBox->currentIndex();
731     //contestCatPower = contestCatPowerComboBox->currentIndex();
732     //contestCatOperators = contestCatOperatorsComboBox->currentIndex();
733     //contestCatAssisted = contestCatAssistedComboBox->currentIndex();
734     //typeContestSelected = typeComboBox->currentIndex();
735     //contestCatOverlay = contestCatOverlayComboBox->currentIndex();
736     //typeContest = getSelectedTypeContest();
737 
738     // The previous lines will be removed once more contest types have been added
739 
740     logData.clear();
741     logData << stationCallsign << operators << comment << dateString;
742 
743     /*
744             << typeConteststr
745             << QString::number(contestCatMode)
746             << QString::number(contestCatOperators)
747             << QString::number(contestCatAssisted)
748             << QString::number(contestCatPower)
749             << QString::number(contestCatBands)
750             << QString::number(contestBands)
751             << QString::number(contestCatOverlay)
752             << QString::number(typeContest);
753     */
754 
755     if (editing)
756     {
757         logData << "1";
758         editing = false;
759     }
760     else
761     {
762         logData << "0";
763     }
764 
765 
766     //logData << QString::number(typeContest)
767     // Update the SetupPageLogs::slotAnalyzeNewLogData if you add or remove any field (Today 12)
768 
769        //qDebug() << "SetupPageSubdivisionNew::gatherAndSend: EMITED" << QT_ENDL;
770     emit newLogData(logData);
771 
772 }
773 
slotCancelButtonClicked()774 void SetupPageSubdivisionNew::slotCancelButtonClicked()
775 {
776        //qDebug() << "SetupPageSubdivisionNew::slotCancelButtonClicked" << QT_ENDL;
777     logData.clear();
778     emit cancelled(true);
779     setResult(QDialog::Rejected);
780     clear();
781     close();
782 }
783 
784 /*
785 QStringList SetupPageSubdivisionNew::getValidCatOptions(const int _currentCat, const int _higherCat)
786 {// currentCat is the current category and highercat is the category we want to know the information
787 // being:
788 // 1 - contestcatoperator
789 // 2 - contestcatassisted
790 // 3 - contestcatpower
791 // 4 - contestcatband
792 // 5 - contestcatoverlay
793 // 6 - contestcatmode
794 
795        //qDebug() << "SetupPageSubdivisionNew::getValidCatOptions: " << QString::number(_currentCat) <<"/"<< QString::number(_higherCat) << QT_ENDL;
796     //return dataProxy->getValidCatOptions(_currentCat, _higherCat);
797     return QStringList();
798 }
799 */
800 
setStationCallSign(const QString & _st)801 void SetupPageSubdivisionNew::setStationCallSign(const QString &_st)
802 {
803     stationCallsign = _st;
804     stationCallsignLineEdit->setText(stationCallsign.toUpper());
805 }
806 
setOperators(const QString & _st)807 void SetupPageSubdivisionNew::setOperators(const QString &_st)
808 {
809     operators = _st;
810     operatorsLineEdit->setText(operators.toUpper());
811 }
812 
setComment(const QString & _st)813 void SetupPageSubdivisionNew::setComment(const QString &_st)
814 {
815     comment = _st;
816     commentLineEdit->setText(comment);
817 }
818 
setDateString(const QString & _st)819 void SetupPageSubdivisionNew::setDateString(const QString &_st)
820 {
821     dateString = _st;
822     dateEdit->setDate(QDate::fromString(dateString, "yyyy-MM-dd"));
823 
824 }
825 
826 /*
827 void SetupPageSubdivisionNew::setType(const QString &_st)
828 {
829     typeConteststr = _st;
830     //typeConteststr = typeComboBox->currentText();
831     typeComboBox->setCurrentIndex(typeComboBox->findText(typeConteststr, Qt::MatchExactly));
832 
833 //findText ( const QString & text, Qt::MatchFlags flags = static_cast<Qt::MatchFlags> ( Qt::MatchExactly | Qt::MatchCaseSensitive ) ) const
834 }
835 
836 void SetupPageSubdivisionNew::setCMode(const int _n)
837 {
838     contestCatMode = _n;
839     contestCatModeComboBox->setCurrentIndex(contestCatMode);
840 }
841 
842 void SetupPageSubdivisionNew::setCOperators(const int _n)
843 {
844     contestCatOperators = _n;
845     contestCatOperatorsComboBox->setCurrentIndex(contestCatOperators);
846 }
847 
848 void SetupPageSubdivisionNew::setCAssisted(const int _n)
849 {
850     contestCatAssisted = _n;
851     contestCatAssistedComboBox->setCurrentIndex(contestCatAssisted);
852 }
853 
854 void SetupPageSubdivisionNew::setCPower(const int _n)
855 {
856     contestCatPower = _n;
857     contestCatPowerComboBox->setCurrentIndex(contestCatPower);
858 }
859 
860 void SetupPageSubdivisionNew::setCBands(const int _n)
861 {
862     contestCatBands = _n;
863     contestCatBandsComboBox->setCurrentIndex(contestCatBands);
864 }
865 
866 void SetupPageSubdivisionNew::setBands(const int _n)
867 {
868     contestBands = _n;
869     contestBandsComboBox->setCurrentIndex(contestBands);
870 }
871 
872 void SetupPageSubdivisionNew::setCOverlay(const int _n)
873 {
874     contestCatOverlay = _n;
875     contestCatOverlayComboBox->setCurrentIndex(contestCatOverlay);
876 
877 }
878 */
879 
setEditing(const bool b)880 void SetupPageSubdivisionNew::setEditing(const bool b)
881 {
882     editing = b;
883     if (!editing)
884     {
885         clear();
886     }
887 }
888 
889 /*
890 int SetupPageSubdivisionNew::getSelectedTypeContest()
891 {
892        //qDebug() << "SetupPageSubdivisionNew::getSelectedTypeContest: " << QT_ENDL;
893     //is/contest/catoperator/catassisted/catpower/catband/catoverlay/catmode
894     int i = dataProxy->getContestTypeN(typeContestSelected, contestCatOperators, contestCatAssisted, contestCatPower, contestCatBands, contestCatOverlay, contestCatMode);
895        //qDebug() << "SetupPageSubdivisionNew::getSelectedTypeContest: " << QString::number(i) << QT_ENDL;
896     return i;
897 
898 }
899 
900 void SetupPageSubdivisionNew::setTypeN(const int _n)
901 {
902        //qDebug() << "SetupPageSubdivisionNew::setTypeN: " << QString::number(_n) << QT_ENDL;
903     typeContestSelected = _n;
904     fillWithType(typeContestSelected);
905 }
906 
907 void SetupPageSubdivisionNew::fillWithType(const int _n)
908 {
909        //qDebug() << "SetupPageSubdivisionNew::fillWithType - n = " << QString::number(_n) << QT_ENDL;
910     typeContestSelected = _n;
911     QStringList contestData;
912     contestData << dataProxy->getDataFromContestType(_n);
913        //qDebug() << "SetupPageSubdivisionNew::fillWithType-1 (length = " << QString::number(contestData.length()) << ")" << QT_ENDL;
914     if (contestData.length()== 8)
915     {
916 
917            //qDebug() << "SetupPageSubdivisionNew::fillWithType-2" << QT_ENDL;
918         //setCOperators ((contestData.at(1)).toInt());
919         //setCAssisted ((contestData.at(2)).toInt());
920         //setCPower ((contestData.at(3)).toInt());
921         //setCOverlay ((contestData.at(4)).toInt());
922         //setCMode ((contestData.at(5)).toInt());
923         //setType(contestData.at(6));
924         //setCBands((contestData.at(7)).toInt());
925            //qDebug() << "SetupPageSubdivisionNew::fillWithType: " << contestData.at(6) << QT_ENDL;
926     }
927     else
928     {
929            //qDebug() << "SetupPageSubdivisionNew::fillWithType-3" << QT_ENDL;
930         return;
931     }
932 
933 }
934 
935 
936 void SetupPageSubdivisionNew::updateAllCats()
937 {
938        //qDebug() << "SetupPageSubdivisionNew::updateAllCats" << QT_ENDL;
939 
940     contestCatMode = contestCatModeComboBox->currentIndex();
941     contestCatBands = contestCatBandsComboBox->currentIndex();
942     contestCatPower = contestCatPowerComboBox->currentIndex();
943     contestCatOperators = contestCatOperatorsComboBox->currentIndex();
944     contestCatAssisted = contestCatAssistedComboBox->currentIndex();
945     typeContestSelected = typeComboBox->currentIndex();
946     contestCatOverlay= contestCatOverlayComboBox->currentIndex();
947     typeContest = getSelectedTypeContest();
948 
949 }
950     */
951 
showOK()952 void SetupPageSubdivisionNew::showOK()
953 {
954     //validCats->setText(tr("Data OK"));
955     //validCats->setStyleSheet("QLabel {color : black; }");
956     okButton->setEnabled(true);
957 
958 }
959 
showNOK()960 void SetupPageSubdivisionNew::showNOK()
961 {
962     //validCats->setText(tr("Data not OK"));
963     //validCats->setStyleSheet("QLabel {color : red; }");
964     okButton->setEnabled(false);
965 }
966