3 #include "AbstractNumberFilter.h"
7 #include <QButtonGroup>
13 #include <QRadioButton>
22 AbstractNumberFilter::AbstractNumberFilter(
23 AbstractFilter::FilterEffectivenessFlag flag,
24 int minimumForSuccess) : AbstractFilter(flag, minimumForSuccess) {
30 AbstractNumberFilter::AbstractNumberFilter(
const AbstractNumberFilter &other)
31 : AbstractFilter(other) {
35 m_lineEdit->setText(other.m_lineEdit->text());
36 m_greaterThanLessThan->button(
37 other.m_greaterThanLessThan->checkedId())->click();
42 AbstractNumberFilter::~AbstractNumberFilter() {
43 delete m_lineEditText;
44 m_lineEditText = NULL;
48 void AbstractNumberFilter::nullify() {
49 m_greaterThanLessThan = NULL;
51 m_lineEditText = NULL;
55 void AbstractNumberFilter::createWidget() {
56 QFont greaterThanLessThanFont(
"SansSerif", 9);
58 QRadioButton *lessThanButton =
new QRadioButton(
"<=");
59 lessThanButton->setFont(greaterThanLessThanFont);
60 QRadioButton *greaterThanButton =
new QRadioButton(
">=");
61 greaterThanButton->setFont(greaterThanLessThanFont);
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);
71 getInclusiveExclusiveLayout()->itemAt(0)->widget()->setVisible(
false);
72 getInclusiveExclusiveLayout()->itemAt(1)->widget()->setVisible(
false);
73 getInclusiveExclusiveLayout()->addWidget(lessThanButton);
74 getInclusiveExclusiveLayout()->addWidget(greaterThanButton);
76 m_lineEditText =
new QString;
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()));
86 QHBoxLayout *layout =
new QHBoxLayout;
87 QMargins margins = layout->contentsMargins();
90 layout->setContentsMargins(margins);
91 layout->addWidget(m_lineEdit);
94 getMainLayout()->addLayout(layout);
97 lessThanButton->click();
101 bool AbstractNumberFilter::evaluate(
double number)
const {
102 bool evaluation =
true;
105 QString text = *m_lineEditText;
108 double d = text.toDouble(&ok);
111 evaluation = !(inclusive() ^ lessThan() ^(d <= number));
117 QString AbstractNumberFilter::descriptionSuffix()
const {
124 suffix +=
"less than or equal to \"";
126 suffix +=
"greater than or equal to \"";
128 suffix += *m_lineEditText;
136 bool AbstractNumberFilter::lessThan()
const {
137 return m_greaterThanLessThan->checkedId() == 0;
141 void AbstractNumberFilter::updateLineEditText(QString newText) {
142 *m_lineEditText = newText;