1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
|
/***************************************************************************
SetupPageSatsNew.h - description
-------------------
begin : feb 2015
copyright : (C) 2015 by Jaime Robles
email : jaime@robles.es
***************************************************************************/
/*****************************************************************************
* This file is part of KLog. *
* *
* KLog 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 3 of the License, or *
* (at your option) any later version. *
* *
* KLog is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with KLog. If not, see <https://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
//
// This class implements the Dialog to add a new log
//
#include "setuppagesatsnew.h"
SetupPageSatsNew::SetupPageSatsNew(DataProxy_SQLite *dp, QWidget *parent)
{
//qDebug() << "SetupPageSatsNew::SetupPageSatsNew" ;
Q_UNUSED(parent);
dataProxy = dp;
util = new Utilities(Q_FUNC_INFO);
editing = false;
//checking = false;
shortNameLineEdit = new QLineEdit();
nameLineEdit = new QLineEdit();
uplinkLineEdit = new QLineEdit();
downlinkLineEdit = new QLineEdit();
modesLineEdit = new QLineEdit();
shortNameLabel = new QLabel(tr("Short name"));
nameLabel = new QLabel(tr("Sat name"));
uplinkLabel = new QLabel(tr("UpLink"));
downlinkLabel = new QLabel(tr("DownLink"));
modesLabel = new QLabel(tr("Modes"));
clear();
//satData.clear();
okButton = new QPushButton(tr("&Ok"), this);
cancelButton = new QPushButton(tr("&Cancel"), this);
createUI();
okButton->setEnabled(true);
//qDebug() << "SetupPageSatsNew::SetupPageSatsNew - END" ;
}
SetupPageSatsNew::~SetupPageSatsNew()
{
//delete(dataProxy);
delete(util);
}
void SetupPageSatsNew::clear()
{
shortName = QString();
name = QString();
uplink = QString();
downlink = QString();
modes = QString();
hasShortName = false;
hasName = false;
hasUplink = false;
hasDownlink = false;
hasModes = false;
shortNameLineEdit->clear();
nameLineEdit->clear();
uplinkLineEdit->clear();
downlinkLineEdit->clear();
modesLineEdit->clear();
}
void SetupPageSatsNew::createUI()
{
//qDebug() << "SetupPageSatsNew::createWidget";
shortNameLabel->setWordWrap(true);
nameLabel->setWordWrap(true);
uplinkLabel->setWordWrap(true);
downlinkLabel->setWordWrap(true);
modesLabel->setWordWrap(true);
shortNameLabel->setBuddy(shortNameLineEdit);
nameLabel->setBuddy(nameLineEdit);
uplinkLabel->setBuddy(uplinkLineEdit);
downlinkLabel->setBuddy(downlinkLineEdit);
modesLabel->setBuddy(modesLineEdit);
shortNameLineEdit->setToolTip(tr("Enter the short name. Try to use the LoTW short name so you can upload your QSO to LoTW afterwards."));
nameLineEdit->setToolTip(tr("Enter the name of the satellite."));
uplinkLineEdit->setToolTip(tr("Enter the uplink frequencies in this format: 144.300"));
downlinkLineEdit->setToolTip(tr("Enter the downlink frequencies in this format: 144.300"));
modesLineEdit->setToolTip(tr("Enter the modes in this format: USB"));
connect(shortNameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotShortNameTextChanged() ) );
connect(nameLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotNameTextChanged() ) );
connect(uplinkLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpLinkTextChanged() ) );
connect(downlinkLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotDownLinkTextChanged() ) );
connect(modesLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotModesTextChanged() ) );
connect(okButton,SIGNAL(clicked()), this, SLOT(slotOKButtonClicked() ) );
connect(cancelButton, SIGNAL(clicked()), this, SLOT(slotCancelButtonClicked() ) );
QGridLayout *dataLayout = new QGridLayout; // Widget, row, column
dataLayout->addWidget(shortNameLabel, 0, 0);
dataLayout->addWidget(shortNameLineEdit, 0, 1);
dataLayout->addWidget(nameLabel, 1, 0);
dataLayout->addWidget(nameLineEdit, 1, 1);
dataLayout->addWidget(uplinkLabel, 2, 0);
dataLayout->addWidget(uplinkLineEdit, 2, 1);
dataLayout->addWidget(downlinkLabel, 3, 0);
dataLayout->addWidget(downlinkLineEdit, 3, 1);
dataLayout->addWidget(modesLabel, 4, 0);
dataLayout->addWidget(modesLineEdit, 4, 1);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
//buttonsLayout->addWidget(validCats);
buttonsLayout->addSpacerItem(new QSpacerItem(10,0,QSizePolicy::Expanding,QSizePolicy::Maximum));
buttonsLayout->addWidget(okButton);
buttonsLayout->addWidget(cancelButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(dataLayout);
mainLayout->addLayout(buttonsLayout);
setLayout(mainLayout);
clear();
}
void SetupPageSatsNew::slotShortNameTextChanged()
{
int cursorP = shortNameLineEdit->cursorPosition();
shortNameLineEdit->setText((shortNameLineEdit->text()).toUpper());
if ((shortNameLineEdit->text()).length()>2)
{
hasShortName = true;
}
else
{
hasShortName = false;
}
shortNameLineEdit->setCursorPosition(cursorP);
}
void SetupPageSatsNew::slotNameTextChanged()
{
int cursorP = nameLineEdit->cursorPosition();
nameLineEdit->setText((nameLineEdit->text()).toUpper());
if ((nameLineEdit->text()).length()>2)
{
hasName = true;
}
else
{
hasName = false;
}
nameLineEdit->setCursorPosition(cursorP);
}
void SetupPageSatsNew::slotUpLinkTextChanged()
{
/*
Format: Single freq: 145.600
Range: 145.600-145.700
Two freqs or ranges: 145.600,145.650 or 145.600,145.600-145.700
*/
//qDebug() << "SetupPageSatsNew::slotUpLinkTextChanged:" << uplinkLineEdit->text() ;
if ((uplinkLineEdit->text()).length()<2)
{
return;
}
QStringList freqs;
freqs.clear();
QString aux = uplinkLineEdit->text();
// QString str = QString();
freqs << aux.split(',');
hasUplink = true;
foreach (aux, freqs)
{
if (aux.contains('-'))
{ // It is a range
//qDebug() << "SetupPageSatsNew::slotUpLinkTextChanged: It is a range: " << aux;
}
else
{ //It is just one freq
if (!isItAFreq(aux))
{
hasUplink = false;
}
}
}
}
bool SetupPageSatsNew::isItAFreq(const QString &_st)
{
//qDebug() << "SetupPageSatsNew::isItAFreq: It is one freq: " << _st;
bool ok = false;
double freq = _st.toDouble(&ok);
return ((freq>=0.0) && (ok));
}
void SetupPageSatsNew::slotDownLinkTextChanged()
{
/*
Format: Single freq: 145.600
Range: 145.600-145.700
Two freqs or ranges: 145.600,145.650 or 145.600,145.600-145.700
*/
if ((downlinkLineEdit->text()).length()<2)
{
return;
}
QStringList freqs;
freqs.clear();
QString aux = downlinkLineEdit->text();
// QString str = QString();
freqs << aux.split(',');
hasDownlink = true;
foreach (aux, freqs)
{
if (aux.contains('-'))
{ // It is a range
//qDebug() << "SetupPageSatsNew::slotUpLinkTextChanged: It is a range: " << aux;
}
else
{ //It is just one freq
if (isItAFreq(aux))
{
hasDownlink = false;
}
}
}
}
void SetupPageSatsNew::slotModesTextChanged()
{
/*
Format: Single mode: USB
Two modes: USB,LSB
One mode per up/down USB/LSB
*/
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: " << modesLineEdit->text();
int cursorP = modesLineEdit->cursorPosition();
modesLineEdit->setText((modesLineEdit->text()).toUpper());
QString aux = QString();
QString aux2 = QString();
hasModes = false;
if ((modesLineEdit->text()).length()<2)
{
return;
}
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: length >=2";
QStringList _modes;
_modes.clear();
_modes = (modesLineEdit->text()).split(',');
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Starting to process the list" ;
foreach (aux, _modes)
{
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Processing: " << aux;
if (aux.contains('/'))
{// It s a pair of modes (up and down link)
QStringList _pair;
_pair.clear();
_pair << aux.split('/');
foreach (aux2, _pair)
{
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Processing aux2: " << aux2;
if (dataProxy->getIdFromModeName(aux2)>0)
{
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Checking2: true: " << aux2;
hasModes = true;
}
else
{
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Checking2: false: " << aux2;
hasModes = false;
}
}
}
else
{
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Checking: " << aux;
if (dataProxy->getIdFromModeName(aux)>0)
{
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Checking: true: " << aux;
hasModes = true;
}
else
{
//qDebug() << "SetupPageSatsNew::slotModesTextChanged: Checking: false: " << aux;
hasModes = false;
}
}
}
modesLineEdit->setCursorPosition(cursorP);
}
void SetupPageSatsNew::setShortName(const QString st)
{
shortNameLineEdit->setText(st.toUpper());
}
void SetupPageSatsNew::setName(const QString st)
{
nameLineEdit->setText(st.toUpper());
}
void SetupPageSatsNew::setUpLink(const QString st)
{
uplinkLineEdit->setText(st);
}
void SetupPageSatsNew::setDownLink(const QString st)
{
downlinkLineEdit->setText(st);
}
void SetupPageSatsNew::setModes(const QString st)
{
modesLineEdit->setText(st.toUpper());
}
void SetupPageSatsNew::slotOKButtonClicked()
{
//qDebug() << "SetupPageSatsNew::slotOkButtonClicked";
shortName = shortNameLineEdit->text();
name = nameLineEdit->text();
uplink = uplinkLineEdit->text();
downlink = downlinkLineEdit->text();
modes = modesLineEdit->text();
if (hasShortName && hasName && (hasUplink || hasDownlink) && hasModes)
{
gatherAndSend();
editing = false;
close();
}
else
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Information);
msgBox.setText(tr("Some of the data you have entered is not correct; the satellite can't be added."));
msgBox.exec();
if (!hasShortName)
{
//qDebug() << "SetupPageSatsNew::slotOkButtonClicked hasShortName is FALSE";
}
else if (!hasName)
{
//qDebug() << "SetupPageSatsNew::slotOkButtonClicked hasName is FALSE";
}
else if (!hasUplink)
{
//qDebug() << "SetupPageSatsNew::slotOkButtonClicked hasUpLink is FALSE";
}
else if (!hasDownlink)
{
//qDebug() << "SetupPageSatsNew::slotOkButtonClicked hasDownLink is FALSE";
}
else if (!hasModes)
{
//qDebug() << "SetupPageSatsNew::slotOkButtonClicked hasModes is FALSE";
}
}
//close();
}
void SetupPageSatsNew::gatherAndSend()
{
//qDebug() << "SetupPageSatsNew::gatherAndSend: ";
// The previous lines will be removed once more contest types have been added
satData.clear();
satData << shortNameLineEdit->text() << nameLineEdit->text() << downlinkLineEdit->text() <<
uplinkLineEdit->text() << modesLineEdit->text();
int satId = dataProxy->getDBSatId(shortNameLineEdit->text());
//qDebug() << "SetupPageSatsNew::gatherAndSend: satId: " << QString::number(satId);
if ((editing) && (satId>0))
{
satData << "1";
editing = false;
dataProxy->addSatellite(shortNameLineEdit->text(), nameLineEdit->text(), downlinkLineEdit->text(), uplinkLineEdit->text(), modesLineEdit->text(), satId);
}
else
{
satData << "0";
dataProxy->addSatellite(shortNameLineEdit->text(), nameLineEdit->text(), downlinkLineEdit->text(), uplinkLineEdit->text(), modesLineEdit->text());
}
//qDebug() << "SetupPageSatsNew::gatherAndSend: EMITED";
emit newSatData(satData);
}
void SetupPageSatsNew::slotCancelButtonClicked()
{
//qDebug() << "SetupPageSatsNew::slotCancelButtonClicked";
satData.clear();
clear();
emit cancelled(true);
close();
}
void SetupPageSatsNew::setEditing(const bool b)
{
editing = b;
if (!editing)
{
clear();
}
}
|