BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::UndoStack Class Reference

Default undo stack implementation. More...

Inheritance diagram for ModelView::UndoStack:
[legend]
Collaboration diagram for ModelView::UndoStack:
[legend]

Classes

struct  UndoStackImpl
 

Public Member Functions

 UndoStack ()
 
 ~UndoStack () override
 
void beginMacro (const std::string &name) override
 
bool canRedo () const override
 
bool canUndo () const override
 
void clear () override
 
int count () const override
 
void endMacro () override
 
void execute (std::shared_ptr< AbstractItemCommand > command) override
 Executes the command, then pushes it in the stack for possible undo. More...
 
int index () const override
 
bool isActive () const override
 
void redo () override
 
void setUndoLimit (int limit) override
 
void undo () override
 

Static Public Member Functions

static QUndoStack * qtUndoStack (UndoStackInterface *stack_interface)
 Returns underlying QUndoStack if given object can be casted to UndoStack instance. More...
 

Private Attributes

std::unique_ptr< UndoStackImplp_impl
 

Detailed Description

Default undo stack implementation.

Internally relies on QUndoStack. It serves two goals: a) hides Qt usage b) simplifies future refactoring toward Qt-independent libmvvm_model library.

Definition at line 30 of file undostack.h.

Constructor & Destructor Documentation

◆ UndoStack()

UndoStack::UndoStack ( )

Definition at line 27 of file undostack.cpp.

27 : p_impl(std::make_unique<UndoStackImpl>()) {}
std::unique_ptr< UndoStackImpl > p_impl
Definition: undostack.h:54

◆ ~UndoStack()

UndoStack::~UndoStack ( )
overridedefault

Member Function Documentation

◆ beginMacro()

void UndoStack::beginMacro ( const std::string &  name)
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 94 of file undostack.cpp.

95 {
96  p_impl->undoStack()->beginMacro(QString::fromStdString(name));
97 }
QString const & name(EShape k)
Definition: particles.cpp:21

References RealSpace::Particles::name(), and p_impl.

Here is the call graph for this function:

◆ canRedo()

bool UndoStack::canRedo ( ) const
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 48 of file undostack.cpp.

49 {
50  return p_impl->undoStack()->canRedo();
51 }

References p_impl.

Referenced by TEST_F().

◆ canUndo()

bool UndoStack::canUndo ( ) const
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 43 of file undostack.cpp.

44 {
45  return p_impl->undoStack()->canUndo();
46 }

References p_impl.

Referenced by TEST_F().

◆ clear()

void UndoStack::clear ( )
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 73 of file undostack.cpp.

74 {
75  return p_impl->undoStack()->clear();
76 }

References p_impl.

◆ count()

int UndoStack::count ( ) const
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 58 of file undostack.cpp.

59 {
60  return p_impl->undoStack()->count();
61 }

References p_impl.

Referenced by TEST_F().

◆ endMacro()

void UndoStack::endMacro ( )
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 99 of file undostack.cpp.

100 {
101  p_impl->undoStack()->endMacro();
102 }

References p_impl.

◆ execute()

void UndoStack::execute ( std::shared_ptr< AbstractItemCommand command)
overridevirtual

Executes the command, then pushes it in the stack for possible undo.

Implements ModelView::UndoStackInterface.

Definition at line 29 of file undostack.cpp.

30 {
31  // Wrapping command for Qt. It will be executed by Qt after push.
32  auto adapter = new CommandAdapter(std::move(command));
33  p_impl->undoStack()->push(adapter);
34 }
Adapter to execute our commands within Qt undo/redo framework.

References p_impl.

Referenced by TEST_F().

◆ index()

int UndoStack::index ( ) const
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 53 of file undostack.cpp.

54 {
55  return p_impl->undoStack()->index();
56 }

References p_impl.

Referenced by TEST_F().

◆ isActive()

bool UndoStack::isActive ( ) const
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 38 of file undostack.cpp.

39 {
40  return p_impl->undoStack()->isActive();
41 }

References p_impl.

◆ qtUndoStack()

QUndoStack * UndoStack::qtUndoStack ( UndoStackInterface stack_interface)
static

Returns underlying QUndoStack if given object can be casted to UndoStack instance.

This method is used to "convert" current instance to Qt implementation, and use it with other Qt widgets, if necessary.

Definition at line 87 of file undostack.cpp.

88 {
89  if (auto stack = dynamic_cast<UndoStack*>(stack_interface); stack)
90  return stack->p_impl->undoStack();
91  return nullptr;
92 }
Default undo stack implementation.
Definition: undostack.h:30

◆ redo()

void UndoStack::redo ( )
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 68 of file undostack.cpp.

69 {
70  return p_impl->undoStack()->redo();
71 }

References p_impl.

Referenced by TEST_F().

◆ setUndoLimit()

void UndoStack::setUndoLimit ( int  limit)
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 78 of file undostack.cpp.

79 {
80  return p_impl->undoStack()->setUndoLimit(limit);
81 }

References p_impl.

◆ undo()

void UndoStack::undo ( )
overridevirtual

Implements ModelView::UndoStackInterface.

Definition at line 63 of file undostack.cpp.

64 {
65  return p_impl->undoStack()->undo();
66 }

References p_impl.

Referenced by TEST_F().

Member Data Documentation

◆ p_impl

std::unique_ptr<UndoStackImpl> ModelView::UndoStack::p_impl
private

The documentation for this class was generated from the following files: