mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 08:10:05 +00:00
add WFO dialog to make selecting a WFO easier, mostly coppied from counties dialog
This commit is contained in:
parent
ed00cec4cc
commit
4ab29fd8f3
6 changed files with 336 additions and 10 deletions
|
|
@ -240,6 +240,7 @@ set(HDR_UI source/scwx/qt/ui/about_dialog.hpp
|
|||
source/scwx/qt/ui/animation_dock_widget.hpp
|
||||
source/scwx/qt/ui/collapsible_group.hpp
|
||||
source/scwx/qt/ui/county_dialog.hpp
|
||||
source/scwx/qt/ui/wfo_dialog.hpp
|
||||
source/scwx/qt/ui/download_dialog.hpp
|
||||
source/scwx/qt/ui/flow_layout.hpp
|
||||
source/scwx/qt/ui/gps_info_dialog.hpp
|
||||
|
|
@ -265,6 +266,7 @@ set(SRC_UI source/scwx/qt/ui/about_dialog.cpp
|
|||
source/scwx/qt/ui/animation_dock_widget.cpp
|
||||
source/scwx/qt/ui/collapsible_group.cpp
|
||||
source/scwx/qt/ui/county_dialog.cpp
|
||||
source/scwx/qt/ui/wfo_dialog.cpp
|
||||
source/scwx/qt/ui/download_dialog.cpp
|
||||
source/scwx/qt/ui/flow_layout.cpp
|
||||
source/scwx/qt/ui/gps_info_dialog.cpp
|
||||
|
|
@ -290,6 +292,7 @@ set(UI_UI source/scwx/qt/ui/about_dialog.ui
|
|||
source/scwx/qt/ui/animation_dock_widget.ui
|
||||
source/scwx/qt/ui/collapsible_group.ui
|
||||
source/scwx/qt/ui/county_dialog.ui
|
||||
source/scwx/qt/ui/wfo_dialog.ui
|
||||
source/scwx/qt/ui/gps_info_dialog.ui
|
||||
source/scwx/qt/ui/imgui_debug_dialog.ui
|
||||
source/scwx/qt/ui/layer_dialog.ui
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <scwx/qt/types/time_types.hpp>
|
||||
#include <scwx/qt/types/unit_types.hpp>
|
||||
#include <scwx/qt/ui/county_dialog.hpp>
|
||||
#include <scwx/qt/ui/wfo_dialog.hpp>
|
||||
#include <scwx/qt/ui/radar_site_dialog.hpp>
|
||||
#include <scwx/qt/ui/serial_port_dialog.hpp>
|
||||
#include <scwx/qt/ui/settings/hotkey_settings_widget.hpp>
|
||||
|
|
@ -108,6 +109,7 @@ public:
|
|||
alertAudioRadarSiteDialog_ {new RadarSiteDialog(self)},
|
||||
gpsSourceDialog_ {new SerialPortDialog(self)},
|
||||
countyDialog_ {new CountyDialog(self)},
|
||||
wfoDialog_ {new WFODialog(self)},
|
||||
fontDialog_ {new QFontDialog(self)},
|
||||
fontCategoryModel_ {new QStandardItemModel(self)},
|
||||
settings_ {std::initializer_list<settings::SettingsInterfaceBase*> {
|
||||
|
|
@ -209,6 +211,7 @@ public:
|
|||
RadarSiteDialog* alertAudioRadarSiteDialog_;
|
||||
SerialPortDialog* gpsSourceDialog_;
|
||||
CountyDialog* countyDialog_;
|
||||
WFODialog* wfoDialog_;
|
||||
QFontDialog* fontDialog_;
|
||||
|
||||
QStandardItemModel* fontCategoryModel_;
|
||||
|
|
@ -979,7 +982,8 @@ void SettingsDialogImpl::SetupAudioTab()
|
|||
countyEntryEnabled);
|
||||
self_->ui->resetAlertAudioCountyButton->setEnabled(countyEntryEnabled);
|
||||
|
||||
self_->ui->alertAudioWFOComboBox->setEnabled(wfoEntryEnabled);
|
||||
self_->ui->alertAudioWFOLineEdit->setEnabled(wfoEntryEnabled);
|
||||
self_->ui->alertAudioWFOSelectButton->setEnabled(wfoEntryEnabled);
|
||||
self_->ui->resetAlertAudioWFOButton->setEnabled(wfoEntryEnabled);
|
||||
});
|
||||
|
||||
|
|
@ -1202,13 +1206,41 @@ void SettingsDialogImpl::SetupAudioTab()
|
|||
alertAudioCounty_.SetEditWidget(self_->ui->alertAudioCountyLineEdit);
|
||||
alertAudioCounty_.SetResetButton(self_->ui->resetAlertAudioCountyButton);
|
||||
|
||||
QObject::connect(
|
||||
self_->ui->alertAudioWFOSelectButton,
|
||||
&QAbstractButton::clicked,
|
||||
self_,
|
||||
[this]()
|
||||
{
|
||||
wfoDialog_->show();
|
||||
});
|
||||
QObject::connect(wfoDialog_,
|
||||
&WFODialog::accepted,
|
||||
self_,
|
||||
[this]()
|
||||
{
|
||||
std::string wfoId = wfoDialog_->wfo_id();
|
||||
QString qWFOId = QString::fromStdString(wfoId);
|
||||
self_->ui->alertAudioWFOLineEdit->setText(qWFOId);
|
||||
|
||||
// setText does not emit the textEdited signal
|
||||
Q_EMIT self_->ui->alertAudioWFOLineEdit->textEdited(
|
||||
qWFOId);
|
||||
});
|
||||
QObject::connect(self_->ui->alertAudioWFOLineEdit,
|
||||
&QLineEdit::textChanged,
|
||||
self_,
|
||||
[this](const QString& text)
|
||||
{
|
||||
std::string wfoName =
|
||||
config::CountyDatabase::GetWFOName(
|
||||
text.toStdString());
|
||||
self_->ui->alertAudioWFOLabel->setText(
|
||||
QString::fromStdString(wfoName));
|
||||
});
|
||||
|
||||
alertAudioWFO_.SetSettingsVariable(audioSettings.alert_wfo());
|
||||
for (const auto& pair : config::CountyDatabase::GetWFOs())
|
||||
{
|
||||
self_->ui->alertAudioWFOComboBox->addItem(
|
||||
QString::fromStdString(pair.first));
|
||||
}
|
||||
alertAudioWFO_.SetEditWidget(self_->ui->alertAudioWFOComboBox);
|
||||
alertAudioWFO_.SetEditWidget(self_->ui->alertAudioWFOLineEdit);
|
||||
alertAudioWFO_.SetResetButton(self_->ui->resetAlertAudioWFOButton);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -951,9 +951,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="alertAudioWFOComboBox"/>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_29">
|
||||
<property name="text">
|
||||
|
|
@ -972,6 +969,23 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QLineEdit" name="alertAudioWFOLineEdit"/>
|
||||
</item>
|
||||
<item row="8" column="2">
|
||||
<widget class="QLabel" name="alertAudioWFOLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="3">
|
||||
<widget class="QToolButton" name="alertAudioWFOSelectButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
142
scwx-qt/source/scwx/qt/ui/wfo_dialog.cpp
Normal file
142
scwx-qt/source/scwx/qt/ui/wfo_dialog.cpp
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
#include "wfo_dialog.hpp"
|
||||
#include "ui_wfo_dialog.h"
|
||||
|
||||
#include <scwx/qt/config/county_database.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ = "scwx::qt::ui::wfo_dialog";
|
||||
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||
|
||||
class WFODialog::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl(WFODialog* self) :
|
||||
self_ {self},
|
||||
model_ {new QStandardItemModel(self)},
|
||||
proxyModel_ {new QSortFilterProxyModel(self)}
|
||||
{
|
||||
}
|
||||
~Impl() = default;
|
||||
|
||||
void UpdateModel();
|
||||
|
||||
WFODialog* self_;
|
||||
QStandardItemModel* model_;
|
||||
QSortFilterProxyModel* proxyModel_;
|
||||
|
||||
std::string selectedWFO_ {"?"};
|
||||
};
|
||||
|
||||
WFODialog::WFODialog(QWidget* parent) :
|
||||
QDialog(parent), p {std::make_unique<Impl>(this)}, ui(new Ui::WFODialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
p->proxyModel_->setSourceModel(p->model_);
|
||||
ui->wfoView->setModel(p->proxyModel_);
|
||||
ui->wfoView->setEditTriggers(
|
||||
QAbstractItemView::EditTrigger::NoEditTriggers);
|
||||
ui->wfoView->sortByColumn(0, Qt::SortOrder::AscendingOrder);
|
||||
ui->wfoView->header()->setSectionResizeMode(
|
||||
QHeaderView::ResizeMode::Stretch);
|
||||
|
||||
p->UpdateModel();
|
||||
|
||||
// Button Box
|
||||
ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)
|
||||
->setEnabled(false);
|
||||
|
||||
connect(ui->wfoView,
|
||||
&QTreeView::doubleClicked,
|
||||
this,
|
||||
[this]() { Q_EMIT accept(); });
|
||||
connect(
|
||||
ui->wfoView->selectionModel(),
|
||||
&QItemSelectionModel::selectionChanged,
|
||||
this,
|
||||
[this](const QItemSelection& selected, const QItemSelection& deselected)
|
||||
{
|
||||
if (selected.size() == 0 && deselected.size() == 0)
|
||||
{
|
||||
// Items which stay selected but change their index are not
|
||||
// included in selected and deselected. Thus, this signal might
|
||||
// be emitted with both selected and deselected empty, if only
|
||||
// the indices of selected items change.
|
||||
return;
|
||||
}
|
||||
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)
|
||||
->setEnabled(selected.size() > 0);
|
||||
|
||||
if (selected.size() > 0)
|
||||
{
|
||||
QModelIndex selectedIndex =
|
||||
p->proxyModel_->mapToSource(selected[0].indexes()[0]);
|
||||
selectedIndex = p->model_->index(selectedIndex.row(), 1);
|
||||
QVariant variantData = p->model_->data(selectedIndex);
|
||||
if (variantData.typeId() == QMetaType::QString)
|
||||
{
|
||||
p->selectedWFO_ = variantData.toString().toStdString();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger_->warn("Unexpected selection data type");
|
||||
p->selectedWFO_ = std::string {"?"};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p->selectedWFO_ = std::string {"?"};
|
||||
}
|
||||
|
||||
logger_->debug("Selected: {}", p->selectedWFO_);
|
||||
});
|
||||
}
|
||||
|
||||
WFODialog::~WFODialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
std::string WFODialog::wfo_id()
|
||||
{
|
||||
return p->selectedWFO_;
|
||||
}
|
||||
|
||||
void WFODialog::Impl::UpdateModel()
|
||||
{
|
||||
// Clear existing counties
|
||||
model_->clear();
|
||||
|
||||
// Disable OK button
|
||||
self_->ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)
|
||||
->setEnabled(false);
|
||||
|
||||
// Reset headers
|
||||
model_->setHorizontalHeaderLabels({tr("State and City"), tr("ID")});
|
||||
|
||||
QStandardItem* root = model_->invisibleRootItem();
|
||||
|
||||
// Add each wfo to the model
|
||||
for (auto& wfo : config::CountyDatabase::GetWFOs())
|
||||
{
|
||||
root->appendRow(
|
||||
{new QStandardItem(QString::fromStdString(wfo.second)),
|
||||
new QStandardItem(QString::fromStdString(wfo.first))});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
34
scwx-qt/source/scwx/qt/ui/wfo_dialog.hpp
Normal file
34
scwx-qt/source/scwx/qt/ui/wfo_dialog.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class WFODialog;
|
||||
}
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace ui
|
||||
{
|
||||
class WFODialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY_MOVE(WFODialog)
|
||||
|
||||
public:
|
||||
explicit WFODialog(QWidget* parent = nullptr);
|
||||
~WFODialog();
|
||||
|
||||
std::string wfo_id();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
Ui::WFODialog* ui;
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
101
scwx-qt/source/scwx/qt/ui/wfo_dialog.ui
Normal file
101
scwx-qt/source/scwx/qt/ui/wfo_dialog.ui
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>WFODialog</class>
|
||||
<widget class="QDialog" name="WFODialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Select WFO</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeView" name="wfoView">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="indentation">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>WFODialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>WFODialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Loading…
Add table
Add a link
Reference in a new issue