BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ShortcodeFilter Class Reference

Description

Event filter for global tracking of shortcodes.

Definition at line 74 of file CustomEventFilters.h.

Inheritance diagram for ShortcodeFilter:
[legend]
Collaboration diagram for ShortcodeFilter:
[legend]

Signals

void found ()
 

Public Member Functions

 ShortcodeFilter (QString shortcode, QObject *parent=nullptr)
 

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event) override
 

Protected Attributes

int m_index
 
QString m_shortcode
 

Constructor & Destructor Documentation

◆ ShortcodeFilter()

ShortcodeFilter::ShortcodeFilter ( QString  shortcode,
QObject *  parent = nullptr 
)

Definition at line 108 of file CustomEventFilters.cpp.

109  : QObject(parent)
110  , m_shortcode(std::move(shortcode))
111  , m_index(0)
112 {
113 }

Member Function Documentation

◆ eventFilter()

bool ShortcodeFilter::eventFilter ( QObject *  obj,
QEvent *  event 
)
overrideprotected

Definition at line 115 of file CustomEventFilters.cpp.

116 {
117  Q_UNUSED(obj);
118  if (event->type() == QEvent::KeyPress) {
119  auto* keyEvent = dynamic_cast<QKeyEvent*>(event);
120  if (m_shortcode.at(m_index) == keyEvent->text()) {
121  m_index++;
122  if (m_index == m_shortcode.length()) {
123  emit found();
124  m_index = 0;
125  }
126  } else {
127  int right = m_index;
128  while (m_index > 0) {
129  if (m_shortcode.at(m_index - 1) == keyEvent->text()
130  && m_shortcode.left(m_index - 1)
131  == m_shortcode.mid(right - m_index + 1, m_index - 1))
132  break;
133  m_index--;
134  }
135  }
136  }
137  return false;
138 }

References found(), m_index, and m_shortcode.

◆ found

void ShortcodeFilter::found ( )
signal

Member Data Documentation

◆ m_index

int ShortcodeFilter::m_index
protected

Definition at line 85 of file CustomEventFilters.h.

Referenced by eventFilter().

◆ m_shortcode

QString ShortcodeFilter::m_shortcode
protected

Definition at line 84 of file CustomEventFilters.h.

Referenced by eventFilter().


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