Skip to content

Commit 8de915f

Browse files
committed
refactor(settings): R.1 migrate config to user directory, deprecate .dsproj defaults
- Remove ProjectSettingsBackend, DsLabeler now uses AppSettingsBackend - Move AppSettingsBackend from label-suite/ to shared/settings/ - Move SlicerConfig from defaults.slicer to slicer.params - Move ExportConfig from defaults.export to top-level export - Stop writing defaults section to .dsproj (backward-compatible read) - Bump .dsproj version to 3.1.0 - Update tests for new API (exportConfig(), slicerState().params)
1 parent 604a2fd commit 8de915f

12 files changed

Lines changed: 186 additions & 300 deletions

File tree

docs/refactoring-roadmap-v2.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@
6969

7070
### R.1 配置迁移到用户目录
7171

72-
- [ ] 废弃 `ProjectSettingsBackend`
73-
- [ ] `ISettingsBackend` 仅保留 `AppSettingsBackend`
74-
- [ ] DsLabeler Settings 页切换到 `AppSettingsBackend`
75-
- [ ] `.dsproj` `defaults` 字段废弃(读取时忽略,不再写入)
72+
- [x] 废弃 `ProjectSettingsBackend`
73+
- [x] `ISettingsBackend` 仅保留 `AppSettingsBackend`
74+
- [x] DsLabeler Settings 页切换到 `AppSettingsBackend`
75+
- [x] `.dsproj` `defaults` 字段废弃(读取时迁移,不再写入)
76+
- [x] `SlicerConfig``defaults.slicer` 迁移到 `slicer.params`
77+
- [x] `ExportConfig``defaults.export` 迁移到顶层 `export`
78+
- [x] 版本号升级到 3.1.0
7679
- [ ] `ds-format.md` 更新
7780

7881
### R.2 模型懒加载

src/apps/ds-labeler/DsSlicerPage.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,12 @@ namespace dstools {
644644
auto *project = m_dataSource->project();
645645

646646
// Load slicer params from project defaults
647-
const auto &slicerConfig = project->defaults().slicerConfig;
648-
m_thresholdSpin->setValue(slicerConfig.threshold);
649-
m_minLengthSpin->setValue(slicerConfig.minLength);
650-
m_minIntervalSpin->setValue(slicerConfig.minInterval);
651-
m_hopSizeSpin->setValue(slicerConfig.hopSize);
652-
m_maxSilenceSpin->setValue(slicerConfig.maxSilence);
647+
const auto &slicerParams = project->slicerState().params;
648+
m_thresholdSpin->setValue(slicerParams.threshold);
649+
m_minLengthSpin->setValue(slicerParams.minLength);
650+
m_minIntervalSpin->setValue(slicerParams.minInterval);
651+
m_hopSizeSpin->setValue(slicerParams.hopSize);
652+
m_maxSilenceSpin->setValue(slicerParams.maxSilence);
653653

654654
// Load slicer state (audio files + slice points) from project
655655
const auto &slicerState = project->slicerState();
@@ -1086,16 +1086,17 @@ namespace dstools {
10861086
if (!m_dataSource || !m_dataSource->project())
10871087
return;
10881088

1089-
auto defaults = m_dataSource->project()->defaults();
1090-
defaults.slicerConfig.threshold = m_thresholdSpin->value();
1091-
defaults.slicerConfig.minLength = m_minLengthSpin->value();
1092-
defaults.slicerConfig.minInterval = m_minIntervalSpin->value();
1093-
defaults.slicerConfig.hopSize = m_hopSizeSpin->value();
1094-
defaults.slicerConfig.maxSilence = m_maxSilenceSpin->value();
1095-
m_dataSource->project()->setDefaults(defaults);
1089+
auto *project = m_dataSource->project();
1090+
auto state = project->slicerState();
1091+
state.params.threshold = m_thresholdSpin->value();
1092+
state.params.minLength = m_minLengthSpin->value();
1093+
state.params.minInterval = m_minIntervalSpin->value();
1094+
state.params.hopSize = m_hopSizeSpin->value();
1095+
state.params.maxSilence = m_maxSilenceSpin->value();
1096+
project->setSlicerState(std::move(state));
10961097

10971098
QString saveError;
1098-
m_dataSource->project()->save(saveError);
1099+
project->save(saveError);
10991100
}
11001101

11011102
void DsSlicerPage::saveSlicerStateToProject() {

src/apps/ds-labeler/ProjectSettingsBackend.cpp

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/apps/ds-labeler/ProjectSettingsBackend.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/apps/ds-labeler/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "DsSlicerPage.h"
1515
#include "ExportPage.h"
1616
#include "ProjectDataSource.h"
17-
#include "ProjectSettingsBackend.h"
17+
#include <AppSettingsBackend.h>
1818
#include "WelcomePage.h"
1919

2020
#include <MinLabelPage.h>
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
6161

6262
// Shared data source (lifetime = app)
6363
auto *dataSource = new dstools::ProjectDataSource(&shell);
64-
auto *settingsBackend = new dstools::ProjectSettingsBackend(&shell);
64+
auto *settingsBackend = new dstools::AppSettingsBackend(&shell);
6565
std::unique_ptr<dstools::DsProject> project;
6666

6767
// ── Register all 7 pages ─────────────────────────────────────────────
@@ -109,7 +109,6 @@ int main(int argc, char *argv[]) {
109109
: project->workingDirectory();
110110

111111
dataSource->setProject(project.get(), workDir);
112-
settingsBackend->setProject(project.get());
113112

114113
shell.setWindowTitle(
115114
QStringLiteral("DsLabeler — %1").arg(QFileInfo(path).fileName()));

src/apps/label-suite/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ dstools_add_executable(${PROJECT_NAME}
88
DEPLOY WIN32_EXECUTABLE MACOSX_BUNDLE WINRC
99
SOURCES
1010
main.cpp
11-
AppSettingsBackend.h
12-
AppSettingsBackend.cpp
1311
TaskWindowAdapter.h
1412
TaskWindowAdapter.cpp
1513
CleanupDialog.h

src/apps/label-suite/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "CleanupDialog.h"
1818

19-
#include "AppSettingsBackend.h"
19+
#include <AppSettingsBackend.h>
2020

2121
// Page includes
2222
#include <SlicerPage.h>
File renamed without changes.
File renamed without changes.

src/domain/include/dstools/DsProject.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct ExportConfig {
4242
bool includeDiscarded = false;
4343
};
4444

45-
/// @brief Slicer parameter configuration stored in .dsproj defaults.slicer.
45+
/// @brief Slicer parameter configuration stored in .dsproj slicer.params.
4646
struct SlicerConfig {
4747
double threshold = -40.0; ///< dB threshold for silence detection.
4848
int minLength = 5000; ///< Minimum slice length in ms.
@@ -53,18 +53,20 @@ struct SlicerConfig {
5353

5454
/// @brief Slicer runtime state stored in .dsproj slicer section.
5555
struct SlicerState {
56+
SlicerConfig params; ///< Slicer parameters.
5657
QStringList audioFiles; ///< Audio file paths (POSIX).
5758
std::map<QString, std::vector<double>> slicePoints; ///< filePath → boundary times (seconds).
5859
};
5960

60-
/// Default model paths and inference parameters stored in a .dsproj file.
61+
/// Default model paths and inference parameters.
62+
/// @deprecated The `defaults` section is no longer written to .dsproj.
63+
/// Model/device config is stored in AppSettings (user directory).
64+
/// This struct is kept for backward-compatible migration on load only.
6165
struct DsProjectDefaults {
62-
QString globalProvider = QStringLiteral("cpu"); ///< Global inference provider.
63-
int deviceIndex = 0; ///< Global GPU device index.
64-
std::map<QString, TaskModelConfig> taskModels; ///< Task name → model config.
65-
std::map<QString, PreloadConfig> preload; ///< Task name → preload config.
66-
ExportConfig exportConfig;
67-
SlicerConfig slicerConfig;
66+
QString globalProvider = QStringLiteral("cpu");
67+
int deviceIndex = 0;
68+
std::map<QString, TaskModelConfig> taskModels;
69+
std::map<QString, PreloadConfig> preload;
6870
};
6971

7072
/// @brief A single slice within an item.
@@ -124,6 +126,11 @@ class DsProject {
124126
const SlicerState &slicerState() const;
125127
void setSlicerState(SlicerState state);
126128

129+
// ── Export config ──────────────────────────────────────────────────
130+
131+
const ExportConfig &exportConfig() const;
132+
void setExportConfig(ExportConfig config);
133+
127134
// ── Path utilities ────────────────────────────────────────────────
128135

129136
static QString toPosixPath(const QString &nativePath);
@@ -135,6 +142,7 @@ class DsProject {
135142
DsProjectDefaults m_defaults;
136143
std::vector<Item> m_items;
137144
SlicerState m_slicerState;
145+
ExportConfig m_exportConfig;
138146
nlohmann::json m_extraFields; // preserve unknown fields for round-trip
139147
};
140148

0 commit comments

Comments
 (0)