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

Event filter for global tracking of shortcodes. More...

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

Signals

void found ()
 

Public Member Functions

 ShortcodeFilter (const QString &shortcode, QObject *parent=0)
 

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event)
 

Protected Attributes

int m_index
 
QString m_shortcode
 

Detailed Description

Event filter for global tracking of shortcodes.

Definition at line 70 of file CustomEventFilters.h.

Constructor & Destructor Documentation

◆ ShortcodeFilter()

ShortcodeFilter::ShortcodeFilter ( const QString &  shortcode,
QObject *  parent = 0 
)

Definition at line 100 of file CustomEventFilters.cpp.

101  : QObject(parent), m_shortcode(shortcode), m_index(0)
102 {
103 }

Member Function Documentation

◆ eventFilter()

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

Definition at line 105 of file CustomEventFilters.cpp.

106 {
107  Q_UNUSED(obj);
108  if (event->type() == QEvent::KeyPress) {
109  QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
110  if (m_shortcode.at(m_index) == keyEvent->text()) {
111  m_index++;
112  if (m_index == m_shortcode.length()) {
113  emit found();
114  m_index = 0;
115  }
116  } else {
117  int right = m_index;
118  while (m_index > 0) {
119  if (m_shortcode.at(m_index - 1) == keyEvent->text()
120  && m_shortcode.left(m_index - 1)
121  == m_shortcode.mid(right - m_index + 1, m_index - 1))
122  break;
123  m_index--;
124  }
125  }
126  }
127  return false;
128 }

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 81 of file CustomEventFilters.h.

Referenced by eventFilter().

◆ m_shortcode

QString ShortcodeFilter::m_shortcode
protected

Definition at line 80 of file CustomEventFilters.h.

Referenced by eventFilter().


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