Skip to content

Commit 963ab22

Browse files
feat(toolbox, dialog): remove_data_source slot + WidgetData list-item colors
Two related ABI additions for the upcoming Filter Editor toolbox panel: 1. remove_data_source runtime-host slot Add an optional tail slot remove_data_source(handle) to PJ_toolbox_runtime_host_vtable_t so a toolbox can drop a data source it created via create_data_source — closes the create/notify/remove triangle on the toolbox runtime host. Currently the immediate driver is the Mosaico Cancel path, which already flags the gap in mosaico_dialog.cpp; the slot also unblocks toolbox_filter_editor's Reset flow on the staged write path. 2. WidgetData setListItemColors / listItemColors Add a per-item foreground-color channel to the WidgetData dialog protocol so plugins (concretely the Filter Editor dialog) can color source-list entries to match the curve colors in the plot. Mirrored by the host in widget_data_view so the dialog engine can read it back when rebuilding the Qt model. ABI: both are tail-appended optional additions, no field reorder, no struct shrink. ToolboxRuntimeHostView::removeDataSource() guards the read with PJ_HAS_TAIL_SLOT; older hosts no-op for the new slot and older plugins ignore it. WidgetData additions follow the same backward-compatible pattern. Test plan - abidiff against baseline reports additions only. - Existing toolbox_plugin_test builds and passes; the host vtable initializer gains .remove_data_source = nullptr. - Downstream plugin (Filter Editor) consumes both additions in pj-official-plugins#141 + PlotJuggler/PJ4#160.
1 parent 0c3aa51 commit 963ab22

5 files changed

Lines changed: 33 additions & 0 deletions

File tree

pj_base/include/pj_base/sdk/toolbox_plugin_base.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ class ToolboxRuntimeHostView {
5656
}
5757
}
5858

59+
/// Ask the host to remove a data source this toolbox created (its derived
60+
/// topics leave the catalog). No-op on hosts that predate this slot.
61+
void removeDataSource(PJ_data_source_handle_t handle) const {
62+
if (valid() && PJ_HAS_TAIL_SLOT(PJ_toolbox_runtime_host_vtable_t, host_.vtable, remove_data_source)) {
63+
host_.vtable->remove_data_source(host_.ctx, handle);
64+
}
65+
}
66+
5967
[[nodiscard]] const PJ_toolbox_runtime_host_t& raw() const {
6068
return host_;
6169
}

pj_base/include/pj_base/toolbox_protocol.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ typedef struct PJ_toolbox_runtime_host_vtable_t {
7474

7575
/** [thread-safe] Notify the host that data has been modified; host refreshes UI. */
7676
void (*notify_data_changed)(void* ctx) PJ_NOEXCEPT;
77+
78+
/* ====================================================================
79+
* Tail slots beyond here are OPTIONAL (added after v4.0). Plugins MUST
80+
* guard reads via PJ_HAS_TAIL_SLOT(struct_size + nullability).
81+
* ==================================================================== */
82+
83+
/** [thread-safe] Remove a data source the toolbox previously created via the
84+
* write host's create_data_source, so its derived topics disappear from the
85+
* host catalog — a clean reset that leaves no residue. The host tombstones
86+
* the data source's topics; cached reader handles are not invalidated.
87+
* Optional tail slot: hosts may omit it, so plugins guard with
88+
* PJ_HAS_TAIL_SLOT(PJ_toolbox_runtime_host_vtable_t, vtable, remove_data_source). */
89+
void (*remove_data_source)(void* ctx, PJ_data_source_handle_t handle) PJ_NOEXCEPT;
7790
} PJ_toolbox_runtime_host_vtable_t;
7891

7992
typedef struct {

pj_plugins/dialog_protocol/include/pj_plugins/host/widget_data_view.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class WidgetDataView {
7575
[[nodiscard]] std::optional<std::vector<std::string>> selectedItems(std::string_view name) const {
7676
return getStringArray(name, "selected_items");
7777
}
78+
[[nodiscard]] std::optional<std::vector<std::string>> listItemColors(std::string_view name) const {
79+
return getStringArray(name, "list_item_colors");
80+
}
7881

7982
// --- QTableWidget ---
8083
[[nodiscard]] std::optional<std::vector<std::string>> tableHeaders(std::string_view name) const {

pj_plugins/dialog_protocol/include/pj_plugins/sdk/widget_data.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ class WidgetData {
9393
return *this;
9494
}
9595

96+
// Set foreground colors for QListWidget items, parallel to the items vector
97+
// set by setListItems. Each entry is a CSS color string (e.g. "#ff0000") or
98+
// empty to use the default palette color. Size must match the items vector.
99+
WidgetData& setListItemColors(std::string_view name, const std::vector<std::string>& colors) {
100+
entry(name)["list_item_colors"] = colors;
101+
return *this;
102+
}
103+
96104
// --- QTableWidget ---
97105
WidgetData& setTableHeaders(std::string_view name, const std::vector<std::string>& headers) {
98106
entry(name)["headers"] = headers;

pj_plugins/tests/toolbox_plugin_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ PJ_toolbox_runtime_host_t makeRuntimeHost(RuntimeState* state) {
103103
.struct_size = sizeof(PJ_toolbox_runtime_host_vtable_t),
104104
.report_message = rhReportMessage,
105105
.notify_data_changed = rhNotifyDataChanged,
106+
.remove_data_source = nullptr,
106107
};
107108
return PJ_toolbox_runtime_host_t{.ctx = state, .vtable = &vtable};
108109
}

0 commit comments

Comments
 (0)