logplus/Workflow/WFEngine/Component/WorkflowWidget/src/PaiJobErrorInfoItem.cpp
2026-01-16 17:18:41 +08:00

339 lines
8.5 KiB
C++

#include "PaiJobErrorInfoItem.h"
#include "PaiJobErrorInfoWidget.h"
#include "PaiJobErrorInfoBar.h"
#include <QPen>
#include <QPainter>
#include <QStringList>
#include <QVBoxLayout>
#include <QPalette>
#include <QIcon>
#include <QPixmap>
#include <QDebug>
const int LIST_VALUE_MAX = 6; //列表框的最大条数
namespace pai
{
namespace gui
{
PaiArrowButton::PaiArrowButton(QString text, QWidget* pParent) :
QPushButton(pParent)
{
SetBtnIcon(text);
}
void PaiArrowButton::SetUpIcon(const QString& icon)
{
m_UpIcon = icon;
}
void PaiArrowButton::SetDownIcon(const QString& icon)
{
m_DownIcon = icon;
}
void PaiArrowButton::enterEvent(QEvent *pEevent)
{
SetBtnIcon(m_UpIcon);
QPushButton::enterEvent(pEevent);
}
void PaiArrowButton::leaveEvent(QEvent * pEevent)
{
SetBtnIcon(m_DownIcon);
QPushButton::leaveEvent(pEevent);
}
void PaiArrowButton::SetBtnIcon(const QString& icon)
{
QIcon IConUp;
QPixmap pixmap0(icon);
IConUp.addPixmap(pixmap0);
resize(510, 15);
setIcon(IConUp);
setIconSize(QSize(510, 15));
setAutoDefault(true);
}
PaiJobErrorInfoItemAgentWgt::PaiJobErrorInfoItemAgentWgt(QWidget *pParent, PaiJobErrorInfoItem *pItem) :
QWidget(pParent)
{
m_pJobItem = pItem;
QPalette palFather = palette();
palFather.setColor(QPalette::Background, Qt::white);
setPalette(palFather);
resize(680, 281);
m_pBtnUp = new PaiArrowButton(":/log_Error_upmoren_tint.png", this);
m_pBtnUp->SetUpIcon(":/log_Error_upmoren.png");
m_pBtnUp->SetDownIcon(":/log_Error_upmoren_tint.png");
m_pBtnDown = new PaiArrowButton(":/log_Error_downmoren_tint.png", this);
m_pBtnDown->SetUpIcon(":/log_Error_downmoren.png");
m_pBtnDown->SetDownIcon(":/log_Error_downmoren_tint.png");
m_pBtnDown->move(0, 255);
connect(m_pBtnUp, SIGNAL(clicked(bool)), this, SLOT(UpErrorBar(bool)));
connect(m_pBtnDown, SIGNAL(clicked(bool)), this, SLOT(DownErrorBar(bool)));
}
PaiJobErrorInfoItemAgentWgt::~PaiJobErrorInfoItemAgentWgt()
{
}
void PaiJobErrorInfoItemAgentWgt::setScroBarValue(QScrollBar *pScrollBar)
{
m_pVerScrollBar = pScrollBar;
}
void PaiJobErrorInfoItemAgentWgt::UpErrorBar(bool)
{
if(m_pJobItem)
{
m_pJobItem->UpButtonErrorInfo();
}
}
void PaiJobErrorInfoItemAgentWgt::DownErrorBar(bool)
{
if(m_pJobItem)
{
m_pJobItem->DownButtonErrorInfo();
}
}
void PaiJobErrorInfoItemAgentWgt::HideItem()
{
if(m_pJobItem)
{
m_pJobItem->hide();
}
}
PaiJobErrorInfoItem::PaiJobErrorInfoItem(QGraphicsItem *PaiJobErrorInfoItem) :
QGraphicsItem(PaiJobErrorInfoItem)
{
m_width = 10;
m_height = 10;
QVBoxLayout *playout = new QVBoxLayout();
m_pErrorAgentWgt = new PaiJobErrorInfoItemAgentWgt(NULL,this);
QWidget *pParent = new QWidget(m_pErrorAgentWgt);
QPalette pal = pParent->palette();
pal.setColor(QPalette::Background, Qt::white);
pParent->setPalette(pal);
m_pErrorAgentWgt->hide();
pParent->setLayout(playout);
pParent->resize(680,230);
pParent->move(0,20);
m_pJobErrorInofDlg = new PaiJobErrorInofWidget(pParent);
QGraphicsProxyWidget *proxyWidgetItem = new QGraphicsProxyWidget(this);
proxyWidgetItem->setWidget(m_pErrorAgentWgt);
m_pscrollArea = new QScrollArea(pParent);
QPalette pal1 = m_pscrollArea->palette();
pal1.setColor(QPalette::Background, Qt::white);
m_pscrollArea->setPalette(pal);
m_pErrorAgentWgt->setScroBarValue(m_pscrollArea->verticalScrollBar());
m_pscrollArea->move(-1,-1);
m_pscrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pscrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pscrollArea->setWidget(m_pJobErrorInofDlg);
m_pscrollArea->resize(685,240);
m_pscrollArea->show();
m_UpdatePos = 1;
}
PaiJobErrorInfoItem::~PaiJobErrorInfoItem()
{
}
int PaiJobErrorInfoItem::type() const
{
return Type;
}
void PaiJobErrorInfoItem::UpButtonErrorInfo()
{
if((m_pJobErrorInofDlg != NULL) && (m_pJobErrorInofDlg->GetEnableExpand()))
{
//获取展开项的索引号
int index = GetExpandedIndex();
if(index < m_pJobErrorInofDlg->GetErrorBarList().size())
{
QList<struct ErrorBarPos> errorBarPosList = m_pJobErrorInofDlg->GetErrorBarList();
//关闭展开项
CloseExpanded(errorBarPosList);
//打开下一项
if(errorBarPosList.at(index).pJobErrorBar != NULL)
{
errorBarPosList.at(index).pJobErrorBar->move(0,0);
errorBarPosList.at(index).pJobErrorBar->show();
errorBarPosList.at(index).pJobErrorBar->GetDownWidget()->show();
}
//记录当前被展开项
m_pJobErrorInofDlg->SetExpandedError(errorBarPosList.at(index).pJobErrorBar);
}
}
if(m_errors.size() < LIST_VALUE_MAX)
{
return;
}
else
{
//判断更新条目不能超过存储日志的列表
if(m_errors.size() <= (LIST_VALUE_MAX - 1 + m_UpdatePos))
{
return;
}
if(m_pJobErrorInofDlg != NULL)
{
m_pJobErrorInofDlg->AddErrorInofToBar(m_errors.at(5 + m_UpdatePos));
}
}
m_UpdatePos++;
}
void PaiJobErrorInfoItem::DownButtonErrorInfo()
{
if((m_pJobErrorInofDlg != NULL) && (m_pJobErrorInofDlg->GetEnableExpand()))
{
//获取当前被展开的infoBar索引
int index = GetExpandedIndex();
if(index > 1)
{
QList<struct ErrorBarPos> errorBarPosList = m_pJobErrorInofDlg->GetErrorBarList();
//关闭展开项
CloseExpanded(errorBarPosList);
//打开下一项
if(errorBarPosList.at(index - 2).pJobErrorBar)
{
errorBarPosList.at(index-2).pJobErrorBar->move(0,0);
errorBarPosList.at(index-2).pJobErrorBar->show();
errorBarPosList.at(index-2).pJobErrorBar->GetDownWidget()->show();
}
//记录当前被展开项
m_pJobErrorInofDlg->SetExpandedError(errorBarPosList.at(index-2).pJobErrorBar);
}
}
if(m_errors.size() < LIST_VALUE_MAX)
{
return;
}
else
{
if(m_UpdatePos < 1)
{
m_UpdatePos = 1;
}
m_UpdatePos--;
if(m_pJobErrorInofDlg)
{
m_pJobErrorInofDlg->AddErrorInofToBar(m_errors.at(5 + m_UpdatePos));
}
}
}
void PaiJobErrorInfoItem::ShowErrorInfoWgt()
{
if((m_pErrorAgentWgt != NULL) && (m_pErrorAgentWgt->isHidden()))
{
m_pErrorAgentWgt->show();
}
}
QRectF PaiJobErrorInfoItem::boundingRect() const
{
qreal dPenWidth = 2;
qreal topLeftX = -(m_width + dPenWidth) / 2;
qreal topLeftY = -(m_height + dPenWidth) / 2;
return QRectF(topLeftX, topLeftY, m_width + dPenWidth, m_height + dPenWidth);
}
void PaiJobErrorInfoItem::AddErrorInfo(const QString& error)
{
if(m_pJobErrorInofDlg != NULL)
{
m_errors = error.split("[ERROR]");
for(int i = 0; i < m_errors.size() - 1; ++i)
{
m_pJobErrorInofDlg->AddErrorInofToBar(m_errors.at(i + 1));
}
}
}
int PaiJobErrorInfoItem::GetExpandedIndex() const
{
if((m_pJobErrorInofDlg != NULL) && (m_pJobErrorInofDlg->GetExpandedError() != NULL))
{
QString infoBarText = m_pJobErrorInofDlg->GetExpandedError()->GetLabel()->text();
int index = (infoBarText.data()[infoBarText.size()-1]).digitValue();
return index;
}
else
{
return -1;
}
}
void PaiJobErrorInfoItem::CloseExpanded(QList<struct ErrorBarPos> &errorList)
{
if(m_pJobErrorInofDlg)
{
for(int i = 0; i < errorList.size(); ++i)
{
if((errorList.at(i).pJobErrorBar != NULL) && (errorList.at(i).pJobErrorBar == m_pJobErrorInofDlg->GetExpandedError()))
{
errorList.at(i).pJobErrorBar->move(0,errorList[i].yPos);
errorList.at(i).pJobErrorBar->hide();
if(!errorList.at(i).pJobErrorBar->GetDownWidget()->isHidden())
{
errorList.at(i).pJobErrorBar->GetDownWidget()->hide();
}
break;
}
}
}
}
bool PaiJobErrorInfoItem::EnableError()
{
if((m_pJobErrorInofDlg != NULL) && (0 == (m_pJobErrorInofDlg->GetErrorBarList().size())))
{
return false;
}
else
{
return true;
}
}
void PaiJobErrorInfoItem::UpdatePosition()
{
}
void PaiJobErrorInfoItem::paint(QPainter */*pPainter*/, const QStyleOptionGraphicsItem */*pOption*/, QWidget */*pWidget*/)
{
// TODO
}
}
}