221 lines
5.2 KiB
C++
221 lines
5.2 KiB
C++
#include <QScrollArea>
|
|
#include <QVBoxLayout>
|
|
#include <QPushButton>
|
|
#include <QMessageBox>
|
|
#include <QPainter>
|
|
#include "PaiJobErrorInfoWidget.h"
|
|
#include "PaiJobErrorInfoBar.h"
|
|
#include "PaiJobErrorInfoItem.h"
|
|
#include <QDebug>
|
|
#include <QStringList>
|
|
|
|
using namespace pai::gui;
|
|
|
|
PaiJobErrorInofWidget::PaiJobErrorInofWidget(QWidget *pParent) :
|
|
QWidget(pParent)
|
|
{
|
|
QPalette pal = palette();
|
|
pal.setColor(QPalette::Background, Qt::white);
|
|
setPalette(pal);
|
|
|
|
m_list.clear();
|
|
m_Value = 1;
|
|
m_NumErrorBar = 1;
|
|
m_EnableExpand = false;
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
this->setLayout(mainLayout);
|
|
this->resize(640, 230);
|
|
|
|
if(pParent && pParent->parent())
|
|
{
|
|
connect(this, SIGNAL(HideItem()),pParent->parent(),SLOT(HideItem()));
|
|
}
|
|
}
|
|
|
|
void PaiJobErrorInofWidget::UpdateEroorBarInfo(const QString& error)
|
|
{
|
|
//以此更新显示的信息
|
|
QString strTemp;
|
|
for(int i = m_list.size(); i > 0 ; --i)
|
|
{
|
|
if(i == m_list.size())
|
|
{
|
|
strTemp = error;
|
|
}
|
|
else
|
|
{
|
|
strTemp = m_list.at(i - 1).pJobErrorBar->GetTextEdit()->toPlainText();
|
|
}
|
|
m_list.at(i - 1).pJobErrorBar->ErrorBarInfo(strTemp);
|
|
}
|
|
}
|
|
|
|
void PaiJobErrorInofWidget::AddErrorInofToBar(const QString& error)
|
|
{
|
|
if(m_NumErrorBar > 6)
|
|
{
|
|
UpdateEroorBarInfo(error);
|
|
return;
|
|
}
|
|
m_NumErrorBar++;
|
|
|
|
PaiJobErrorInfoBar *pJobErrorBar = new PaiJobErrorInfoBar(this);
|
|
ErrorBarPos errorbarpos;
|
|
errorbarpos.pJobErrorBar = pJobErrorBar;
|
|
errorbarpos.yPos = 0;
|
|
|
|
QString str;
|
|
str.sprintf("Error Info %d", m_Value);
|
|
|
|
m_Value++;
|
|
pJobErrorBar->GetLabel()->setText(str);
|
|
pJobErrorBar->ErrorBarInfo(error);
|
|
|
|
m_list.push_back(errorbarpos);
|
|
|
|
//重新定义infoBar位置
|
|
int infoBarNum = m_list.size();
|
|
for(int i = 0; i < infoBarNum; i++)
|
|
{
|
|
m_list[i].yPos = (infoBarNum-i-1)*40;
|
|
m_list[i].pJobErrorBar->move(0,m_list[i].yPos);
|
|
m_list[i].pJobErrorBar->show();
|
|
}
|
|
|
|
connect(pJobErrorBar, SIGNAL(ExpendDialog(bool)), this, SLOT(ErrorInfo(bool)));
|
|
connect(pJobErrorBar, SIGNAL(CloseDialog()), this, SLOT(UpdatePosition()));
|
|
}
|
|
|
|
void PaiJobErrorInofWidget::UpdatePosition()
|
|
{
|
|
PaiJobErrorInfoBar *pPaiJobError = qobject_cast< PaiJobErrorInfoBar * > (sender());
|
|
|
|
m_EnableExpand = false;
|
|
int iNum = 0;
|
|
QList< ErrorBarPos >::Iterator it = m_list.begin();
|
|
QList< ErrorBarPos >::Iterator end = m_list.end();
|
|
while(it != end)
|
|
{
|
|
if((*it).pJobErrorBar == pPaiJobError)
|
|
{
|
|
it = m_list.erase(it);
|
|
end = m_list.end();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
++iNum;
|
|
++it;
|
|
}
|
|
}
|
|
|
|
//移动显示条,并更新位置
|
|
for(int i = 0; i < m_list.size(); ++i)
|
|
{
|
|
if(i < iNum)
|
|
{
|
|
int iMove = m_list[i].yPos - 40;
|
|
m_list.at(i).pJobErrorBar->move(0, iMove);
|
|
m_list[i].yPos = iMove;
|
|
}
|
|
else
|
|
{
|
|
m_list.at(i).pJobErrorBar->GetLabel()->setText(QString("Error Info %1").arg(i+1));
|
|
}
|
|
|
|
if(m_list.at(i).pJobErrorBar->isHidden())
|
|
{
|
|
m_list.at(i).pJobErrorBar->show();
|
|
}
|
|
}
|
|
pPaiJobError->close();
|
|
if(m_list.isEmpty())
|
|
{
|
|
emit HideItem();
|
|
}
|
|
}
|
|
|
|
void PaiJobErrorInofWidget::ErrorInfo(bool show)
|
|
{
|
|
PaiJobErrorInfoBar *pPaiJobError = qobject_cast< PaiJobErrorInfoBar * > (sender());
|
|
if(pPaiJobError == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(show)
|
|
{
|
|
pPaiJobError->move(0, 0);
|
|
m_EnableExpand = true;
|
|
m_pJobErrorInfoBar = pPaiJobError;
|
|
for(int i = 0; i < m_list.size(); ++i)
|
|
{
|
|
if(m_list.at(i).pJobErrorBar != pPaiJobError)
|
|
{
|
|
m_list.at(i).pJobErrorBar->hide();
|
|
if(!m_list.at(i).pJobErrorBar->GetDownWidget()->isHidden())
|
|
{
|
|
m_list.at(i).pJobErrorBar->GetDownWidget()->hide();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_EnableExpand = false;
|
|
m_pJobErrorInfoBar = NULL;
|
|
for(int i = 0; i < m_list.size(); ++i)
|
|
{
|
|
if(m_list.at(i).pJobErrorBar == pPaiJobError)
|
|
{
|
|
if(i == m_list.size() - 1)
|
|
{
|
|
break;
|
|
}
|
|
m_list.at(i).pJobErrorBar->move(0, m_list[i].yPos);
|
|
}
|
|
else
|
|
{
|
|
m_list.at(i).pJobErrorBar->show();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
PaiJobErrorInofWidget::~PaiJobErrorInofWidget()
|
|
{
|
|
}
|
|
|
|
void PaiJobErrorInofWidget::paintEvent(QPaintEvent*)
|
|
{
|
|
QPainter paint(this);
|
|
QPen pen;
|
|
pen.setWidth(5);
|
|
pen.setColor(Qt::white);
|
|
paint.setPen(pen);
|
|
|
|
paint.drawRect(0.5, 0.5, this->width() - 2, this->height() - 2);
|
|
}
|
|
|
|
QList<ErrorBarPos> PaiJobErrorInofWidget::GetErrorBarList() const
|
|
{
|
|
return m_list;
|
|
}
|
|
|
|
bool PaiJobErrorInofWidget::GetEnableExpand() const
|
|
{
|
|
return m_EnableExpand;
|
|
}
|
|
|
|
void PaiJobErrorInofWidget::SetExpandedError(PaiJobErrorInfoBar* pExpandedError)
|
|
{
|
|
m_pJobErrorInfoBar = pExpandedError;
|
|
}
|
|
|
|
PaiJobErrorInfoBar* PaiJobErrorInofWidget::GetExpandedError() const
|
|
{
|
|
return m_pJobErrorInfoBar;
|
|
}
|