iVS3D v2.0.9
Loading...
Searching...
No Matches
ModelSettingsWidget.h
Go to the documentation of this file.
1#pragma once
2
10#include <QWidget>
11#include <QComboBox>
12#include <QLineEdit>
13#include <QLabel>
14#include <QPushButton>
15#include <QVector>
16#include <QString>
17#include <QScrollArea>
18#include <QCheckBox>
19#include <QGroupBox>
20#include <memory>
21#include <QMetaType>
22#include <memory>
23#include "ModelManager.h"
24
25namespace MCFG {
26
47class ModelSettingsWidget : public QWidget {
48 Q_OBJECT
49
50public:
56 explicit ModelSettingsWidget(ModelManager& manager,
57 QWidget* parent = nullptr);
60
65 void refreshModelList();
66
72 bool setSelectedModel(const QString& modelName);
73
78 QString selectedModel() const;
79
84 QVector<uint> selectedClassIds() const;
85
90 void setSelectedClassIds(const QVector<uint>& classIds);
91
92signals:
98 void modelChanged(const QString& modelName, bool isValid);
99
104 void classSelectionChanged(const QVector<uint>& selectedClassIds);
105
111
112 // Internal signals for communicating with ModelManager on worker thread
113 void modelActivationRequested(const QString& modelName);
114 void classSelectionRequested(const QString& modelName, uint classId, bool selected);
115 void modelsRefreshRequested();
116 void applyMeanStdRequested(const QString& modelName, bool apply);
117 void normalizeTo01Requested(const QString& modelName, bool normalize);
118 void inputAlignmentRequested(const QString& modelName, uint alignment);
119
120private slots:
121 // Slots to handle responses from ModelManager
122 void onModelActivated(const QString& modelName, ModelManager::ModelState modelState, const QString& error);
123 void onClassListUpdated(const QVector<ModelConfig::ClassInfo>& classes);
124 void onModelsListUpdated(const QVector<ModelManager::ModelEntry>& models);
125
126 // Slots to handle UI interactions
127 void onModelIndexChanged(int index);
128 void onClassCheckBoxToggled();
129 void onInvertSelectionClicked();
130 void onSearchTextChanged(const QString& text);
131 void onApplyMeanStdToggled(bool checked);
132 void onNormalizeTo01Toggled(bool checked);
133 void onInputAlignmentChanged(const QString& text);
134
135protected:
136 bool eventFilter(QObject* watched, QEvent* event) override;
137
138private:
142 void updateModelDisplay();
143
147 void updateClassList();
148
153 const QString& errorMessage);
154
158 void setupUi();
159
164
168 QString getResolutionHint(ModelManager::ModelState state) const;
169
173 QString getStateString(ModelManager::ModelState state) const;
174
179
184
185 // UI Elements
186 QComboBox* m_modelCombo = nullptr;
187 QLabel* m_statusLabel = nullptr;
188 QCheckBox* m_applyMeanStdCheckBox = nullptr;
189 QCheckBox* m_normalizeTo01CheckBox = nullptr;
190 QLineEdit* m_inputAlignmentEdit = nullptr;
191 QLabel* m_meanStdDisplayLabel = nullptr;
192 QLabel* m_configChangeWarningLabel = nullptr;
193 QPushButton* m_configSectionToggleButton = nullptr;
194 QWidget* m_configurationSection = nullptr;
195 QGroupBox* m_configContentWidget = nullptr;
196 QWidget* m_classContainer = nullptr;
197 QWidget* m_errorContainer = nullptr;
198 QLabel* m_errorMessageLabel = nullptr;
199 QLabel* m_errorHintLabel = nullptr;
200 QLineEdit* m_searchEdit = nullptr;
201 QPushButton* m_invertButton = nullptr;
202 QWidget* m_classGridWidget = nullptr;
203 QScrollArea* m_classScrollArea = nullptr;
204
205 // Data
206 ModelManager& m_manager;
207 QString m_currentModelName;
208 QVector<QCheckBox*> m_classCheckBoxes;
209 QVector<QWidget*> m_classContainers;
210 QVector<uint> m_classIds; // Maps checkbox index to class ID
211
212 // Cache for model state (since we can't directly query manager from GUI thread)
213 QVector<ModelManager::ModelEntry> m_cachedModels;
214 QVector<ModelConfig::ClassInfo> m_cachedClasses;
215 ModelManager::ModelState m_cachedModelState = ModelManager::ModelState::MissingConfig;
216 QString m_cachedModelError;
217 bool m_cachedApplyMeanStd = true;
218 bool m_cachedNormalizeTo01 = true;
219 uint m_cachedInputAlignment = 1;
220 std::vector<float> m_cachedMean;
221 std::vector<float> m_cachedStd;
222 std::shared_ptr<ModelConfig> m_cachedCurrentConfig;
223
224 // Original configuration values (for detecting changes)
225 bool m_originalApplyMeanStd = true;
226 bool m_originalNormalizeTo01 = true;
227 uint m_originalInputAlignment = 1;
228
229 bool m_blockSignals = false;
230 bool m_configurationSectionExpanded = false;
231};
232
233} // namespace MCFG
Discovery, validation, activation, and state tracking for model configs.
Manages model configurations in a directory and exposes UI-friendly state.
Definition ModelManager.h:43
ModelState
High-level availability state of a model entry.
Definition ModelManager.h:50
Reusable UI widget for selecting detection models and configuring class selection.
Definition ModelSettingsWidget.h:47
void setupManagerConnections()
Setup connections to ModelManager signals/slots.
Definition ModelSettingsWidget.cpp:261
bool setSelectedModel(const QString &modelName)
Set the currently selected model.
Definition ModelSettingsWidget.cpp:372
void modelChanged(const QString &modelName, bool isValid)
Emitted when user selects a different model.
QVector< uint > selectedClassIds() const
Get the class selection state for the current model.
Definition ModelSettingsWidget.cpp:394
void modelConfigChanged()
Emitted when any model configuration parameter changes This includes normalizeTo01,...
QString getStateString(ModelManager::ModelState state) const
Get human-readable string for model state.
Definition ModelSettingsWidget.cpp:567
void showModelError(ModelManager::ModelState state, const QString &errorMessage)
Show error message for invalid model.
Definition ModelSettingsWidget.cpp:538
void updateClassList()
Rebuild the class checkbox list.
Definition ModelSettingsWidget.cpp:468
QString getResolutionHint(ModelManager::ModelState state) const
Get human-readable hint for resolving model errors.
Definition ModelSettingsWidget.cpp:545
~ModelSettingsWidget()=default
Destructor.
void updateConfigurationSection()
Update configuration section with current model config.
Definition ModelSettingsWidget.cpp:747
void classSelectionChanged(const QVector< uint > &selectedClassIds)
Emitted when user changes class selection.
void checkConfigurationChanges()
Check if configuration has changed from original values.
Definition ModelSettingsWidget.cpp:733
void updateModelDisplay()
Update the display based on currently selected model.
Definition ModelSettingsWidget.cpp:432
QString selectedModel() const
Get the currently selected model name.
Definition ModelSettingsWidget.cpp:388
void setupUi()
Create all UI elements.
Definition ModelSettingsWidget.cpp:67
void refreshModelList()
Refresh the model list from the manager Call this after the manager's refresh() method or when models...
Definition ModelSettingsWidget.cpp:302
void setSelectedClassIds(const QVector< uint > &classIds)
Set which classes are selected (by class ID)
Definition ModelSettingsWidget.cpp:405
Namespace containing model-configuration components used by iVS3D plugins.
Definition ModelConfig.h:35