14 #include "AbstractFilter.h"
17 #include <QAbstractButton>
18 #include <QButtonGroup>
21 #include <QHBoxLayout>
27 #include <QRadioButton>
30 #include <QVBoxLayout>
31 #include <QWriteLocker>
33 #include "ControlMeasure.h"
34 #include "ControlNet.h"
35 #include "ControlPoint.h"
37 #include "AbstractFilterSelector.h"
41 AbstractFilter::AbstractFilter(FilterEffectivenessFlag effectiveness,
42 int minimumForSuccess) {
45 m_minForSuccess = minimumForSuccess;
47 m_effectivenessFlags =
new FilterEffectivenessFlag(effectiveness);
49 m_smallFont =
new QFont(
"SansSerif", 9);
55 AbstractFilter::AbstractFilter(
const AbstractFilter &other) {
58 m_minForSuccess = other.m_minForSuccess;
60 m_effectivenessFlags =
new FilterEffectivenessFlag(*other.m_effectivenessFlags);
62 m_smallFont =
new QFont(*other.m_smallFont);
66 m_inclusiveExclusiveGroup->button(
67 other.m_inclusiveExclusiveGroup->checkedId())->click();
71 AbstractFilter::~AbstractFilter() {
72 delete m_effectivenessFlags;
73 m_effectivenessFlags = NULL;
75 delete m_inclusiveExclusiveGroup;
76 m_inclusiveExclusiveGroup = NULL;
83 bool AbstractFilter::canFilterImages()
const {
84 return m_effectivenessFlags->testFlag(Images);
88 bool AbstractFilter::canFilterPoints()
const {
89 return m_effectivenessFlags->testFlag(Points);
93 bool AbstractFilter::canFilterMeasures()
const {
94 return m_effectivenessFlags->testFlag(Measures);
98 QString AbstractFilter::getImageDescription()
const {
99 return "have at least " + QString::number(getMinForSuccess()) +
" ";
103 QString AbstractFilter::getPointDescription()
const {
108 QString AbstractFilter::getMeasureDescription()
const {
113 void AbstractFilter::nullify() {
114 m_effectivenessGroup = NULL;
115 m_inclusiveExclusiveGroup = NULL;
116 m_inclusiveExclusiveLayout = NULL;
119 m_effectivenessFlags = NULL;
124 void AbstractFilter::createWidget() {
125 QRadioButton *inclusiveButton =
new QRadioButton(
"Inclusive");
126 inclusiveButton->setFont(*m_smallFont);
127 QRadioButton *exclusiveButton =
new QRadioButton(
"Exclusive");
128 exclusiveButton->setFont(*m_smallFont);
130 m_inclusiveExclusiveGroup =
new QButtonGroup;
131 connect(m_inclusiveExclusiveGroup, SIGNAL(buttonClicked(
int)),
132 this, SIGNAL(filterChanged()));
133 m_inclusiveExclusiveGroup->addButton(inclusiveButton, 0);
134 m_inclusiveExclusiveGroup->addButton(exclusiveButton, 1);
136 m_inclusiveExclusiveLayout =
new QHBoxLayout;
137 QMargins margins = m_inclusiveExclusiveLayout->contentsMargins();
139 margins.setBottom(0);
140 m_inclusiveExclusiveLayout->setContentsMargins(margins);
141 m_inclusiveExclusiveLayout->addWidget(inclusiveButton);
142 m_inclusiveExclusiveLayout->addWidget(exclusiveButton);
144 QHBoxLayout *controlsLayout =
new QHBoxLayout;
145 margins = controlsLayout->contentsMargins();
147 margins.setBottom(0);
148 controlsLayout->setContentsMargins(margins);
150 controlsLayout->addLayout(m_inclusiveExclusiveLayout);
152 m_effectivenessGroup =
new QButtonGroup();
153 m_effectivenessGroup->setExclusive(
false);
155 if (m_effectivenessFlags->testFlag(Images))
156 m_effectivenessGroup->addButton(
157 createEffectivenessCheckBox(
"&Images"), 0);
159 if (m_effectivenessFlags->testFlag(Points))
160 m_effectivenessGroup->addButton(
161 createEffectivenessCheckBox(
"&Points"), 1);
163 if (m_effectivenessFlags->testFlag(Measures))
164 m_effectivenessGroup->addButton(
165 createEffectivenessCheckBox(
"&Measures"), 2);
167 QString firstGroupEntry;
168 ASSERT(m_effectivenessGroup->buttons().size());
169 if (m_effectivenessGroup->buttons().size()) {
170 firstGroupEntry = m_effectivenessGroup->buttons()[0]->text();
171 firstGroupEntry.remove(0, 1);
175 if (m_effectivenessGroup->buttons().size() >= 2) {
176 QHBoxLayout *effectivenessLayout =
new QHBoxLayout;
177 QMargins effectivenessMargins = effectivenessLayout->contentsMargins();
178 effectivenessMargins.setTop(0);
179 effectivenessMargins.setBottom(0);
180 effectivenessLayout->setContentsMargins(effectivenessMargins);
182 for (
int i = 0; i < buttons.size(); i++)
183 effectivenessLayout->addWidget(buttons[i]);
185 controlsLayout->addLayout(effectivenessLayout);
188 for (
int i = 0; i < buttons.size(); i++)
190 delete m_effectivenessGroup;
191 m_effectivenessGroup = NULL;
194 if (m_minForSuccess != -1) {
195 QLabel *label =
new QLabel;
197 "<span>Min Count<br/>for " + firstGroupEntry +
"</span>");
198 label->setFont(QFont(
"SansSerif", 7));
200 spinBox->setRange(1, std::numeric_limits< int >::max());
201 spinBox->setValue(1);
202 connect(spinBox, SIGNAL(valueChanged(
int)),
203 this, SLOT(updateMinForSuccess(
int)));
204 QHBoxLayout *minLayout =
new QHBoxLayout;
205 margins = minLayout->contentsMargins();
207 margins.setBottom(0);
208 minLayout->setContentsMargins(margins);
209 minLayout->addWidget(label);
210 minLayout->addWidget(spinBox);
212 m_minWidget->setLayout(minLayout);
214 controlsLayout->addWidget(m_minWidget);
215 controlsLayout->setAlignment(m_minWidget, Qt::AlignTop);
216 m_minWidget->setVisible(
true);
219 controlsLayout->addStretch();
221 m_mainLayout =
new QVBoxLayout;
222 margins = m_mainLayout->contentsMargins();
224 margins.setBottom(0);
225 m_mainLayout->setContentsMargins(margins);
226 m_mainLayout->addLayout(controlsLayout);
229 setLayout(m_mainLayout);
232 inclusiveButton->click();
236 QCheckBox *AbstractFilter::createEffectivenessCheckBox(QString text) {
237 QCheckBox *checkBox =
new QCheckBox(text,
this);
238 checkBox->setChecked(
true);
239 checkBox->setFont(*m_smallFont);
240 connect(checkBox, SIGNAL(toggled(
bool)),
241 this, SLOT(updateEffectiveness()));
242 connect(checkBox, SIGNAL(toggled(
bool)),
this, SIGNAL(filterChanged()));
247 bool AbstractFilter::inclusive()
const {
248 return m_inclusiveExclusiveGroup->checkedId() == 0;
252 AbstractFilter::FilterEffectivenessFlag *
253 AbstractFilter::getEffectivenessFlags()
const {
254 return m_effectivenessFlags;
258 QBoxLayout *AbstractFilter::getMainLayout()
const {
259 ASSERT(m_mainLayout);
265 QBoxLayout *AbstractFilter::getInclusiveExclusiveLayout()
const {
266 ASSERT(m_inclusiveExclusiveLayout);
268 return m_inclusiveExclusiveLayout;
273 bool usePoints)
const {
276 foreach (ControlMeasure * measure, measures) {
280 ControlPoint *point = measure->Parent();
282 if (point && evaluate(point))
286 if (measure && evaluate(measure))
291 return passedCount >= getMinForSuccess();
295 bool AbstractFilter::evaluateImageFromPointFilter(
297 bool evaluation =
true;
299 if (canFilterImages()) {
300 evaluation = evaluateFromCount(imageAndNet->second->GetMeasuresInCube(imageAndNet->first),
308 bool AbstractFilter::evaluateImageFromMeasureFilter(
310 bool evaluation =
true;
312 if (canFilterImages()) {
313 evaluation = evaluateFromCount(imageAndNet->second->GetMeasuresInCube(imageAndNet->first),
321 bool AbstractFilter::evaluatePointFromMeasureFilter(
322 const ControlPoint *point)
const {
325 bool evaluation =
true;
327 if (canFilterPoints())
328 evaluation = evaluateFromCount(point->getMeasures(),
false);
334 bool AbstractFilter::evaluate(
const ControlPoint *point,
335 bool (ControlPoint::*meth)()
const)
const {
338 return !((point->*meth)() ^ inclusive());
342 bool AbstractFilter::evaluate(
const ControlMeasure *measure,
343 bool (ControlMeasure::*meth)()
const)
const {
346 return !((measure->*meth)() ^ inclusive());
350 void AbstractFilter::updateEffectiveness() {
351 ASSERT(m_effectivenessGroup);
353 if (m_effectivenessGroup) {
354 FilterEffectivenessFlag newFlags;
359 m_minWidget->setVisible(
false);
361 for (
int i = 0; i < buttons.size(); i++) {
362 if (buttons[i]->isChecked()) {
363 if (buttons[i]->text() ==
"&Images")
365 else if (buttons[i]->text() ==
"&Points")
367 else if (buttons[i]->text() ==
"&Measures")
368 newFlags |= Measures;
370 if (i == 0 && m_minWidget)
371 m_minWidget->setVisible(
true);
375 *m_effectivenessFlags = newFlags;
380 void AbstractFilter::updateMinForSuccess(
int newMin) {
381 m_minForSuccess = newMin;
382 emit filterChanged();