[ref]同步711
This commit is contained in:
parent
7a7a833210
commit
343e7a8d41
@ -1,4 +1,4 @@
|
|||||||
#include "CDbInterface.h"
|
#include "CDbInterface.h"
|
||||||
#include "service/perm_mng_api/PermMngApi.h"
|
#include "service/perm_mng_api/PermMngApi.h"
|
||||||
#include "pub_logger_api/logger.h"
|
#include "pub_logger_api/logger.h"
|
||||||
|
|
||||||
@ -424,7 +424,7 @@ bool CDbInterface::isSetValueEnable(int status, int table)
|
|||||||
|
|
||||||
bool CDbInterface::isBitEnable(int status, int checkNum)
|
bool CDbInterface::isBitEnable(int status, int checkNum)
|
||||||
{
|
{
|
||||||
return (status >> (checkNum)) & 0x01 == 0x01;
|
return ((status >> (checkNum)) & 0x01) == 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CDbInterface::getDiStatusStr(int status)
|
QString CDbInterface::getDiStatusStr(int status)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#ifndef CDBINTERFACE_H
|
#ifndef CDBINTERFACE_H
|
||||||
#define CDBINTERFACE_H
|
#define CDBINTERFACE_H
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "CDevRealDataPluginWidget.h"
|
#include "CDevRealDataPluginWidget.h"
|
||||||
#include "CDevRealDataWidget.h"
|
#include "CDevRealDataWidget.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#ifndef CDEVREALDATAPLUGINWIDGET_H
|
#ifndef CDEVREALDATAPLUGINWIDGET_H
|
||||||
#define CDEVREALDATAPLUGINWIDGET_H
|
#define CDEVREALDATAPLUGINWIDGET_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@ -7,7 +7,7 @@
|
|||||||
class CDevRealDataPluginWidget : public QObject, public CPluginWidgetInterface
|
class CDevRealDataPluginWidget : public QObject, public CPluginWidgetInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "kbd.PluginWidgetInterface/1.0")
|
Q_PLUGIN_METADATA(IID HMI_WidgetPlugin_IID)
|
||||||
Q_INTERFACES(CPluginWidgetInterface)
|
Q_INTERFACES(CPluginWidgetInterface)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "CDevRealDataWidget.h"
|
#include "CDevRealDataWidget.h"
|
||||||
#include "ui_CDevRealDataWidget.h"
|
#include "ui_CDevRealDataWidget.h"
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include "pub_utility_api/FileStyle.h"
|
#include "pub_utility_api/FileStyle.h"
|
||||||
@ -129,10 +129,16 @@ void CDevRealDataWidget::setTableColumnWidth(int column, int width)
|
|||||||
ui->m_tableView->setColumnWidth(column, width);
|
ui->m_tableView->setColumnWidth(column, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDevRealDataWidget::setTableColumnName(int column, const QString &name)
|
||||||
|
{
|
||||||
|
CRealTableModel* model = (CRealTableModel*)ui->m_tableView->model();
|
||||||
|
model->setTableColumnName(column,name);
|
||||||
|
}
|
||||||
|
|
||||||
void CDevRealDataWidget::resetDeviceGroup(const QStringList &tagList)
|
void CDevRealDataWidget::resetDeviceGroup(const QStringList &tagList)
|
||||||
{
|
{
|
||||||
ui->widget->setHidden(true);
|
// ui->widget->setHidden(true);
|
||||||
ui->frame_5->setVisible(true);
|
// ui->frame_5->setVisible(true);
|
||||||
ui->m_devGroupComb->blockSignals(true);
|
ui->m_devGroupComb->blockSignals(true);
|
||||||
ui->m_devGroupComb->clear();
|
ui->m_devGroupComb->clear();
|
||||||
|
|
||||||
@ -141,12 +147,17 @@ void CDevRealDataWidget::resetDeviceGroup(const QStringList &tagList)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//非其他设备组
|
||||||
|
|
||||||
QMap<QString, QString>::const_iterator iter = devGroup.constBegin();
|
QMap<QString, QString>::const_iterator iter = devGroup.constBegin();
|
||||||
for(; iter != devGroup.constEnd(); ++iter)
|
for(; iter != devGroup.constEnd(); ++iter)
|
||||||
{
|
{
|
||||||
ui->m_devGroupComb->addItem(iter.value(), iter.key());
|
ui->m_devGroupComb->addItem(iter.value(), iter.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTreeWidgetFromGroup(tagList);
|
||||||
|
|
||||||
ui->m_devGroupComb->blockSignals(false);
|
ui->m_devGroupComb->blockSignals(false);
|
||||||
emit ui->m_devGroupComb->currentIndexChanged(0);
|
emit ui->m_devGroupComb->currentIndexChanged(0);
|
||||||
}
|
}
|
||||||
@ -237,9 +248,16 @@ void CDevRealDataWidget::initialize()
|
|||||||
m_pCollectThread->start();
|
m_pCollectThread->start();
|
||||||
|
|
||||||
//< 初始化表格模型
|
//< 初始化表格模型
|
||||||
m_realModel = new CRealTableModel(this);
|
m_realModel = new CRealTableModel(ui->m_tableView);
|
||||||
|
|
||||||
ui->m_tableView->setModel(m_realModel);
|
ui->m_tableView->setModel(m_realModel);
|
||||||
|
ui->m_tableView->horizontalHeader()->setDefaultSectionSize(350);
|
||||||
ui->m_tableView->horizontalHeader()->setStretchLastSection(true);
|
ui->m_tableView->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
ui->m_tableView->setAlternatingRowColors(true);
|
||||||
|
ui->m_tableView->setHorizontalHeader(new CustomHeaderView(Qt::Horizontal,ui->m_tableView));
|
||||||
|
ui->m_tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||||
|
connect(ui->m_tableView->horizontalHeader(),&QHeaderView::sectionCountChanged,ui->m_tableView,&CTableView::adjustHeaderWidth);
|
||||||
|
|
||||||
connect(ui->m_tableView->selectionModel(),
|
connect(ui->m_tableView->selectionModel(),
|
||||||
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
||||||
this,
|
this,
|
||||||
@ -251,8 +269,7 @@ void CDevRealDataWidget::initialize()
|
|||||||
SLOT(slotDataChanged(const QModelIndex &, const QModelIndex &)));
|
SLOT(slotDataChanged(const QModelIndex &, const QModelIndex &)));
|
||||||
|
|
||||||
ui->treeWidget->setColumnCount(1);
|
ui->treeWidget->setColumnCount(1);
|
||||||
setTableColumnWidth(0,300);
|
|
||||||
setTableColumnWidth(2,300);
|
|
||||||
connect(ui->m_subCb, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTreeWidget()));
|
connect(ui->m_subCb, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTreeWidget()));
|
||||||
connect(ui->m_locCb, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTreeWidget()));
|
connect(ui->m_locCb, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTreeWidget()));
|
||||||
connect(ui->m_devGroupComb, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDeviceUpdate()));
|
connect(ui->m_devGroupComb, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDeviceUpdate()));
|
||||||
@ -299,6 +316,8 @@ void CDevRealDataWidget::updateTreeWidget()
|
|||||||
slotShowMess(tr("查询设备组信息失败!"));
|
slotShowMess(tr("查询设备组信息失败!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for(int nIndex(0);nIndex<devgList.count();nIndex++)
|
for(int nIndex(0);nIndex<devgList.count();nIndex++)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *devgItem = new QTreeWidgetItem();
|
QTreeWidgetItem *devgItem = new QTreeWidgetItem();
|
||||||
@ -309,7 +328,64 @@ void CDevRealDataWidget::updateTreeWidget()
|
|||||||
|
|
||||||
QMap<QString, QString> devInfo = CDbInterface::instance()->deviceInfo(devgList.at(nIndex).first);
|
QMap<QString, QString> devInfo = CDbInterface::instance()->deviceInfo(devgList.at(nIndex).first);
|
||||||
QMap<QString,QString>::iterator pos = devInfo.begin();
|
QMap<QString,QString>::iterator pos = devInfo.begin();
|
||||||
while (pos != devInfo.end()) {
|
while (pos != devInfo.end())
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *devItem = new QTreeWidgetItem();
|
||||||
|
devItem->setText(0,pos.value());
|
||||||
|
devItem->setData(0,Qt::UserRole,(int)EN_TREE_DEV);//类型
|
||||||
|
devItem->setData(0,Qt::UserRole+1,pos.key());//值
|
||||||
|
devgItem->addChild(devItem);
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
devgItem->sortChildren(0,Qt::SortOrder::AscendingOrder);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ui->treeWidget->topLevelItem(0))
|
||||||
|
{
|
||||||
|
emit ui->treeWidget->itemClicked(ui->treeWidget->topLevelItem(0), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDevRealDataWidget::updateTreeWidgetFromGroup(const QStringList &tagList)
|
||||||
|
{
|
||||||
|
ui->mSearchLineEdit->clear();
|
||||||
|
cleanTreeWidget();
|
||||||
|
int nLocId = ui->m_locCb->currentData().toInt();
|
||||||
|
int nSubId = ui->m_subCb->currentData().toInt();
|
||||||
|
QList<QPair<QString,QString>> devgList;
|
||||||
|
if(!CDbInterface::instance()->queryDevGroupInfoList(nLocId,nSubId,devgList))
|
||||||
|
{
|
||||||
|
slotShowMess(tr("查询设备组信息失败!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> devGroup = CDbInterface::instance()->readDevGroupDesc(tagList);
|
||||||
|
if(devGroup.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int nIndex(0);nIndex<devgList.count();nIndex++)
|
||||||
|
{
|
||||||
|
|
||||||
|
QMap<QString, QString>::const_iterator iterGroup = devGroup.constBegin();
|
||||||
|
for(; iterGroup != devGroup.constEnd(); ++iterGroup)
|
||||||
|
{
|
||||||
|
// ui->m_devGroupComb->addItem(iterGroup.value(), iterGroup.key());
|
||||||
|
|
||||||
|
if(devgList.at(nIndex).first ==iterGroup.key())
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *devgItem = new QTreeWidgetItem();
|
||||||
|
devgItem->setText(0,devgList.at(nIndex).second);
|
||||||
|
devgItem->setData(0,Qt::UserRole,(int)EN_TREE_DEVG);//类型
|
||||||
|
devgItem->setData(0,Qt::UserRole+1,devgList.at(nIndex).first);//值
|
||||||
|
ui->treeWidget->addTopLevelItem(devgItem);
|
||||||
|
|
||||||
|
QMap<QString, QString> devInfo = CDbInterface::instance()->deviceInfo(devgList.at(nIndex).first);
|
||||||
|
QMap<QString,QString>::iterator pos = devInfo.begin();
|
||||||
|
while (pos != devInfo.end())
|
||||||
|
{
|
||||||
QTreeWidgetItem *devItem = new QTreeWidgetItem();
|
QTreeWidgetItem *devItem = new QTreeWidgetItem();
|
||||||
devItem->setText(0,pos.value());
|
devItem->setText(0,pos.value());
|
||||||
devItem->setData(0,Qt::UserRole,(int)EN_TREE_DEV);//类型
|
devItem->setData(0,Qt::UserRole,(int)EN_TREE_DEV);//类型
|
||||||
@ -318,6 +394,9 @@ void CDevRealDataWidget::updateTreeWidget()
|
|||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(ui->treeWidget->topLevelItem(0))
|
if(ui->treeWidget->topLevelItem(0))
|
||||||
{
|
{
|
||||||
emit ui->treeWidget->itemClicked(ui->treeWidget->topLevelItem(0), 0);
|
emit ui->treeWidget->itemClicked(ui->treeWidget->topLevelItem(0), 0);
|
||||||
@ -772,6 +851,7 @@ void CDevRealDataWidget::slotUpdateAi(QMap<QString, QPair<float, uint> > aiMap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QList<SRealData> dataList = m_realData.values();
|
QList<SRealData> dataList = m_realData.values();
|
||||||
|
LOGINFO("slotUpdateAi dataList:%d",dataList.count());
|
||||||
m_realModel->updateRealValue(dataList);
|
m_realModel->updateRealValue(dataList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,6 +925,7 @@ void CDevRealDataWidget::slotUpdatePi(QMap<QString, QPair<double, uint> > piMap)
|
|||||||
|
|
||||||
void CDevRealDataWidget::slotUpdateMi(QMap<QString, QPair<int, uint> > miMap)
|
void CDevRealDataWidget::slotUpdateMi(QMap<QString, QPair<int, uint> > miMap)
|
||||||
{
|
{
|
||||||
|
|
||||||
QMap<QString, QPair<int, uint> >::iterator iter = miMap.begin();
|
QMap<QString, QPair<int, uint> >::iterator iter = miMap.begin();
|
||||||
for(; iter != miMap.end(); iter++)
|
for(; iter != miMap.end(); iter++)
|
||||||
{
|
{
|
||||||
@ -903,6 +984,9 @@ void CDevRealDataWidget::treeItemClicked(QTreeWidgetItem *item, int column)
|
|||||||
brush();
|
brush();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGINFO("点击树节点");
|
||||||
|
|
||||||
if(item->data(0,Qt::UserRole).toInt() == EN_TREE_LOC)
|
if(item->data(0,Qt::UserRole).toInt() == EN_TREE_LOC)
|
||||||
{
|
{
|
||||||
return ;
|
return ;
|
||||||
@ -931,7 +1015,7 @@ void CDevRealDataWidget::brush()
|
|||||||
m_piMap.clear();
|
m_piMap.clear();
|
||||||
m_miMap.clear();
|
m_miMap.clear();
|
||||||
m_pDpcdaForApp->unsubscribeAll();
|
m_pDpcdaForApp->unsubscribeAll();
|
||||||
// LOGINFO("DEVREAL slotPointTableUpdate --unsubscribeAll()");
|
LOGINFO("DEVREAL slotPointTableUpdate --unsubscribeAll()");
|
||||||
|
|
||||||
QMap<QString, QMap<QString, QString>> pointMap = CDbInterface::instance()->readPointInfo(m_devList, curPointTable().split(",", QString::SkipEmptyParts));
|
QMap<QString, QMap<QString, QString>> pointMap = CDbInterface::instance()->readPointInfo(m_devList, curPointTable().split(",", QString::SkipEmptyParts));
|
||||||
QMap<QString, QMap<QString, QString>>::const_iterator fIter = pointMap.constBegin();
|
QMap<QString, QMap<QString, QString>>::const_iterator fIter = pointMap.constBegin();
|
||||||
@ -996,6 +1080,8 @@ void CDevRealDataWidget::brush()
|
|||||||
// LOGINFO("DEVREAL subscribe value,status tag_name: %s", iter.key().toStdString().c_str());
|
// LOGINFO("DEVREAL subscribe value,status tag_name: %s", iter.key().toStdString().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGINFO("m_realData count:%d" +m_realData.count());
|
||||||
m_realModel->updateRealData(m_realData.values());
|
m_realModel->updateRealData(m_realData.values());
|
||||||
emit ui->m_filterBtn->click();
|
emit ui->m_filterBtn->click();
|
||||||
}
|
}
|
||||||
@ -1080,7 +1166,6 @@ bool CDevRealDataWidget::OptTagInfo(const STOptTagInfo &info)
|
|||||||
msg.setSubject(info.subSystem, CH_HMI_TO_OPT_OPTCMD_DOWN);
|
msg.setSubject(info.subSystem, CH_HMI_TO_OPT_OPTCMD_DOWN);
|
||||||
SOptTagSet sOptTagSet;
|
SOptTagSet sOptTagSet;
|
||||||
SOptTagQueue optTagQueue;
|
SOptTagQueue optTagQueue;
|
||||||
COptTagSet cOptTagSet;
|
|
||||||
|
|
||||||
if(!createReqHead(sOptTagSet.stHead, info))
|
if(!createReqHead(sOptTagSet.stHead, info))
|
||||||
{
|
{
|
||||||
@ -1096,7 +1181,7 @@ bool CDevRealDataWidget::OptTagInfo(const STOptTagInfo &info)
|
|||||||
optTagQueue.nSubSystem = info.subSystem;
|
optTagQueue.nSubSystem = info.subSystem;
|
||||||
|
|
||||||
sOptTagSet.vecTagQueue.push_back(optTagQueue);
|
sOptTagSet.vecTagQueue.push_back(optTagQueue);
|
||||||
std::string content = cOptTagSet.generate(sOptTagSet);
|
std::string content = COptTagSet::generate(sOptTagSet);
|
||||||
|
|
||||||
msg.setMsgType(info.optType);
|
msg.setMsgType(info.optType);
|
||||||
|
|
||||||
@ -1182,7 +1267,7 @@ QString CDevRealDataWidget::checkPerm(int location, int region)
|
|||||||
|
|
||||||
void CDevRealDataWidget::readNodeInfo()
|
void CDevRealDataWidget::readNodeInfo()
|
||||||
{
|
{
|
||||||
if(m_sysInfoPtr->getLocalNodeInfo(m_nodeInfo) == kbdFailed)
|
if(m_sysInfoPtr->getLocalNodeInfo(m_nodeInfo) == iotFailed)
|
||||||
{
|
{
|
||||||
LOGERROR("获取本机节点信息失败!");
|
LOGERROR("获取本机节点信息失败!");
|
||||||
}
|
}
|
||||||
@ -1191,7 +1276,7 @@ void CDevRealDataWidget::readNodeInfo()
|
|||||||
bool CDevRealDataWidget::createReqHead(SOptReqHead &head, const STOptTagInfo &info)
|
bool CDevRealDataWidget::createReqHead(SOptReqHead &head, const STOptTagInfo &info)
|
||||||
{
|
{
|
||||||
SAppInfo stAppInfo;
|
SAppInfo stAppInfo;
|
||||||
if(kbdSuccess != m_sysInfoPtr->getAppInfoBySubsystemId(info.subSystem, stAppInfo))
|
if(iotSuccess != m_sysInfoPtr->getAppInfoBySubsystemId(info.subSystem, stAppInfo))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#ifndef CDEVREALDATAWIDGET_H
|
#ifndef CDEVREALDATAWIDGET_H
|
||||||
#define CDEVREALDATAWIDGET_H
|
#define CDEVREALDATAWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -44,6 +44,7 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void setTableColumnHidden(int column, bool hide);
|
void setTableColumnHidden(int column, bool hide);
|
||||||
void setTableColumnWidth(int column, int width);
|
void setTableColumnWidth(int column, int width);
|
||||||
|
void setTableColumnName(int column,const QString &name);
|
||||||
void resetDeviceGroup(const QStringList& tagList);
|
void resetDeviceGroup(const QStringList& tagList);
|
||||||
void setShowSubSystem(bool isShow);
|
void setShowSubSystem(bool isShow);
|
||||||
|
|
||||||
@ -89,6 +90,7 @@ private slots:
|
|||||||
void treeItemClicked(QTreeWidgetItem *item, int column);
|
void treeItemClicked(QTreeWidgetItem *item, int column);
|
||||||
|
|
||||||
void updateTreeWidget();
|
void updateTreeWidget();
|
||||||
|
void updateTreeWidgetFromGroup(const QStringList &tagList);
|
||||||
void brush();
|
void brush();
|
||||||
|
|
||||||
void slotEnableRefreshBtnClick();//禁止刷新
|
void slotEnableRefreshBtnClick();//禁止刷新
|
||||||
|
|||||||
@ -397,7 +397,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="placeholderText">
|
<property name="placeholderText">
|
||||||
<string>关键字查询</string>
|
<string>测点关键字查询</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "CRealDataCollect.h"
|
#include "CRealDataCollect.h"
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include "pub_logger_api/logger.h"
|
||||||
|
|
||||||
CRealDataCollect::CRealDataCollect(QObject *parent)
|
CRealDataCollect::CRealDataCollect(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
@ -114,6 +115,7 @@ void CRealDataCollect::processChangeData()
|
|||||||
{
|
{
|
||||||
if(!m_aiMap.isEmpty())
|
if(!m_aiMap.isEmpty())
|
||||||
{
|
{
|
||||||
|
LOGINFO("emit signal_updateAi dataList:%d",m_aiMap.count());
|
||||||
emit signal_updateAi(m_aiMap);
|
emit signal_updateAi(m_aiMap);
|
||||||
m_aiMap.clear();
|
m_aiMap.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#ifndef CREALDATACOLLECT_H
|
#ifndef CREALDATACOLLECT_H
|
||||||
#define CREALDATACOLLECT_H
|
#define CREALDATACOLLECT_H
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "CRealTableModel.h"
|
#include "CRealTableModel.h"
|
||||||
|
|
||||||
CRealTableModel::CRealTableModel(QObject *parent)
|
CRealTableModel::CRealTableModel(QObject *parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
@ -39,6 +39,14 @@ QVariant CRealTableModel::headerData(int section, Qt::Orientation orientation, i
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRealTableModel::setTableColumnName(int column, const QString &name)
|
||||||
|
{
|
||||||
|
//if(column < m_header.length())
|
||||||
|
{
|
||||||
|
m_header.replace(column,name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int CRealTableModel::rowCount(const QModelIndex &parent) const
|
int CRealTableModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
@ -178,3 +186,29 @@ QVariant CRealTableModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CustomHeaderView::CustomHeaderView(Qt::Orientation orientation ,QWidget *parent)
|
||||||
|
:QHeaderView(orientation,parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
CustomHeaderView::~CustomHeaderView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
|
||||||
|
{
|
||||||
|
//就简单几句
|
||||||
|
//拿到text数据,在写数据的时候,设置textwordwrap,居中。
|
||||||
|
QString textstr = model()->headerData(visualIndex(logicalIndex),Qt::Horizontal).toString();
|
||||||
|
painter->save();
|
||||||
|
// 从当前样式中获取边框颜色
|
||||||
|
QStyleOptionHeader opt;
|
||||||
|
initStyleOption(&opt);
|
||||||
|
opt.rect = rect;
|
||||||
|
opt.section = logicalIndex;
|
||||||
|
|
||||||
|
// 使用样式绘制边框
|
||||||
|
style()->drawControl(QStyle::CE_HeaderSection, &opt, painter, this);
|
||||||
|
painter->drawText(rect,Qt::TextWordWrap | Qt::AlignCenter, textstr);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
#ifndef CREALTABLEMODEL_H
|
#ifndef CREALTABLEMODEL_H
|
||||||
#define CREALTABLEMODEL_H
|
#define CREALTABLEMODEL_H
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QPainter>
|
||||||
#include "CDbInterface.h"
|
#include "CDbInterface.h"
|
||||||
|
|
||||||
struct SortKey
|
struct SortKey
|
||||||
@ -77,6 +79,7 @@ public:
|
|||||||
|
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
void setTableColumnName(int column, const QString &name);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
@ -87,4 +90,17 @@ private:
|
|||||||
QList<SRealData> m_listRealData;
|
QList<SRealData> m_listRealData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class CustomHeaderView : public QHeaderView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CustomHeaderView(Qt::Orientation orientation = Qt::Horizontal,QWidget *parent = nullptr); //这里为了省事,给默认值为水平表头,因为我正好使用水平的表头
|
||||||
|
~CustomHeaderView();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // CREALTABLEMODEL_H
|
#endif // CREALTABLEMODEL_H
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "CTableView.h"
|
#include "CTableView.h"
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
CTableView::CTableView(QWidget *parent)
|
CTableView::CTableView(QWidget *parent)
|
||||||
: QTableView(parent)
|
: QTableView(parent)
|
||||||
@ -30,3 +31,50 @@ void CTableView::setTableRowHeight(const int &nHeight)
|
|||||||
|
|
||||||
verticalHeader()->setDefaultSectionSize(m_nTableRowHeight);
|
verticalHeader()->setDefaultSectionSize(m_nTableRowHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自动调整表头宽度以适应文本
|
||||||
|
void CTableView::adjustHeaderWidth() {
|
||||||
|
QHeaderView *header = horizontalHeader();
|
||||||
|
int sections = header->count();
|
||||||
|
int maxWidth = 0;
|
||||||
|
QFontMetrics fm(header->font());
|
||||||
|
int maxWidthThreshold = 200;
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < sections; ++i) {
|
||||||
|
QString text = model()->headerData(i, Qt::Horizontal).toString();
|
||||||
|
int width = fm.width(text) + 10; // 加上一些额外空间
|
||||||
|
maxWidth = qMax(maxWidth, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
int heightBase=30;
|
||||||
|
int heightCount=1;
|
||||||
|
for (int i = 0; i < sections; ++i) {
|
||||||
|
QString text = model()->headerData(i, Qt::Horizontal).toString();
|
||||||
|
int width = fm.width(text) + 20; // 加上一些额外空间
|
||||||
|
// 如果宽度超过阈值,则换行
|
||||||
|
if (width > maxWidthThreshold) {
|
||||||
|
header->resizeSection(i, maxWidthThreshold);
|
||||||
|
qreal tmpHeightCount=qreal(width)/qreal(maxWidthThreshold);
|
||||||
|
if(tmpHeightCount>heightCount){
|
||||||
|
heightCount=qCeil(tmpHeightCount);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
maxWidth=210;
|
||||||
|
}
|
||||||
|
header->resizeSection(i, maxWidth);
|
||||||
|
heightCount=2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header->setFixedHeight(heightCount*heightBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void CTableView::showEvent(QShowEvent *event){
|
||||||
|
QTableView::showEvent(event);
|
||||||
|
adjustHeaderWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#ifndef CTABLEVIEW_H
|
#ifndef CTABLEVIEW_H
|
||||||
#define CTABLEVIEW_H
|
#define CTABLEVIEW_H
|
||||||
|
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
@ -17,6 +17,10 @@ public:
|
|||||||
|
|
||||||
int tableRowHeight();
|
int tableRowHeight();
|
||||||
void setTableRowHeight(const int &nHeight);
|
void setTableRowHeight(const int &nHeight);
|
||||||
|
void adjustHeaderWidth();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent(QShowEvent *event) override ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_nTableColWidth;
|
int m_nTableColWidth;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#ifndef CDEVREALDATACOMMON_H
|
#ifndef CDEVREALDATACOMMON_H
|
||||||
#define CDEVREALDATACOMMON_H
|
#define CDEVREALDATACOMMON_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "SetValueInputDialog.h"
|
#include "SetValueInputDialog.h"
|
||||||
#include "ui_SetValueInputDialog.h"
|
#include "ui_SetValueInputDialog.h"
|
||||||
#include "CDbInterface.h"
|
#include "CDbInterface.h"
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#ifndef SETVALUEINPUTDIALOG_H
|
#ifndef SETVALUEINPUTDIALOG_H
|
||||||
#define SETVALUEINPUTDIALOG_H
|
#define SETVALUEINPUTDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "CDevRealDataWidget.h"
|
#include "CDevRealDataWidget.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include "dp_chg_data_api/CDpcdaForApp.h"
|
#include "dp_chg_data_api/CDpcdaForApp.h"
|
||||||
#include "net/net_msg_bus_api/MsgBusApi.h"
|
#include "net/net_msg_bus_api/MsgBusApi.h"
|
||||||
@ -17,7 +17,7 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(perm->SysLogin("Test", "kbdct", 1, 12*60*60, "hmi") != 0)
|
if(perm->SysLogin("Test", "Test", 1, 12*60*60, "hmi") != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user