Skip to content

Commit 4cd2544

Browse files
committedJan 17, 2025
saving on/off mapView state
Signed-off-by: Evgeniy Saltykov <evgeniysaltykov38@gmail.com>
1 parent 834f67e commit 4cd2544

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed
 

‎QML/Scene3DToolbar.qml

+9
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,15 @@ ColumnLayout {
13701370
}
13711371
}
13721372
*/
1373+
1374+
Component.onCompleted: {
1375+
MapViewControlMenuController.onVisibilityChanged(checked)
1376+
}
1377+
1378+
1379+
Settings {
1380+
property alias mapViewCheckButton: mapViewCheckButton.checked
1381+
}
13731382
}
13741383

13751384
ButtonGroup{

‎controllers/map_view_control_menu_controller.cpp

+31-2
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,36 @@
55

66
MapViewControlMenuController::MapViewControlMenuController(QObject *parent) :
77
QmlComponentController(parent),
8-
m_graphicsSceneView(nullptr)
8+
m_graphicsSceneView(nullptr),
9+
pendingLambda_(nullptr),
10+
visibility_(false)
911
{ }
1012

1113
void MapViewControlMenuController::setGraphicsSceneView(GraphicsScene3dView *sceneView)
1214
{
1315
m_graphicsSceneView = sceneView;
16+
17+
if (pendingLambda_) {
18+
pendingLambda_();
19+
pendingLambda_ = nullptr;
20+
}
1421
}
1522

1623
void MapViewControlMenuController::onVisibilityChanged(bool state)
1724
{
1825
qDebug() << "MapViewControlMenuController::onVisibilityChanged" << state;
1926

27+
visibility_ = state;
28+
2029
if (m_graphicsSceneView) {
21-
m_graphicsSceneView->getMapViewPtr()->setVisible(state);
30+
m_graphicsSceneView->getMapViewPtr()->setVisible(visibility_);
2231
if (state) {
2332
m_graphicsSceneView->updateMapView();
2433
}
2534
}
35+
else {
36+
tryInitPendingLambda();
37+
}
2638
}
2739
void MapViewControlMenuController::onUpdateClicked()
2840
{
@@ -31,6 +43,9 @@ void MapViewControlMenuController::onUpdateClicked()
3143
if (m_graphicsSceneView) {
3244
m_graphicsSceneView->getMapViewPtr()->update();
3345
}
46+
else {
47+
tryInitPendingLambda();
48+
}
3449
}
3550

3651
MapView* MapViewControlMenuController::getMapViewPtr() const
@@ -45,3 +60,17 @@ void MapViewControlMenuController::findComponent()
4560
{
4661
m_component = m_engine->findChild<QObject*>("mapViewControlMenu");
4762
}
63+
64+
void MapViewControlMenuController::tryInitPendingLambda()
65+
{
66+
if (!pendingLambda_) {
67+
pendingLambda_ = [this] () -> void {
68+
if (m_graphicsSceneView) {
69+
if (auto mapPtr = m_graphicsSceneView->getMapViewPtr(); mapPtr) {
70+
mapPtr->setVisible(visibility_);
71+
mapPtr->update();
72+
}
73+
}
74+
};
75+
}
76+
}

‎controllers/map_view_control_menu_controller.h

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class MapViewControlMenuController : public QmlComponentController
2323
virtual void findComponent() override;
2424

2525
private:
26+
void tryInitPendingLambda();
27+
28+
/*data*/
2629
MapView* getMapViewPtr() const;
2730
GraphicsScene3dView* m_graphicsSceneView;
31+
std::function<void()> pendingLambda_;
32+
bool visibility_;
2833
};

0 commit comments

Comments
 (0)
Please sign in to comment.