Compare commits

...

3 Commits

6 changed files with 126 additions and 17 deletions

View File

@ -5,9 +5,10 @@
#include <QHBoxLayout>
#include <QFileInfo>
#include <QMessageBox>
#include <QVariant>
LightPanel::LightPanel(int index, const QString& filePath, QWidget* parent)
: DataPanel(index, FileEntryType::Curve, filePath, parent)
: DataPanel(index, FileEntryType::Light, filePath, parent)
{
LOG_INFO("Created LightPanel {} for file: {}", index, filePath.toStdString());
}
@ -45,10 +46,6 @@ void LightPanel::RefreshPanel()
void LightPanel::InitUI()
{
QHBoxLayout* mainLayout = new QHBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
//mainLayout->addWidget(m_pTableWidget);
setLayout(mainLayout);
}
QString LightPanel::GetTypeDisplayName() const
@ -61,19 +58,41 @@ void LightPanel::OnDataPanelUpdated(FileEntryLight* fileEntry)
QString strName = fileEntry->GetName();
updateTitle(strName);
//FileEntryTable::ChartProperties propChart = fileEntry->GetChartProperties();
FileEntryLight::ColorProperties propChart = fileEntry->GetColorProperties();
//QStringList tableHeader = propChart.headerString.split(',', Qt::SkipEmptyParts);
//SetHeader(tableHeader);
QString openColor = QColorToString(propChart.openColor);
QString closeColor = QColorToString(propChart.closeColor);
updateLampColor(openColor, closeColor);
//QString strFile = fileEntry->GetPath() + "/" + fileEntry->GetFileName();
//FileEntryTable::TableProperties listCurve = fileEntry->GetTableProperties();
//updateParseFile(strFile, propChart.timeParam, listCurve);
QString strFile = fileEntry->GetPath() + "/" + fileEntry->GetFileName();
FileEntryLight::LightRowProperties 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)
@ -83,3 +102,82 @@ void LightPanel::updateTitle(const QString & title)
dockWidget_->setWindowTitle(title);
}
}
void LightPanel::updateParseFile(const QString & strFile, int nT, FileEntryLight::LightRowProperties listCurve)
{
if (strFile.isEmpty())
{
QMessageBox::information(nullptr, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请检查数据文件路径!"));
return;
}
QFile file(strFile);
if (file.open(QIODevice::ReadOnly))
{
QGridLayout* pMainLyt = new QGridLayout(this);
for (int nI = 0; nI < listCurve.size(); nI++)
{
FileEntryLight::LightRowProperty prop = listCurve.at(nI);
for (auto i = 0; i < prop.name.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(prop.name.at(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++)
{
FileEntryLight::LightRowProperty prop = listCurve.at(nI);
for (int nJ = 0; nJ < prop.data.size(); ++nJ)
{
int nIndex = prop.data.at(nJ);
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);
}
}

View File

@ -3,6 +3,8 @@
#include "DataPanel.h"
#include "workspace/FileEntry.h"
#include <memory>
#include "ui/Layout/SignalLabel.h"
#include <QMap>
class LightPanel : public DataPanel
{
@ -59,5 +61,12 @@ protected:
private:
void updateTitle(const QString& title);
void updateParseFile(const QString& strFile, int nT, FileEntryLight::LightRowProperties listCurve);
void updateLampColor(const QString& strOpenColor, const QString& strCloseColor);
private:
QMap<int, QString> m_lampColor;
QMap<QString, SignalLabel*> m_mapLamp;
QMap< double, QVariantMap > m_dataLamp;
};

View File

@ -8,7 +8,7 @@
#include <Q3DCamera>
SurfacePanel::SurfacePanel(int index, const QString& filePath, QWidget* parent)
: DataPanel(index, FileEntryType::Curve, filePath, parent)
: DataPanel(index, FileEntryType::Surface, filePath, parent)
{
m_iMinX = 0; m_iMaxX = 0;
m_iMinY = 0; m_iMaxY = 0;

View File

@ -8,7 +8,7 @@
#include <QHeaderView>
TablePanel::TablePanel(int index, const QString& filePath, QWidget* parent)
: DataPanel(index, FileEntryType::Curve, filePath, parent)
: DataPanel(index, FileEntryType::Table, filePath, parent)
{
LOG_INFO("Created TablePanel {} for file: {}", index, filePath.toStdString());
}

View File

@ -648,4 +648,4 @@ bool FileEntryCurve::ParseFiles(const tinyxml2::XMLElement* chartElement) {
}
return true;
}
}

View File

@ -86,6 +86,9 @@ protected:
QString name_;
};
QString QColorToString(const QColor& color);
QColor StringToQColor(const QString& colorStr);
// Factory functions for creating FileEntry objects
std::shared_ptr<FileEntry> CreateFileEntry(FileEntryType type, const QString& filePath);
std::shared_ptr<FileEntryCurve> CreateFileEntryCurve(const QString& filePath);
@ -262,6 +265,7 @@ public:
struct ColorProperties {
QColor openColor;
QColor closeColor;
double timeParam;
};
struct LightRowProperty {
@ -269,7 +273,6 @@ public:
QList<int> data;
};
using LightRowProperties = QList<LightRowProperty>;
public:
@ -284,7 +287,6 @@ public:
FileEntryLight* AsLight() override { return this; }
// XML处理方法
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
bool ParseFiles(const tinyxml2::XMLElement* element) override;