Isis 3 Programmer Reference
AbstractNumberFilter.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "AbstractNumberFilter.h"
10
11#include <iostream>
12
13#include <QButtonGroup>
14#include <QFont>
15#include <QHBoxLayout>
16#include <QLabel>
17#include <QLineEdit>
18#include <QMargins>
19#include <QRadioButton>
20
21#include "ControlMeasure.h"
22#include "ControlPoint.h"
23
24
25namespace Isis {
26 AbstractNumberFilter::AbstractNumberFilter(
27 AbstractFilter::FilterEffectivenessFlag flag,
28 int minimumForSuccess) : AbstractFilter(flag, minimumForSuccess) {
29 nullify();
30 createWidget();
31 }
32
33
34 AbstractNumberFilter::AbstractNumberFilter(const AbstractNumberFilter &other)
35 : AbstractFilter(other) {
36 nullify();
37 createWidget();
38
39 m_lineEdit->setText(other.m_lineEdit->text());
40 m_greaterThanLessThan->button(
41 other.m_greaterThanLessThan->checkedId())->click();
42 }
43
44
45
46 AbstractNumberFilter::~AbstractNumberFilter() {
47 delete m_lineEditText;
48 m_lineEditText = NULL;
49 }
50
51
52 void AbstractNumberFilter::nullify() {
53 m_greaterThanLessThan = NULL;
54 m_lineEdit = NULL;
55 m_lineEditText = NULL;
56 }
57
58
59 void AbstractNumberFilter::createWidget() {
60 QFont greaterThanLessThanFont("SansSerif", 9);
61
62 QRadioButton *lessThanButton = new QRadioButton("<=");
63 lessThanButton->setFont(greaterThanLessThanFont);
64 QRadioButton *greaterThanButton = new QRadioButton(">=");
65 greaterThanButton->setFont(greaterThanLessThanFont);
66
67 m_greaterThanLessThan = new QButtonGroup;
68 connect(m_greaterThanLessThan, SIGNAL(buttonClicked(int)),
69 this, SIGNAL(filterChanged()));
70 m_greaterThanLessThan->addButton(lessThanButton, 0);
71 m_greaterThanLessThan->addButton(greaterThanButton, 1);
72
73 // hide inclusive and exclusive buttons, and add greater than and less than
74 // in the inclusiveExclusiveLayout.
75 getInclusiveExclusiveLayout()->itemAt(0)->widget()->setVisible(false);
76 getInclusiveExclusiveLayout()->itemAt(1)->widget()->setVisible(false);
77 getInclusiveExclusiveLayout()->addWidget(lessThanButton);
78 getInclusiveExclusiveLayout()->addWidget(greaterThanButton);
79
80 m_lineEditText = new QString;
81
82 m_lineEdit = new QLineEdit;
83 m_lineEdit->setMinimumWidth(75);
84 connect(m_lineEdit, SIGNAL(textChanged(QString)),
85 this, SLOT(updateLineEditText(QString)));
86 connect(m_lineEdit, SIGNAL(textChanged(QString)),
87 this, SIGNAL(filterChanged()));
88
89
90 QHBoxLayout *layout = new QHBoxLayout;
91 QMargins margins = layout->contentsMargins();
92 margins.setTop(0);
93 margins.setBottom(0);
94 layout->setContentsMargins(margins);
95 layout->addWidget(m_lineEdit);
96 layout->addStretch();
97
98 getMainLayout()->addLayout(layout);
99
100 // FIXME: QSettings should handle this
101 lessThanButton->click();
102 }
103
104
105 bool AbstractNumberFilter::evaluate(double number) const {
106 bool evaluation = true;
107
108 // multiple threads reading the m_lineEditText so lock it
109 QString text = *m_lineEditText;
110
111 bool ok = false;
112 double d = text.toDouble(&ok);
113
114 if (ok)
115 evaluation = !(inclusive() ^ lessThan() ^(d <= number));
116
117 return evaluation;
118 }
119
120
121 QString AbstractNumberFilter::descriptionSuffix() const {
122 QString suffix;
123
124 if (!inclusive())
125 suffix += "not ";
126
127 if (lessThan())
128 suffix += "less than or equal to \"";
129 else
130 suffix += "greater than or equal to \"";
131
132 suffix += *m_lineEditText;
133
134 suffix += "\"";
135
136 return suffix;
137 }
138
139
140 bool AbstractNumberFilter::lessThan() const {
141 return m_greaterThanLessThan->checkedId() == 0;
142 }
143
144
145 void AbstractNumberFilter::updateLineEditText(QString newText) {
146 *m_lineEditText = newText;
147 }
148}
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16