78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
#include "AsyncActionDialog.h"
|
||
|
||
#include <QVBoxLayout>
|
||
#include <QLabel>
|
||
|
||
#include "action/AsyncAction.h"
|
||
#include "components/LoadingWidget.h"
|
||
|
||
AsyncActionDialog::AsyncActionDialog(AsyncAction* aAsyncAction,const QString& aTitle, QWidget* aParent, Qt::WindowFlags aFlags)
|
||
: GUIFormBaseDialog(aParent,aFlags)
|
||
, mContentWidget(new QWidget(mFormWidget))
|
||
, mLoadingWidget(new QWidget(mFormWidget))
|
||
, mAction(aAsyncAction)
|
||
, mLayout(new QVBoxLayout(mFormWidget))
|
||
{
|
||
setFocusPolicy(Qt::ClickFocus);
|
||
mLoadingWidget->hide();
|
||
|
||
initializeTitle(aTitle);
|
||
initializeProgressBar();
|
||
//注意本处的connect连接的槽函数是一个虚函数,会在子类中被override
|
||
connect(mAction,&AsyncAction::actionCompleted,this,&AsyncActionDialog::handleFinishedAction);
|
||
|
||
mLayout->setSpacing(10);
|
||
mLayout->addWidget(mContentWidget);
|
||
mLayout->addWidget(mLoadingWidget);
|
||
QMargins margin = mLayout->contentsMargins();
|
||
margin.setBottom(1);
|
||
mLayout->setContentsMargins(margin);
|
||
}
|
||
|
||
AsyncActionDialog::~AsyncActionDialog()
|
||
{
|
||
|
||
}
|
||
|
||
void AsyncActionDialog::initializeTitle(const QString& aTitle)
|
||
{
|
||
QLabel* title = new QLabel(this);
|
||
title->setAlignment(Qt::AlignCenter);
|
||
title->setText(tr(aTitle.toLatin1()));
|
||
title->setObjectName("title");
|
||
title->setFixedHeight(40);
|
||
mLayout->addWidget(title);
|
||
}
|
||
|
||
void AsyncActionDialog::initializeProgressBar()
|
||
{
|
||
QVBoxLayout* loadingLayout = new QVBoxLayout(mLoadingWidget);
|
||
|
||
LoadingWidget* loadingWidget = new LoadingWidget(mLoadingWidget);
|
||
loadingLayout->addWidget(loadingWidget);
|
||
|
||
}
|
||
|
||
AsyncAction* AsyncActionDialog::getAction()
|
||
{
|
||
return mAction;
|
||
}
|
||
|
||
bool AsyncActionDialog::updateReferenceData()
|
||
{
|
||
mAction->execute();
|
||
mContentWidget->hide();
|
||
mBtnWidget->hide();
|
||
mLoadingWidget->show();
|
||
return false;
|
||
}
|
||
|
||
void AsyncActionDialog::handleFinishedAction(const ActionResult& aResult)
|
||
{
|
||
mLoadingWidget->hide();
|
||
if (aResult.Code == Sucessed)
|
||
{
|
||
accept();
|
||
}
|
||
}
|