forked from cbrnr/sigviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab_context.cpp
86 lines (69 loc) · 2.27 KB
/
tab_context.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2016 The SigViewer Development Team
// Licensed under the GNU General Public License (GPL)
// https://www.gnu.org/licenses/gpl
#include "tab_context.h"
#include <QDebug>
namespace sigviewer
{
//-----------------------------------------------------------------------------
TabContext::TabContext ()
: selection_state_ (TAB_STATE_NO_EVENT_SELECTED),
edit_state_ (TAB_STATE_NO_REDO_NO_UNDO)
{
// nothing to do here
}
//-----------------------------------------------------------------------------
TabContext::~TabContext ()
{
emit selectionStateChanged (NO_TAB_SELECTION_STATE);
emit editStateChanged (NO_TAB_EDIT_STATE);
}
//-----------------------------------------------------------------------------
void TabContext::gotActive ()
{
emit selectionStateChanged (selection_state_);
emit editStateChanged (edit_state_);
}
//-----------------------------------------------------------------------------
void TabContext::executeCommand (QUndoCommand* command)
{
edit_undo_stack_.push (command);
updateUndoRedoEditState ();
}
//-------------------------------------------------------------------------
void TabContext::undo ()
{
edit_undo_stack_.undo ();
updateUndoRedoEditState ();
}
//-------------------------------------------------------------------------
void TabContext::redo ()
{
edit_undo_stack_.redo ();
updateUndoRedoEditState ();
}
//-----------------------------------------------------------------------------
void TabContext::updateUndoRedoEditState ()
{
if (!edit_undo_stack_.canUndo () && !edit_undo_stack_.canRedo())
setEditState (TAB_STATE_NO_REDO_NO_UNDO);
else if (!edit_undo_stack_.canUndo ())
setEditState (TAB_STATE_NO_UNDO);
else if (!edit_undo_stack_.canRedo())
setEditState (TAB_STATE_NO_REDO);
else
setEditState (TAB_STATE_CAN_REDO_UNDO);
}
//-----------------------------------------------------------------------------
void TabContext::setSelectionState (TabSelectionState state)
{
selection_state_ = state;
emit selectionStateChanged (selection_state_);
}
//-----------------------------------------------------------------------------
void TabContext::setEditState (TabEditState state)
{
edit_state_ = state;
emit editStateChanged (edit_state_);
}
}