2022-09-29 17:36:55 +08:00
|
|
|
|
#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();
|
2024-06-03 16:47:37 +08:00
|
|
|
|
//注意本处的connect连接的槽函数是一个虚函数,会在子类中被override
|
2022-09-29 17:36:55 +08:00
|
|
|
|
connect(mAction,&AsyncAction::actionCompleted,this,&AsyncActionDialog::handleFinishedAction);
|
|
|
|
|
|
|
|
|
|
|
|
mLayout->setSpacing(10);
|
|
|
|
|
|
mLayout->addWidget(mContentWidget);
|
2024-06-25 10:25:26 +08:00
|
|
|
|
mLayout->addWidget(mLoadingWidget);
|
|
|
|
|
|
QMargins margin = mLayout->contentsMargins();
|
|
|
|
|
|
margin.setBottom(1);
|
|
|
|
|
|
mLayout->setContentsMargins(margin);
|
2022-09-29 17:36:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|