命名审查与垃圾代码清理(纯重命名 / 死代码删除,无行为变更)
前提:加载完成后全部采样都已驻留内存,程序此后与源文件再无联系。 据此修正了一批会让人误以为"仍在读写文件"的命名: - SampleFileAt → SampleSignalAt(取的是内存信号在给定时刻的采样值)。 - DataSet::AddPreparedFile → AddDataFile。 - PlotView::InvalidatePolylineCache → InvalidateDerivedCaches (它同时清空折线、边沿统计、中心平均值曲线、静态场景缓存与悬停引用)。 - PlotView::CursorColor(int which) → CursorColor()(两条光标同色,参数从未使用)。 - UiEllipsize(g,…) → UiEllipsize(…):纯测量不绘制,删掉被忽略的绘图上下文参数; 同时删除与 UiMeasureTextWidth 完全重复的 UiTextWidth,调用点统一到 UiMeasureTextWidth。 清理残留参数((void)xxx;): - TabConfig 的可见性/网格族(SetVisible / ToggleVisible / SetFileVisible / SetAllVisible / SoloSignal / SetMode / SyncLanes / FileHasVisible / FileAllVisible)去掉从未使用的 const DataSet& 参数(仅 SyncToDataSet 真正需要数据层,保留)。 - PlotView::OnLButtonUp(int y)、OnMouseWheel(int delta, bool shift);PainterSignalHalo 去掉未用的 ref。 - BuildDataFile 中未使用的局部 rowCount。 删除无人调用的死函数: DataSet::Clear / AddFromTable;SignalColorCount;WideToUtf8 / StartsWith; PlotView::ViewMinTime / ViewMaxTime / EdgePanelRect / EdgePanelCloseRect / EdgeCenterPanelRect / ScaleLaneRange / BeginLaneValueEdit / LaneContentHeight; SignalPanel::NeedsScrollBar / IsFilterEditing / FilterText / ContentHeight; PopupMenu::EditingItemId;TabBar::IsDragging;TextEdit::PlaceCaret。 删除只写不读的死字段:CsvTable::sourceRowCount(与 rowCount 等义)与 skippedRowCount。 以 VERY_BIG_DATA.CSV 回归验证:加载与勾选、筛选框(含"无匹配的筛选信号")、 样式区线宽文案省略、选区放大(横向与纵向)、双光标读数与 Δt、右键菜单(Y 轴数值与 实验性功能子菜单)、合并/拆分网格、标签与信号重命名省略号,行为均与改动前一致; make clean && make all 无任何警告。
This commit is contained in:
1 parent
f5028b1e18
commit
350538c634
21 files changed
+118
-456
No files matched your search
@@ -303,11 +303,6 @@ namespace jdi
|
||||
return true;
|
||||
}
|
||||
|
||||
if (state.fields.size() != table.headers.size())
|
||||
{
|
||||
++table.skippedRowCount;
|
||||
}
|
||||
|
||||
bool rowHasValue = false;
|
||||
for (std::size_t column = 0; column < state.rowValues.size(); ++column)
|
||||
{
|
||||
@@ -332,7 +327,6 @@ namespace jdi
|
||||
table.columns[column].push_back(state.rowValues[column]);
|
||||
}
|
||||
++table.rowCount;
|
||||
++table.sourceRowCount;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-43
@@ -464,7 +464,6 @@ namespace jdi
|
||||
}
|
||||
|
||||
const std::size_t columnCount = table.headers.size();
|
||||
const std::size_t rowCount = table.rowCount;
|
||||
if (table.columns.size() < columnCount)
|
||||
{
|
||||
error = L"数据表列结构不完整。";
|
||||
@@ -599,18 +598,12 @@ namespace jdi
|
||||
}
|
||||
file.minTime = tMin;
|
||||
file.maxTime = tMax;
|
||||
(void)rowCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================ DataSet ============================
|
||||
|
||||
void DataSet::Clear()
|
||||
{
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
bool DataSet::AddPreparedFile(DataFile&& file, int& fileIndex)
|
||||
bool DataSet::AddDataFile(DataFile&& file, int& fileIndex)
|
||||
{
|
||||
fileIndex = -1;
|
||||
if (file.signals.empty())
|
||||
@@ -622,21 +615,6 @@ namespace jdi
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataSet::AddFromTable(const CsvTable& table, const std::wstring& filePath, std::wstring& error,
|
||||
int& fileIndex)
|
||||
{
|
||||
fileIndex = -1;
|
||||
|
||||
// 兼容入口:复制一份表格后走与后台加载完全一致的构建流程。
|
||||
CsvTable local = table;
|
||||
DataFile file;
|
||||
if (!BuildDataFile(std::move(local), filePath, SignalCount(), file, error))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return AddPreparedFile(std::move(file), fileIndex);
|
||||
}
|
||||
|
||||
bool DataSet::InsertDerivedSignal(int fileIndex, int afterSignalIndex, SignalData&& signal,
|
||||
int& newSignalIndex)
|
||||
{
|
||||
@@ -992,7 +970,8 @@ namespace jdi
|
||||
return best;
|
||||
}
|
||||
|
||||
bool SampleFileAt(const DataFile& file, const SignalData& signal, double time, bool interpolate, double& value)
|
||||
bool SampleSignalAt(const DataFile& file, const SignalData& signal, double time, bool interpolate,
|
||||
double& value)
|
||||
{
|
||||
value = kMissing;
|
||||
|
||||
@@ -1093,7 +1072,7 @@ namespace jdi
|
||||
[](const Lane& lane) { return lane.signals.empty(); }),
|
||||
m_lanes.end());
|
||||
|
||||
SyncLanes(dataSet);
|
||||
SyncLanes();
|
||||
}
|
||||
|
||||
void TabConfig::RemapAfterFileRemoval(int fileIndex)
|
||||
@@ -1147,7 +1126,7 @@ namespace jdi
|
||||
return fileVisible[static_cast<std::size_t>(ref.signalIndex)];
|
||||
}
|
||||
|
||||
void TabConfig::SetVisible(const DataSet& dataSet, const SignalRef& ref, bool visible)
|
||||
void TabConfig::SetVisible(const SignalRef& ref, bool visible)
|
||||
{
|
||||
if (ref.fileIndex < 0 || static_cast<std::size_t>(ref.fileIndex) >= m_visible.size())
|
||||
{
|
||||
@@ -1171,15 +1150,15 @@ namespace jdi
|
||||
m_laneMode = LaneMode::CUSTOM;
|
||||
}
|
||||
|
||||
SyncLanes(dataSet);
|
||||
SyncLanes();
|
||||
}
|
||||
|
||||
void TabConfig::ToggleVisible(const DataSet& dataSet, const SignalRef& ref)
|
||||
void TabConfig::ToggleVisible(const SignalRef& ref)
|
||||
{
|
||||
SetVisible(dataSet, ref, !IsVisible(ref));
|
||||
SetVisible(ref, !IsVisible(ref));
|
||||
}
|
||||
|
||||
void TabConfig::SetFileVisible(const DataSet& dataSet, int fileIndex, bool visible)
|
||||
void TabConfig::SetFileVisible(int fileIndex, bool visible)
|
||||
{
|
||||
if (fileIndex < 0 || static_cast<std::size_t>(fileIndex) >= m_visible.size())
|
||||
{
|
||||
@@ -1187,30 +1166,29 @@ namespace jdi
|
||||
}
|
||||
std::vector<bool>& fileVisible = m_visible[static_cast<std::size_t>(fileIndex)];
|
||||
std::fill(fileVisible.begin(), fileVisible.end(), visible);
|
||||
SyncLanes(dataSet);
|
||||
SyncLanes();
|
||||
}
|
||||
|
||||
void TabConfig::SetAllVisible(const DataSet& dataSet, bool visible)
|
||||
void TabConfig::SetAllVisible(bool visible)
|
||||
{
|
||||
for (std::vector<bool>& fileVisible : m_visible)
|
||||
{
|
||||
std::fill(fileVisible.begin(), fileVisible.end(), visible);
|
||||
}
|
||||
SyncLanes(dataSet);
|
||||
SyncLanes();
|
||||
}
|
||||
|
||||
void TabConfig::SoloSignal(const DataSet& dataSet, const SignalRef& ref)
|
||||
void TabConfig::SoloSignal(const SignalRef& ref)
|
||||
{
|
||||
for (std::vector<bool>& fileVisible : m_visible)
|
||||
{
|
||||
std::fill(fileVisible.begin(), fileVisible.end(), false);
|
||||
}
|
||||
SetVisible(dataSet, ref, true);
|
||||
SetVisible(ref, true);
|
||||
}
|
||||
|
||||
bool TabConfig::FileHasVisible(const DataSet& dataSet, int fileIndex) const
|
||||
bool TabConfig::FileHasVisible(int fileIndex) const
|
||||
{
|
||||
(void)dataSet;
|
||||
if (fileIndex < 0 || static_cast<std::size_t>(fileIndex) >= m_visible.size())
|
||||
{
|
||||
return false;
|
||||
@@ -1219,9 +1197,8 @@ namespace jdi
|
||||
return std::find(fileVisible.begin(), fileVisible.end(), true) != fileVisible.end();
|
||||
}
|
||||
|
||||
bool TabConfig::FileAllVisible(const DataSet& dataSet, int fileIndex) const
|
||||
bool TabConfig::FileAllVisible(int fileIndex) const
|
||||
{
|
||||
(void)dataSet;
|
||||
if (fileIndex < 0 || static_cast<std::size_t>(fileIndex) >= m_visible.size())
|
||||
{
|
||||
return false;
|
||||
@@ -1256,15 +1233,14 @@ namespace jdi
|
||||
return count;
|
||||
}
|
||||
|
||||
void TabConfig::SetMode(const DataSet& dataSet, LaneMode mode)
|
||||
void TabConfig::SetMode(LaneMode mode)
|
||||
{
|
||||
m_laneMode = mode;
|
||||
SyncLanes(dataSet);
|
||||
SyncLanes();
|
||||
}
|
||||
|
||||
void TabConfig::SyncLanes(const DataSet& dataSet)
|
||||
void TabConfig::SyncLanes()
|
||||
{
|
||||
(void)dataSet;
|
||||
RebuildLanes(m_visible, m_lanes, m_laneMode);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,16 +249,6 @@ namespace jdi
|
||||
g.ReleaseHDC(hdc);
|
||||
}
|
||||
|
||||
float UiTextWidth(gd::Graphics& g, const std::wstring& text, HFONT font)
|
||||
{
|
||||
// 直接复用 UiMeasureTextWidth:后者用 GetDC(nullptr) 取度量 HDC,
|
||||
// 不会触发 **Graphics::GetHDC() 的 GDI+ 批次刷新**(实测每次约 5µs)。
|
||||
// UiEllipsize 会反复调用本函数(逐字符回退时每步一次),
|
||||
// 若走 GetHDC 路线,一个长名称就要刷新十几次,是拖拽掉帧的隐性来源之一。
|
||||
(void)g;
|
||||
return UiMeasureTextWidth(font, text);
|
||||
}
|
||||
|
||||
float UiMeasureTextWidth(HFONT font, const std::wstring& text)
|
||||
{
|
||||
if (text.empty() || font == nullptr)
|
||||
@@ -281,19 +271,19 @@ namespace jdi
|
||||
return static_cast<float>(size.cx);
|
||||
}
|
||||
|
||||
std::wstring UiEllipsize(gd::Graphics& g, const std::wstring& text, HFONT font, float maxWidth)
|
||||
std::wstring UiEllipsize(const std::wstring& text, HFONT font, float maxWidth)
|
||||
{
|
||||
if (text.empty() || font == nullptr || maxWidth <= 0.0f)
|
||||
{
|
||||
return std::wstring();
|
||||
}
|
||||
if (UiTextWidth(g, text, font) <= maxWidth)
|
||||
if (UiMeasureTextWidth(font, text) <= maxWidth)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
const std::wstring ellipsis = L"…";
|
||||
const float ellipsisWidth = UiTextWidth(g, ellipsis, font);
|
||||
const float ellipsisWidth = UiMeasureTextWidth(font, ellipsis);
|
||||
if (ellipsisWidth > maxWidth)
|
||||
{
|
||||
return std::wstring();
|
||||
@@ -303,7 +293,7 @@ namespace jdi
|
||||
while (!result.empty())
|
||||
{
|
||||
result.pop_back();
|
||||
if (UiTextWidth(g, result, font) + ellipsisWidth <= maxWidth)
|
||||
if (UiMeasureTextWidth(font, result) + ellipsisWidth <= maxWidth)
|
||||
{
|
||||
return result + ellipsis;
|
||||
}
|
||||
|
||||
@@ -318,15 +318,6 @@ namespace jdi
|
||||
rect.Y + (rect.Height - height) * 0.5f, width, height);
|
||||
}
|
||||
|
||||
int PopupMenu::EditingItemId() const
|
||||
{
|
||||
if (m_editIndex < 0 || m_editIndex >= static_cast<int>(m_items.size()))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return m_items[static_cast<std::size_t>(m_editIndex)].id;
|
||||
}
|
||||
|
||||
bool PopupMenu::IsOnEditField(int x, int y) const
|
||||
{
|
||||
if (m_editIndex < 0)
|
||||
@@ -1050,7 +1041,7 @@ namespace jdi
|
||||
const float labelLeft = rect.X + kItemPad * m_scale;
|
||||
const gd::RectF fieldRect = EditFieldRect(static_cast<int>(index));
|
||||
const float labelWidth = std::max(8.0f, fieldRect.X - labelLeft - kEditFieldGap * m_scale);
|
||||
UiText(g, UiEllipsize(g, item.label, m_fonts->uiSmall, labelWidth), m_fonts->uiSmall,
|
||||
UiText(g, UiEllipsize(item.label, m_fonts->uiSmall, labelWidth), m_fonts->uiSmall,
|
||||
gd::RectF(labelLeft, rect.Y, labelWidth, rect.Height), labelColor, TextAlign::LEFT);
|
||||
|
||||
if (static_cast<int>(index) == m_editIndex)
|
||||
@@ -1062,7 +1053,7 @@ namespace jdi
|
||||
UiFillRoundRect(g, fieldRect, 3.0f * m_scale, m_theme->pressed);
|
||||
UiDrawRoundRect(g, fieldRect, 3.0f * m_scale, m_theme->border, 1.0f);
|
||||
const std::wstring text =
|
||||
UiEllipsize(g, item.value, m_fonts->uiSmall, fieldRect.Width - 12.0f * m_scale);
|
||||
UiEllipsize(item.value, m_fonts->uiSmall, fieldRect.Width - 12.0f * m_scale);
|
||||
UiText(g, text, m_fonts->uiSmall,
|
||||
gd::RectF(fieldRect.X + 6.0f * m_scale, fieldRect.Y,
|
||||
std::max(8.0f, fieldRect.Width - 12.0f * m_scale), fieldRect.Height),
|
||||
@@ -1146,7 +1137,7 @@ namespace jdi
|
||||
const float textLeft = rect.X + kItemPad * m_scale;
|
||||
const float textWidth =
|
||||
rect.Width - 2.0f * kItemPad * m_scale - kMarkerColumn * m_scale - kMarkerGap * m_scale;
|
||||
UiText(g, UiEllipsize(g, item.label, m_fonts->uiSmall, textWidth), m_fonts->uiSmall,
|
||||
UiText(g, UiEllipsize(item.label, m_fonts->uiSmall, textWidth), m_fonts->uiSmall,
|
||||
gd::RectF(textLeft, rect.Y, std::max(8.0f, textWidth), rect.Height), textColor,
|
||||
TextAlign::LEFT);
|
||||
}
|
||||
@@ -1206,12 +1197,12 @@ namespace jdi
|
||||
const float labelLeft = rect.X + kItemPad * m_scale;
|
||||
const gd::RectF fieldRect = EditFieldRect(static_cast<int>(index));
|
||||
const float labelWidth = std::max(8.0f, fieldRect.X - labelLeft - kEditFieldGap * m_scale);
|
||||
UiText(g, UiEllipsize(g, item.label, m_fonts->uiSmall, labelWidth), m_fonts->uiSmall,
|
||||
UiText(g, UiEllipsize(item.label, m_fonts->uiSmall, labelWidth), m_fonts->uiSmall,
|
||||
gd::RectF(labelLeft, rect.Y, labelWidth, rect.Height), labelColor, TextAlign::LEFT);
|
||||
UiFillRoundRect(g, fieldRect, 3.0f * m_scale, m_theme->pressed);
|
||||
UiDrawRoundRect(g, fieldRect, 3.0f * m_scale, m_theme->border, 1.0f);
|
||||
const std::wstring text =
|
||||
UiEllipsize(g, item.value, m_fonts->uiSmall, fieldRect.Width - 12.0f * m_scale);
|
||||
UiEllipsize(item.value, m_fonts->uiSmall, fieldRect.Width - 12.0f * m_scale);
|
||||
UiText(g, text, m_fonts->uiSmall,
|
||||
gd::RectF(fieldRect.X + 6.0f * m_scale, fieldRect.Y,
|
||||
std::max(8.0f, fieldRect.Width - 12.0f * m_scale), fieldRect.Height),
|
||||
@@ -1258,7 +1249,7 @@ namespace jdi
|
||||
const float textLeft = rect.X + kItemPad * m_scale;
|
||||
const float textWidth =
|
||||
rect.Width - 2.0f * kItemPad * m_scale - kMarkerColumn * m_scale - kMarkerGap * m_scale;
|
||||
UiText(g, UiEllipsize(g, item.label, m_fonts->uiSmall, textWidth), m_fonts->uiSmall,
|
||||
UiText(g, UiEllipsize(item.label, m_fonts->uiSmall, textWidth), m_fonts->uiSmall,
|
||||
gd::RectF(textLeft, rect.Y, std::max(8.0f, textWidth), rect.Height), textColor,
|
||||
TextAlign::LEFT);
|
||||
}
|
||||
|
||||
@@ -322,21 +322,6 @@ namespace jdi
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool TextEdit::PlaceCaret(std::size_t offset)
|
||||
{
|
||||
if (!m_active)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::size_t target = ClampOffset(offset);
|
||||
const bool changed = HasSelection() || (m_caret != target);
|
||||
m_caret = target;
|
||||
m_anchor = target;
|
||||
m_fresh = false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
void TextEdit::BeginDrag(std::size_t offset)
|
||||
{
|
||||
if (!m_active)
|
||||
|
||||
@@ -80,9 +80,4 @@ namespace jdi
|
||||
return kSignalPalette;
|
||||
}
|
||||
|
||||
int SignalColorCount()
|
||||
{
|
||||
return static_cast<int>(sizeof(kSignalPalette) / sizeof(kSignalPalette[0]));
|
||||
}
|
||||
|
||||
} // namespace jdi
|
||||
@@ -50,30 +50,6 @@ namespace jdi
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string WideToUtf8(const wchar_t* text)
|
||||
{
|
||||
if (text == nullptr)
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
int wideCount = static_cast<int>(std::wcslen(text));
|
||||
if (wideCount <= 0)
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
int byteCount = WideCharToMultiByte(CP_UTF8, 0, text, wideCount, nullptr, 0, nullptr, nullptr);
|
||||
if (byteCount <= 0)
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string result(static_cast<size_t>(byteCount), '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, text, wideCount, &result[0], byteCount, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring Trim(const std::wstring& text)
|
||||
{
|
||||
size_t begin = 0;
|
||||
@@ -117,15 +93,6 @@ namespace jdi
|
||||
return result;
|
||||
}
|
||||
|
||||
bool StartsWith(const std::wstring& text, const std::wstring& prefix)
|
||||
{
|
||||
if (prefix.size() > text.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return text.compare(0, prefix.size(), prefix) == 0;
|
||||
}
|
||||
|
||||
bool ContainsInsensitive(const std::wstring& text, const std::wstring& needle)
|
||||
{
|
||||
if (needle.empty())
|
||||
|
||||
Reference in new issue
Block a user