#ifndef CUSTOMDISPLAYPANEL_H
#define CUSTOMDISPLAYPANEL_H

#include <QWidget>
#include <QHBoxLayout>
#include <QStringList>
#include <QLabel>
#include <QVector>
#include <QTableWidget>

#include "openjson.h"

/**
 *  创建一个自定义的显示面板
 *  上半部分的左边为图示,右边为显示的主要KPI指标标签
 *  下半部为表格,显示主要的参数
*/

class CustomDisplayPanel : public QWidget
{
    Q_OBJECT
public:
    explicit CustomDisplayPanel(QWidget *parent = nullptr);

protected:
    int m_label_count;
    int m_table_rows_count;
    int m_table_rols_count;
    QStringList m_lables;
    QStringList m_rowItems;
    QString m_imagePath;
    QString m_mainLabel;

    QVector<QLabel*> m_txtLabels;
    QTableWidget* m_pTableWidget;

public:
    typedef enum _tagPanelType: int
    {
        PANEL_TEMPERATURE = 1, //温度传感器
        PANEL_BATTERY = 2,  //电池Pack
        PANEL_DCPOWER = 3, //直流电源
        PANEL_ACFAN = 4,       //空调风扇
        PANEL_PV = 5,       //太阳能
        PANEL_ALARM = 6,    //告警
        PANEL_INVERTER = 7, //逆变器整流器
        PANEL_ACPOWER = 8,      //交流电源
        PANEL_OTHER = 88,       //其它
        PANEL_HOME = 99,        //传感器,水浸门禁
    } PanelType;

public:
    void setImage(const QString& img)
    {
        m_imagePath = img;
    }

    //设置显示指标和表格数据,其中显示的标签数量需要跟QStringlist的数量一致
    void setLableCount(int number = 5)
    {
        m_label_count = number;
    };
    void setTableRolCount(int number = 2)
    {
        m_table_rols_count = number;
    }
    void setTableRowsCount(int number = 10)
    {
        m_table_rows_count = number;
    };

    void setLables(const QStringList& sl)
    {
        m_lables = sl;
    }
    void setRowItems(const QStringList& sl)
    {
        m_rowItems = sl;
    }
    //设置Panel的标题
    void setMainLabel(QString label)
    {
        m_mainLabel = label;
    }

    virtual void Build();

public:
    //更新数据
    void UpdateData(OpenJson& json,bool app=false);

    void UpdateTemperature(OpenJson& json,bool app=false);
    void UpdateAlarm(OpenJson& json,bool app=false);
public:


signals:
};

class CustomWarningPanel : public CustomDisplayPanel
{
    Q_OBJECT
public:
    explicit CustomWarningPanel(QWidget *parent = nullptr);
    virtual void Build();
};

#endif // CUSTOMDISPLAYPANEL_H