3 #include "AbstractNumberFilter.h" 7 #include <QButtonGroup> 13 #include <QRadioButton> 20 AbstractNumberFilter::AbstractNumberFilter(
21 AbstractFilter::FilterEffectivenessFlag flag,
22 int minimumForSuccess) : AbstractFilter(flag, minimumForSuccess) {
28 AbstractNumberFilter::AbstractNumberFilter(
const AbstractNumberFilter &other)
29 : AbstractFilter(other) {
33 m_lineEdit->setText(other.m_lineEdit->text());
34 m_greaterThanLessThan->button(
35 other.m_greaterThanLessThan->checkedId())->click();
40 AbstractNumberFilter::~AbstractNumberFilter() {
41 delete m_lineEditText;
42 m_lineEditText = NULL;
46 void AbstractNumberFilter::nullify() {
47 m_greaterThanLessThan = NULL;
49 m_lineEditText = NULL;
53 void AbstractNumberFilter::createWidget() {
54 QFont greaterThanLessThanFont(
"SansSerif", 9);
56 QRadioButton *lessThanButton =
new QRadioButton(
"<=");
57 lessThanButton->setFont(greaterThanLessThanFont);
58 QRadioButton *greaterThanButton =
new QRadioButton(
">=");
59 greaterThanButton->setFont(greaterThanLessThanFont);
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);
69 getInclusiveExclusiveLayout()->itemAt(0)->widget()->setVisible(
false);
70 getInclusiveExclusiveLayout()->itemAt(1)->widget()->setVisible(
false);
71 getInclusiveExclusiveLayout()->addWidget(lessThanButton);
72 getInclusiveExclusiveLayout()->addWidget(greaterThanButton);
74 m_lineEditText =
new QString;
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()));
84 QHBoxLayout *layout =
new QHBoxLayout;
85 QMargins margins = layout->contentsMargins();
88 layout->setContentsMargins(margins);
89 layout->addWidget(m_lineEdit);
92 getMainLayout()->addLayout(layout);
95 lessThanButton->click();
99 bool AbstractNumberFilter::evaluate(
double number)
const {
100 bool evaluation =
true;
103 QString text = *m_lineEditText;
106 double d = text.toDouble(&ok);
109 evaluation = !(inclusive() ^ lessThan() ^(d <= number));
115 QString AbstractNumberFilter::descriptionSuffix()
const {
122 suffix +=
"less than or equal to \"";
124 suffix +=
"greater than or equal to \"";
126 suffix += *m_lineEditText;
134 bool AbstractNumberFilter::lessThan()
const {
135 return m_greaterThanLessThan->checkedId() == 0;
139 void AbstractNumberFilter::updateLineEditText(QString newText) {
140 *m_lineEditText = newText;
Namespace for ISIS/Bullet specific routines.