mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 04:50:04 +00:00
Adding gridded map
This commit is contained in:
parent
2f47f0c229
commit
372848c25f
2 changed files with 79 additions and 20 deletions
|
|
@ -1,11 +1,13 @@
|
||||||
#include "main_window.hpp"
|
#include "main_window.hpp"
|
||||||
#include "./ui_main_window.h"
|
#include "./ui_main_window.h"
|
||||||
|
|
||||||
|
#include <scwx/qt/manager/settings_manager.hpp>
|
||||||
#include <scwx/qt/map/map_widget.hpp>
|
#include <scwx/qt/map/map_widget.hpp>
|
||||||
#include <scwx/qt/ui/flow_layout.hpp>
|
#include <scwx/qt/ui/flow_layout.hpp>
|
||||||
#include <scwx/common/characters.hpp>
|
#include <scwx/common/characters.hpp>
|
||||||
#include <scwx/common/products.hpp>
|
#include <scwx/common/products.hpp>
|
||||||
|
|
||||||
|
#include <QSplitter>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
@ -26,23 +28,30 @@ class MainWindowImpl : public QObject
|
||||||
public:
|
public:
|
||||||
explicit MainWindowImpl(MainWindow* mainWindow) :
|
explicit MainWindowImpl(MainWindow* mainWindow) :
|
||||||
mainWindow_ {mainWindow},
|
mainWindow_ {mainWindow},
|
||||||
map_ {nullptr},
|
settings_ {},
|
||||||
|
activeMap_ {nullptr},
|
||||||
|
maps_ {},
|
||||||
elevationCuts_ {},
|
elevationCuts_ {},
|
||||||
resizeElevationButtons_ {false}
|
resizeElevationButtons_ {false}
|
||||||
{
|
{
|
||||||
|
settings_.setCacheDatabasePath("/tmp/mbgl-cache.db");
|
||||||
|
settings_.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
|
||||||
}
|
}
|
||||||
~MainWindowImpl() = default;
|
~MainWindowImpl() = default;
|
||||||
|
|
||||||
|
void ConfigureMapLayout();
|
||||||
void InitializeConnections();
|
void InitializeConnections();
|
||||||
void SelectElevation(map::MapWidget* mapWidget, float elevation);
|
void SelectElevation(map::MapWidget* mapWidget, float elevation);
|
||||||
void SelectRadarProduct(common::Level2Product product);
|
void SelectRadarProduct(common::Level2Product product);
|
||||||
void UpdateElevationSelection(float elevation);
|
void UpdateElevationSelection(float elevation);
|
||||||
void UpdateRadarProductSettings(map::MapWidget* mapWidget);
|
void UpdateRadarProductSettings(map::MapWidget* mapWidget);
|
||||||
|
|
||||||
MainWindow* mainWindow_;
|
MainWindow* mainWindow_;
|
||||||
map::MapWidget* map_;
|
QMapboxGLSettings settings_;
|
||||||
|
map::MapWidget* activeMap_;
|
||||||
|
|
||||||
std::vector<float> elevationCuts_;
|
std::vector<map::MapWidget*> maps_;
|
||||||
|
std::vector<float> elevationCuts_;
|
||||||
|
|
||||||
bool resizeElevationButtons_;
|
bool resizeElevationButtons_;
|
||||||
};
|
};
|
||||||
|
|
@ -54,13 +63,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
QMapboxGLSettings settings;
|
p->ConfigureMapLayout();
|
||||||
settings.setCacheDatabasePath("/tmp/mbgl-cache.db");
|
|
||||||
settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
|
|
||||||
|
|
||||||
p->map_ = new map::MapWidget(settings);
|
|
||||||
|
|
||||||
ui->centralwidget->layout()->addWidget(p->map_);
|
|
||||||
|
|
||||||
// Add Level 2 Products
|
// Add Level 2 Products
|
||||||
QLayout* level2Layout = new ui::FlowLayout();
|
QLayout* level2Layout = new ui::FlowLayout();
|
||||||
|
|
@ -162,13 +165,64 @@ void MainWindow::on_actionExit_triggered()
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindowImpl::ConfigureMapLayout()
|
||||||
|
{
|
||||||
|
auto generalSettings = manager::SettingsManager::general_settings();
|
||||||
|
|
||||||
|
const int64_t gridWidth = generalSettings->grid_width();
|
||||||
|
const int64_t gridHeight = generalSettings->grid_height();
|
||||||
|
const int64_t mapCount = gridWidth * gridHeight;
|
||||||
|
|
||||||
|
size_t mapIndex = 0;
|
||||||
|
|
||||||
|
QSplitter* vs = new QSplitter(Qt::Vertical);
|
||||||
|
vs->setHandleWidth(1);
|
||||||
|
|
||||||
|
maps_.resize(mapCount);
|
||||||
|
|
||||||
|
auto MoveSplitter = [=](int pos, int index) {
|
||||||
|
QSplitter* s = dynamic_cast<QSplitter*>(sender());
|
||||||
|
|
||||||
|
if (s != nullptr)
|
||||||
|
{
|
||||||
|
auto sizes = s->sizes();
|
||||||
|
for (QSplitter* hs : vs->findChildren<QSplitter*>())
|
||||||
|
{
|
||||||
|
hs->setSizes(sizes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int64_t y = 0; y < gridHeight; y++)
|
||||||
|
{
|
||||||
|
QSplitter* hs = new QSplitter(vs);
|
||||||
|
hs->setHandleWidth(1);
|
||||||
|
|
||||||
|
for (int64_t x = 0; x < gridWidth; x++, mapIndex++)
|
||||||
|
{
|
||||||
|
if (maps_.at(mapIndex) == nullptr)
|
||||||
|
{
|
||||||
|
maps_[mapIndex] = new map::MapWidget(settings_);
|
||||||
|
}
|
||||||
|
|
||||||
|
hs->addWidget(maps_[mapIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(hs, &QSplitter::splitterMoved, this, MoveSplitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
mainWindow_->ui->centralwidget->layout()->addWidget(vs);
|
||||||
|
|
||||||
|
activeMap_ = maps_.at(0);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindowImpl::InitializeConnections()
|
void MainWindowImpl::InitializeConnections()
|
||||||
{
|
{
|
||||||
connect(
|
connect(
|
||||||
map_,
|
activeMap_,
|
||||||
&map::MapWidget::RadarSweepUpdated,
|
&map::MapWidget::RadarSweepUpdated,
|
||||||
this,
|
this,
|
||||||
[this]() { UpdateRadarProductSettings(map_); },
|
[this]() { UpdateRadarProductSettings(activeMap_); },
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +254,7 @@ void MainWindowImpl::SelectRadarProduct(common::Level2Product product)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map_->SelectRadarProduct(product);
|
activeMap_->SelectRadarProduct(product);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowImpl::UpdateElevationSelection(float elevation)
|
void MainWindowImpl::UpdateElevationSelection(float elevation)
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ public:
|
||||||
radarProductView_ {nullptr},
|
radarProductView_ {nullptr},
|
||||||
overlayLayer_ {nullptr},
|
overlayLayer_ {nullptr},
|
||||||
lastPos_(),
|
lastPos_(),
|
||||||
|
currentStyleIndex_ {0},
|
||||||
frameDraws_(0)
|
frameDraws_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +69,7 @@ public:
|
||||||
std::shared_ptr<OverlayLayer> overlayLayer_;
|
std::shared_ptr<OverlayLayer> overlayLayer_;
|
||||||
|
|
||||||
QPointF lastPos_;
|
QPointF lastPos_;
|
||||||
|
uint8_t currentStyleIndex_;
|
||||||
|
|
||||||
uint64_t frameDraws_;
|
uint64_t frameDraws_;
|
||||||
};
|
};
|
||||||
|
|
@ -156,22 +158,25 @@ qreal MapWidget::pixelRatio()
|
||||||
|
|
||||||
void MapWidget::changeStyle()
|
void MapWidget::changeStyle()
|
||||||
{
|
{
|
||||||
static uint8_t currentStyleIndex = 0;
|
|
||||||
|
|
||||||
auto& styles = mapboxStyles_;
|
auto& styles = mapboxStyles_;
|
||||||
|
|
||||||
p->map_->setStyleUrl(styles[currentStyleIndex].first.c_str());
|
p->map_->setStyleUrl(styles[p->currentStyleIndex_].first.c_str());
|
||||||
setWindowTitle(QString("Mapbox GL: ") +
|
setWindowTitle(QString("Mapbox GL: ") +
|
||||||
styles[currentStyleIndex].second.c_str());
|
styles[p->currentStyleIndex_].second.c_str());
|
||||||
|
|
||||||
if (++currentStyleIndex == styles.size())
|
if (++p->currentStyleIndex_ == styles.size())
|
||||||
{
|
{
|
||||||
currentStyleIndex = 0;
|
p->currentStyleIndex_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidget::AddLayers()
|
void MapWidget::AddLayers()
|
||||||
{
|
{
|
||||||
|
if (p->radarProductView_ == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Improve this
|
// TODO: Improve this
|
||||||
if (p->map_->layerExists("radar"))
|
if (p->map_->layerExists("radar"))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue