@@ -1,1 +1,1 | |||||
1 | Subproject commit e3779b99a071447cf8b6781a8ae6b414d6106b82 |
|
1 | Subproject commit cc47cd67a7b3418c7c0b065e7cb178abb63b0036 |
@@ -11,13 +11,19 | |||||
11 |
|
11 | |||
12 | #include <qcustomplot.h> |
|
12 | #include <qcustomplot.h> | |
13 |
|
13 | |||
14 | QPoint center(QWidget* widget) |
|
14 | template <typename T> | |
|
15 | QPoint center(T* widget) | |||
15 | { |
|
16 | { | |
16 | return QPoint{widget->width()/2,widget->height()/2}; |
|
17 | return QPoint{widget->width()/2,widget->height()/2}; | |
17 | } |
|
18 | } | |
18 |
|
19 | |||
19 | HAS_METHOD(viewport) |
|
20 | HAS_METHOD(viewport) | |
20 |
|
21 | |||
|
22 | template <typename T> | |||
|
23 | using is_QWidgetOrDerived = std::is_base_of<QWidget,T>; | |||
|
24 | ||||
|
25 | template <typename T> using viewport_type = decltype(std::declval<T>().viewport()); | |||
|
26 | ||||
21 | HAS_METHOD(topLevelItem) |
|
27 | HAS_METHOD(topLevelItem) | |
22 |
|
28 | |||
23 | template<typename T> |
|
29 | template<typename T> | |
@@ -25,7 +31,7 void mouseMove(T* widget, QPoint pos, Qt::MouseButton mouseModifier) | |||||
25 | { |
|
31 | { | |
26 | QCursor::setPos(widget->mapToGlobal(pos)); |
|
32 | QCursor::setPos(widget->mapToGlobal(pos)); | |
27 | QMouseEvent event(QEvent::MouseMove, pos, Qt::NoButton, mouseModifier, Qt::NoModifier); |
|
33 | QMouseEvent event(QEvent::MouseMove, pos, Qt::NoButton, mouseModifier, Qt::NoModifier); | |
28 | if constexpr(has_viewport<T>) |
|
34 | if constexpr(has_viewport<T> && is_QWidgetOrDerived<viewport_type<T>>::value ) | |
29 | { |
|
35 | { | |
30 | qApp->sendEvent(widget->viewport(), &event); |
|
36 | qApp->sendEvent(widget->viewport(), &event); | |
31 | } |
|
37 | } | |
@@ -40,7 +46,7 void mouseMove(T* widget, QPoint pos, Qt::MouseButton mouseModifier) | |||||
40 | template <typename T> |
|
46 | template <typename T> | |
41 | void setMouseTracking(T* widget) |
|
47 | void setMouseTracking(T* widget) | |
42 | { |
|
48 | { | |
43 | if constexpr(has_viewport<T>) |
|
49 | if constexpr(has_viewport<T> && is_QWidgetOrDerived<viewport_type<T>>::value) | |
44 | { |
|
50 | { | |
45 | widget->viewport()->setMouseTracking(true); |
|
51 | widget->viewport()->setMouseTracking(true); | |
46 | } |
|
52 | } | |
@@ -50,12 +56,6 void setMouseTracking(T* widget) | |||||
50 | } |
|
56 | } | |
51 | } |
|
57 | } | |
52 |
|
58 | |||
53 | template <> |
|
|||
54 | void setMouseTracking<QCustomPlot>(QCustomPlot* widget) |
|
|||
55 | { |
|
|||
56 | widget->setMouseTracking(true); |
|
|||
57 | } |
|
|||
58 |
|
||||
59 | template <typename T, typename T2> |
|
59 | template <typename T, typename T2> | |
60 | auto getItem(T* widget, T2 itemIndex) |
|
60 | auto getItem(T* widget, T2 itemIndex) | |
61 | { |
|
61 | { |
@@ -9,46 +9,65 | |||||
9 |
|
9 | |||
10 | #include <SqpApplication.h> |
|
10 | #include <SqpApplication.h> | |
11 | #include <Variable/VariableController2.h> |
|
11 | #include <Variable/VariableController2.h> | |
|
12 | #include <Common/cpp_utils.h> | |||
12 |
|
13 | |||
13 | #include <Visualization/VisualizationGraphWidget.h> |
|
14 | #include <Visualization/VisualizationGraphWidget.h> | |
14 | #include <TestProviders.h> |
|
15 | #include <TestProviders.h> | |
15 | #include <GUITestUtils.h> |
|
16 | #include <GUITestUtils.h> | |
16 |
|
17 | |||
|
18 | ||||
|
19 | ALIAS_TEMPLATE_FUNCTION(isReady, static_cast<SqpApplication *>(qApp)->variableController().isReady) | |||
|
20 | ||||
|
21 | #define A_SIMPLE_GRAPH_FIXTURE \ | |||
|
22 | VisualizationGraphWidget w;\ | |||
|
23 | PREPARE_GUI_TEST(w);\ | |||
|
24 | auto provider = std::make_shared<SimpleRange<10> >();\ | |||
|
25 | auto range = DateTimeRange::fromDateTime(QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7),\ | |||
|
26 | QTime(16, 00));\ | |||
|
27 | auto var = static_cast<SqpApplication *>(qApp)->variableController().createVariable(\ | |||
|
28 | "V1", {{"", "scalar"}}, provider, range);\ | |||
|
29 | while (!isReady(var))\ | |||
|
30 | QCoreApplication::processEvents();\ | |||
|
31 | w.addVariable(var, range);\ | |||
|
32 | GET_CHILD_WIDGET_FOR_GUI_TESTS(w, plot, QCustomPlot, "widget");\ | |||
|
33 | auto cent = center(plot);\ | |||
|
34 | ||||
|
35 | ||||
17 | class A_SimpleGraph : public QObject { |
|
36 | class A_SimpleGraph : public QObject { | |
18 | Q_OBJECT |
|
37 | Q_OBJECT | |
19 | public: |
|
38 | public: | |
20 |
A_SimpleGraph(QObject* |
|
39 | explicit A_SimpleGraph(QObject *parent = Q_NULLPTR) : QObject(parent) {} | |
21 | :QObject(parent) |
|
|||
22 | { |
|
|||
23 |
|
||||
24 | } |
|
|||
25 |
|
40 | |||
26 | private slots: |
|
41 | private slots: | |
27 |
void scrolls_with_mouse |
|
42 | void scrolls_with_mouse() | |
28 | { |
|
43 | { | |
29 | VisualizationGraphWidget w; |
|
44 | A_SIMPLE_GRAPH_FIXTURE | |
30 | PREPARE_GUI_TEST(w); |
|
45 | ||
31 | auto provider = std::make_shared<SimpleRange<10>>(); |
|
46 | for (auto i = 0; i < 10; i++) { | |
32 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00), |
|
47 | QTest::mousePress(plot, Qt::LeftButton, Qt::NoModifier, cent, 5); | |
33 | QDate(2018,8,7),QTime(16,00)); |
|
48 | mouseMove(plot, {cent.x() + 200, cent.y()}, Qt::LeftButton); | |
34 | auto var = static_cast<SqpApplication*>(qApp)->variableController().createVariable("V1", {{"","scalar"}}, provider, range); |
|
|||
35 | while(!static_cast<SqpApplication*>(qApp)->variableController().isReady(var))QCoreApplication::processEvents(); |
|
|||
36 | w.addVariable(var, range); |
|
|||
37 | GET_CHILD_WIDGET_FOR_GUI_TESTS(w,plot,QCustomPlot,"widget"); |
|
|||
38 | auto cent = center(static_cast<QWidget*>(plot)); |
|
|||
39 | for(auto i=0;i<10;i++) |
|
|||
40 | { |
|
|||
41 | QTest::mousePress(plot, Qt::LeftButton, Qt::NoModifier, cent, 10); |
|
|||
42 | QTest::mouseMove(plot, {cent.x()+100,cent.y()},10); |
|
|||
43 | QTest::mouseRelease(plot,Qt::LeftButton); |
|
49 | QTest::mouseRelease(plot, Qt::LeftButton); | |
|
50 | while (!isReady(var)) | |||
|
51 | QCoreApplication::processEvents(); | |||
|
52 | /* | |||
|
53 | * Just for visual inspection while running tests | |||
|
54 | */ | |||
|
55 | plot->rescaleAxes(); | |||
|
56 | plot->replot(); | |||
|
57 | QCoreApplication::processEvents(); | |||
44 | } |
|
58 | } | |
45 | while(!static_cast<SqpApplication*>(qApp)->variableController().isReady(var))QCoreApplication::processEvents(); |
|
59 | while (!isReady(var)) | |
|
60 | QCoreApplication::processEvents(); | |||
|
61 | auto r = var->range(); | |||
|
62 | QVERIFY(r.m_TEnd < range.m_TEnd); | |||
|
63 | // this fails :( | |||
|
64 | QVERIFY(SciQLop::numeric::almost_equal<double>(r.delta(),range.delta(),1)); | |||
46 | } |
|
65 | } | |
47 | }; |
|
66 | }; | |
48 |
|
67 | |||
49 | QT_BEGIN_NAMESPACE |
|
68 | QT_BEGIN_NAMESPACE | |
50 | QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS |
|
69 | QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS | |
51 |
QT_END_NAMESPACE |
|
70 | QT_END_NAMESPACE | |
52 | int main(int argc, char *argv[]) |
|
71 | int main(int argc, char *argv[]) | |
53 | { |
|
72 | { | |
54 | SqpApplication app{argc, argv}; |
|
73 | SqpApplication app{argc, argv}; |
General Comments 0
You need to be logged in to leave comments.
Login now