mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:40:05 +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 "./ui_main_window.h"
|
||||
|
||||
#include <scwx/qt/manager/settings_manager.hpp>
|
||||
#include <scwx/qt/map/map_widget.hpp>
|
||||
#include <scwx/qt/ui/flow_layout.hpp>
|
||||
#include <scwx/common/characters.hpp>
|
||||
#include <scwx/common/products.hpp>
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QToolButton>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
|
@ -26,13 +28,18 @@ class MainWindowImpl : public QObject
|
|||
public:
|
||||
explicit MainWindowImpl(MainWindow* mainWindow) :
|
||||
mainWindow_ {mainWindow},
|
||||
map_ {nullptr},
|
||||
settings_ {},
|
||||
activeMap_ {nullptr},
|
||||
maps_ {},
|
||||
elevationCuts_ {},
|
||||
resizeElevationButtons_ {false}
|
||||
{
|
||||
settings_.setCacheDatabasePath("/tmp/mbgl-cache.db");
|
||||
settings_.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
|
||||
}
|
||||
~MainWindowImpl() = default;
|
||||
|
||||
void ConfigureMapLayout();
|
||||
void InitializeConnections();
|
||||
void SelectElevation(map::MapWidget* mapWidget, float elevation);
|
||||
void SelectRadarProduct(common::Level2Product product);
|
||||
|
|
@ -40,8 +47,10 @@ public:
|
|||
void UpdateRadarProductSettings(map::MapWidget* mapWidget);
|
||||
|
||||
MainWindow* mainWindow_;
|
||||
map::MapWidget* map_;
|
||||
QMapboxGLSettings settings_;
|
||||
map::MapWidget* activeMap_;
|
||||
|
||||
std::vector<map::MapWidget*> maps_;
|
||||
std::vector<float> elevationCuts_;
|
||||
|
||||
bool resizeElevationButtons_;
|
||||
|
|
@ -54,13 +63,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QMapboxGLSettings settings;
|
||||
settings.setCacheDatabasePath("/tmp/mbgl-cache.db");
|
||||
settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024);
|
||||
|
||||
p->map_ = new map::MapWidget(settings);
|
||||
|
||||
ui->centralwidget->layout()->addWidget(p->map_);
|
||||
p->ConfigureMapLayout();
|
||||
|
||||
// Add Level 2 Products
|
||||
QLayout* level2Layout = new ui::FlowLayout();
|
||||
|
|
@ -162,13 +165,64 @@ void MainWindow::on_actionExit_triggered()
|
|||
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()
|
||||
{
|
||||
connect(
|
||||
map_,
|
||||
activeMap_,
|
||||
&map::MapWidget::RadarSweepUpdated,
|
||||
this,
|
||||
[this]() { UpdateRadarProductSettings(map_); },
|
||||
[this]() { UpdateRadarProductSettings(activeMap_); },
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +254,7 @@ void MainWindowImpl::SelectRadarProduct(common::Level2Product product)
|
|||
}
|
||||
}
|
||||
|
||||
map_->SelectRadarProduct(product);
|
||||
activeMap_->SelectRadarProduct(product);
|
||||
}
|
||||
|
||||
void MainWindowImpl::UpdateElevationSelection(float elevation)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public:
|
|||
radarProductView_ {nullptr},
|
||||
overlayLayer_ {nullptr},
|
||||
lastPos_(),
|
||||
currentStyleIndex_ {0},
|
||||
frameDraws_(0)
|
||||
{
|
||||
}
|
||||
|
|
@ -68,6 +69,7 @@ public:
|
|||
std::shared_ptr<OverlayLayer> overlayLayer_;
|
||||
|
||||
QPointF lastPos_;
|
||||
uint8_t currentStyleIndex_;
|
||||
|
||||
uint64_t frameDraws_;
|
||||
};
|
||||
|
|
@ -156,22 +158,25 @@ qreal MapWidget::pixelRatio()
|
|||
|
||||
void MapWidget::changeStyle()
|
||||
{
|
||||
static uint8_t currentStyleIndex = 0;
|
||||
|
||||
auto& styles = mapboxStyles_;
|
||||
|
||||
p->map_->setStyleUrl(styles[currentStyleIndex].first.c_str());
|
||||
p->map_->setStyleUrl(styles[p->currentStyleIndex_].first.c_str());
|
||||
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()
|
||||
{
|
||||
if (p->radarProductView_ == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Improve this
|
||||
if (p->map_->layerExists("radar"))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue