Isis 3 Programmer Reference
AbstractStringFilter.cpp
1 #include "IsisDebug.h"
2 
3 #include "AbstractStringFilter.h"
4 
5 #include <iostream>
6 
7 #include <QHBoxLayout>
8 #include <QLineEdit>
9 
10 #include "ControlMeasure.h"
11 #include "ControlPoint.h"
12 
13 
14 namespace Isis {
15  AbstractStringFilter::AbstractStringFilter(
16  AbstractFilter::FilterEffectivenessFlag flag,
17  int minimumForSuccess) : AbstractFilter(flag, minimumForSuccess) {
18  nullify();
19  createWidget();
20  }
21 
22  AbstractStringFilter::AbstractStringFilter(
23  const AbstractStringFilter &other) : AbstractFilter(other) {
24  nullify();
25  createWidget();
26 
27  m_lineEdit->setText(other.m_lineEdit->text());
28  }
29 
30 
31 
32  AbstractStringFilter::~AbstractStringFilter() {
33  if (m_lineEditText) {
34  delete m_lineEditText;
35  m_lineEditText = NULL;
36  }
37  }
38 
39 
40  void AbstractStringFilter::nullify() {
41  m_lineEdit = NULL;
42  m_lineEditText = NULL;
43  }
44 
45 
46  void AbstractStringFilter::createWidget() {
47  m_lineEditText = new QString;
48 
49  m_lineEdit = new QLineEdit;
50  m_lineEdit->setMinimumWidth(250);
51  connect(m_lineEdit, SIGNAL(textChanged(QString)),
52  this, SLOT(updateLineEditText(QString)));
53  connect(m_lineEdit, SIGNAL(textChanged(QString)),
54  this, SIGNAL(filterChanged()));
55 
56  QHBoxLayout *layout = new QHBoxLayout;
57  QMargins margins = layout->contentsMargins();
58  margins.setTop(0);
59  margins.setBottom(0);
60  layout->setContentsMargins(margins);
61  layout->addWidget(m_lineEdit);
62  layout->addStretch();
63 
64  getMainLayout()->addLayout(layout);
65  }
66 
67 
68  bool AbstractStringFilter::evaluate(QString str) const {
69  bool evaluation = true;
70 
71  // multiple threads reading the lineEditText so lock it
72  QString text = *m_lineEditText;
73 
74  if (text.size() >= 1) {
75  bool match = str.contains(text, Qt::CaseInsensitive);
76 
77  // inclusive() and match must either be both true or both false
78  evaluation = !(inclusive() ^ match);
79  }
80 
81  return evaluation;
82  }
83 
84 
85  QString AbstractStringFilter::descriptionSuffix() const {
86  QString suffix;
87 
88  if (inclusive())
89  suffix += "containing \"";
90  else
91  suffix += "not containing \"";
92 
93  suffix += *m_lineEditText;
94 
95  suffix += "\"";
96  return suffix;
97  }
98 
99 
100  void AbstractStringFilter::updateLineEditText(QString newText) {
101  *m_lineEditText = newText;
102  }
103 }
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31