Skip to content

Commit

Permalink
Add select Map Layers to View menu
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulat committed Jan 15, 2024
1 parent 54047b7 commit 9e3b291
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 5 deletions.
95 changes: 95 additions & 0 deletions scwx-qt/source/scwx/qt/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <scwx/qt/manager/update_manager.hpp>
#include <scwx/qt/map/map_provider.hpp>
#include <scwx/qt/map/map_widget.hpp>
#include <scwx/qt/model/layer_model.hpp>
#include <scwx/qt/model/radar_site_model.hpp>
#include <scwx/qt/settings/general_settings.hpp>
#include <scwx/qt/settings/map_settings.hpp>
Expand All @@ -36,6 +37,8 @@
#include <scwx/util/logger.hpp>
#include <scwx/util/time.hpp>

#include <set>

#include <boost/asio/post.hpp>
#include <boost/asio/thread_pool.hpp>
#include <QDesktopServices>
Expand Down Expand Up @@ -142,6 +145,7 @@ class MainWindowImpl : public QObject
void ConnectMapSignals();
void ConnectOtherSignals();
void HandleFocusChange(QWidget* focused);
void InitializeLayerDisplayActions();
void PopulateMapStyles();
void SelectElevation(map::MapWidget* mapWidget, float elevation);
void SelectRadarProduct(map::MapWidget* mapWidget,
Expand Down Expand Up @@ -197,11 +201,17 @@ class MainWindowImpl : public QObject
std::shared_ptr<manager::TimelineManager> timelineManager_;
std::shared_ptr<manager::UpdateManager> updateManager_;

std::shared_ptr<model::LayerModel> layerModel_ {
model::LayerModel::Instance()};
std::shared_ptr<model::RadarSiteModel> radarSiteModel_ {
model::RadarSiteModel::Instance()};
std::map<std::string, std::shared_ptr<QAction>> radarSitePresetsActions_ {};
QMenu* radarSitePresetsMenu_ {nullptr};

std::set<std::tuple<types::LayerType, types::LayerDescription, QAction*>>
layerActions_ {};
bool layerActionsInitialized_ {false};

std::vector<map::MapWidget*> maps_;

std::chrono::system_clock::time_point volumeTime_ {};
Expand All @@ -221,6 +231,8 @@ MainWindow::MainWindow(QWidget* parent) :
{
ui->setupUi(this);

p->InitializeLayerDisplayActions();

// Assign the bottom left corner to the left dock widget
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);

Expand Down Expand Up @@ -494,6 +506,26 @@ void MainWindow::on_actionExit_triggered()
close();
}

void MainWindow::on_actionColorTable_triggered(bool checked)
{
p->layerModel_->SetLayerDisplayed(types::LayerType::Information,
types::InformationLayer::ColorTable,
checked);
}

void MainWindow::on_actionRadarRange_triggered(bool checked)
{
p->layerModel_->SetLayerDisplayed(
types::LayerType::Data, types::DataLayer::RadarRange, checked);
}

void MainWindow::on_actionRadarSites_triggered(bool checked)
{
p->layerModel_->SetLayerDisplayed(types::LayerType::Information,
types::InformationLayer::RadarSite,
checked);
}

void MainWindow::on_actionPlacefileManager_triggered()
{
p->placefileDialog_->show();
Expand Down Expand Up @@ -989,6 +1021,39 @@ void MainWindowImpl::ConnectOtherSignals()
&MainWindow::ActiveMapMoved,
radarSiteDialog_,
&ui::RadarSiteDialog::HandleMapUpdate);
connect(layerModel_.get(),
&model::LayerModel::LayerDisplayChanged,
this,
[this](types::LayerInfo layer)
{
// Find matching layer action
auto it =
std::find_if(layerActions_.begin(),
layerActions_.end(),
[&](const auto& layerAction)
{
const auto& [type, description, action] =
layerAction;
return layer.type_ == type &&
layer.description_ == description;
});

// If matching layer action was found
if (it != layerActions_.end())
{
// Check the action if the layer is displayed on any map
bool anyDisplayed = std::find(layer.displayed_.begin(),
layer.displayed_.end(),
true) != layer.displayed_.end();

auto& action = std::get<2>(*it);
action->setChecked(anyDisplayed);
}
});
connect(layerModel_.get(),
&QAbstractItemModel::modelReset,
this,
[this]() { InitializeLayerDisplayActions(); });
connect(radarSiteDialog_,
&ui::RadarSiteDialog::accepted,
this,
Expand Down Expand Up @@ -1046,6 +1111,36 @@ void MainWindowImpl::ConnectOtherSignals()
clockTimer_.start(1000);
}

void MainWindowImpl::InitializeLayerDisplayActions()
{
if (!layerActionsInitialized_)
{
layerActions_.emplace(types::LayerType::Information,
types::InformationLayer::ColorTable,
mainWindow_->ui->actionColorTable);
layerActions_.emplace(types::LayerType::Information,
types::InformationLayer::RadarSite,
mainWindow_->ui->actionRadarSites);
layerActions_.emplace(types::LayerType::Data,
types::DataLayer::RadarRange,
mainWindow_->ui->actionRadarRange);
layerActionsInitialized_ = true;
}

for (auto& layerAction : layerActions_)
{
auto& [type, description, action] = layerAction;

types::LayerInfo layer = layerModel_->GetLayerInfo(type, description);

bool anyDisplayed =
std::find(layer.displayed_.begin(), layer.displayed_.end(), true) !=
layer.displayed_.end();

action->setChecked(anyDisplayed);
}
}

void MainWindowImpl::AddRadarSitePreset(const std::string& siteId)
{
auto radarSite = config::RadarSite::Get(siteId);
Expand Down
3 changes: 3 additions & 0 deletions scwx-qt/source/scwx/qt/main/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ private slots:
void on_actionOpenTextEvent_triggered();
void on_actionSettings_triggered();
void on_actionExit_triggered();
void on_actionColorTable_triggered(bool checked);
void on_actionRadarRange_triggered(bool checked);
void on_actionRadarSites_triggered(bool checked);
void on_actionPlacefileManager_triggered();
void on_actionLayerManager_triggered();
void on_actionImGuiDebug_triggered();
Expand Down
36 changes: 35 additions & 1 deletion scwx-qt/source/scwx/qt/main/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@
<property name="title">
<string>&amp;View</string>
</property>
<widget class="QMenu" name="menuMapLayers">
<property name="title">
<string>&amp;Map Layers</string>
</property>
<addaction name="actionColorTable"/>
<addaction name="actionRadarSites"/>
<addaction name="actionRadarRange"/>
</widget>
<addaction name="actionRadarToolbox"/>
<addaction name="actionAlerts"/>
<addaction name="separator"/>
<addaction name="menuMapLayers"/>
</widget>
<widget class="QMenu" name="menuDebug">
<property name="title">
Expand Down Expand Up @@ -166,7 +176,7 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0,0">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0">
<item row="0" column="2">
<widget class="QLabel" name="radarSiteValueLabel">
<property name="sizePolicy">
Expand Down Expand Up @@ -447,6 +457,30 @@
<string>Dump &amp;Layer List</string>
</property>
</action>
<action name="actionRadarRange">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Radar &amp;Range</string>
</property>
</action>
<action name="actionColorTable">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Color Table</string>
</property>
</action>
<action name="actionRadarSites">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Radar &amp;Sites</string>
</property>
</action>
</widget>
<resources>
<include location="../../../../scwx-qt.qrc"/>
Expand Down
53 changes: 53 additions & 0 deletions scwx-qt/source/scwx/qt/model/layer_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,63 @@ void LayerModel::Impl::WriteLayerSettings()
util::json::WriteJsonFile(layerSettingsPath_, layerJson);
}

types::LayerInfo
LayerModel::GetLayerInfo(types::LayerType type,
types::LayerDescription description) const
{
// Find the matching layer
auto it = std::find_if(p->layers_.begin(),
p->layers_.end(),
[&](const types::LayerInfo& layer) {
return layer.type_ == type &&
layer.description_ == description;
});
if (it != p->layers_.end())
{
// Return the layer info
return *it;
}

return {};
}

types::LayerVector LayerModel::GetLayers() const
{
return p->layers_;
}

void LayerModel::SetLayerDisplayed(types::LayerType type,
types::LayerDescription description,
bool displayed)
{
// Find the matching layer
auto it = std::find_if(p->layers_.begin(),
p->layers_.end(),
[&](const types::LayerInfo& layer) {
return layer.type_ == type &&
layer.description_ == description;
});

if (it != p->layers_.end())
{
// Find the row
const int row = std::distance(p->layers_.begin(), it);
QModelIndex topLeft =
createIndex(row, static_cast<int>(Column::DisplayMap1));
QModelIndex bottomRight =
createIndex(row, static_cast<int>(Column::DisplayMap4));

// Set the layer to displayed
for (std::size_t i = 0; i < kMapCount_; ++i)
{
it->displayed_[i] = displayed;
}

// Notify observers
Q_EMIT dataChanged(topLeft, bottomRight);
}
}

void LayerModel::ResetLayers()
{
// Initialize a new layer vector from the default
Expand Down Expand Up @@ -751,6 +803,7 @@ bool LayerModel::setData(const QModelIndex& index,
if (result)
{
Q_EMIT dataChanged(index, index);
Q_EMIT LayerDisplayChanged(layer);
}

return result;
Expand Down
9 changes: 9 additions & 0 deletions scwx-qt/source/scwx/qt/model/layer_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace model

class LayerModel : public QAbstractTableModel
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(LayerModel)

public:
Expand All @@ -36,7 +37,12 @@ class LayerModel : public QAbstractTableModel
explicit LayerModel(QObject* parent = nullptr);
~LayerModel();

types::LayerInfo GetLayerInfo(types::LayerType type,
types::LayerDescription description) const;
types::LayerVector GetLayers() const;
void SetLayerDisplayed(types::LayerType type,
types::LayerDescription description,
bool displayed);

void ResetLayers();

Expand Down Expand Up @@ -77,6 +83,9 @@ class LayerModel : public QAbstractTableModel

static std::shared_ptr<LayerModel> Instance();

signals:
void LayerDisplayChanged(types::LayerInfo layer);

private:
class Impl;
std::unique_ptr<Impl> p;
Expand Down
8 changes: 4 additions & 4 deletions scwx-qt/source/scwx/qt/ui/layer_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class LayerDialogImpl
void UpdateMapDisplayColumns();
void UpdateMoveButtonsEnabled();

std::vector<int> GetSelectedRows();
std::vector<std::vector<int>> GetContiguousRows();
std::vector<int> GetSelectedRows() const;
std::vector<std::vector<int>> GetContiguousRows() const;

LayerDialog* self_;
std::shared_ptr<model::LayerModel> layerModel_;
Expand Down Expand Up @@ -247,7 +247,7 @@ void LayerDialogImpl::ConnectSignals()
});
}

std::vector<int> LayerDialogImpl::GetSelectedRows()
std::vector<int> LayerDialogImpl::GetSelectedRows() const
{
QModelIndexList selectedRows =
self_->ui->layerTreeView->selectionModel()->selectedRows();
Expand All @@ -260,7 +260,7 @@ std::vector<int> LayerDialogImpl::GetSelectedRows()
return rows;
}

std::vector<std::vector<int>> LayerDialogImpl::GetContiguousRows()
std::vector<std::vector<int>> LayerDialogImpl::GetContiguousRows() const
{
std::vector<std::vector<int>> contiguousRows {};
std::vector<int> currentContiguousRows {};
Expand Down

0 comments on commit 9e3b291

Please sign in to comment.