implemented filter list enable/disable functionality
also refactored much of the filter list code to be much cleaner and modular.
This commit is contained in:
parent
3202243ed0
commit
083005b8a9
4 changed files with 266 additions and 229 deletions
|
@ -4,17 +4,48 @@
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
LogicMap::~LogicMap()
|
template <class T>
|
||||||
|
FilterListNode *FilterListInnerNode<T>::nodeAt(int i) const
|
||||||
{
|
{
|
||||||
while(!isEmpty())
|
return ((childNodes.size() > i)? childNodes.at(i) : NULL);
|
||||||
delete takeFirst();
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void FilterListInnerNode<T>::deleteAt(int i)
|
||||||
|
{
|
||||||
|
preRemoveChild(this, i);
|
||||||
|
delete childNodes.takeAt(i);
|
||||||
|
postRemoveChild(this, i);
|
||||||
|
nodeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
int FilterListInnerNode<T>::childIndex(const FilterListNode *node) const
|
||||||
|
{
|
||||||
|
FilterListNode *unconst;
|
||||||
|
T downcasted;
|
||||||
|
|
||||||
|
/* to do the dynamic cast to T we will lose const'ness, but we can
|
||||||
|
* trust QList::indexOf */
|
||||||
|
unconst = (FilterListNode *) node;
|
||||||
|
downcasted = dynamic_cast<T>(unconst);
|
||||||
|
if(downcasted == NULL)
|
||||||
|
return -1;
|
||||||
|
return childNodes.indexOf(downcasted);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
FilterListInnerNode<T>::~FilterListInnerNode()
|
||||||
|
{
|
||||||
|
while(!childNodes.isEmpty())
|
||||||
|
delete childNodes.takeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
const FilterItemList *LogicMap::findTypeList(CardFilter::Type type) const
|
const FilterItemList *LogicMap::findTypeList(CardFilter::Type type) const
|
||||||
{
|
{
|
||||||
LogicMap::const_iterator i;
|
QList<FilterItemList *>::const_iterator i;
|
||||||
|
|
||||||
for(i = constBegin(); i != constEnd(); i++)
|
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||||
if ((*i)->type == type)
|
if ((*i)->type == type)
|
||||||
return *i;
|
return *i;
|
||||||
|
|
||||||
|
@ -23,19 +54,20 @@ const FilterItemList *LogicMap::findTypeList(CardFilter::Type type) const
|
||||||
|
|
||||||
FilterItemList *LogicMap::typeList(CardFilter::Type type)
|
FilterItemList *LogicMap::typeList(CardFilter::Type type)
|
||||||
{
|
{
|
||||||
LogicMap::iterator i;
|
QList<FilterItemList *>::iterator i;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
for(i = begin(); i != end(); i++) {
|
for(i = childNodes.begin(); i != childNodes.end(); i++) {
|
||||||
if ((*i)->type == type)
|
if ((*i)->type == type)
|
||||||
break;
|
break;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (i == end()) {
|
if (i == childNodes.end()) {
|
||||||
p->preInsertChild(this, count);
|
preInsertChild(this, count);
|
||||||
i = insert(i, new FilterItemList(type, this));
|
i = childNodes.insert(i, new FilterItemList(type, this));
|
||||||
p->postInsertChild(this, count);
|
postInsertChild(this, count);
|
||||||
|
nodeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *i;
|
return *i;
|
||||||
|
@ -46,142 +78,81 @@ FilterListNode *LogicMap::parent() const
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterListNode *LogicMap::nodeAt(int i) const
|
int FilterItemList::termIndex(const QString &term) const
|
||||||
{
|
{
|
||||||
return ((size() > i)? at(i) : NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogicMap::deleteAt(int i)
|
|
||||||
{
|
|
||||||
delete takeAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
int LogicMap::index() const
|
|
||||||
{
|
|
||||||
return p->indexOf(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterListNode *FilterItemList::nodeAt(int i) const
|
|
||||||
{
|
|
||||||
return ((size() > i)? at(i) : NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FilterItemList::deleteAt(int i) {
|
|
||||||
delete takeAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterItemList::~FilterItemList()
|
|
||||||
{
|
|
||||||
while(!isEmpty())
|
|
||||||
delete takeFirst();
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterList::~FilterList()
|
|
||||||
{
|
|
||||||
while(!logicAttrs.isEmpty()) {
|
|
||||||
delete logicAttrs.takeFirst();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LogicMap *FilterList::attrLogicMap(CardFilter::Attr attr)
|
|
||||||
{
|
|
||||||
QList<LogicMap *>::iterator i;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
for(i = logicAttrs.begin(); i != logicAttrs.end(); i++) {
|
|
||||||
if((*i)->attr == attr)
|
|
||||||
break;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i == logicAttrs.end()) {
|
|
||||||
preInsertChild(this, count);
|
|
||||||
i = logicAttrs.insert(i, new LogicMap(attr, this));
|
|
||||||
postInsertChild(this, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return *i;
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterItemList *FilterList::attrTypeList(CardFilter::Attr attr,
|
|
||||||
CardFilter::Type type)
|
|
||||||
{
|
|
||||||
return attrLogicMap(attr)->typeList(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FilterList::findTermIndex(CardFilter::Attr attr, CardFilter::Type type,
|
|
||||||
const QString &term)
|
|
||||||
{
|
|
||||||
FilterItemList *fis;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fis = attrTypeList(attr, type);
|
for(i = 0; i < childNodes.count(); i++)
|
||||||
for(i = 0; i < fis->count(); i++)
|
if((childNodes.at(i))->term == term)
|
||||||
if((fis->at(i))->term == term)
|
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FilterList::findTermIndex(const CardFilter *f)
|
FilterListNode *FilterItemList::termNode(const QString &term)
|
||||||
{
|
{
|
||||||
return findTermIndex(f->attr(), f->type(), f->term());
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterListNode *FilterList::termNode(CardFilter::Attr attr, CardFilter::Type type,
|
|
||||||
const QString &term)
|
|
||||||
{
|
|
||||||
FilterItemList *fis;
|
|
||||||
FilterItem *fi;
|
|
||||||
int i, count;
|
int i, count;
|
||||||
|
FilterItem *fi;
|
||||||
|
|
||||||
fis = attrTypeList(attr, type);
|
i = termIndex(term);
|
||||||
i = findTermIndex(attr, type, term);
|
|
||||||
if(i < 0) {
|
if(i < 0) {
|
||||||
fi = new FilterItem(term, fis);
|
fi = new FilterItem(term, this);
|
||||||
count = fis->childCount();
|
count = childNodes.count();
|
||||||
preInsertChild(fis, count);
|
preInsertChild(this, count);
|
||||||
fis->append(fi);
|
childNodes.append(fi);
|
||||||
postInsertChild(fis, count);
|
postInsertChild(this, count);
|
||||||
|
nodeChanged();
|
||||||
return fi;
|
return fi;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fis->at(i);
|
return childNodes.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterListNode *FilterList::termNode(const CardFilter *f)
|
bool FilterItemList::testTypeAnd(const CardInfo *info, CardFilter::Attr attr) const
|
||||||
{
|
{
|
||||||
return termNode(f->attr(), f->type(), f->term());
|
QList<FilterItem *>::const_iterator i;
|
||||||
|
|
||||||
|
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||||
|
if (!(*i)->acceptCardAttr(info, attr))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterListNode *FilterList::attrTypeNode(CardFilter::Attr attr,
|
bool FilterItemList::testTypeAndNot(const CardInfo *info, CardFilter::Attr attr) const
|
||||||
CardFilter::Type type)
|
|
||||||
{
|
{
|
||||||
return attrTypeList(attr, type);
|
// if any one in the list is true, return false
|
||||||
|
return !testTypeOr(info, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FilterList::count(CardFilter::Attr attr, CardFilter::Type type)
|
bool FilterItemList::testTypeOr(const CardInfo *info, CardFilter::Attr attr) const
|
||||||
{
|
{
|
||||||
return attrTypeList(attr, type)->count();
|
QList<FilterItem *>::const_iterator i;
|
||||||
|
|
||||||
|
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||||
|
if ((*i)->acceptCardAttr(info, attr))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FilterList::count(const CardFilter *f)
|
bool FilterItemList::testTypeOrNot(const CardInfo *info, CardFilter::Attr attr) const
|
||||||
{
|
{
|
||||||
return count(f->attr(), f->type());
|
// if any one in the list is false, return true
|
||||||
|
return !testTypeAnd(info, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptName(const CardInfo *info, const QString &term) const
|
bool FilterItem::acceptName(const CardInfo *info) const
|
||||||
{
|
{
|
||||||
return info->getName().contains(term, Qt::CaseInsensitive);
|
return info->getName().contains(term, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptType(const CardInfo *info, const QString &term) const
|
bool FilterItem::acceptType(const CardInfo *info) const
|
||||||
{
|
{
|
||||||
return info->getCardType().contains(term, Qt::CaseInsensitive);
|
return info->getCardType().contains(term, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptColor(const CardInfo *info, const QString &term) const
|
bool FilterItem::acceptColor(const CardInfo *info) const
|
||||||
{
|
{
|
||||||
QStringList::const_iterator i;
|
QStringList::const_iterator i;
|
||||||
bool status;
|
bool status;
|
||||||
|
@ -196,12 +167,12 @@ bool FilterList::acceptColor(const CardInfo *info, const QString &term) const
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptText(const CardInfo *info, const QString &term) const
|
bool FilterItem::acceptText(const CardInfo *info) const
|
||||||
{
|
{
|
||||||
return info->getText().contains(term, Qt::CaseInsensitive);
|
return info->getText().contains(term, Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptSet(const CardInfo *info, const QString &term) const
|
bool FilterItem::acceptSet(const CardInfo *info) const
|
||||||
{
|
{
|
||||||
SetList::const_iterator i;
|
SetList::const_iterator i;
|
||||||
bool status;
|
bool status;
|
||||||
|
@ -217,34 +188,36 @@ bool FilterList::acceptSet(const CardInfo *info, const QString &term) const
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptManaCost(const CardInfo *info, const QString &term) const
|
bool FilterItem::acceptManaCost(const CardInfo *info) const
|
||||||
{
|
{
|
||||||
return (info->getManaCost() == term);
|
return (info->getManaCost() == term);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptCardAttr(const CardInfo *info, const QString &term,
|
bool FilterItem::acceptCardAttr(const CardInfo *info, CardFilter::Attr attr) const
|
||||||
CardFilter::Attr attr) const
|
|
||||||
{
|
{
|
||||||
bool status;
|
bool status;
|
||||||
|
|
||||||
|
if(!isEnabled())
|
||||||
|
return true;
|
||||||
|
|
||||||
switch(attr) {
|
switch(attr) {
|
||||||
case CardFilter::AttrName:
|
case CardFilter::AttrName:
|
||||||
status = acceptName(info, term);
|
status = acceptName(info);
|
||||||
break;
|
break;
|
||||||
case CardFilter::AttrType:
|
case CardFilter::AttrType:
|
||||||
status = acceptType(info, term);
|
status = acceptType(info);
|
||||||
break;
|
break;
|
||||||
case CardFilter::AttrColor:
|
case CardFilter::AttrColor:
|
||||||
status = acceptColor(info, term);
|
status = acceptColor(info);
|
||||||
break;
|
break;
|
||||||
case CardFilter::AttrText:
|
case CardFilter::AttrText:
|
||||||
status = acceptText(info, term);
|
status = acceptText(info);
|
||||||
break;
|
break;
|
||||||
case CardFilter::AttrSet:
|
case CardFilter::AttrSet:
|
||||||
status = acceptSet(info, term);
|
status = acceptSet(info);
|
||||||
break;
|
break;
|
||||||
case CardFilter::AttrManaCost:
|
case CardFilter::AttrManaCost:
|
||||||
status = acceptManaCost(info, term);
|
status = acceptManaCost(info);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status = true; /* ignore this attribute */
|
status = true; /* ignore this attribute */
|
||||||
|
@ -253,84 +226,104 @@ bool FilterList::acceptCardAttr(const CardInfo *info, const QString &term,
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::testTypeAnd(const CardInfo *info, CardFilter::Attr attr,
|
/* need to define these here to make QT happy, otherwise
|
||||||
const FilterItemList *fil) const
|
* moc doesnt find some of the FilterListInnerNode symbols.
|
||||||
|
*/
|
||||||
|
FilterList::FilterList() {}
|
||||||
|
FilterList::~FilterList() {}
|
||||||
|
|
||||||
|
LogicMap *FilterList::attrLogicMap(CardFilter::Attr attr)
|
||||||
{
|
{
|
||||||
FilterItemList::const_iterator i;
|
QList<LogicMap *>::iterator i;
|
||||||
|
int count;
|
||||||
|
|
||||||
for(i = fil->constBegin(); i != fil->constEnd(); i++)
|
count = 0;
|
||||||
if(!acceptCardAttr(info, (*i)->term, attr))
|
for(i = childNodes.begin(); i != childNodes.end(); i++) {
|
||||||
return false;
|
if((*i)->attr == attr)
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FilterList::testTypeAndNot(const CardInfo *info, CardFilter::Attr attr,
|
|
||||||
const FilterItemList *fil) const
|
|
||||||
{
|
|
||||||
FilterItemList::const_iterator i;
|
|
||||||
|
|
||||||
for(i = fil->constBegin(); i != fil->constEnd(); i++)
|
|
||||||
if(acceptCardAttr(info, (*i)->term, attr))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FilterList::testTypeOr(const CardInfo *info, CardFilter::Attr attr,
|
|
||||||
const FilterItemList *filOr,
|
|
||||||
const FilterItemList *filOrNot) const
|
|
||||||
{
|
|
||||||
FilterItemList::const_iterator i;
|
|
||||||
bool status;
|
|
||||||
|
|
||||||
if(filOr == NULL && filOrNot == NULL)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
status = false;
|
|
||||||
if (filOr != NULL)
|
|
||||||
for(i = filOr->constBegin(); i != filOr->constEnd(); i++)
|
|
||||||
if(acceptCardAttr(info, (*i)->term, attr)) {
|
|
||||||
status = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (status != true && filOrNot != NULL)
|
|
||||||
for(i = filOrNot->constBegin(); i != filOrNot->constEnd(); i++)
|
|
||||||
if(!acceptCardAttr(info, (*i)->term, attr)) {
|
|
||||||
status = true;
|
|
||||||
break;
|
break;
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
if(i == childNodes.end()) {
|
||||||
|
preInsertChild(this, count);
|
||||||
|
i = childNodes.insert(i, new LogicMap(attr, this));
|
||||||
|
postInsertChild(this, count);
|
||||||
|
nodeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
return *i;
|
||||||
|
}
|
||||||
|
|
||||||
|
FilterItemList *FilterList::attrTypeList(CardFilter::Attr attr,
|
||||||
|
CardFilter::Type type)
|
||||||
|
{
|
||||||
|
return attrLogicMap(attr)->typeList(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FilterList::findTermIndex(CardFilter::Attr attr, CardFilter::Type type,
|
||||||
|
const QString &term)
|
||||||
|
{
|
||||||
|
attrTypeList(attr, type)->termIndex(term);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FilterList::findTermIndex(const CardFilter *f)
|
||||||
|
{
|
||||||
|
return findTermIndex(f->attr(), f->type(), f->term());
|
||||||
|
}
|
||||||
|
|
||||||
|
FilterListNode *FilterList::termNode(CardFilter::Attr attr, CardFilter::Type type,
|
||||||
|
const QString &term)
|
||||||
|
{
|
||||||
|
return attrTypeList(attr, type)->termNode(term);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilterListNode *FilterList::termNode(const CardFilter *f)
|
||||||
|
{
|
||||||
|
return termNode(f->attr(), f->type(), f->term());
|
||||||
|
}
|
||||||
|
|
||||||
|
FilterListNode *FilterList::attrTypeNode(CardFilter::Attr attr,
|
||||||
|
CardFilter::Type type)
|
||||||
|
{
|
||||||
|
return attrTypeList(attr, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::testAttr(const CardInfo *info, const LogicMap *lm) const
|
bool FilterList::testAttr(const CardInfo *info, const LogicMap *lm) const
|
||||||
{
|
{
|
||||||
|
const FilterItemList *fil;
|
||||||
bool status;
|
bool status;
|
||||||
const FilterItemList *fil, *fil2;
|
|
||||||
|
status = true;
|
||||||
|
|
||||||
fil = lm->findTypeList(CardFilter::TypeAnd);
|
fil = lm->findTypeList(CardFilter::TypeAnd);
|
||||||
if (fil != NULL && !testTypeAnd(info, lm->attr, fil))
|
if (fil != NULL && fil->isEnabled() && !fil->testTypeAnd(info, lm->attr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fil = lm->findTypeList(CardFilter::TypeAndNot);
|
fil = lm->findTypeList(CardFilter::TypeAndNot);
|
||||||
if (fil != NULL && !testTypeAndNot(info, lm->attr, fil))
|
if (fil != NULL && fil->isEnabled() && !fil->testTypeAndNot(info, lm->attr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fil = lm->findTypeList(CardFilter::TypeOr);
|
fil = lm->findTypeList(CardFilter::TypeOr);
|
||||||
fil2 = lm->findTypeList(CardFilter::TypeOrNot);
|
if (fil != NULL && fil->isEnabled()) {
|
||||||
if (!testTypeOr(info, lm->attr, fil, fil2))
|
status = false;
|
||||||
return false;
|
// if this is true we can return because it is OR'd with the OrNot list
|
||||||
|
if (fil->testTypeOr(info, lm->attr))
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fil = lm->findTypeList(CardFilter::TypeOrNot);
|
||||||
|
if (fil != NULL && fil->isEnabled() && fil->testTypeOrNot(info, lm->attr))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterList::acceptsCard(const CardInfo *info) const
|
bool FilterList::acceptsCard(const CardInfo *info) const
|
||||||
{
|
{
|
||||||
QList<LogicMap *>::const_iterator i;
|
QList<LogicMap *>::const_iterator i;
|
||||||
|
|
||||||
for(i = logicAttrs.constBegin(); i != logicAttrs.constEnd(); i++)
|
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||||
if(!testAttr(info, *i))
|
if ((*i)->isEnabled() && !testAttr(info, *i))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -15,45 +15,71 @@ private:
|
||||||
public:
|
public:
|
||||||
FilterListNode() : enabled(true) {}
|
FilterListNode() : enabled(true) {}
|
||||||
virtual bool isEnabled() const { return enabled; }
|
virtual bool isEnabled() const { return enabled; }
|
||||||
virtual void enable() { enabled = true; }
|
virtual void enable() { enabled = true; nodeChanged(); }
|
||||||
virtual void disable() { enabled = false; }
|
virtual void disable() { enabled = false; nodeChanged(); }
|
||||||
virtual FilterListNode *parent() const { return NULL; }
|
virtual FilterListNode *parent() const { return NULL; }
|
||||||
virtual FilterListNode *nodeAt(int i) const { return NULL; }
|
virtual FilterListNode *nodeAt(int i) const { return NULL; }
|
||||||
virtual void deleteAt(int i) {}
|
virtual void deleteAt(int i) {}
|
||||||
virtual int childCount() const { return 0; }
|
virtual int childCount() const { return 0; }
|
||||||
virtual int index() const { return -1; }
|
virtual int childIndex(const FilterListNode *node) const { return -1; }
|
||||||
|
virtual int index() const { return (parent() != NULL)? parent()->childIndex(this) : -1; }
|
||||||
virtual QString text() const { return ""; }
|
virtual QString text() const { return ""; }
|
||||||
virtual bool isLeaf() const { return false; }
|
virtual bool isLeaf() const { return false; }
|
||||||
virtual const char *textCStr() const { return text().toStdString().c_str(); }
|
virtual const char *textCStr() const { return text().toStdString().c_str(); }
|
||||||
|
virtual void nodeChanged() const {
|
||||||
|
printf("%s -> ", textCStr());
|
||||||
|
if (parent() != NULL) parent()->nodeChanged();
|
||||||
|
}
|
||||||
|
virtual void preInsertChild(const FilterListNode *p, int i) const {
|
||||||
|
//printf("%s -> ", textCStr());
|
||||||
|
if (parent() != NULL) parent()->preInsertChild(p, i);
|
||||||
|
}
|
||||||
|
virtual void postInsertChild(const FilterListNode *p, int i) const {
|
||||||
|
//printf("%s -> ", textCStr());
|
||||||
|
if (parent() != NULL) parent()->postInsertChild(p, i);
|
||||||
|
}
|
||||||
|
virtual void preRemoveChild(const FilterListNode *p, int i) const {
|
||||||
|
printf("%s -> ", textCStr());
|
||||||
|
if (parent() != NULL) parent()->preRemoveChild(p, i);
|
||||||
|
}
|
||||||
|
virtual void postRemoveChild(const FilterListNode *p, int i) const {
|
||||||
|
printf("%s -> ", textCStr());
|
||||||
|
if (parent() != NULL) parent()->postRemoveChild(p, i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class FilterListInnerNode : public FilterListNode {
|
||||||
|
protected:
|
||||||
|
QList<T> childNodes;
|
||||||
|
public:
|
||||||
|
~FilterListInnerNode();
|
||||||
|
FilterListNode *nodeAt(int i) const;
|
||||||
|
void deleteAt(int i);
|
||||||
|
int childCount() const { return childNodes.size(); }
|
||||||
|
int childIndex(const FilterListNode *node) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FilterItemList;
|
class FilterItemList;
|
||||||
class FilterList;
|
class FilterList;
|
||||||
class LogicMap
|
class LogicMap : public FilterListInnerNode<FilterItemList *> {
|
||||||
: public QList<FilterItemList *>
|
|
||||||
, public FilterListNode {
|
|
||||||
private:
|
private:
|
||||||
FilterList *const p;
|
FilterList *const p;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const CardFilter::Attr attr;
|
const CardFilter::Attr attr;
|
||||||
|
|
||||||
LogicMap(CardFilter::Attr a, FilterList *parent)
|
LogicMap(CardFilter::Attr a, FilterList *parent)
|
||||||
: attr(a), p(parent) {}
|
: attr(a), p(parent) {}
|
||||||
~LogicMap();
|
|
||||||
const FilterItemList *findTypeList(CardFilter::Type type) const;
|
const FilterItemList *findTypeList(CardFilter::Type type) const;
|
||||||
FilterItemList *typeList(CardFilter::Type type);
|
FilterItemList *typeList(CardFilter::Type type);
|
||||||
virtual FilterListNode *parent() const;
|
FilterListNode *parent() const;
|
||||||
virtual FilterListNode *nodeAt(int i) const;
|
QString text() const { return QString(CardFilter::attrName(attr)); }
|
||||||
virtual void deleteAt(int i);
|
|
||||||
virtual int childCount() const { return size(); }
|
|
||||||
virtual int index() const;
|
|
||||||
virtual QString text() const { return QString(CardFilter::attrName(attr)); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FilterItem;
|
class FilterItem;
|
||||||
class FilterItemList
|
class FilterItemList : public FilterListInnerNode<FilterItem *> {
|
||||||
: public QList<FilterItem *>
|
|
||||||
, public FilterListNode {
|
|
||||||
private:
|
private:
|
||||||
LogicMap *const p;
|
LogicMap *const p;
|
||||||
public:
|
public:
|
||||||
|
@ -61,14 +87,16 @@ public:
|
||||||
|
|
||||||
FilterItemList(CardFilter::Type t, LogicMap *parent)
|
FilterItemList(CardFilter::Type t, LogicMap *parent)
|
||||||
: type(t), p(parent) {}
|
: type(t), p(parent) {}
|
||||||
~FilterItemList();
|
|
||||||
CardFilter::Attr attr() const { return p->attr; }
|
CardFilter::Attr attr() const { return p->attr; }
|
||||||
virtual FilterListNode *parent() const { return p; }
|
FilterListNode *parent() const { return p; }
|
||||||
virtual FilterListNode *nodeAt(int i) const;
|
int termIndex(const QString &term) const;
|
||||||
virtual void deleteAt(int i);
|
FilterListNode *termNode(const QString &term);
|
||||||
virtual int childCount() const { return size(); }
|
QString text() const { return QString(CardFilter::typeName(type)); }
|
||||||
virtual int index() const { return p->indexOf((FilterItemList *) this); }
|
|
||||||
virtual QString text() const { return QString(CardFilter::typeName(type)); }
|
bool testTypeAnd(const CardInfo *info, CardFilter::Attr attr) const;
|
||||||
|
bool testTypeAndNot(const CardInfo *info, CardFilter::Attr attr) const;
|
||||||
|
bool testTypeOr(const CardInfo *info, CardFilter::Attr attr) const;
|
||||||
|
bool testTypeOrNot(const CardInfo *info, CardFilter::Attr attr) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FilterItem : public FilterListNode {
|
class FilterItem : public FilterListNode {
|
||||||
|
@ -82,48 +110,38 @@ public:
|
||||||
|
|
||||||
CardFilter::Attr attr() const { return p->attr(); }
|
CardFilter::Attr attr() const { return p->attr(); }
|
||||||
CardFilter::Type type() const { return p->type; }
|
CardFilter::Type type() const { return p->type; }
|
||||||
virtual FilterListNode *parent() const { return p; }
|
FilterListNode *parent() const { return p; }
|
||||||
virtual int index() const { return p->indexOf((FilterItem *)this); }
|
QString text() const { return term; }
|
||||||
virtual QString text() const { return term; }
|
bool isLeaf() const { return true; }
|
||||||
virtual bool isLeaf() const { return true; }
|
|
||||||
|
bool acceptName(const CardInfo *info) const;
|
||||||
|
bool acceptType(const CardInfo *info) const;
|
||||||
|
bool acceptColor(const CardInfo *info) const;
|
||||||
|
bool acceptText(const CardInfo *info) const;
|
||||||
|
bool acceptSet(const CardInfo *info) const;
|
||||||
|
bool acceptManaCost(const CardInfo *info) const;
|
||||||
|
bool acceptCardAttr(const CardInfo *info, CardFilter::Attr attr) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FilterList : public QObject, public FilterListNode {
|
class FilterList : public QObject, public FilterListInnerNode<LogicMap *> {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void preInsertRow(const FilterListNode *parent, int i) const;
|
void preInsertRow(const FilterListNode *parent, int i) const;
|
||||||
void postInsertRow(const FilterListNode *parent, int i) const;
|
void postInsertRow(const FilterListNode *parent, int i) const;
|
||||||
|
void preRemoveRow(const FilterListNode *parent, int i) const;
|
||||||
|
void postRemoveRow(const FilterListNode *parent, int i) const;
|
||||||
void changed() const;
|
void changed() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<LogicMap *> logicAttrs;
|
|
||||||
|
|
||||||
LogicMap *attrLogicMap(CardFilter::Attr attr);
|
LogicMap *attrLogicMap(CardFilter::Attr attr);
|
||||||
FilterItemList *attrTypeList(CardFilter::Attr attr,
|
FilterItemList *attrTypeList(CardFilter::Attr attr,
|
||||||
CardFilter::Type type);
|
CardFilter::Type type);
|
||||||
|
|
||||||
bool acceptName(const CardInfo *info, const QString &term) const;
|
|
||||||
bool acceptType(const CardInfo *info, const QString &term) const;
|
|
||||||
bool acceptColor(const CardInfo *info, const QString &term) const;
|
|
||||||
bool acceptCardAttr(const CardInfo *info, const QString &term,
|
|
||||||
CardFilter::Attr attr) const;
|
|
||||||
bool acceptText(const CardInfo *info, const QString &term) const;
|
|
||||||
bool acceptSet(const CardInfo *info, const QString &term) const;
|
|
||||||
bool acceptManaCost(const CardInfo *info, const QString &term) const;
|
|
||||||
|
|
||||||
bool testTypeAnd(const CardInfo *info, CardFilter::Attr attr,
|
|
||||||
const FilterItemList *fil) const;
|
|
||||||
bool testTypeAndNot(const CardInfo *info, CardFilter::Attr attr,
|
|
||||||
const FilterItemList *fil) const;
|
|
||||||
bool testTypeOr(const CardInfo *info, CardFilter::Attr attr,
|
|
||||||
const FilterItemList *filOr,
|
|
||||||
const FilterItemList *filOrNot) const;
|
|
||||||
|
|
||||||
bool testAttr(const CardInfo *info, const LogicMap *lm) const;
|
bool testAttr(const CardInfo *info, const LogicMap *lm) const;
|
||||||
public:
|
public:
|
||||||
|
FilterList();
|
||||||
~FilterList();
|
~FilterList();
|
||||||
int indexOf(const LogicMap *val) const { return logicAttrs.indexOf((LogicMap *) val); }
|
|
||||||
int findTermIndex(CardFilter::Attr attr, CardFilter::Type type,
|
int findTermIndex(CardFilter::Attr attr, CardFilter::Type type,
|
||||||
const QString &term);
|
const QString &term);
|
||||||
int findTermIndex(const CardFilter *f);
|
int findTermIndex(const CardFilter *f);
|
||||||
|
@ -132,16 +150,14 @@ public:
|
||||||
FilterListNode *termNode(const CardFilter *f);
|
FilterListNode *termNode(const CardFilter *f);
|
||||||
FilterListNode *attrTypeNode(CardFilter::Attr attr,
|
FilterListNode *attrTypeNode(CardFilter::Attr attr,
|
||||||
CardFilter::Type type);
|
CardFilter::Type type);
|
||||||
int count(CardFilter::Attr attr, CardFilter::Type type);
|
QString text() const { return QString("root"); }
|
||||||
int count(const CardFilter *f);
|
int index() const { return 0; }
|
||||||
virtual FilterListNode *nodeAt(int i) const { return ((logicAttrs.size() > i)? logicAttrs.at(i) : NULL); }
|
|
||||||
virtual void deleteAt(int i) { delete logicAttrs.takeAt(i); }
|
void nodeChanged() const { printf("root\n"); emit changed(); }
|
||||||
virtual int childCount() const { return logicAttrs.size(); }
|
|
||||||
virtual QString text() const { return QString("root"); }
|
|
||||||
virtual int index() const { return 0; }
|
|
||||||
void preInsertChild(const FilterListNode *p, int i) const { emit preInsertRow(p, i); }
|
void preInsertChild(const FilterListNode *p, int i) const { emit preInsertRow(p, i); }
|
||||||
void postInsertChild(const FilterListNode *p, int i) const { emit postInsertRow(p, i); emit changed(); }
|
void postInsertChild(const FilterListNode *p, int i) const { emit postInsertRow(p, i); }
|
||||||
void emitChanged() const { emit changed(); }
|
void preRemoveChild(const FilterListNode *p, int i) const { printf("root\n"); emit preRemoveRow(p, i); }
|
||||||
|
void postRemoveChild(const FilterListNode *p, int i) const { printf("root\n"); emit postRemoveRow(p, i); }
|
||||||
|
|
||||||
bool acceptsCard(const CardInfo *info) const;
|
bool acceptsCard(const CardInfo *info) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,6 +13,12 @@ FilterListModel::FilterListModel(QObject *parent)
|
||||||
connect(fList,
|
connect(fList,
|
||||||
SIGNAL(postInsertRow(const FilterListNode *, int)),
|
SIGNAL(postInsertRow(const FilterListNode *, int)),
|
||||||
this, SLOT(proxyEndInsertRow(const FilterListNode *, int)));
|
this, SLOT(proxyEndInsertRow(const FilterListNode *, int)));
|
||||||
|
connect(fList,
|
||||||
|
SIGNAL(preRemoveRow(const FilterListNode *, int)),
|
||||||
|
this, SLOT(proxyBeginRemoveRow(const FilterListNode *, int)));
|
||||||
|
connect(fList,
|
||||||
|
SIGNAL(postRemoveRow(const FilterListNode *, int)),
|
||||||
|
this, SLOT(proxyEndRemoveRow(const FilterListNode *, int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterListModel::~FilterListModel()
|
FilterListModel::~FilterListModel()
|
||||||
|
@ -38,6 +44,24 @@ void FilterListModel::proxyEndInsertRow(const FilterListNode *node, int)
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilterListModel::proxyBeginRemoveRow(const FilterListNode *node, int i)
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
idx = node->index();
|
||||||
|
if(idx >= 0)
|
||||||
|
beginRemoveRows(createIndex(idx, 0, (void *) node), i, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FilterListModel::proxyEndRemoveRow(const FilterListNode *node, int)
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
idx = node->index();
|
||||||
|
if(idx >= 0)
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
|
||||||
FilterListNode *FilterListModel::indexToNode(const QModelIndex &idx) const
|
FilterListNode *FilterListModel::indexToNode(const QModelIndex &idx) const
|
||||||
{
|
{
|
||||||
void *ip;
|
void *ip;
|
||||||
|
@ -235,11 +259,13 @@ bool FilterListModel::removeRows(int row, int count, const QModelIndex & parent)
|
||||||
if(node == NULL || last >= node->childCount())
|
if(node == NULL || last >= node->childCount())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginRemoveRows(parent, row, last);
|
printf("delete children in %s\n", node->textCStr());
|
||||||
for(i = 0; i < count; i++)
|
fflush(stdout);
|
||||||
|
for(i = 0; i < count; i++) {
|
||||||
|
printf(" delete %d\n", i);
|
||||||
|
fflush(stdout);
|
||||||
node->deleteAt(row);
|
node->deleteAt(row);
|
||||||
endRemoveRows();
|
}
|
||||||
fList->emitChanged();
|
|
||||||
|
|
||||||
if(node != fList && node->childCount() < 1)
|
if(node != fList && node->childCount() < 1)
|
||||||
return removeRow(parent.row(), parent.parent());
|
return removeRow(parent.row(), parent.parent());
|
||||||
|
|
|
@ -17,7 +17,9 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void proxyBeginInsertRow(const FilterListNode *, int);
|
void proxyBeginInsertRow(const FilterListNode *, int);
|
||||||
void proxyEndInsertRow(const FilterListNode *node, int i);
|
void proxyEndInsertRow(const FilterListNode *, int);
|
||||||
|
void proxyBeginRemoveRow(const FilterListNode *, int);
|
||||||
|
void proxyEndRemoveRow(const FilterListNode *, int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FilterListNode *indexToNode(const QModelIndex &idx) const;
|
FilterListNode *indexToNode(const QModelIndex &idx) const;
|
||||||
|
|
Loading…
Reference in a new issue