tests: Use generic view instead of QWidget NonClosableWidget
This commit is contained in:
@@ -135,6 +135,9 @@ public:
|
||||
/// For example a line edit. This is used to for testing focus related features.
|
||||
virtual View *tests_createFocusableView(CreateViewOptions, View *parent = nullptr) = 0;
|
||||
|
||||
/// @brief Returns a view that rejects close events
|
||||
virtual View *tests_createNonClosableView(View *parent = nullptr) = 0;
|
||||
|
||||
/// @brief halts the test during the specified number of milliseconds
|
||||
/// The event loop keeps running. Use this for debugging purposes so you can interact with your test
|
||||
/// and see what's goign on
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
void tests_deinitPlatform_impl() override;
|
||||
View *tests_createView(CreateViewOptions, View *parent = nullptr) override;
|
||||
View *tests_createFocusableView(CreateViewOptions, View *parent = nullptr) override;
|
||||
View *tests_createNonClosableView(View *parent = nullptr) override;
|
||||
#endif
|
||||
private:
|
||||
void init();
|
||||
|
||||
@@ -92,6 +92,12 @@ View *Platform_qtquick::tests_createFocusableView(CreateViewOptions opts, View *
|
||||
auto view = tests_createView(opts, parent);
|
||||
view->setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
View *Platform_qtquick::tests_createNonClosableView(View *parent)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
void tests_deinitPlatform_impl() override;
|
||||
View *tests_createView(CreateViewOptions, View *parent = nullptr) override;
|
||||
View *tests_createFocusableView(CreateViewOptions, View *parent = nullptr) override;
|
||||
View *tests_createNonClosableView(View *parent = nullptr) override;
|
||||
#endif
|
||||
protected:
|
||||
void init();
|
||||
|
||||
@@ -75,6 +75,22 @@ private:
|
||||
Platform::CreateViewOptions m_opts;
|
||||
};
|
||||
|
||||
class NonClosableTestView_qtwidgets : public Views::View_qtwidgets<QWidget>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NonClosableTestView_qtwidgets(QWidget *parent)
|
||||
: Views::View_qtwidgets<QWidget>(nullptr, Type::None, parent)
|
||||
{
|
||||
create();
|
||||
}
|
||||
|
||||
void closeEvent(QCloseEvent *ev) override
|
||||
{
|
||||
ev->ignore(); // don't allow to close
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Platform_qtwidgets::Platform_qtwidgets(int &argc, char **argv)
|
||||
@@ -118,6 +134,14 @@ View *Platform_qtwidgets::tests_createFocusableView(CreateViewOptions opts, View
|
||||
return newWidget;
|
||||
}
|
||||
|
||||
View *Platform_qtwidgets::tests_createNonClosableView(View *parent)
|
||||
{
|
||||
QWidget *parentWidget = Views::View_qtwidgets<QWidget>::asQWidget(parent);
|
||||
auto newWidget = new NonClosableTestView_qtwidgets(parentWidget);
|
||||
|
||||
return newWidget;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include "TestHelpers_qtwidgets.moc"
|
||||
|
||||
@@ -2821,9 +2821,9 @@ void TestDocks::tst_preventClose()
|
||||
{
|
||||
EnsureTopLevelsDeleted e;
|
||||
|
||||
auto nonClosableWidget = new NonClosableWidget();
|
||||
auto nonClosableWidget = Platform::instance()->tests_createNonClosableView();
|
||||
auto dock1 = new Controllers::DockWidget("1");
|
||||
dock1->setGuestView(std::shared_ptr<ViewWrapper>(new Views::ViewWrapper_qtwidgets(nonClosableWidget)));
|
||||
dock1->setGuestView(nonClosableWidget->asWrapper());
|
||||
|
||||
// 1. Test a floating dock widget
|
||||
dock1->view()->resize(QSize(200, 200));
|
||||
@@ -3485,7 +3485,7 @@ void TestDocks::tst_restoreWithNonClosableWidget()
|
||||
{
|
||||
EnsureTopLevelsDeleted e;
|
||||
auto m = createMainWindow(QSize(500, 500), {}, "tst_restoreWithNonClosableWidget");
|
||||
auto dock1 = createDockWidget("1", new NonClosableWidget(), Controllers::DockWidget::Option_NotClosable);
|
||||
auto dock1 = createDockWidget("1", Platform::instance()->tests_createNonClosableView(), Controllers::DockWidget::Option_NotClosable);
|
||||
m->addDockWidget(dock1, Location_OnLeft);
|
||||
auto layout = m->multiSplitter();
|
||||
|
||||
|
||||
@@ -160,24 +160,6 @@ std::unique_ptr<MainWindow> KDDockWidgets::Tests::createMainWindow(QVector<DockD
|
||||
return m;
|
||||
}
|
||||
|
||||
#ifdef KDDOCKWIDGETS_QTWIDGETS
|
||||
|
||||
NonClosableWidget::NonClosableWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
NonClosableWidget::~NonClosableWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void NonClosableWidget::closeEvent(QCloseEvent *ev)
|
||||
{
|
||||
ev->ignore(); // don't allow to close
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool KDDockWidgets::Tests::shouldBlacklistWarning(const QString &msg, const QString &category)
|
||||
{
|
||||
if (category == QLatin1String("qt.qpa.xcb"))
|
||||
|
||||
@@ -173,30 +173,6 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
class MyWidget2 : public QWidgetAdapter
|
||||
{
|
||||
public:
|
||||
explicit MyWidget2(QSize minSz = QSize(1, 1))
|
||||
{
|
||||
setMinimumSize(minSz);
|
||||
setSizeHint(minSz);
|
||||
}
|
||||
|
||||
~MyWidget2();
|
||||
|
||||
QSize sizeHint() const
|
||||
{
|
||||
return m_sizeHint;
|
||||
}
|
||||
|
||||
void setSizeHint(QSize s)
|
||||
{
|
||||
m_sizeHint = s;
|
||||
}
|
||||
|
||||
QSize m_sizeHint;
|
||||
};
|
||||
|
||||
class EmbeddedWindow : public QWidgetAdapter
|
||||
{
|
||||
public:
|
||||
@@ -225,18 +201,6 @@ public:
|
||||
Controllers::MainWindow *const mainWindow;
|
||||
};
|
||||
|
||||
class NonClosableWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NonClosableWidget(QWidget *parent = nullptr);
|
||||
~NonClosableWidget() override;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
};
|
||||
|
||||
namespace {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user