DYTSrouce/src/ui/Panel/LightPanel.cpp

187 lines
4.8 KiB
C++
Raw Normal View History

2025-10-27 12:39:49 +00:00
#include "ui/Panel/LightPanel.h"
#include "ui/DockWidget.h"
#include "ui/DockTitleBar.h"
#include "common/SpdLogger.h"
#include <QHBoxLayout>
#include <QFileInfo>
#include <QMessageBox>
2025-10-27 14:09:22 +00:00
#include <QVariant>
2025-10-27 12:39:49 +00:00
LightPanel::LightPanel(int index, const QString& filePath, QWidget* parent)
2025-10-27 14:09:22 +00:00
: DataPanel(index, FileEntryType::Light, filePath, parent)
2025-10-27 12:39:49 +00:00
{
LOG_INFO("Created LightPanel {} for file: {}", index, filePath.toStdString());
}
LightPanel::LightPanel(int index, std::shared_ptr<FileEntryLight> fileEntry, QWidget* parent)
: DataPanel(index, fileEntry, parent)
{
if (fileEntry) {
LOG_INFO("Created LightPanel {} for chart: {}", index, fileEntry->GetName().toStdString());
// Override the title with chart name
title_ = QString("Light Panel %1 - %2").arg(index).arg(fileEntry->GetName());
}
else {
LOG_WARN("Created LightPanel {} with null chart data", index);
}
}
LightPanel::~LightPanel()
{
LOG_INFO("Destroyed LightPanel {}", GetIndex());
}
void LightPanel::RefreshPanel()
{
// Implement curve-specific refresh logic here
DataPanel::RefreshPanel();
if (auto fileEntry = fileEntry_->AsLight()) {
OnDataPanelUpdated(fileEntry);
}
LOG_INFO("Refreshed TablePanel {}", GetIndex());
}
void LightPanel::InitUI()
{
}
QString LightPanel::GetTypeDisplayName() const
{
return "Light";
}
void LightPanel::OnDataPanelUpdated(FileEntryLight* fileEntry)
{
QString strName = fileEntry->GetName();
updateTitle(strName);
2025-10-27 14:09:22 +00:00
FileEntryLight::ColorProperties propChart = fileEntry->GetColorProperties();
2025-10-27 12:39:49 +00:00
2025-10-27 14:09:22 +00:00
QString openColor = QColorToString(propChart.openColor);
QString closeColor = QColorToString(propChart.closeColor);
updateLampColor(openColor, closeColor);
2025-10-27 12:39:49 +00:00
2025-10-27 14:09:22 +00:00
QString strFile = fileEntry->GetPath() + "/" + fileEntry->GetFileName();
FileEntryLight::LightProperties listCurve = fileEntry->GetLightProperties();
updateParseFile(strFile, propChart.timeParam, listCurve);
2025-10-27 12:39:49 +00:00
}
void LightPanel::OnTimeChanged(double time)
{
2025-10-27 14:09:22 +00:00
if (m_dataLamp.size() > 0)
{
QMap< double, QVariantMap >::const_iterator ite = m_dataLamp.lowerBound(time);
if (ite == m_dataLamp.end())
{
ite--;
}
QVariantMap mapData = ite.value();
for (QVariantMap::Iterator it = mapData.begin(); it != mapData.end(); it++)
{
QString strKey = it.key();
int nState = it.value().toFloat();
SignalLabel* pLampLab = m_mapLamp.value(strKey);
if (pLampLab)
{
QString strStyle = m_lampColor.value(nState);
pLampLab->setStyleSheet(strStyle);
}
}
}
2025-10-27 12:39:49 +00:00
}
void LightPanel::updateTitle(const QString & title)
{
if (nullptr != dockWidget_)
{
dockWidget_->setWindowTitle(title);
}
}
2025-10-27 14:09:22 +00:00
void LightPanel::updateParseFile(const QString & strFile, int nT, FileEntryLight::LightProperties listCurve)
{
if (strFile.isEmpty())
{
QMessageBox::information(nullptr, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
return;
}
QFile file(strFile);
if (file.open(QIODevice::ReadOnly))
{
/*QGridLayout* pMainLyt = new QGridLayout(this);
for (int nI = 0; nI < listCurve.size(); nI++)
{
QVariantMap mapCurve = listCurve.at(nI).toMap();
QString strName = mapCurve.value("Name").toString();
QStringList lamps = strName.split(",");
for (auto i = 0; i < lamps.size(); ++i)
{
SignalLabel* pLampLab = new SignalLabel;
pLampLab->setFixedSize(24, 24);
QString strStyle = m_lampColor.value(0);
pLampLab->setStyleSheet(strStyle);
QLabel* pTextLab = new QLabel;
pTextLab->setText(lamps[i]);
QHBoxLayout* pLyt = new QHBoxLayout;
pLyt->addWidget(pLampLab);
pLyt->addWidget(pTextLab);
pMainLyt->addLayout(pLyt, nI, i);
QString strKey = QString::number(nI) + "-" + QString::number(i);
m_mapLamp.insert(strKey, pLampLab);
}
}
while (!file.atEnd())
{
QString strLine = file.readLine().simplified();
if (!strLine.isEmpty())
{
QStringList listLine = strLine.split(" ");
double t = listLine.at(nT).toDouble();
QVariantMap mapData;
for (int nI = 0; nI < listCurve.size(); nI++)
{
QVariantMap mapCurve = listCurve.at(nI).toMap();
QString strData = mapCurve.value("Data").toString();
QStringList lamps = strData.split(",");
for (int nJ = 0; nJ < lamps.size(); ++nJ)
{
int nIndex = lamps.at(nJ).toInt();
QString nState = listLine.at(nIndex);
QString strKey = QString::number(nI) + "-" + QString::number(nJ);
mapData.insert(strKey, nState);
}
}
m_dataLamp.insert(t, mapData);
}
}*/
file.close();
}
}
void LightPanel::updateLampColor(const QString & strOpenColor, const QString & strCloseColor)
{
{
QString strStyle = "QLabel{background-color: rgb(" + strCloseColor + ");border-radius: 10px;}; ";
m_lampColor.insert(0, strStyle);
}
{
QString strStyle = "QLabel{background-color: rgb(" + strOpenColor + ");border-radius: 10px;}; ";
m_lampColor.insert(1, strStyle);
}
}