morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
inspector.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4#include <functional>
5#include <memory>
6#include <string>
7
8#include "../ui/inspector.hpp"
9
10/// @file
11/// @brief `morph::qt_quick::InspectorWindow`: the development inspector's window (spec 6 §21), opened with
12/// Ctrl+Shift+I over the focused screen.
13///
14/// Specified in `docs/spec/ui/inspector.md`.
15
16class QQuickWindow;
17
18namespace morph::qt_quick {
19
20/// @brief Hands the inspector over the focused screen to a visitor, or calls nothing when no screen is shown:
21/// `ui::MountedShell::inspectFocused`, bound to a shell.
22using InspectFocused = std::function<void(std::function<void(ui::Inspector& inspector)> const& visit)>;
23
24/// @brief A window that shows the focused screen's mounted nodes with their evaluated properties, its queries and
25/// mutations with a refetch button each, its command log and the reactive counters.
26///
27/// It reads the screen through `ui::Inspector` each time it refreshes, twice a second while it is shown, and keeps
28/// nothing of it in between, so a screen that closes or is remounted leaves nothing behind. Its refetch button runs
29/// the document's `refetch` command, as a user's event would. Use it on the GUI thread.
31public:
32 /// @brief A hidden inspector window.
33 /// @param focused Where it finds the focused screen's inspector.
36 InspectorWindow(InspectorWindow const&) = delete;
37 InspectorWindow& operator=(InspectorWindow const&) = delete;
39 InspectorWindow& operator=(InspectorWindow&&) = delete;
40
41 /// @brief Makes Ctrl+Shift+I in @p window show or hide this inspector, whichever item has focus.
42 /// @param window The application's window; it outlives the inspector.
43 void attachTo(QQuickWindow& window);
44
45 /// @brief Shows the window if it is hidden, hides it otherwise.
46 void toggle();
47
48 /// @brief Hides the window and stops refreshing it.
49 void hide();
50
51 /// @brief Whether the window is shown.
52 /// @return It.
53 [[nodiscard]] bool isVisible() const;
54
55 /// @brief Reads the focused screen again and redraws.
56 void refresh();
57
58 /// @brief What the window shows, as plain text, section by section: what a test reads.
59 /// @return The text.
60 [[nodiscard]] std::string text() const;
61
62 /// @brief What the refetch button of a query does: runs `{"refetch": "<query>"}` on the focused screen.
63 /// @param query The query's name.
64 void refetch(std::string const& query);
65
66private:
67 struct Impl;
68 std::unique_ptr<Impl> _impl;
69};
70
71} // namespace morph::qt_quick
void toggle()
Shows the window if it is hidden, hides it otherwise.
std::string text() const
What the window shows, as plain text, section by section: what a test reads.
bool isVisible() const
Whether the window is shown.
void refresh()
Reads the focused screen again and redraws.
InspectorWindow(InspectFocused focused)
A hidden inspector window.
void hide()
Hides the window and stops refreshing it.
void refetch(std::string const &query)
What the refetch button of a query does: runs {"refetch": "<query>"} on the focused screen.
void attachTo(QQuickWindow &window)
Makes Ctrl+Shift+I in window show or hide this inspector, whichever item has focus.
The development inspector over one mounted screen: its mounted nodes, its queries and mutations,...
Definition inspector.hpp:70
std::function< void(std::function< void(ui::Inspector &inspector)> const &visit)> InspectFocused
Hands the inspector over the focused screen to a visitor, or calls nothing when no screen is shown: u...
Definition inspector.hpp:22
morph::ui::Inspector: the development inspector's read-only view of a mounted screen (spec 6 §21).