modified lightpanel
This commit is contained in:
parent
843d2cf158
commit
cedda254e5
@ -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::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)
|
||||
@ -83,3 +102,86 @@ void LightPanel::updateTitle(const QString & title)
|
||||
dockWidget_->setWindowTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
void LightPanel::updateParseFile(const QString & strFile, int nT, FileEntryLight::LightProperties 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++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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::LightProperties 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;
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -546,3 +546,53 @@ bool FileEntryCurve::ParseFiles(const tinyxml2::XMLElement* chartElement) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileEntryLight::SaveFiles(tinyxml2::XMLElement * scene, tinyxml2::XMLDocument * doc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileEntryLight::ParseFiles(const tinyxml2::XMLElement * element)
|
||||
{
|
||||
if (!element) {
|
||||
LOG_ERROR("Invalid XML element");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 解析chart属性
|
||||
const char* nameAttr = element->Attribute("name");
|
||||
const char* pathAttr = element->Attribute("path");
|
||||
if (nameAttr) name_ = QString::fromUtf8(nameAttr);
|
||||
if (pathAttr) {
|
||||
QString fullPath = QString::fromUtf8(pathAttr);
|
||||
QFileInfo fileInfo(fullPath);
|
||||
fileName_ = fileInfo.fileName();
|
||||
path_ = fileInfo.absolutePath();
|
||||
}
|
||||
|
||||
const char* openColorAttr = element->Attribute("openColor");
|
||||
if (openColorAttr) colorProperties_.openColor = StringToQColor(QString::fromUtf8(openColorAttr));
|
||||
|
||||
const char* closeColorAttr = element->Attribute("closeColor");
|
||||
if (closeColorAttr) colorProperties_.closeColor = StringToQColor(QString::fromUtf8(closeColorAttr));
|
||||
|
||||
colorProperties_.timeParam = element->DoubleAttribute("t", 0.0);
|
||||
|
||||
// 解析所有<curve>元素
|
||||
lightProperties_.clear();
|
||||
for (const tinyxml2::XMLElement* curveElement = element->FirstChildElement("curve");
|
||||
curveElement != nullptr;
|
||||
curveElement = curveElement->NextSiblingElement("curve")) {
|
||||
|
||||
LightProperty light;
|
||||
|
||||
const char* curveNameAttr = curveElement->Attribute("name");
|
||||
const char* dataAttr = curveElement->Attribute("data");
|
||||
//if (curveNameAttr) light.names = QString::fromUtf8(curveNameAttr);
|
||||
//if (dataAttr) light.datas = QString::fromUtf8(dataAttr);
|
||||
|
||||
lightProperties_.append(light);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -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,11 +265,13 @@ public:
|
||||
struct ColorProperties {
|
||||
QColor openColor;
|
||||
QColor closeColor;
|
||||
double timeParam;
|
||||
};
|
||||
|
||||
struct LightProperty {
|
||||
QString name;
|
||||
int index;
|
||||
int indexRow;
|
||||
int indexColumn;
|
||||
};
|
||||
|
||||
using LightProperties = QList<LightProperty>;
|
||||
@ -283,6 +288,10 @@ public:
|
||||
|
||||
FileEntryLight* AsLight() override { return this; }
|
||||
|
||||
// XML处理方法
|
||||
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) override;
|
||||
bool ParseFiles(const tinyxml2::XMLElement* element) override;
|
||||
|
||||
private:
|
||||
ColorProperties colorProperties_;
|
||||
LightProperties lightProperties_;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user