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