5
5
6
6
MapViewControlMenuController::MapViewControlMenuController (QObject *parent) :
7
7
QmlComponentController(parent),
8
- m_graphicsSceneView(nullptr )
8
+ m_graphicsSceneView(nullptr ),
9
+ pendingLambda_(nullptr ),
10
+ visibility_(false )
9
11
{ }
10
12
11
13
void MapViewControlMenuController::setGraphicsSceneView (GraphicsScene3dView *sceneView)
12
14
{
13
15
m_graphicsSceneView = sceneView;
16
+
17
+ if (pendingLambda_) {
18
+ pendingLambda_ ();
19
+ pendingLambda_ = nullptr ;
20
+ }
14
21
}
15
22
16
23
void MapViewControlMenuController::onVisibilityChanged (bool state)
17
24
{
18
25
qDebug () << " MapViewControlMenuController::onVisibilityChanged" << state;
19
26
27
+ visibility_ = state;
28
+
20
29
if (m_graphicsSceneView) {
21
- m_graphicsSceneView->getMapViewPtr ()->setVisible (state );
30
+ m_graphicsSceneView->getMapViewPtr ()->setVisible (visibility_ );
22
31
if (state) {
23
32
m_graphicsSceneView->updateMapView ();
24
33
}
25
34
}
35
+ else {
36
+ tryInitPendingLambda ();
37
+ }
26
38
}
27
39
void MapViewControlMenuController::onUpdateClicked ()
28
40
{
@@ -31,6 +43,9 @@ void MapViewControlMenuController::onUpdateClicked()
31
43
if (m_graphicsSceneView) {
32
44
m_graphicsSceneView->getMapViewPtr ()->update ();
33
45
}
46
+ else {
47
+ tryInitPendingLambda ();
48
+ }
34
49
}
35
50
36
51
MapView* MapViewControlMenuController::getMapViewPtr () const
@@ -45,3 +60,17 @@ void MapViewControlMenuController::findComponent()
45
60
{
46
61
m_component = m_engine->findChild <QObject*>(" mapViewControlMenu" );
47
62
}
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
+ }
0 commit comments