3 #include "FilterWidget.h"     7 #include <QButtonGroup>    12 #include <QPushButton>    13 #include <QRadioButton>    15 #include <QVBoxLayout>    21 #include "FilterGroup.h"    29   FilterWidget::FilterWidget(QString type) {
    32     m_filterType = 
new QString(type);
    40   FilterWidget::FilterWidget(
const FilterWidget &other) {
    43     m_filterType = 
new QString(*other.m_filterType);
    47     foreach (FilterGroup * group, *other.m_filterGroups) {
    48       addGroup(
new FilterGroup(*group));
    51     m_buttonGroup->button(other.m_buttonGroup->checkedId())->click();
    57   FilterWidget::~FilterWidget() {
    64       delete m_filterGroups;
    65       m_filterGroups = NULL;
    76     return evaluate(imageAndNet, &AbstractFilter::canFilterImages);
    80   bool FilterWidget::evaluate(
const ControlPoint *point)
 const {
    81     return evaluate(point, &AbstractFilter::canFilterPoints);
    85   bool FilterWidget::evaluate(
const ControlMeasure *measure)
 const {
    86     return evaluate(measure, &AbstractFilter::canFilterMeasures);
    90   bool FilterWidget::hasFilter(
bool (AbstractFilter::*meth)() 
const)
 const {
    93     for (
int i = 0; !found && i < m_filterGroups->size(); i++)
    94       found = m_filterGroups->at(i)->hasFilter(meth);
   100   FilterWidget &FilterWidget::operator=(FilterWidget other) {
   101     ASSERT(m_filterType);
   102     ASSERT(m_filterGroups);
   103     ASSERT(m_buttonGroup);
   107     foreach (FilterGroup * group, *other.m_filterGroups) {
   108       FilterGroup *newGroup = 
new(nothrow) FilterGroup(*other.m_filterType);
   111         newGroups.append(newGroup);
   116     if (newGroups.size() == other.m_filterGroups->size()) {
   117       foreach (FilterGroup * group, *m_filterGroups) {
   121       foreach (FilterGroup * newGroup, newGroups) {
   125       swap(*m_filterType, *other.m_filterType);
   126       m_buttonGroup->button(other.m_buttonGroup->checkedId())->click();
   130       foreach (FilterGroup * newGroup, newGroups) {
   137       IString msg = 
"Assignment of FilterWidget failed";
   145   void FilterWidget::nullify() {
   146     m_addGroupButton = NULL;
   147     m_buttonGroup = NULL;
   148     m_imageDescription = NULL;
   149     m_pointDescription = NULL;
   150     m_measureDescription = NULL;
   152     m_filterGroups = NULL;
   157   void FilterWidget::init() {
   160     QString whatsThis = 
"<html>Filters are organized into groups (bounded by a box)."   161         "  Filters within a group will be combined using either AND or OR "   162         "logic.  Furthermore, multiple groups are supported, and the logic "   163         "used to combine the various groups is also configurable.<br/><br/>"   164         "For example, let A, B, and C be filters.  By creating two "   165         "groups, one with A and B and the other with C, it is possible to "   166         "build the expression \"(A and B) or C\".<br/><br/>"   167         "Each group has a green plus (+) button, which adds a new filter to "   168         "the group.  There is also a green plus (+) button outside any group "   169         "for adding a new group.</html>";
   171     ASSERT(m_filterType);
   173     QString title = 
"Filter " + *m_filterType;
   174     QLabel *titleLabel = 
new QLabel(title);
   175     titleLabel->setFont(QFont(
"SansSerif", 15, QFont::DemiBold));
   177     QHBoxLayout *titleLayout = 
new QHBoxLayout;
   178     titleLayout->addStretch();
   179     titleLayout->addWidget(titleLabel);
   180     titleLayout->addStretch();
   182     QLabel *logicTypeLabel = 
new QLabel(
"Combine groups using logic type: ");
   183     QFont logicTypeLabelFont(
"SansSerif", 12);
   184     logicTypeLabel->setFont(logicTypeLabelFont);
   186     QFont logicTypeFont(
"SansSerif", 12, QFont::Bold);
   187     QRadioButton *andButton = 
new QRadioButton(
"AND");
   188     andButton->setFont(logicTypeFont);
   189     QRadioButton *orButton = 
new QRadioButton(
"OR");
   190     orButton->setFont(logicTypeFont);
   191     m_buttonGroup = 
new QButtonGroup;
   192     m_buttonGroup->addButton(andButton, 0);
   193     m_buttonGroup->addButton(orButton, 1);
   194     connect(m_buttonGroup, SIGNAL(buttonClicked(
int)), 
this,
   195         SLOT(changeGroupCombinationLogic(
int)));
   200     QHBoxLayout *buttonLayout = 
new QHBoxLayout;
   201     buttonLayout->addStretch();
   202     buttonLayout->addWidget(logicTypeLabel);
   203     buttonLayout->addWidget(andButton);
   204     buttonLayout->addWidget(orButton);
   205     buttonLayout->addStretch();
   207     m_logicWidget->setLayout(buttonLayout);
   209     m_addGroupButton = 
new QPushButton;
   210     m_addGroupButton->setIcon(QIcon(FileName(
"$base/icons/add.png").expanded()));
   211     QString addGroupTooltip = 
"Add new filter group";
   212     m_addGroupButton->setToolTip(addGroupTooltip);
   213     m_addGroupButton->setStatusTip(addGroupTooltip);
   214     m_addGroupButton->setWhatsThis(whatsThis);
   215     connect(m_addGroupButton, SIGNAL(clicked()), 
this, SLOT(addGroup()));
   216     QHBoxLayout *addGroupLayout = 
new QHBoxLayout;
   217     addGroupLayout->addWidget(m_addGroupButton);
   218     addGroupLayout->addStretch();
   220     QLabel *titleDummy = 
new QLabel;
   221     titleDummy->setFont(QFont(
"SansSerif", 6)); 
   223     m_imageDescription = 
new QLabel;
   224     m_imageDescription->setWordWrap(
true);
   225     m_imageDescription->setFont(QFont(
"SansSerif", 10)); 
   227     m_pointDescription = 
new QLabel;
   228     m_pointDescription->setWordWrap(
true);
   229     m_pointDescription->setFont(QFont(
"SansSerif", 10)); 
   231     m_measureDescription = 
new QLabel;
   232     m_measureDescription->setWordWrap(
true);
   233     m_measureDescription->setFont(QFont(
"SansSerif", 10)); 
   235     QVBoxLayout *descriptionLayout = 
new QVBoxLayout;
   236     descriptionLayout->addWidget(titleDummy);
   237     descriptionLayout->addWidget(m_imageDescription);
   238     descriptionLayout->addWidget(m_pointDescription);
   239     descriptionLayout->addWidget(m_measureDescription);
   241     connect(
this, SIGNAL(filterChanged()),
   242         this, SLOT(updateDescription()));
   244     m_mainLayout = 
new QVBoxLayout;
   245     m_mainLayout->addLayout(titleLayout);
   246     m_mainLayout->addLayout(descriptionLayout);
   247     m_mainLayout->addWidget(m_logicWidget);
   248     m_mainLayout->addLayout(addGroupLayout);
   249     m_mainLayout->addStretch();
   251     setLayout(m_mainLayout);
   252     setWhatsThis(whatsThis);
   256   void FilterWidget::updateDescription() {
   257     updateDescription(m_imageDescription, &AbstractFilter::canFilterImages,
   258         &AbstractFilter::getImageDescription, 
"images");
   259     updateDescription(m_pointDescription, &AbstractFilter::canFilterPoints,
   260         &AbstractFilter::getPointDescription, 
"points");
   261     updateDescription(m_measureDescription, &AbstractFilter::canFilterMeasures,
   262         &AbstractFilter::getMeasureDescription, 
"measures");
   266   void FilterWidget::updateDescription(QLabel *label,
   267       bool (AbstractFilter::*hasFilterMeth)() 
const,
   268       QString(AbstractFilter::*descriptionMeth)() 
const,
   276       for (
int i = 0; i < m_filterGroups->size(); i++)
   277         if (m_filterGroups->at(i)->hasFilter(hasFilterMeth))
   278           groups.append(m_filterGroups->at(i));
   280       const int GROUP_SIZE = groups.size();
   283         QString black = 
"<font color=black>";
   284         QString blue = 
"<font color=darkBlue>";
   285         QString red = 
"<font color=darkRed>";
   286         QString end = 
"</font>";
   288         QString text = 
"Showing " + red + title + end + black + 
" which " + end;
   291         if (m_andGroupsTogether)
   292           groupLogic += 
" AND ";
   294           groupLogic += 
" OR ";
   296         QString leftParen = black + 
"<b>(</b>" + end;
   297         QString rightParen = black + 
"<b>)</b>" + end;
   299         for (
int i = 0; i < GROUP_SIZE - 1; i++) {
   302           text += blue + groups[i]->getDescription(
   303               hasFilterMeth, descriptionMeth) + end;
   305             text += rightParen + black + 
"<b>" + groupLogic + 
"</b>" + end;
   310         text += blue + groups[GROUP_SIZE - 1]->getDescription(
   311             hasFilterMeth, descriptionMeth) + end;
   315         text += black + 
"." + end;
   317         label->setText(text);
   323   void FilterWidget::maybeScroll(FilterGroup *group) {
   324     ASSERT(m_filterGroups);
   325     ASSERT(m_filterGroups->size());
   327     if (m_filterGroups && m_filterGroups->size() &&
   328         m_filterGroups->at(m_filterGroups->size() - 1) == group)
   329       emit scrollToBottom();
   333   void FilterWidget::addGroup() {
   334     FilterGroup *newGroup = 
new FilterGroup(*m_filterType);
   339   void FilterWidget::addGroup(FilterGroup *newGroup) {
   340     connect(newGroup, SIGNAL(close(FilterGroup *)),
   341         this, SLOT(deleteGroup(FilterGroup *)));
   342     connect(newGroup, SIGNAL(filterChanged()), 
this, SIGNAL(filterChanged()));
   343     connect(newGroup, SIGNAL(sizeChanged(FilterGroup *)),
   344         this, SLOT(maybeScroll(FilterGroup *)));
   345     m_mainLayout->insertWidget(m_mainLayout->count() - 2, newGroup);
   346     m_filterGroups->append(newGroup);
   347     m_filterGroups->size() > 1 ? m_logicWidget->show() : m_logicWidget->hide();
   349     emit scrollToBottom();
   350     emit filterChanged();
   354   void FilterWidget::deleteGroup(FilterGroup *filterGroup) {
   355     m_mainLayout->removeWidget(filterGroup);
   357     m_filterGroups->removeOne(filterGroup);
   358     m_filterGroups->size() > 1 ? m_logicWidget->show() : m_logicWidget->hide();
   359     emit filterChanged();
   363   void FilterWidget::changeGroupCombinationLogic(
int button) {
   364     m_andGroupsTogether = button == 0;
   365     emit filterChanged();
 
This error is for when a programmer made an API call that was illegal. 
 
#define _FILEINFO_
Macro for the filename and line number. 
 
Namespace for ISIS/Bullet specific routines.