BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
undoscenario.test.cpp File Reference

Implements class CLASS? More...

Include dependency graph for undoscenario.test.cpp:

Go to the source code of this file.

Classes

class  UndoScenarioTest
 Testing various undo/redo scenario. More...
 

Functions

 TEST_F (UndoScenarioTest, undoViewportSetRange)
 Check undo/redo of ViewportAxisItem range, when it is listened by the controller. More...
 

Detailed Description

Implements class CLASS?

Homepage:\n http://www.bornagainproject.org
License:\n GNU General Public License v3 or higher (see COPYING)
Authors
Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)

Definition in file undoscenario.test.cpp.

Function Documentation

◆ TEST_F()

TEST_F ( UndoScenarioTest  ,
undoViewportSetRange   
)

Check undo/redo of ViewportAxisItem range, when it is listened by the controller.

Real-life bug.

Definition at line 36 of file undoscenario.test.cpp.

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 }
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.

References ModelView::SessionModel::insertItem(), ModelView::BasicAxisItem::P_MAX, ModelView::BasicAxisItem::P_MIN, ModelView::ItemListenerBase::setItem(), ModelView::SessionItem::setProperty(), ModelView::SessionModel::setUndoRedoEnabled(), and ModelView::SessionModel::undoStack().

Here is the call graph for this function: