Skip to main content

AutoParamWidget

AutoParamWidget

Generic Qt form widget generated from a ParameterSchema. More…

#include <AutoParamWidget.hpp>

Inherits from QWidget

Public Types

Name
using std::function< std::string(std::string const &json)> PostEditHook
Callback type for post-edit hooks.
using std::function< QString( QWidget *parent, QString dialog_id, QString caption, QString filter, QString fallback_dir, bool pick_directory)> FileDialogOpener
Callback invoked when the user clicks Browse on a path field.

Public Signals

Name
void parametersChanged()
Emitted whenever any parameter value changes.

Public Functions

Name
AutoParamWidget(QWidget * parent =[nullptr])
~AutoParamWidget() override
void setSchema(ParameterSchema const & schema)
Set the schema and rebuild the form.
std::string toJson() const
Serialize current widget values to a JSON string.
bool fromJson(std::string const & json)
Populate widget values from a JSON string.
void clear()
Clear all fields and remove the schema.
void setPostEditHook(PostEditHook hook)
Install a post-edit hook that can transform parameter values after each edit.
void updateAllowedValues(std::string const & field_name, std::vector< std::string > const & values)
Dynamically update the combo items for a string/enum field.
void updateVariantAlternatives(std::string const & field_name, std::vector< std::string > const & allowed_tags)
Show or hide variant alternatives by tag name.
void setFileDialogOpener(FileDialogOpener opener)
Install the global file/directory dialog opener (defaults to QFileDialog).
void registerDialogFallback(QString const & dialog_id, std::function< QString()> resolver)
Register a fallback directory resolver for a dialog id.

Detailed Description

class AutoParamWidget;

Generic Qt form widget generated from a ParameterSchema.

This widget reads a ParameterSchema and dynamically creates a form with appropriate Qt widgets for each field. It provides bidirectional JSON ↔︎ UI synchronization.

Public Types Documentation

using PostEditHook

using AutoParamWidget::PostEditHook =  std::function<std::string(std::string const & json)>;

Callback type for post-edit hooks.

Receives the current JSON from the widget after a user edit. Should return the (possibly modified) JSON. If the returned JSON differs from the input, the widget re-populates itself with the new values (without re-triggering the hook).

Use cases:

  • Bidirectional derived-field calculation (e.g., alpha/beta ↔︎ min/max)
  • Clamping or snapping values (e.g., forcing odd kernel sizes)

using FileDialogOpener

using AutoParamWidget::FileDialogOpener =  std::function<QString(
            QWidget * parent,
            QString dialog_id,
            QString caption,
            QString filter,
            QString fallback_dir,
            bool pick_directory)>;

Callback invoked when the user clicks Browse on a path field.

Parameters:

  • parent Parent widget for the dialog
  • dialog_id Session id for path memory (AppFileDialog)
  • caption Dialog window title
  • filter File filter when picking files; ignored for directories
  • fallback_dir Initial directory when no session memory exists
  • pick_directory True for directory picker, false for file open

Return: Selected path, or empty if cancelled

Public Signals Documentation

signal parametersChanged

void parametersChanged()

Emitted whenever any parameter value changes.

Public Functions Documentation

function AutoParamWidget

explicit AutoParamWidget(
    QWidget * parent =nullptr
)

function ~AutoParamWidget

~AutoParamWidget() override

function setSchema

void setSchema(
    ParameterSchema const & schema
)

Set the schema and rebuild the form.

Parameters:

  • schema The parameter schema to generate UI from

function toJson

std::string toJson() const

Serialize current widget values to a JSON string.

Return: JSON string representing current parameter values

function fromJson

bool fromJson(
    std::string const & json
)

Populate widget values from a JSON string.

Parameters:

  • json JSON string to load values from

Return: true if parsing succeeded (partial updates still applied)

function clear

void clear()

Clear all fields and remove the schema.

function setPostEditHook

void setPostEditHook(
    PostEditHook hook
)

Install a post-edit hook that can transform parameter values after each edit.

Parameters:

  • hook Callback invoked after each edit; pass nullptr / empty function to remove

function updateAllowedValues

void updateAllowedValues(
    std::string const & field_name,
    std::vector< std::string > const & values
)

Dynamically update the combo items for a string/enum field.

Finds the FieldRow(s) matching field_name. If the field has a combo_box, repopulates it with values while preserving the current selection. If include_none_sentinel was set, “(None)” is prepended. If the field is a QLineEdit (non-dynamic), this is a no-op.

Does not emit parametersChanged unless the selection actually changes.

function updateVariantAlternatives

void updateVariantAlternatives(
    std::string const & field_name,
    std::vector< std::string > const & allowed_tags
)

Show or hide variant alternatives by tag name.

Finds the variant FieldRow matching field_name. Hides alternatives whose tags are not in allowed_tags. If the currently selected alternative is hidden, switches to the first visible one.

Does not emit parametersChanged unless the active alternative changes.

function setFileDialogOpener

static void setFileDialogOpener(
    FileDialogOpener opener
)

Install the global file/directory dialog opener (defaults to QFileDialog).

Parameters:

  • opener Callback; pass empty function to restore the built-in default

function registerDialogFallback

static void registerDialogFallback(
    QString const & dialog_id,
    std::function< QString()> resolver
)

Register a fallback directory resolver for a dialog id.

Used when no session path memory exists yet. Typically registered once at app startup.


Updated on 2026-11-13 at 20:25:41 +0000