12#include "AbstractFilter.h"
15#include <QAbstractButton>
16#include <QButtonGroup>
25#include <QRadioButton>
29#include <QWriteLocker>
31#include "ControlMeasure.h"
32#include "ControlNet.h"
33#include "ControlPoint.h"
35#include "AbstractFilterSelector.h"
39 AbstractFilter::AbstractFilter(FilterEffectivenessFlag effectiveness,
40 int minimumForSuccess) {
43 m_minForSuccess = minimumForSuccess;
45 m_effectivenessFlags =
new FilterEffectivenessFlag(effectiveness);
47 m_smallFont =
new QFont(
"SansSerif", 9);
53 AbstractFilter::AbstractFilter(
const AbstractFilter &other) {
56 m_minForSuccess = other.m_minForSuccess;
58 m_effectivenessFlags =
new FilterEffectivenessFlag(*other.m_effectivenessFlags);
60 m_smallFont =
new QFont(*other.m_smallFont);
64 m_inclusiveExclusiveGroup->button(
65 other.m_inclusiveExclusiveGroup->checkedId())->click();
69 AbstractFilter::~AbstractFilter() {
70 delete m_effectivenessFlags;
71 m_effectivenessFlags = NULL;
73 delete m_inclusiveExclusiveGroup;
74 m_inclusiveExclusiveGroup = NULL;
81 bool AbstractFilter::canFilterImages()
const {
82 return m_effectivenessFlags->testFlag(Images);
86 bool AbstractFilter::canFilterPoints()
const {
87 return m_effectivenessFlags->testFlag(Points);
91 bool AbstractFilter::canFilterMeasures()
const {
92 return m_effectivenessFlags->testFlag(Measures);
96 QString AbstractFilter::getImageDescription()
const {
97 return "have at least " + QString::number(getMinForSuccess()) +
" ";
101 QString AbstractFilter::getPointDescription()
const {
106 QString AbstractFilter::getMeasureDescription()
const {
111 void AbstractFilter::nullify() {
112 m_effectivenessGroup = NULL;
113 m_inclusiveExclusiveGroup = NULL;
114 m_inclusiveExclusiveLayout = NULL;
117 m_effectivenessFlags = NULL;
122 void AbstractFilter::createWidget() {
123 QRadioButton *inclusiveButton =
new QRadioButton(
"Inclusive");
124 inclusiveButton->setFont(*m_smallFont);
125 QRadioButton *exclusiveButton =
new QRadioButton(
"Exclusive");
126 exclusiveButton->setFont(*m_smallFont);
128 m_inclusiveExclusiveGroup =
new QButtonGroup;
129 connect(m_inclusiveExclusiveGroup, SIGNAL(buttonClicked(
int)),
130 this, SIGNAL(filterChanged()));
131 m_inclusiveExclusiveGroup->addButton(inclusiveButton, 0);
132 m_inclusiveExclusiveGroup->addButton(exclusiveButton, 1);
134 m_inclusiveExclusiveLayout =
new QHBoxLayout;
135 QMargins margins = m_inclusiveExclusiveLayout->contentsMargins();
137 margins.setBottom(0);
138 m_inclusiveExclusiveLayout->setContentsMargins(margins);
139 m_inclusiveExclusiveLayout->addWidget(inclusiveButton);
140 m_inclusiveExclusiveLayout->addWidget(exclusiveButton);
142 QHBoxLayout *controlsLayout =
new QHBoxLayout;
143 margins = controlsLayout->contentsMargins();
145 margins.setBottom(0);
146 controlsLayout->setContentsMargins(margins);
148 controlsLayout->addLayout(m_inclusiveExclusiveLayout);
150 m_effectivenessGroup =
new QButtonGroup();
151 m_effectivenessGroup->setExclusive(
false);
153 if (m_effectivenessFlags->testFlag(Images))
154 m_effectivenessGroup->addButton(
155 createEffectivenessCheckBox(
"&Images"), 0);
157 if (m_effectivenessFlags->testFlag(Points))
158 m_effectivenessGroup->addButton(
159 createEffectivenessCheckBox(
"&Points"), 1);
161 if (m_effectivenessFlags->testFlag(Measures))
162 m_effectivenessGroup->addButton(
163 createEffectivenessCheckBox(
"&Measures"), 2);
165 QString firstGroupEntry;
167 if (m_effectivenessGroup->buttons().size()) {
168 firstGroupEntry = m_effectivenessGroup->buttons()[0]->text();
169 firstGroupEntry.remove(0, 1);
172 QList<QAbstractButton *> buttons = m_effectivenessGroup->buttons();
173 if (m_effectivenessGroup->buttons().size() >= 2) {
174 QHBoxLayout *effectivenessLayout =
new QHBoxLayout;
175 QMargins effectivenessMargins = effectivenessLayout->contentsMargins();
176 effectivenessMargins.setTop(0);
177 effectivenessMargins.setBottom(0);
178 effectivenessLayout->setContentsMargins(effectivenessMargins);
180 for (
int i = 0; i < buttons.size(); i++)
181 effectivenessLayout->addWidget(buttons[i]);
183 controlsLayout->addLayout(effectivenessLayout);
186 for (
int i = 0; i < buttons.size(); i++)
188 delete m_effectivenessGroup;
189 m_effectivenessGroup = NULL;
192 if (m_minForSuccess != -1) {
193 QLabel *label =
new QLabel;
195 "<span>Min Count<br/>for " + firstGroupEntry +
"</span>");
196 label->setFont(QFont(
"SansSerif", 7));
198 spinBox->setRange(1, std::numeric_limits< int >::max());
199 spinBox->setValue(1);
200 connect(spinBox, SIGNAL(valueChanged(
int)),
201 this, SLOT(updateMinForSuccess(
int)));
202 QHBoxLayout *minLayout =
new QHBoxLayout;
203 margins = minLayout->contentsMargins();
205 margins.setBottom(0);
206 minLayout->setContentsMargins(margins);
207 minLayout->addWidget(label);
208 minLayout->addWidget(spinBox);
210 m_minWidget->setLayout(minLayout);
212 controlsLayout->addWidget(m_minWidget);
213 controlsLayout->setAlignment(m_minWidget, Qt::AlignTop);
214 m_minWidget->setVisible(
true);
217 controlsLayout->addStretch();
219 m_mainLayout =
new QVBoxLayout;
220 margins = m_mainLayout->contentsMargins();
222 margins.setBottom(0);
223 m_mainLayout->setContentsMargins(margins);
224 m_mainLayout->addLayout(controlsLayout);
227 setLayout(m_mainLayout);
230 inclusiveButton->click();
234 QCheckBox *AbstractFilter::createEffectivenessCheckBox(QString text) {
235 QCheckBox *checkBox =
new QCheckBox(text,
this);
236 checkBox->setChecked(
true);
237 checkBox->setFont(*m_smallFont);
238 connect(checkBox, SIGNAL(toggled(
bool)),
239 this, SLOT(updateEffectiveness()));
240 connect(checkBox, SIGNAL(toggled(
bool)),
this, SIGNAL(filterChanged()));
245 bool AbstractFilter::inclusive()
const {
246 return m_inclusiveExclusiveGroup->checkedId() == 0;
250 AbstractFilter::FilterEffectivenessFlag *
251 AbstractFilter::getEffectivenessFlags()
const {
252 return m_effectivenessFlags;
256 QBoxLayout *AbstractFilter::getMainLayout()
const {
262 QBoxLayout *AbstractFilter::getInclusiveExclusiveLayout()
const {
264 return m_inclusiveExclusiveLayout;
268 bool AbstractFilter::evaluateFromCount(QList< ControlMeasure * > measures,
269 bool usePoints)
const {
272 foreach (ControlMeasure * measure, measures) {
275 ControlPoint *point = measure->Parent();
277 if (point && evaluate(point))
281 if (measure && evaluate(measure))
286 return passedCount >= getMinForSuccess();
290 bool AbstractFilter::evaluateImageFromPointFilter(
291 const QPair<QString, ControlNet *> *imageAndNet)
const {
292 bool evaluation =
true;
294 if (canFilterImages()) {
295 evaluation = evaluateFromCount(imageAndNet->second->GetMeasuresInCube(imageAndNet->first),
303 bool AbstractFilter::evaluateImageFromMeasureFilter(
304 const QPair<QString, ControlNet *> *imageAndNet)
const {
305 bool evaluation =
true;
307 if (canFilterImages()) {
308 evaluation = evaluateFromCount(imageAndNet->second->GetMeasuresInCube(imageAndNet->first),
316 bool AbstractFilter::evaluatePointFromMeasureFilter(
317 const ControlPoint *point)
const {
319 bool evaluation =
true;
321 if (canFilterPoints())
322 evaluation = evaluateFromCount(point->getMeasures(),
false);
328 bool AbstractFilter::evaluate(
const ControlPoint *point,
329 bool (ControlPoint::*meth)() const) const {
331 return !((point->*meth)() ^ inclusive());
335 bool AbstractFilter::evaluate(
const ControlMeasure *measure,
336 bool (ControlMeasure::*meth)() const) const {
338 return !((measure->*meth)() ^ inclusive());
342 void AbstractFilter::updateEffectiveness() {
344 if (m_effectivenessGroup) {
345 FilterEffectivenessFlag newFlags;
347 QList< QAbstractButton * > buttons = m_effectivenessGroup->buttons();
350 m_minWidget->setVisible(
false);
352 for (
int i = 0; i < buttons.size(); i++) {
353 if (buttons[i]->isChecked()) {
354 if (buttons[i]->text() ==
"&Images")
356 else if (buttons[i]->text() ==
"&Points")
358 else if (buttons[i]->text() ==
"&Measures")
359 newFlags |= Measures;
361 if (i == 0 && m_minWidget)
362 m_minWidget->setVisible(
true);
366 *m_effectivenessFlags = newFlags;
371 void AbstractFilter::updateMinForSuccess(
int newMin) {
372 m_minForSuccess = newMin;
373 emit filterChanged();
This is free and unencumbered software released into the public domain.