main.cpp
111 lines
| 3.4 KiB
| text/x-c
|
CppLexer
r1420 | #include <QMainWindow> | |||
r1368 | #include <QObject> | |||
#include <QScreen> | ||||
r1420 | #include <QString> | |||
r1368 | #include <QWheelEvent> | |||
r1420 | #include <QtTest> | |||
r1368 | ||||
#include <qcustomplot.h> | ||||
r1489 | #include <cpp_utils.hpp> | |||
r1368 | #include <SqpApplication.h> | |||
#include <Variable/VariableController2.h> | ||||
#include <GUITestUtils.h> | ||||
r1420 | #include <TestProviders.h> | |||
#include <Visualization/VisualizationGraphWidget.h> | ||||
#include <Visualization/VisualizationZoneWidget.h> | ||||
r1368 | ||||
r1420 | template <int GraphCount = 2> | |||
std::tuple<std::unique_ptr<VisualizationZoneWidget>, std::vector<std::shared_ptr<Variable2>>, | ||||
std::vector<VisualizationGraphWidget*>, DateTimeRange> | ||||
r1369 | build_multi_graph_test() | |||
{ | ||||
auto w = std::make_unique<VisualizationZoneWidget>(); | ||||
r1420 | auto provider = std::make_shared<SimpleRange<10>>(); | |||
auto range = DateTimeRange::fromDateTime( | ||||
QDate(2018, 8, 7), QTime(14, 00), QDate(2018, 8, 7), QTime(16, 00)); | ||||
std::vector<std::shared_ptr<Variable2>> variables; | ||||
r1369 | std::vector<VisualizationGraphWidget*> graphs; | |||
r1420 | for (auto i = 0; i < GraphCount; i++) | |||
r1369 | { | |||
r1420 | auto var = static_cast<SqpApplication*>(qApp)->variableController().createVariable( | |||
QString("V%1").arg(i), { { "", "scalar" } }, provider, range); | ||||
r1369 | auto graph = new VisualizationGraphWidget(); | |||
graph->addVariable(var, range); | ||||
while (!isReady(var)) | ||||
QCoreApplication::processEvents(); | ||||
variables.push_back(var); | ||||
graphs.push_back(graph); | ||||
w->addGraph(graph); | ||||
} | ||||
r1420 | return { std::move(w), variables, graphs, range }; | |||
r1369 | } | |||
r1368 | ||||
r1420 | class A_MultipleSyncGraphs : public QObject | |||
{ | ||||
r1368 | Q_OBJECT | |||
public: | ||||
r1420 | explicit A_MultipleSyncGraphs(QObject* parent = Q_NULLPTR) : QObject(parent) {} | |||
r1368 | ||||
private slots: | ||||
void scrolls_left_with_mouse() | ||||
{ | ||||
r1371 | auto [w, variables, graphs, range] = build_multi_graph_test<3>(); | |||
r1420 | auto var = variables.front(); | |||
r1371 | auto graph = graphs.front(); | |||
r1369 | QVERIFY(prepare_gui_test(w.get())); | |||
r1420 | for (auto i = 0; i < 100; i++) | |||
{ | ||||
r1371 | scroll_graph(graph, -200); | |||
waitForVar(var); | ||||
} | ||||
auto r = variables.back()->range(); | ||||
r1368 | ||||
/* | ||||
r1421 | * Scrolling to the left implies going forward in time | |||
* Scroll only implies keeping the same delta T -> shift only transformation | ||||
r1420 | */ | |||
r1421 | QVERIFY(r.m_TEnd > range.m_TEnd); | |||
r1489 | QVERIFY(cpp_utils::numeric::almost_equal<double>(r.delta(), range.delta(), 1)); | |||
r1368 | } | |||
void scrolls_right_with_mouse() | ||||
{ | ||||
r1371 | auto [w, variables, graphs, range] = build_multi_graph_test<3>(); | |||
r1420 | auto var = variables.front(); | |||
r1371 | auto graph = graphs.front(); | |||
r1369 | QVERIFY(prepare_gui_test(w.get())); | |||
r1420 | for (auto i = 0; i < 100; i++) | |||
{ | ||||
r1371 | scroll_graph(graph, 200); | |||
waitForVar(var); | ||||
} | ||||
auto r = variables.back()->range(); | ||||
r1368 | ||||
/* | ||||
r1421 | * Scrolling to the right implies going back in time | |||
* Scroll only implies keeping the same delta T -> shift only transformation | ||||
r1420 | */ | |||
r1421 | QVERIFY(r.m_TEnd < range.m_TEnd); | |||
r1489 | QVERIFY(cpp_utils::numeric::almost_equal<double>(r.delta(), range.delta(), 1)); | |||
r1368 | } | |||
}; | ||||
r1369 | ||||
r1368 | QT_BEGIN_NAMESPACE | |||
QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS | ||||
QT_END_NAMESPACE | ||||
r1420 | int main(int argc, char* argv[]) | |||
r1368 | { | |||
r1420 | SqpApplication app { argc, argv }; | |||
r1368 | app.setAttribute(Qt::AA_Use96Dpi, true); | |||
QTEST_DISABLE_KEYPAD_NAVIGATION; | ||||
QTEST_ADD_GPU_BLACKLIST_SUPPORT; | ||||
r1369 | A_MultipleSyncGraphs tc; | |||
r1368 | QTEST_SET_MAIN_SOURCE_PATH; | |||
return QTest::qExec(&tc, argc, argv); | ||||
} | ||||
#include "main.moc" | ||||