Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineViewStateContext.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2020 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "EngaugeAssert.h"
13
15{
16 m_states.insert (GUIDELINE_VIEW_STATE_EDIT, new GuidelineViewStateEdit (*this));
17 m_states.insert (GUIDELINE_VIEW_STATE_HIDE, new GuidelineViewStateHide (*this));
18 m_states.insert (GUIDELINE_VIEW_STATE_LOCK, new GuidelineViewStateLock (*this));
19 ENGAUGE_ASSERT (m_states.size () == NUM_GUIDELINE_VIEW_STATES);
20
21 m_currentState = NUM_GUIDELINE_VIEW_STATES; // Value that forces a transition right away
22 m_nextState = GUIDELINE_VIEW_STATE_HIDE;
23
24 transitionIfRequested ();
25}
26
30
32{
33 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_VIEW_STATES);
34
35 m_states[m_currentState]->handleStateChange (state);
36 transitionIfRequested ();
37}
38
45
47{
48 return m_currentState;
49}
50
51void GuidelineViewStateContext::transitionIfRequested ()
52{
53 if (m_currentState != m_nextState) {
54
55 // End the current state if there is one
56 if (m_currentState != NUM_GUIDELINE_VIEW_STATES) {
57 m_states[m_currentState]->end ();
58 }
59
60 m_currentState = m_nextState;
61
62 // Start the requested state
63 m_states[m_currentState]->begin();
64 }
65}
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
GuidelineViewState
Set of possible Guideline view states.
@ GUIDELINE_VIEW_STATE_HIDE
@ GUIDELINE_VIEW_STATE_EDIT
@ NUM_GUIDELINE_VIEW_STATES
@ GUIDELINE_VIEW_STATE_LOCK
GuidelineViewState state() const
Current state for serializing.
void requestStateTransition(GuidelineViewState guidelineState)
Request a state transition.
GuidelineViewStateContext()
Single constructor.
void handleStateChange(GuidelineViewState state)
Handle user or code generated change in selected guideline view mode.
Implements guideline behavior for GUIDELINE_VIEW_STATE_HIDE.
Implements guideline behavior for GUIDELINE_VIEW_STATE_HIDE.
Implements guideline behavior for GUIDELINE_VIEW_STATE_LOCK.