BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
undoscenario.test.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/tests/testintegration/undoscenario.test.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "google_test.h"
20 #include "qcustomplot.h"
21 
22 using namespace ModelView;
23 
24 //! Testing various undo/redo scenario.
25 
26 class UndoScenarioTest : public ::testing::Test {
27 public:
29 };
30 
32 
33 //! Check undo/redo of ViewportAxisItem range, when it is listened by the controller.
34 //! Real-life bug.
35 
36 TEST_F(UndoScenarioTest, undoViewportSetRange)
37 {
38  // initialzing model, custom plot and controller
39  SessionModel model;
40  auto axisItem = model.insertItem<ViewportAxisItem>();
41  axisItem->setProperty(ViewportAxisItem::P_MIN, 1.0);
42  axisItem->setProperty(ViewportAxisItem::P_MAX, 2.0);
43  QCustomPlot custom_plot;
44  ViewportAxisPlotController controller(custom_plot.xAxis);
45  controller.setItem(axisItem);
46 
47  // initial axis state
48  EXPECT_EQ(custom_plot.xAxis->range().lower, 1.0);
49  EXPECT_EQ(custom_plot.xAxis->range().upper, 2.0);
50 
51  // enabling undo/redo, and its initial state
52  model.setUndoRedoEnabled(true);
53  auto stack = model.undoStack();
54  EXPECT_FALSE(stack->canRedo());
55  EXPECT_FALSE(stack->canUndo());
56  EXPECT_EQ(stack->index(), 0);
57  EXPECT_EQ(stack->count(), 0);
58 
59  // changing axis
60  axisItem->setProperty(ViewportAxisItem::P_MAX, 20.0);
61  EXPECT_FALSE(stack->canRedo());
62  EXPECT_TRUE(stack->canUndo());
63  EXPECT_EQ(stack->index(), 1);
64  EXPECT_EQ(stack->count(), 1);
65  EXPECT_EQ(custom_plot.xAxis->range().lower, 1.0);
66  EXPECT_EQ(custom_plot.xAxis->range().upper, 20.0);
67 
68  // undoing
69  stack->undo();
70  EXPECT_TRUE(stack->canRedo());
71  EXPECT_FALSE(stack->canUndo());
72  EXPECT_EQ(stack->index(), 0);
73  EXPECT_EQ(stack->count(), 1);
74  EXPECT_EQ(custom_plot.xAxis->range().lower, 1.0);
75  EXPECT_EQ(custom_plot.xAxis->range().upper, 2.0);
76 
77  // redoing
78  stack->redo();
79  EXPECT_FALSE(stack->canRedo());
80  EXPECT_TRUE(stack->canUndo());
81  EXPECT_EQ(stack->index(), 1);
82  EXPECT_EQ(stack->count(), 1);
83  EXPECT_EQ(custom_plot.xAxis->range().lower, 1.0);
84  EXPECT_EQ(custom_plot.xAxis->range().upper, 20.0);
85 }
Defines class CLASS?
static const std::string P_MAX
Definition: axisitems.h:32
static const std::string P_MIN
Definition: axisitems.h:31
void setItem(SessionItem *item)
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Definition: sessionitem.h:190
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
void setUndoRedoEnabled(bool value)
Sets undo/redo either enabled or disabled. By default undo/redo is disabled.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Definition: sessionmodel.h:104
UndoStackInterface * undoStack() const
Returns command stack to perform undo/redo.
Item to represent viewport axis.
Definition: axisitems.h:43
Establishes communication between QCPAxis and ViewportAxisItem.
Testing various undo/redo scenario.
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
TEST_F(UndoScenarioTest, undoViewportSetRange)
Check undo/redo of ViewportAxisItem range, when it is listened by the controller.
Defines class CLASS?
Defines class CLASS?