mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-10-10 09:11:19 -04:00
QMessageBox::information() and friends build the box on the stack, parent it to the calling widget and run a nested event loop in exec(). If the parent is closed while the box is open, which the Web API can do at any time, the parent deletes the box and its children and the heap is corrupted. MessageDialog offers the same calls, but the box is heap allocated, given Qt::WA_DeleteOnClose and shown rather than exec'd, so nothing runs a nested event loop and the box owns its own lifetime. A box with the same text as one already up is raised instead of a second being created. The trade off is that information(), warning() and critical() return immediately and cannot report which button was pressed. question() takes a callback for the cases that need the answer. Converts the call sites in the device, channel and feature GUIs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
184 lines
7.1 KiB
C++
184 lines
7.1 KiB
C++
///////////////////////////////////////////////////////////////////////////////////
|
|
// Copyright (C) 2021-2022 Jon Beniston, M7RCE <jon@beniston.com> //
|
|
// Copyright (C) 2023 Daniele Forsi <iu5hkx@gmail.com> //
|
|
// //
|
|
// 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 as version 3 of the License, or //
|
|
// (at your option) any later version. //
|
|
// //
|
|
// This program 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 V3 for more details. //
|
|
// //
|
|
// You should have received a copy of the GNU General Public License //
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "mapbeacondialog.h"
|
|
|
|
#include <QDebug>
|
|
#include <QUrl>
|
|
#include <QMessageBox>
|
|
|
|
#include "channel/channelwebapiutils.h"
|
|
#include "mapgui.h"
|
|
|
|
#include "gui/messagedialog.h"
|
|
|
|
MapBeaconDialog::MapBeaconDialog(MapGUI *gui, QWidget* parent) :
|
|
QDialog(parent),
|
|
m_gui(gui),
|
|
ui(new Ui::MapBeaconDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
|
connect(&m_dlm, &HttpDownloadManager::downloadComplete, this, &MapBeaconDialog::downloadFinished);
|
|
}
|
|
|
|
MapBeaconDialog::~MapBeaconDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MapBeaconDialog::updateTable()
|
|
{
|
|
AzEl azEl = *m_gui->getAzEl();
|
|
ui->beacons->setSortingEnabled(false);
|
|
ui->beacons->setRowCount(0);
|
|
QList<Beacon *> *beacons = m_gui->getBeacons();
|
|
if (beacons != nullptr)
|
|
{
|
|
ui->beacons->setRowCount(beacons->size());
|
|
QListIterator<Beacon *> i(*beacons);
|
|
int row = 0;
|
|
while (i.hasNext())
|
|
{
|
|
Beacon *beacon = i.next();
|
|
ui->beacons->setItem(row, BEACON_COL_CALLSIGN, new QTableWidgetItem(beacon->m_callsign));
|
|
QTableWidgetItem *freq = new QTableWidgetItem();
|
|
freq->setText(beacon->getFrequencyText());
|
|
freq->setData(Qt::UserRole, beacon->m_frequency);
|
|
ui->beacons->setItem(row, BEACON_COL_FREQUENCY, freq);
|
|
ui->beacons->item(row, BEACON_COL_FREQUENCY)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
ui->beacons->setItem(row, BEACON_COL_LOCATION, new QTableWidgetItem(beacon->m_locator));
|
|
ui->beacons->setItem(row, BEACON_COL_POWER, new QTableWidgetItem(beacon->m_power));
|
|
ui->beacons->item(row, BEACON_COL_POWER)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
ui->beacons->setItem(row, BEACON_COL_POLARIZATION, new QTableWidgetItem(beacon->m_polarization));
|
|
ui->beacons->setItem(row, BEACON_COL_PATTERN, new QTableWidgetItem(beacon->m_pattern));
|
|
ui->beacons->setItem(row, BEACON_COL_KEY, new QTableWidgetItem(beacon->m_key));
|
|
ui->beacons->setItem(row, BEACON_COL_MGM, new QTableWidgetItem(beacon->m_mgm));
|
|
azEl.setTarget(beacon->m_latitude, beacon->m_longitude, beacon->m_altitude);
|
|
azEl.calculate();
|
|
QTableWidgetItem *azymuth = new QTableWidgetItem();
|
|
azymuth->setData(Qt::DisplayRole, round(azEl.getAzimuth()));
|
|
ui->beacons->setItem(row, BEACON_COL_AZIMUTH, azymuth);
|
|
ui->beacons->item(row, BEACON_COL_AZIMUTH)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
QTableWidgetItem *elevation = new QTableWidgetItem();
|
|
elevation->setData(Qt::DisplayRole, round(azEl.getElevation()));
|
|
ui->beacons->setItem(row, BEACON_COL_ELEVATION, elevation);
|
|
ui->beacons->item(row, BEACON_COL_ELEVATION)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
int km = round(azEl.getDistance()/1000);
|
|
QTableWidgetItem *dist = new QTableWidgetItem();
|
|
dist->setData(Qt::DisplayRole, km);
|
|
ui->beacons->setItem(row, BEACON_COL_DISTANCE, dist);
|
|
ui->beacons->item(row, BEACON_COL_DISTANCE)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
row++;
|
|
}
|
|
}
|
|
ui->beacons->setSortingEnabled(true);
|
|
ui->beacons->resizeColumnsToContents();
|
|
}
|
|
|
|
void MapBeaconDialog::accept()
|
|
{
|
|
QDialog::accept();
|
|
}
|
|
|
|
void MapBeaconDialog::on_downloadIARU_clicked()
|
|
{
|
|
if (!m_dlm.downloading())
|
|
{
|
|
QString beaconFile = MapGUI::getBeaconFilename();
|
|
if (HttpDownloadManagerGUI::confirmDownload(beaconFile, this))
|
|
{
|
|
// Download IARU beacons database to disk
|
|
QUrl dbURL(QString(IARU_BEACONS_URL));
|
|
m_dlm.download(dbURL, beaconFile, this);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MapBeaconDialog::downloadFinished(const QString& filename, bool success, const QString &url, const QString &errorMessage)
|
|
{
|
|
if (success)
|
|
{
|
|
if (filename == MapGUI::getBeaconFilename())
|
|
{
|
|
QList<Beacon *> *beacons = Beacon::readIARUCSV(filename);
|
|
if (beacons != nullptr) {
|
|
m_gui->setBeacons(beacons);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
qDebug() << "MapBeaconDialog::downloadFinished: Unexpected filename: " << filename;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageDialog::warning(this, "Download failed", QString("Failed to download %1 to %2\n%3").arg(url).arg(filename).arg(errorMessage));
|
|
}
|
|
}
|
|
|
|
void MapBeaconDialog::on_beacons_cellDoubleClicked(int row, int column)
|
|
{
|
|
if ((column == BEACON_COL_CALLSIGN) || (column == BEACON_COL_LOCATION))
|
|
{
|
|
// Find beacon on map
|
|
QString location = ui->beacons->item(row, column)->text();
|
|
m_gui->find(location);
|
|
}
|
|
else if (column == BEACON_COL_FREQUENCY)
|
|
{
|
|
// Tune to beacon freq
|
|
ChannelWebAPIUtils::setCenterFrequency(0, ui->beacons->item(row, column)->data(Qt::UserRole).toDouble());
|
|
}
|
|
}
|
|
|
|
void MapBeaconDialog::on_filter_currentIndexChanged(int index)
|
|
{
|
|
for (int row = 0; row < ui->beacons->rowCount(); row++)
|
|
{
|
|
bool hidden = false;
|
|
QTableWidgetItem *item = ui->beacons->item(row, BEACON_COL_FREQUENCY);
|
|
qint64 freq = item->data(Qt::UserRole).toLongLong();
|
|
qint64 band = freq/1000000;
|
|
switch (index)
|
|
{
|
|
case 0: // All
|
|
break;
|
|
case 1:
|
|
hidden = band != 50;
|
|
break;
|
|
case 2:
|
|
hidden = band != 70;
|
|
break;
|
|
case 3:
|
|
hidden = band != 144;
|
|
break;
|
|
case 4:
|
|
hidden = band != 432;
|
|
break;
|
|
case 5:
|
|
hidden = band != 1296;
|
|
break;
|
|
case 6:
|
|
hidden = band <= 1296;
|
|
break;
|
|
}
|
|
ui->beacons->setRowHidden(row, hidden);
|
|
}
|
|
}
|