Skip to main content

src/WhiskerToolbox/DataInspector_Widget/TensorData/TensorDesigner.hpp

src/WhiskerToolbox/DataInspector_Widget/TensorData/TensorDesigner.hpp

Design mode panel for building TensorData with lazy columns. More…

Namespaces

Name
EditorLib
Neuralyzer
Neuralyzer::TensorBuilders

Classes

Name
class TensorDesigner
Design mode panel for building TensorData with lazy columns.

Types

Name
enum class DesignerRowType { None, Interval, Timestamp, Ordinal, DerivedFromSource, TimeFrame}
Row source type for the tensor designer.

Detailed Description

Design mode panel for building TensorData with lazy columns.

TensorDesigner provides an interactive column-building experience for constructing TensorData backed by LazyColumnTensorStorage. Users select a row source (intervals, events, timeframe) and add columns by configuring DataManager source keys with TransformsV2 range reductions or element transforms.

Architecture

  • Row configuration: Select a DigitalIntervalSeries (interval rows), DigitalEventSeries (timestamp rows), or ordinal rows
  • Column building: Each column is a ColumnRecipe that maps to a ColumnProviderFn closure via TensorColumnBuilders
  • Live preview: Columns are lazily materialized in the TensorDataView
  • JSON serialization: Column configurations save/load as JSON
  • CSV export: Export the designed tensor to CSV

TensorColumnBuilders for the builder layer

LazyColumnTensorStorage for the storage backend

TensorInspector for the inspector that hosts this panel

Types Documentation

enum DesignerRowType

Enumerator Value Description
None No row source selected.
Interval Rows from DigitalIntervalSeries.
Timestamp Rows from DigitalEventSeries.
Ordinal Manual ordinal rows.
DerivedFromSource Derive row timestamps from any data source’s timestamps.
TimeFrame Rows from a registered TimeFrame.

Row source type for the tensor designer.

Source code

#ifndef TENSOR_DESIGNER_HPP
#define TENSOR_DESIGNER_HPP


#include <QPointer>
#include <QWidget>

#include <memory>
#include <string>
#include <vector>

class ColumnConfigDialog;
class DataManager;
class DataInspectorState;
class QComboBox;
class QLabel;
class QListWidget;
class QListWidgetItem;
class QPushButton;
class QVBoxLayout;
class QHBoxLayout;
class TensorData;
class SelectionContext;
struct SelectionSource;

namespace EditorLib {
class OperationContext;
}// namespace EditorLib

namespace Neuralyzer::TensorBuilders {
struct ColumnRecipe;
enum class IntervalProperty : std::uint8_t;
}// namespace Neuralyzer::TensorBuilders

enum class DesignerRowType {
    None,             
    Interval,         
    Timestamp,        
    Ordinal,          
    DerivedFromSource,
    TimeFrame         
};

class TensorDesigner : public QWidget {
    Q_OBJECT

public:
    explicit TensorDesigner(
            std::shared_ptr<DataManager> data_manager,
            QWidget * parent = nullptr);
    ~TensorDesigner() override;

    // =========================================================================
    // Selection Context
    // =========================================================================

    void setSelectionContext(SelectionContext * context);

    void setOperationContext(EditorLib::OperationContext * context);

    void setPipelineLibraryDir(QString const & library_dir);

    void setInspectorState(std::shared_ptr<DataInspectorState> state);

    // =========================================================================
    // Tensor Management
    // =========================================================================

    [[nodiscard]] std::string tensorKey() const { return _tensor_key; }

    void setTensorKey(std::string const & key);

    // =========================================================================
    // JSON Serialization
    // =========================================================================

    [[nodiscard]] std::string toJson() const;

    bool fromJson(std::string const & json);

signals:
    void tensorCreated(QString const & key);

    void dataFocusRequested(QString const & key);

private slots:
    void _onRowSourceTypeChanged(int index);
    void _onRowSourceKeyChanged(int index);
    void _onAddColumnClicked();
    void _onApplyDesignPresetClicked();
    void _onAddPresetClicked();
    void _onRemoveColumnClicked();
    void _onEditColumnClicked();
    void _onColumnDoubleClicked(QListWidgetItem * item);
    void _onBuildClicked();
    void _onSaveJsonClicked();
    void _onLoadJsonClicked();
    void _onDataFocusChanged(
            QString const & data_key,
            QString const & data_type);

private:
    void _setupUi();
    void _connectSignals();
    void _populateRowSourceKeys();
    void _refreshColumnList();
    void _buildTensor();
    void _updateStatus(QString const & message);

    void _updateRowTypeDescription(int combo_index);

    void _pinInspectorForDialog();

    void _unpinInspectorAfterDialog();

    void _onDialogAcceptedAdd();

    void _onDialogAcceptedEdit(int row);

    // --- Data ---
    std::shared_ptr<DataManager> _data_manager;
    SelectionContext * _selection_context{nullptr};
    EditorLib::OperationContext * _operation_context{nullptr};
    QString _pipeline_library_dir;
    std::shared_ptr<DataInspectorState> _inspector_state;
    std::string _tensor_key;

    // Dialog tracking
    QPointer<ColumnConfigDialog> _active_dialog;
    bool _was_pinned_before_dialog{false};      

    // --- Row configuration ---
    DesignerRowType _row_type{DesignerRowType::None};
    std::string _row_source_key;

    // --- Column recipes ---
    std::vector<Neuralyzer::TensorBuilders::ColumnRecipe> _column_recipes;

    // --- UI widgets ---
    QVBoxLayout * _main_layout{nullptr};

    // Row source section
    QLabel * _row_section_label{nullptr};
    QComboBox * _row_type_combo{nullptr};
    QComboBox * _row_source_combo{nullptr};
    QLabel * _row_type_description_label{nullptr};
    QLabel * _row_info_label{nullptr};

    // Column management section
    QLabel * _col_section_label{nullptr};
    QListWidget * _column_list{nullptr};
    QHBoxLayout * _col_button_layout{nullptr};
    QPushButton * _add_col_btn{nullptr};
    QPushButton * _apply_design_preset_btn{nullptr};
    QPushButton * _add_preset_btn{nullptr};
    QPushButton * _edit_col_btn{nullptr};
    QPushButton * _remove_col_btn{nullptr};

    // Build / Config section
    QHBoxLayout * _action_layout{nullptr};
    QPushButton * _build_btn{nullptr};
    QPushButton * _save_json_btn{nullptr};
    QPushButton * _load_json_btn{nullptr};

    // Status
    QLabel * _status_label{nullptr};
};

#endif// TENSOR_DESIGNER_HPP

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