okular/autotests/closedialoghelper.cpp
Albert Astals Cid 19d98d6a74 Run clang-format
find . \( -name "*.cpp" -or -name "*.h"  -or -name "*.c"  -or -name "*.cc" \) -exec clang-format -i {} \;

If you reached this file doing a git blame, please see README.clang-format (added 2 commits in the future of this one)
2020-07-11 09:17:33 +02:00

51 lines
1.2 KiB
C++

#include "closedialoghelper.h"
#include <QApplication>
#include <QDialog>
#include <QPushButton>
#include <QTest>
namespace TestingUtils
{
CloseDialogHelper::CloseDialogHelper(Okular::Part *p, QDialogButtonBox::StandardButton b)
: m_widget(p->widget())
, m_button(b)
, m_clicked(false)
{
QTimer::singleShot(0, this, &CloseDialogHelper::closeDialog);
}
CloseDialogHelper::CloseDialogHelper(QWidget *w, QDialogButtonBox::StandardButton b)
: m_widget(w)
, m_button(b)
, m_clicked(false)
{
QTimer::singleShot(0, this, &CloseDialogHelper::closeDialog);
}
CloseDialogHelper::CloseDialogHelper(QDialogButtonBox::StandardButton b)
: m_widget(nullptr)
, m_button(b)
, m_clicked(false)
{
QTimer::singleShot(0, this, &CloseDialogHelper::closeDialog);
}
CloseDialogHelper::~CloseDialogHelper()
{
QVERIFY(m_clicked);
}
void CloseDialogHelper::closeDialog()
{
QWidget *dialog = (m_widget) ? m_widget->findChild<QDialog *>() : qApp->activeModalWidget();
if (!dialog) {
QTimer::singleShot(0, this, &CloseDialogHelper::closeDialog);
return;
}
QDialogButtonBox *buttonBox = dialog->findChild<QDialogButtonBox *>();
buttonBox->button(m_button)->click();
m_clicked = true;
}
}