79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
|
|
#include "LegendForm.h"
|
||
|
|
#include "ui_LegendForm.h"
|
||
|
|
|
||
|
|
#include <QTableWidgetItem>
|
||
|
|
#include <QDebug>
|
||
|
|
|
||
|
|
#define CHAID_ROLE (Qt::UserRole + 2)
|
||
|
|
|
||
|
|
LegendForm::LegendForm(QWidget *parent) :
|
||
|
|
BaseWgt(parent),
|
||
|
|
ui(new Ui::LegendForm)
|
||
|
|
{
|
||
|
|
ui->setupUi(m_pMainWgt);
|
||
|
|
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
|
||
|
|
setCloseBtnVisible(false);
|
||
|
|
|
||
|
|
Init();
|
||
|
|
}
|
||
|
|
|
||
|
|
LegendForm::~LegendForm()
|
||
|
|
{
|
||
|
|
delete ui;
|
||
|
|
}
|
||
|
|
|
||
|
|
void LegendForm::SetChannelIDs(const QStringList &strIDList)
|
||
|
|
{
|
||
|
|
//clear table
|
||
|
|
for (int i = 0; i < ui->tableWidget->rowCount(); ++i)
|
||
|
|
{
|
||
|
|
QTableWidgetItem *pItem = ui->tableWidget->itemAt(i, 0);
|
||
|
|
QTableWidgetItem *pItem1 = ui->tableWidget->itemAt(i, 1);
|
||
|
|
|
||
|
|
if(pItem) delete pItem;
|
||
|
|
if(pItem1) delete pItem1;
|
||
|
|
}
|
||
|
|
ui->tableWidget->clearContents();
|
||
|
|
ui->tableWidget->setRowCount(0);
|
||
|
|
|
||
|
|
m_strIDList = strIDList;
|
||
|
|
foreach(QString strID, strIDList)
|
||
|
|
{
|
||
|
|
QString strNum1 = strID.right(2).left(1);
|
||
|
|
QString strNum2 = strID.right(1);
|
||
|
|
QString strText = QStringLiteral("第%1板卡第%2通道").arg(strNum1).arg(strNum2);
|
||
|
|
QTableWidgetItem*pItem = AddTableWgtItem(strText, strID);
|
||
|
|
pItem->setData(CHAID_ROLE, strID);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void LegendForm::SetValue(QString strID, QString strValue)
|
||
|
|
{
|
||
|
|
qDebug()<<"LegendForm::SetValue"<<strID<<strValue;
|
||
|
|
QTableWidgetItem *pItem = m_mapChannelIDtoItem[strID];
|
||
|
|
pItem->setText(strValue);
|
||
|
|
}
|
||
|
|
|
||
|
|
void LegendForm::Init()
|
||
|
|
{
|
||
|
|
ui->tableWidget->setColumnCount(2);
|
||
|
|
|
||
|
|
ui->tableWidget->setColumnWidth(0, 120);
|
||
|
|
}
|
||
|
|
|
||
|
|
QTableWidgetItem *LegendForm::AddTableWgtItem(QString strText, QString strID)
|
||
|
|
{
|
||
|
|
ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
|
||
|
|
QTableWidgetItem *pItemName = new QTableWidgetItem();
|
||
|
|
pItemName->setText(strText);
|
||
|
|
QTableWidgetItem *pItemValue = new QTableWidgetItem();
|
||
|
|
pItemValue->setText("");
|
||
|
|
|
||
|
|
ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, 0, pItemName);
|
||
|
|
ui->tableWidget->setItem(ui->tableWidget->rowCount() - 1, 1, pItemValue);
|
||
|
|
qDebug()<<"LegendForm::AddTableWgtItem:::::::"<<ui->tableWidget->rowCount() - 1<<strText;
|
||
|
|
|
||
|
|
m_mapChannelIDtoItem[strID] = pItemValue;
|
||
|
|
return pItemName;
|
||
|
|
}
|