Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor event management in Viewer #793

Open
dlyr opened this issue Jul 6, 2021 · 0 comments
Open

Refactor event management in Viewer #793

dlyr opened this issue Jul 6, 2021 · 0 comments
Labels
Feature Request Type of issue: feature request GUI Related to Ra::Gui refactor Related to refactoring actions

Comments

@dlyr
Copy link
Contributor

dlyr commented Jul 6, 2021

PR #776 handles custom events as a map of lamdba
The resulting code looks cleaner than the legacy behavior and we can use it as our new coding style for event management.
e.g.

before

   if ( actionViewer.isValid() )
    {

        if ( actionViewer == VIEWER_TOGGLE_WIREFRAME )
        {
            m_currentRenderer->toggleWireframe();
            eventCatched = true;
        }
        else if ( actionViewer == VIEWER_RELOAD_SHADERS )
        {
            reloadShaders();
            eventCatched = true;
        }
        else if ( actionViewer == VIEWER_PICKING_MULTI_CIRCLE )
        {
            m_isBrushPickingEnabled = !m_isBrushPickingEnabled;
            m_currentRenderer->setBrushRadius( m_isBrushPickingEnabled ? m_brushRadius : 0 );
            emit toggleBrushPicking( m_isBrushPickingEnabled );
            eventCatched = true;
        }
  //...

** after**

    // init somewhere ...
    m_customActions[KeyEventType::KeyPressed][VIEWER_TOGGLE_WIREFRAME] = [this]( QKeyEvent* ) {
        m_currentRenderer->toggleWireframe();
    };
    m_customActions[KeyEventType::KeyPressed][VIEWER_RELOAD_SHADERS] = [this]( QKeyEvent* ) {
        reloadShaders();
    };
    m_customActions[KeyEventType::KeyPressed][VIEWER_PICKING_MULTI_CIRCLE] =
        [this]( QMouseEvent* ) {
            m_isBrushPickingEnabled = !m_isBrushPickingEnabled;
            m_currentRenderer->setBrushRadius( m_isBrushPickingEnabled ? m_brushRadius : 0 );
            emit toggleBrushPicking( m_isBrushPickingEnabled );
        };
    // in handle*Event ...
    auto itr = m_customActions[KeyEventType::KeyPressed].find( actionViewer );
    if ( itr != m_customActions[KeyEventType::KeyPressed].end() )
    {
        itr->second( event );
        eventCatched = true;
    }
@nmellado nmellado added Feature Request Type of issue: feature request GUI Related to Ra::Gui refactor Related to refactoring actions labels Jul 23, 2021
@dlyr dlyr mentioned this issue Apr 24, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Type of issue: feature request GUI Related to Ra::Gui refactor Related to refactoring actions
Projects
None yet
Development

No branches or pull requests

2 participants