35 lines
1.3 KiB
C++
35 lines
1.3 KiB
C++
#pragma once
|
||
#include <vector>
|
||
#include "repo/RepoTypes.hpp"
|
||
|
||
namespace geopro::app {
|
||
|
||
enum class GsCheck { Unchecked, Partial, Checked };
|
||
|
||
// GS 复选框三态(spec §6):
|
||
// Unchecked = 自身 ds 关 且 无子 TM 勾选;
|
||
// Checked = 自身 ds 开 且 全部子 TM 勾选(注意是 AND,不是"父子都打钩即满");
|
||
// Partial = 其余(只 ds 开 / 只部分 TM / ds 开但 TM 未满 等)。
|
||
// 无子 TM(totalTmCount==0)时退化为仅看 dsOn(ds 开=Checked,关=Unchecked)。
|
||
inline GsCheck aggregateGsState(bool dsOn, int checkedTmCount, int totalTmCount) {
|
||
const bool anyOn = dsOn || checkedTmCount > 0;
|
||
if (!anyOn) return GsCheck::Unchecked;
|
||
const bool tmAll = (totalTmCount == 0) || (checkedTmCount == totalTmCount);
|
||
if (dsOn && tmAll) return GsCheck::Checked;
|
||
return GsCheck::Partial;
|
||
}
|
||
|
||
// 对象树勾选产出的数据源并集按 {id,confType} 去重保序(spec §6)。
|
||
inline std::vector<geopro::data::DataSource> dedupeSources(std::vector<geopro::data::DataSource> in) {
|
||
std::vector<geopro::data::DataSource> out;
|
||
for (const auto& s : in) {
|
||
bool dup = false;
|
||
for (const auto& o : out)
|
||
if (o.id == s.id && o.confType == s.confType) { dup = true; break; }
|
||
if (!dup) out.push_back(s);
|
||
}
|
||
return out;
|
||
}
|
||
|
||
} // namespace geopro::app
|