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