mirror of
https://github.com/logos-co/logos-tutorial.git
synced 2026-08-31 04:41:08 +00:00
Part 3's .rep previously declared only slots. Broaden it to cover the whole
Qt Remote Objects contract a universal UI backend can author, so the tutorial
teaches the breadth of .rep, not just call-and-return:
- SLOT(void announceVersion()) — a void / fire-and-forget slot
- PROP(QString versionEvent READONLY) — fed by a typed calc_module event
subscription armed in onContextReady()
- PROP(int computeCount READONLY) — a slot-driven counter (int PROP)
- PROP(int memory READWRITE) — a register the QML view writes back
- SIGNAL(computed(QString op, int result)) — a backend -> view push
The backend gains onContextReady() (event subscription) and a record() helper
(bumps computeCount, emits computed); the QML view gains a Connections block,
Computations / Last-op labels, and a Memory register with Store/Clear buttons
that assign backend.memory. Step 9's UI test drives each surface — the slot
return value, the int PROP (Computations: 1), the signal payload (add = 8),
and the READWRITE round-trip (Memory: 0 -> 8) — and the closing .rep pattern
table now marks every row exercised except Model.
Regenerated outputs/ (md + calc_ui_cpp sources + screenshots). Verified end to
end via the doctest chain (Part 1->2->3): 69/69 steps, UI test 14/14.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
40 lines
1.6 KiB
C++
40 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "rep_calc_ui_cpp_source.h"
|
|
#include "logos_ui_plugin_context.h"
|
|
|
|
// The whole hand-written backend. Derives:
|
|
// - CalcUiCppSimpleSource — generated from calc_ui_cpp.rep; override its
|
|
// slots (the QML replica gets each return value via Qt Remote Objects).
|
|
// - LogosUiPluginContext — supplies modules() (Qt-typed callers + typed event
|
|
// subscriptions for "dependencies") and onContextReady(). A UI plugin is a
|
|
// view, not a module, so that is all the context carries.
|
|
// The *Plugin / *Interface classes (Q_PLUGIN_METADATA, initLogos wiring,
|
|
// QtRO registration) are generated around it.
|
|
class CalcUiCppBackend : public CalcUiCppSimpleSource,
|
|
public LogosUiPluginContext
|
|
{
|
|
public:
|
|
// Slots from calc_ui_cpp.rep — each delegates to calc_module.
|
|
int add(int a, int b) override;
|
|
int multiply(int a, int b) override;
|
|
int factorial(int n) override;
|
|
int fibonacci(int n) override;
|
|
QString libVersion() override;
|
|
|
|
// Tells calc_module to emit its `versionReady` event.
|
|
void announceVersion() override;
|
|
|
|
// Fires once when ui-host hands the plugin its LogosAPI — the
|
|
// typed dependency surface is live, so we arm the event
|
|
// subscription here (before the view's first call).
|
|
void onContextReady() override;
|
|
|
|
private:
|
|
// Feeds the non-slot surfaces of the .rep after each calculation:
|
|
// bumps the computeCount PROP (setComputeCount, generated) and
|
|
// emits the `computed` SIGNAL. The READWRITE `memory` PROP is
|
|
// driven from QML, so the backend doesn't have to touch it.
|
|
void record(const QString& op, int result);
|
|
};
|