USGS

Isis 3.0 Object Programmers' Reference

Home

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