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
|
/***************************************************************************
mapwidget.cpp - description
-------------------
begin : May 2021
copyright : (C) 2021 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/>. *
* *
*****************************************************************************/
#include "mapwindowwidget.h"
MapWindowWidget::MapWindowWidget(DataProxy_SQLite *dp, QWidget *parent)
{
Q_UNUSED(parent);
//qDebug() << Q_FUNC_INFO;
dataProxy = dp;
//qDebug() << Q_FUNC_INFO << "1";
mapWidget = new MapWidget(this);
//qDebug() << Q_FUNC_INFO << "2";
propComboBox = new QComboBox;
bandComboBox = new QComboBox;
modeComboBox = new QComboBox;
satNameComboBox = new QComboBox;
confirmedCheckBox = new QCheckBox;
//locatorsCheckBox = new QCheckBox;
//qDebug() << Q_FUNC_INFO << " - END";
}
MapWindowWidget::~MapWindowWidget()
{
//qDebug() << Q_FUNC_INFO << " - Start";
//delete(dataProxy);
delete(mapWidget);
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::init()
{
//qDebug() << Q_FUNC_INFO << " - Start";
workedColor = Qt::black;
confirmedColor = Qt::black;
defaultColor = Qt::black;
createUI();
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::addMarker(const Coordinate _coord, const QString _loc)
{
Q_UNUSED(_loc);
//qDebug() << Q_FUNC_INFO << QString(" %1 = %2/%3(lat/lon)").arg(_loc).arg(_coord.lat).arg(_coord.lon);
mapWidget->addMarker(_coord);
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::createUI()
{
//qDebug() << Q_FUNC_INFO << " - Start";
bandComboBox->setToolTip(tr("Select QSOs in this band."));
modeComboBox->setToolTip(tr("Select QSOs in this mode."));
propComboBox->setToolTip(tr("Select QSOs in this propagation mode."));
satNameComboBox->setToolTip(tr("Select QSOs using this Satellite."));
confirmedCheckBox->setText(tr("Only confirmed"));
confirmedCheckBox->setToolTip(tr("Select only confirmed QSOs."));
//locatorsCheckBox->setText(tr("Show Locators"));
//locatorsCheckBox->setToolTip(tr("Show Locators or QSO positons."));
QGridLayout *buttonsLayout = new QGridLayout;
buttonsLayout->addWidget(bandComboBox, 0, 0);
buttonsLayout->addWidget(modeComboBox, 0, 1);
buttonsLayout->addWidget(propComboBox, 1, 0);
buttonsLayout->addWidget(satNameComboBox, 1, 1);
//buttonsLayout->addWidget(okButton, 1, 2);
buttonsLayout->addWidget(confirmedCheckBox, 0, 2);
//buttonsLayout->addWidget(locatorsCheckBox, 1, 2);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addLayout(buttonsLayout);
layout->addWidget(mapWidget);
setLayout (layout);
setPropModes();
setSatNames();
//qDebug() << Q_FUNC_INFO << "3";
mapWidget->init(); // Creates map and paints persistent global grid
connect(bandComboBox, SIGNAL(currentTextChanged (QString)), this, SLOT(slotBandsComboBoxChanged()));
connect(modeComboBox, SIGNAL(currentTextChanged (QString)), this, SLOT(slotModesComboBoxChanged()));
connect(propComboBox, SIGNAL(currentTextChanged (QString)), this, SLOT(slotPropComboBoxChanged()));
connect(satNameComboBox, SIGNAL(currentTextChanged (QString)), this, SLOT(slotSatsComboBoxChanged()));
connect(confirmedCheckBox, SIGNAL(clicked()), this, SLOT(slotConfirmedCheckBoxChanged()));
satNameComboBox->setEnabled(false);// Starts disable until propagation = SAT
//qDebug() << Q_FUNC_INFO << "-END";
}
void MapWindowWidget::setCenter(const Coordinate &_c)
{
//qDebug() << Q_FUNC_INFO << " - Start";
mapWidget->setCenter(_c);
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::setBands(const QStringList _bands)
{
//qDebug() << Q_FUNC_INFO << " - Start";
QStringList bands;
bands.clear();
bands = _bands;
bands.removeDuplicates();
//bands = dataProxy->sortBandNamesBottonUp(bands);
bandComboBox->clear();
bands.prepend("All - " + tr("All bands"));
bands.prepend("None - " + tr("Show nothing"));
bandComboBox->addItems(bands);
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::setModes(const QStringList _modes)
{
//qDebug() << Q_FUNC_INFO << " - Start";
QStringList modes;
modes.clear();
modes = _modes;
modes.removeDuplicates();
modes.sort();
modes.prepend("All - " + tr("All modes"));
modeComboBox->clear();
modeComboBox->addItems(modes);
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::setPropModes()
{
//qDebug() << Q_FUNC_INFO << " - Start";
QStringList propModeList;
propModeList.clear();
propModeList = dataProxy->getPropModeList();
if (propModeList.size()>1)
{
propModeList.prepend("All - " + tr("All propagation modes"));
//propModeList.prepend("01 - " + tr("Not - Not Identified"));
propComboBox->addItems(propModeList);
}
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::setSatNames()
{
//qDebug() << Q_FUNC_INFO << " - Start";
QString nosat = tr("All satellites");
//QString othersat = tr("Other - Sat not in the list");
QStringList satellitesList;
satellitesList.clear();
satellitesList = dataProxy->getSatellitesList();
//satellitesList.prepend(othersat);
satellitesList.prepend("All - " + nosat);
if (satellitesList.size()>1)
{
satNameComboBox->clear();
satNameComboBox->addItems(satellitesList);
}
else
{
//TODO: Check how to do it better... now I could simply remove the if
satNameComboBox->addItems(satellitesList);
}
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::showFiltered()
{
//qDebug() << Q_FUNC_INFO << " - Start";
// Always keep the grid visible; only manage overlays here.
// If the "None - Show nothing" band is selected, just clear overlays and return.
if (bandComboBox->currentIndex() == 0)
{
mapWidget->clearDataLayers();
return;
}
QStringList confirmedLocators;
QStringList shortLocators, confirmedShortLocators;
confirmedShortLocators.clear();
QString satName = satNameComboBox->currentText();
confirmedLocators << dataProxy->getFilteredLocators(
bandComboBox->currentText(),
modeComboBox->currentText(),
getPropModeFromComboBox(),
satName.section(' ', 0, 0),
true);
QColor color;
Locator locator;
confirmedShortLocators << locator.getShortLocators(confirmedLocators);
confirmedShortLocators << confirmedLocators;
confirmedShortLocators.removeDuplicates();
confirmedShortLocators.sort();
if (!confirmedShortLocators.isEmpty())
{
color = confirmedColor;
color.setAlpha(127);
addLocators(confirmedShortLocators, color);
}
else
{
mapWidget->clearDataLayers();
}
if (!confirmedCheckBox->isChecked())
{
QStringList wLocators;
wLocators << dataProxy->getFilteredLocators(
bandComboBox->currentText(),
modeComboBox->currentText(),
getPropModeFromComboBox(),
satName.section(' ', 0, 0),
false);
QStringList workedLocators;
workedLocators.clear();
for (const QString &loc : wLocators)
{
if (!confirmedShortLocators.contains(loc))
workedLocators.append(loc);
}
shortLocators.clear();
shortLocators << locator.getShortLocators(workedLocators);
shortLocators << workedLocators;
shortLocators.removeDuplicates();
workedLocators.clear();
for (const QString &loc : shortLocators)
{
if (!confirmedShortLocators.contains(loc))
workedLocators.append(loc);
}
workedLocators.sort();
if (!workedLocators.isEmpty())
{
color = workedColor;
color.setAlpha(127);
appendLocators(workedLocators, color);
}
}
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::slotBandsComboBoxChanged()
{
//qDebug() << Q_FUNC_INFO << " - Start";
showFiltered();
bandComboBox->setFocus();
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::slotModesComboBoxChanged()
{
//qDebug() << Q_FUNC_INFO << " - Start";
showFiltered();
modeComboBox->setFocus();
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::slotPropComboBoxChanged()
{
//qDebug() << Q_FUNC_INFO << " - Start";
if (getPropModeFromComboBox() == "SAT")
{
//qDebug() << Q_FUNC_INFO << ": SAT";
satNameComboBox->setCurrentIndex(0);
satNameComboBox->setEnabled(true);
}
else
{
//qDebug() << Q_FUNC_INFO << ": NO SAT";
satNameComboBox->setCurrentIndex(0);
satNameComboBox->setEnabled(false);
}
showFiltered();
propComboBox->setFocus();
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::slotSatsComboBoxChanged()
{
//qDebug() << Q_FUNC_INFO << " - Start";
showFiltered();
satNameComboBox->setFocus();
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::slotConfirmedCheckBoxChanged()
{
//qDebug() << Q_FUNC_INFO << " - Start";
showFiltered();
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::addQSO(const QString &_loc)
{
Q_UNUSED(_loc);
//qDebug() << Q_FUNC_INFO << ": " << _loc;
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::addLocator(const QString &_loc, const QColor &_color)
{
//qDebug() << Q_FUNC_INFO << ": " << _loc;
//if (!locator.isValidLocator(_loc))
//{
// return;
//}
mapWidget->addLocator(_loc, _color);
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::addLocators(const QStringList &_locators, const QColor &_color)
{
//qDebug() << Q_FUNC_INFO << " - Start";
// Clear only overlays; keep the persistent grid
mapWidget->clearDataLayers();
foreach(QString i, _locators)
{
if (i.contains ("IN99"))
{
//qDebug() << Q_FUNC_INFO << ": " << i;
}
mapWidget->addLocator(i, _color);
}
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::appendLocators(const QStringList &_locators, const QColor &_color)
{
//qDebug() << Q_FUNC_INFO << " - Start";
foreach(const QString &i, _locators)
{
//mapWidget->addLocator(i, confirmedColor);
mapWidget->addLocator(i, _color);
}
//qDebug() << Q_FUNC_INFO << " - END";
}
QString MapWindowWidget::getPropModeFromComboBox()
{
//qDebug() << Q_FUNC_INFO << " - Start";
QString _pm = QString();
//qDebug() << Q_FUNC_INFO << ": " << propComboBox->currentText();
_pm = (((propComboBox->currentText()).split('-')).at(1)).simplified();
QString _n = (((propComboBox->currentText()).split('-')).at(0)).simplified();
//qDebug() << Q_FUNC_INFO << ": " << _pm;
if (_n == "00")
{
//qDebug() << Q_FUNC_INFO << " - END1";
return QString();
}
//qDebug() << Q_FUNC_INFO << " - END";
return _pm;
}
void MapWindowWidget::paintGlobalGrid()
{
//qDebug() << Q_FUNC_INFO << " - Start";
//qDebug() << Q_FUNC_INFO << " - END";
}
void MapWindowWidget::setColors (const QColor &_worked, const QColor &_confirmed, const QColor &_default)
{
//qDebug() << Q_FUNC_INFO << " - Start";
defaultColor = _default;
workedColor = _worked;
confirmedColor = _confirmed;
//qDebug() << " - DefaultColor: " << defaultColor.name(QColor::HexRgb);
//qDebug() << " - WorkedColor: " << workedColor.name(QColor::HexRgb);
//qDebug() << " - ConfirmedColor: " << confirmedColor.name(QColor::HexRgb);
//qDebug() << Q_FUNC_INFO << " - END";
}
|