187 lines
4.8 KiB
C++
187 lines
4.8 KiB
C++
#include "ui/Panel/LightPanel.h"
|
||
#include "ui/DockWidget.h"
|
||
#include "ui/DockTitleBar.h"
|
||
#include "common/SpdLogger.h"
|
||
#include <QHBoxLayout>
|
||
#include <QFileInfo>
|
||
#include <QMessageBox>
|
||
#include <QVariant>
|
||
|
||
LightPanel::LightPanel(int index, const QString& filePath, QWidget* parent)
|
||
: DataPanel(index, FileEntryType::Light, filePath, parent)
|
||
{
|
||
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);
|
||
|
||
FileEntryLight::ColorProperties propChart = fileEntry->GetColorProperties();
|
||
|
||
QString openColor = QColorToString(propChart.openColor);
|
||
QString closeColor = QColorToString(propChart.closeColor);
|
||
updateLampColor(openColor, closeColor);
|
||
|
||
QString strFile = fileEntry->GetPath() + "/" + fileEntry->GetFileName();
|
||
FileEntryLight::LightProperties listCurve = fileEntry->GetLightProperties();
|
||
updateParseFile(strFile, propChart.timeParam, listCurve);
|
||
}
|
||
|
||
void LightPanel::OnTimeChanged(double time)
|
||
{
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void LightPanel::updateTitle(const QString & title)
|
||
{
|
||
if (nullptr != dockWidget_)
|
||
{
|
||
dockWidget_->setWindowTitle(title);
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
} |