miscellaneous code cleanup
renamed filter list modules to filter tree to more accurately reflect the nature of the data structure.
This commit is contained in:
parent
083005b8a9
commit
16d30fb9e1
13 changed files with 197 additions and 206 deletions
|
@ -36,8 +36,8 @@ SET(cockatrice_SOURCES
|
|||
src/cardframe.cpp
|
||||
src/filterbuilder.cpp
|
||||
src/cardfilter.cpp
|
||||
src/filterlistmodel.cpp
|
||||
src/filterlist.cpp
|
||||
src/filtertreemodel.cpp
|
||||
src/filtertree.cpp
|
||||
src/messagelogwidget.cpp
|
||||
src/zoneviewzone.cpp
|
||||
src/zoneviewwidget.cpp
|
||||
|
@ -118,8 +118,8 @@ SET(cockatrice_HEADERS
|
|||
src/cardframe.h
|
||||
src/filterbuilder.h
|
||||
src/cardfilter.h
|
||||
src/filterlistmodel.h
|
||||
src/filterlist.h
|
||||
src/filtertreemodel.h
|
||||
src/filtertree.h
|
||||
src/messagelogwidget.h
|
||||
src/zoneviewzone.h
|
||||
src/zoneviewwidget.h
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "carddatabasemodel.h"
|
||||
#include "filterlist.h"
|
||||
#include "filtertree.h"
|
||||
|
||||
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
||||
: QAbstractListModel(parent), db(_db)
|
||||
|
@ -110,7 +110,7 @@ CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
|||
: QSortFilterProxyModel(parent),
|
||||
isToken(ShowAll)
|
||||
{
|
||||
filterList = NULL;
|
||||
filterTree = NULL;
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
}
|
||||
|
@ -146,8 +146,8 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
|
|||
if (!cardTypes.contains(info->getMainCardType()))
|
||||
return false;
|
||||
|
||||
if (filterList != NULL)
|
||||
return filterList->acceptsCard(info);
|
||||
if (filterTree != NULL)
|
||||
return filterTree->acceptsCard(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -161,17 +161,17 @@ void CardDatabaseDisplayModel::clearSearch()
|
|||
invalidateFilter();
|
||||
}
|
||||
|
||||
void CardDatabaseDisplayModel::setFilterList(const FilterList *filterList)
|
||||
void CardDatabaseDisplayModel::setFilterTree(const FilterTree *filterTree)
|
||||
{
|
||||
if(this->filterList != NULL)
|
||||
disconnect(this->filterList, 0, this, 0);
|
||||
if (this->filterTree != NULL)
|
||||
disconnect(this->filterTree, 0, this, 0);
|
||||
|
||||
this->filterList = filterList;
|
||||
connect(this->filterList, SIGNAL(changed()), this, SLOT(filterListChanged()));
|
||||
this->filterTree = filterTree;
|
||||
connect(this->filterTree, SIGNAL(changed()), this, SLOT(filterTreeChanged()));
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void CardDatabaseDisplayModel::filterListChanged()
|
||||
void CardDatabaseDisplayModel::filterTreeChanged()
|
||||
{
|
||||
invalidate();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <QSet>
|
||||
#include "carddatabase.h"
|
||||
|
||||
class FilterList;
|
||||
class FilterTree;
|
||||
|
||||
class CardDatabaseModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
@ -38,10 +38,10 @@ private:
|
|||
FilterBool isToken;
|
||||
QString cardNameBeginning, cardName, cardText;
|
||||
QSet<QString> cardNameSet, cardTypes, cardColors;
|
||||
const FilterList *filterList;
|
||||
const FilterTree *filterTree;
|
||||
public:
|
||||
CardDatabaseDisplayModel(QObject *parent = 0);
|
||||
void setFilterList(const FilterList *filterList);
|
||||
void setFilterTree(const FilterTree *filterTree);
|
||||
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
|
||||
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
|
||||
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
private slots:
|
||||
void filterListChanged();
|
||||
void filterTreeChanged();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const char *CardFilter::typeName(Type t)
|
||||
{
|
||||
switch(t) {
|
||||
switch (t) {
|
||||
case TypeAnd:
|
||||
return "and";
|
||||
case TypeOr:
|
||||
|
@ -18,7 +18,7 @@ const char *CardFilter::typeName(Type t)
|
|||
|
||||
const char *CardFilter::attrName(Attr a)
|
||||
{
|
||||
switch(a) {
|
||||
switch (a) {
|
||||
case AttrName:
|
||||
return "name";
|
||||
case AttrType:
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
TypeAndNot,
|
||||
TypeOrNot,
|
||||
TypeEnd
|
||||
};
|
||||
};
|
||||
|
||||
/* if you add an atribute here you also need to
|
||||
* add its string representation in attrName */
|
||||
|
|
|
@ -16,12 +16,12 @@ FilterBuilder::FilterBuilder(QWidget *parent)
|
|||
QHBoxLayout *addFilter = new QHBoxLayout;
|
||||
|
||||
filterCombo = new QComboBox;
|
||||
for(i = 0; i < CardFilter::AttrEnd; i++)
|
||||
for (i = 0; i < CardFilter::AttrEnd; i++)
|
||||
filterCombo->addItem(
|
||||
CardFilter::attrName(static_cast<CardFilter::Attr>(i)), QVariant(i));
|
||||
|
||||
typeCombo = new QComboBox;
|
||||
for(i = 0; i < CardFilter::TypeEnd; i++)
|
||||
for (i = 0; i < CardFilter::TypeEnd; i++)
|
||||
typeCombo->addItem(
|
||||
CardFilter::typeName(static_cast<CardFilter::Type>(i)), QVariant(i));
|
||||
|
||||
|
@ -52,7 +52,7 @@ FilterBuilder::~FilterBuilder()
|
|||
|
||||
void FilterBuilder::destroyFilter()
|
||||
{
|
||||
if(fltr)
|
||||
if (fltr)
|
||||
delete fltr;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ void FilterBuilder::add_released()
|
|||
QString txt;
|
||||
|
||||
txt = edit->text();
|
||||
if(txt.length() < 1)
|
||||
if (txt.length() < 1)
|
||||
return;
|
||||
|
||||
destroyFilter();
|
||||
|
@ -75,9 +75,3 @@ void FilterBuilder::add_released()
|
|||
static_cast<CardFilter::Attr>(comboCurrentIntData(filterCombo)));
|
||||
emit add(fltr);
|
||||
}
|
||||
|
||||
bool FilterBuilder::filter(const CardFilter *f) const
|
||||
{
|
||||
f = fltr;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ public:
|
|||
FilterBuilder(QWidget *parent = 0);
|
||||
~FilterBuilder();
|
||||
|
||||
bool filter(const CardFilter *f) const;
|
||||
|
||||
signals:
|
||||
void add(const CardFilter *f);
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#include "filterlist.h"
|
||||
#include "filtertree.h"
|
||||
#include "cardfilter.h"
|
||||
#include "carddatabase.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
template <class T>
|
||||
FilterListNode *FilterListInnerNode<T>::nodeAt(int i) const
|
||||
FilterTreeNode *FilterTreeBranch<T>::nodeAt(int i) const
|
||||
{
|
||||
return ((childNodes.size() > i)? childNodes.at(i) : NULL);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void FilterListInnerNode<T>::deleteAt(int i)
|
||||
void FilterTreeBranch<T>::deleteAt(int i)
|
||||
{
|
||||
preRemoveChild(this, i);
|
||||
delete childNodes.takeAt(i);
|
||||
|
@ -20,24 +20,24 @@ void FilterListInnerNode<T>::deleteAt(int i)
|
|||
}
|
||||
|
||||
template <class T>
|
||||
int FilterListInnerNode<T>::childIndex(const FilterListNode *node) const
|
||||
int FilterTreeBranch<T>::childIndex(const FilterTreeNode *node) const
|
||||
{
|
||||
FilterListNode *unconst;
|
||||
FilterTreeNode *unconst;
|
||||
T downcasted;
|
||||
|
||||
/* to do the dynamic cast to T we will lose const'ness, but we can
|
||||
* trust QList::indexOf */
|
||||
unconst = (FilterListNode *) node;
|
||||
unconst = (FilterTreeNode *) node;
|
||||
downcasted = dynamic_cast<T>(unconst);
|
||||
if(downcasted == NULL)
|
||||
if (downcasted == NULL)
|
||||
return -1;
|
||||
return childNodes.indexOf(downcasted);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
FilterListInnerNode<T>::~FilterListInnerNode()
|
||||
FilterTreeBranch<T>::~FilterTreeBranch()
|
||||
{
|
||||
while(!childNodes.isEmpty())
|
||||
while (!childNodes.isEmpty())
|
||||
delete childNodes.takeFirst();
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ const FilterItemList *LogicMap::findTypeList(CardFilter::Type type) const
|
|||
{
|
||||
QList<FilterItemList *>::const_iterator i;
|
||||
|
||||
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
for (i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
if ((*i)->type == type)
|
||||
return *i;
|
||||
|
||||
|
@ -58,7 +58,7 @@ FilterItemList *LogicMap::typeList(CardFilter::Type type)
|
|||
int count;
|
||||
|
||||
count = 0;
|
||||
for(i = childNodes.begin(); i != childNodes.end(); i++) {
|
||||
for (i = childNodes.begin(); i != childNodes.end(); i++) {
|
||||
if ((*i)->type == type)
|
||||
break;
|
||||
count++;
|
||||
|
@ -73,7 +73,7 @@ FilterItemList *LogicMap::typeList(CardFilter::Type type)
|
|||
return *i;
|
||||
}
|
||||
|
||||
FilterListNode *LogicMap::parent() const
|
||||
FilterTreeNode *LogicMap::parent() const
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
@ -82,20 +82,20 @@ int FilterItemList::termIndex(const QString &term) const
|
|||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < childNodes.count(); i++)
|
||||
if((childNodes.at(i))->term == term)
|
||||
for (i = 0; i < childNodes.count(); i++)
|
||||
if ((childNodes.at(i))->term == term)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
FilterListNode *FilterItemList::termNode(const QString &term)
|
||||
FilterTreeNode *FilterItemList::termNode(const QString &term)
|
||||
{
|
||||
int i, count;
|
||||
FilterItem *fi;
|
||||
|
||||
i = termIndex(term);
|
||||
if(i < 0) {
|
||||
if (i < 0) {
|
||||
fi = new FilterItem(term, this);
|
||||
count = childNodes.count();
|
||||
preInsertChild(this, count);
|
||||
|
@ -112,7 +112,7 @@ bool FilterItemList::testTypeAnd(const CardInfo *info, CardFilter::Attr attr) co
|
|||
{
|
||||
QList<FilterItem *>::const_iterator i;
|
||||
|
||||
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
for (i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
if (!(*i)->acceptCardAttr(info, attr))
|
||||
return false;
|
||||
|
||||
|
@ -129,7 +129,7 @@ bool FilterItemList::testTypeOr(const CardInfo *info, CardFilter::Attr attr) con
|
|||
{
|
||||
QList<FilterItem *>::const_iterator i;
|
||||
|
||||
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
for (i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
if ((*i)->acceptCardAttr(info, attr))
|
||||
return true;
|
||||
|
||||
|
@ -158,7 +158,7 @@ bool FilterItem::acceptColor(const CardInfo *info) const
|
|||
bool status;
|
||||
|
||||
status = false;
|
||||
for(i = info->getColors().constBegin(); i != info->getColors().constEnd(); i++)
|
||||
for (i = info->getColors().constBegin(); i != info->getColors().constEnd(); i++)
|
||||
if ((*i).contains(term, Qt::CaseInsensitive)) {
|
||||
status = true;
|
||||
break;
|
||||
|
@ -178,7 +178,7 @@ bool FilterItem::acceptSet(const CardInfo *info) const
|
|||
bool status;
|
||||
|
||||
status = false;
|
||||
for(i = info->getSets().constBegin(); i != info->getSets().constEnd(); i++)
|
||||
for (i = info->getSets().constBegin(); i != info->getSets().constEnd(); i++)
|
||||
if ((*i)->getShortName() == term
|
||||
|| (*i)->getLongName().contains(term, Qt::CaseInsensitive)) {
|
||||
status = true;
|
||||
|
@ -197,10 +197,10 @@ bool FilterItem::acceptCardAttr(const CardInfo *info, CardFilter::Attr attr) con
|
|||
{
|
||||
bool status;
|
||||
|
||||
if(!isEnabled())
|
||||
if (!isEnabled())
|
||||
return true;
|
||||
|
||||
switch(attr) {
|
||||
switch (attr) {
|
||||
case CardFilter::AttrName:
|
||||
status = acceptName(info);
|
||||
break;
|
||||
|
@ -227,24 +227,24 @@ bool FilterItem::acceptCardAttr(const CardInfo *info, CardFilter::Attr attr) con
|
|||
}
|
||||
|
||||
/* need to define these here to make QT happy, otherwise
|
||||
* moc doesnt find some of the FilterListInnerNode symbols.
|
||||
* moc doesnt find some of the FilterTreeBranch symbols.
|
||||
*/
|
||||
FilterList::FilterList() {}
|
||||
FilterList::~FilterList() {}
|
||||
FilterTree::FilterTree() {}
|
||||
FilterTree::~FilterTree() {}
|
||||
|
||||
LogicMap *FilterList::attrLogicMap(CardFilter::Attr attr)
|
||||
LogicMap *FilterTree::attrLogicMap(CardFilter::Attr attr)
|
||||
{
|
||||
QList<LogicMap *>::iterator i;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
for(i = childNodes.begin(); i != childNodes.end(); i++) {
|
||||
if((*i)->attr == attr)
|
||||
for (i = childNodes.begin(); i != childNodes.end(); i++) {
|
||||
if ((*i)->attr == attr)
|
||||
break;
|
||||
count++;
|
||||
}
|
||||
|
||||
if(i == childNodes.end()) {
|
||||
if (i == childNodes.end()) {
|
||||
preInsertChild(this, count);
|
||||
i = childNodes.insert(i, new LogicMap(attr, this));
|
||||
postInsertChild(this, count);
|
||||
|
@ -254,41 +254,41 @@ LogicMap *FilterList::attrLogicMap(CardFilter::Attr attr)
|
|||
return *i;
|
||||
}
|
||||
|
||||
FilterItemList *FilterList::attrTypeList(CardFilter::Attr attr,
|
||||
FilterItemList *FilterTree::attrTypeList(CardFilter::Attr attr,
|
||||
CardFilter::Type type)
|
||||
{
|
||||
return attrLogicMap(attr)->typeList(type);
|
||||
}
|
||||
|
||||
int FilterList::findTermIndex(CardFilter::Attr attr, CardFilter::Type type,
|
||||
int FilterTree::findTermIndex(CardFilter::Attr attr, CardFilter::Type type,
|
||||
const QString &term)
|
||||
{
|
||||
attrTypeList(attr, type)->termIndex(term);
|
||||
}
|
||||
|
||||
int FilterList::findTermIndex(const CardFilter *f)
|
||||
int FilterTree::findTermIndex(const CardFilter *f)
|
||||
{
|
||||
return findTermIndex(f->attr(), f->type(), f->term());
|
||||
}
|
||||
|
||||
FilterListNode *FilterList::termNode(CardFilter::Attr attr, CardFilter::Type type,
|
||||
FilterTreeNode *FilterTree::termNode(CardFilter::Attr attr, CardFilter::Type type,
|
||||
const QString &term)
|
||||
{
|
||||
return attrTypeList(attr, type)->termNode(term);
|
||||
}
|
||||
|
||||
FilterListNode *FilterList::termNode(const CardFilter *f)
|
||||
FilterTreeNode *FilterTree::termNode(const CardFilter *f)
|
||||
{
|
||||
return termNode(f->attr(), f->type(), f->term());
|
||||
}
|
||||
|
||||
FilterListNode *FilterList::attrTypeNode(CardFilter::Attr attr,
|
||||
FilterTreeNode *FilterTree::attrTypeNode(CardFilter::Attr attr,
|
||||
CardFilter::Type type)
|
||||
{
|
||||
return attrTypeList(attr, type);
|
||||
}
|
||||
|
||||
bool FilterList::testAttr(const CardInfo *info, const LogicMap *lm) const
|
||||
bool FilterTree::testAttr(const CardInfo *info, const LogicMap *lm) const
|
||||
{
|
||||
const FilterItemList *fil;
|
||||
bool status;
|
||||
|
@ -318,11 +318,11 @@ bool FilterList::testAttr(const CardInfo *info, const LogicMap *lm) const
|
|||
return status;
|
||||
}
|
||||
|
||||
bool FilterList::acceptsCard(const CardInfo *info) const
|
||||
bool FilterTree::acceptsCard(const CardInfo *info) const
|
||||
{
|
||||
QList<LogicMap *>::const_iterator i;
|
||||
|
||||
for(i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
for (i = childNodes.constBegin(); i != childNodes.constEnd(); i++)
|
||||
if ((*i)->isEnabled() && !testAttr(info, *i))
|
||||
return false;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef FILTERLIST_H
|
||||
#define FILTERLIST_H
|
||||
#ifndef FILTERTREE_H
|
||||
#define FILTERTREE_H
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
@ -9,19 +9,19 @@
|
|||
|
||||
class CardInfo;
|
||||
|
||||
class FilterListNode {
|
||||
class FilterTreeNode {
|
||||
private:
|
||||
bool enabled;
|
||||
public:
|
||||
FilterListNode() : enabled(true) {}
|
||||
FilterTreeNode() : enabled(true) {}
|
||||
virtual bool isEnabled() const { return enabled; }
|
||||
virtual void enable() { enabled = true; nodeChanged(); }
|
||||
virtual void disable() { enabled = false; nodeChanged(); }
|
||||
virtual FilterListNode *parent() const { return NULL; }
|
||||
virtual FilterListNode *nodeAt(int i) const { return NULL; }
|
||||
virtual FilterTreeNode *parent() const { return NULL; }
|
||||
virtual FilterTreeNode *nodeAt(int i) const { return NULL; }
|
||||
virtual void deleteAt(int i) {}
|
||||
virtual int childCount() const { return 0; }
|
||||
virtual int childIndex(const FilterListNode *node) const { return -1; }
|
||||
virtual int childIndex(const FilterTreeNode *node) const { return -1; }
|
||||
virtual int index() const { return (parent() != NULL)? parent()->childIndex(this) : -1; }
|
||||
virtual QString text() const { return ""; }
|
||||
virtual bool isLeaf() const { return false; }
|
||||
|
@ -30,56 +30,56 @@ public:
|
|||
printf("%s -> ", textCStr());
|
||||
if (parent() != NULL) parent()->nodeChanged();
|
||||
}
|
||||
virtual void preInsertChild(const FilterListNode *p, int i) const {
|
||||
virtual void preInsertChild(const FilterTreeNode *p, int i) const {
|
||||
//printf("%s -> ", textCStr());
|
||||
if (parent() != NULL) parent()->preInsertChild(p, i);
|
||||
}
|
||||
virtual void postInsertChild(const FilterListNode *p, int i) const {
|
||||
virtual void postInsertChild(const FilterTreeNode *p, int i) const {
|
||||
//printf("%s -> ", textCStr());
|
||||
if (parent() != NULL) parent()->postInsertChild(p, i);
|
||||
}
|
||||
virtual void preRemoveChild(const FilterListNode *p, int i) const {
|
||||
virtual void preRemoveChild(const FilterTreeNode *p, int i) const {
|
||||
printf("%s -> ", textCStr());
|
||||
if (parent() != NULL) parent()->preRemoveChild(p, i);
|
||||
}
|
||||
virtual void postRemoveChild(const FilterListNode *p, int i) const {
|
||||
virtual void postRemoveChild(const FilterTreeNode *p, int i) const {
|
||||
printf("%s -> ", textCStr());
|
||||
if (parent() != NULL) parent()->postRemoveChild(p, i);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class FilterListInnerNode : public FilterListNode {
|
||||
class FilterTreeBranch : public FilterTreeNode {
|
||||
protected:
|
||||
QList<T> childNodes;
|
||||
public:
|
||||
~FilterListInnerNode();
|
||||
FilterListNode *nodeAt(int i) const;
|
||||
~FilterTreeBranch();
|
||||
FilterTreeNode *nodeAt(int i) const;
|
||||
void deleteAt(int i);
|
||||
int childCount() const { return childNodes.size(); }
|
||||
int childIndex(const FilterListNode *node) const;
|
||||
int childIndex(const FilterTreeNode *node) const;
|
||||
};
|
||||
|
||||
class FilterItemList;
|
||||
class FilterList;
|
||||
class LogicMap : public FilterListInnerNode<FilterItemList *> {
|
||||
class FilterTree;
|
||||
class LogicMap : public FilterTreeBranch<FilterItemList *> {
|
||||
|
||||
private:
|
||||
FilterList *const p;
|
||||
FilterTree *const p;
|
||||
|
||||
public:
|
||||
const CardFilter::Attr attr;
|
||||
|
||||
LogicMap(CardFilter::Attr a, FilterList *parent)
|
||||
LogicMap(CardFilter::Attr a, FilterTree *parent)
|
||||
: attr(a), p(parent) {}
|
||||
const FilterItemList *findTypeList(CardFilter::Type type) const;
|
||||
FilterItemList *typeList(CardFilter::Type type);
|
||||
FilterListNode *parent() const;
|
||||
FilterTreeNode *parent() const;
|
||||
QString text() const { return QString(CardFilter::attrName(attr)); }
|
||||
};
|
||||
|
||||
class FilterItem;
|
||||
class FilterItemList : public FilterListInnerNode<FilterItem *> {
|
||||
class FilterItemList : public FilterTreeBranch<FilterItem *> {
|
||||
private:
|
||||
LogicMap *const p;
|
||||
public:
|
||||
|
@ -88,9 +88,9 @@ public:
|
|||
FilterItemList(CardFilter::Type t, LogicMap *parent)
|
||||
: type(t), p(parent) {}
|
||||
CardFilter::Attr attr() const { return p->attr; }
|
||||
FilterListNode *parent() const { return p; }
|
||||
FilterTreeNode *parent() const { return p; }
|
||||
int termIndex(const QString &term) const;
|
||||
FilterListNode *termNode(const QString &term);
|
||||
FilterTreeNode *termNode(const QString &term);
|
||||
QString text() const { return QString(CardFilter::typeName(type)); }
|
||||
|
||||
bool testTypeAnd(const CardInfo *info, CardFilter::Attr attr) const;
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
bool testTypeOrNot(const CardInfo *info, CardFilter::Attr attr) const;
|
||||
};
|
||||
|
||||
class FilterItem : public FilterListNode {
|
||||
class FilterItem : public FilterTreeNode {
|
||||
private:
|
||||
FilterItemList *const p;
|
||||
public:
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
|
||||
CardFilter::Attr attr() const { return p->attr(); }
|
||||
CardFilter::Type type() const { return p->type; }
|
||||
FilterListNode *parent() const { return p; }
|
||||
FilterTreeNode *parent() const { return p; }
|
||||
QString text() const { return term; }
|
||||
bool isLeaf() const { return true; }
|
||||
|
||||
|
@ -123,14 +123,14 @@ public:
|
|||
bool acceptCardAttr(const CardInfo *info, CardFilter::Attr attr) const;
|
||||
};
|
||||
|
||||
class FilterList : public QObject, public FilterListInnerNode<LogicMap *> {
|
||||
class FilterTree : public QObject, public FilterTreeBranch<LogicMap *> {
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void preInsertRow(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 preInsertRow(const FilterTreeNode *parent, int i) const;
|
||||
void postInsertRow(const FilterTreeNode *parent, int i) const;
|
||||
void preRemoveRow(const FilterTreeNode *parent, int i) const;
|
||||
void postRemoveRow(const FilterTreeNode *parent, int i) const;
|
||||
void changed() const;
|
||||
|
||||
private:
|
||||
|
@ -140,24 +140,24 @@ private:
|
|||
|
||||
bool testAttr(const CardInfo *info, const LogicMap *lm) const;
|
||||
public:
|
||||
FilterList();
|
||||
~FilterList();
|
||||
FilterTree();
|
||||
~FilterTree();
|
||||
int findTermIndex(CardFilter::Attr attr, CardFilter::Type type,
|
||||
const QString &term);
|
||||
int findTermIndex(const CardFilter *f);
|
||||
FilterListNode *termNode(CardFilter::Attr attr, CardFilter::Type type,
|
||||
FilterTreeNode *termNode(CardFilter::Attr attr, CardFilter::Type type,
|
||||
const QString &term);
|
||||
FilterListNode *termNode(const CardFilter *f);
|
||||
FilterListNode *attrTypeNode(CardFilter::Attr attr,
|
||||
FilterTreeNode *termNode(const CardFilter *f);
|
||||
FilterTreeNode *attrTypeNode(CardFilter::Attr attr,
|
||||
CardFilter::Type type);
|
||||
QString text() const { return QString("root"); }
|
||||
int index() const { return 0; }
|
||||
|
||||
void nodeChanged() const { printf("root\n"); emit changed(); }
|
||||
void preInsertChild(const FilterListNode *p, int i) const { emit preInsertRow(p, i); }
|
||||
void postInsertChild(const FilterListNode *p, int i) const { emit postInsertRow(p, i); }
|
||||
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); }
|
||||
void preInsertChild(const FilterTreeNode *p, int i) const { emit preInsertRow(p, i); }
|
||||
void postInsertChild(const FilterTreeNode *p, int i) const { emit postInsertRow(p, i); }
|
||||
void preRemoveChild(const FilterTreeNode *p, int i) const { printf("root\n"); emit preRemoveRow(p, i); }
|
||||
void postRemoveChild(const FilterTreeNode *p, int i) const { printf("root\n"); emit postRemoveRow(p, i); }
|
||||
|
||||
bool acceptsCard(const CardInfo *info) const;
|
||||
};
|
|
@ -1,100 +1,100 @@
|
|||
#include <QFont>
|
||||
#include "filterlistmodel.h"
|
||||
#include "filterlist.h"
|
||||
#include "filtertreemodel.h"
|
||||
#include "filtertree.h"
|
||||
#include "cardfilter.h"
|
||||
|
||||
FilterListModel::FilterListModel(QObject *parent)
|
||||
FilterTreeModel::FilterTreeModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
fList = new FilterList;
|
||||
connect(fList,
|
||||
SIGNAL(preInsertRow(const FilterListNode *, int)),
|
||||
this, SLOT(proxyBeginInsertRow(const FilterListNode *, int)));
|
||||
connect(fList,
|
||||
SIGNAL(postInsertRow(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)));
|
||||
fTree = new FilterTree;
|
||||
connect(fTree,
|
||||
SIGNAL(preInsertRow(const FilterTreeNode *, int)),
|
||||
this, SLOT(proxyBeginInsertRow(const FilterTreeNode *, int)));
|
||||
connect(fTree,
|
||||
SIGNAL(postInsertRow(const FilterTreeNode *, int)),
|
||||
this, SLOT(proxyEndInsertRow(const FilterTreeNode *, int)));
|
||||
connect(fTree,
|
||||
SIGNAL(preRemoveRow(const FilterTreeNode *, int)),
|
||||
this, SLOT(proxyBeginRemoveRow(const FilterTreeNode *, int)));
|
||||
connect(fTree,
|
||||
SIGNAL(postRemoveRow(const FilterTreeNode *, int)),
|
||||
this, SLOT(proxyEndRemoveRow(const FilterTreeNode *, int)));
|
||||
}
|
||||
|
||||
FilterListModel::~FilterListModel()
|
||||
FilterTreeModel::~FilterTreeModel()
|
||||
{
|
||||
delete fList;
|
||||
delete fTree;
|
||||
}
|
||||
|
||||
void FilterListModel::proxyBeginInsertRow(const FilterListNode *node, int i)
|
||||
void FilterTreeModel::proxyBeginInsertRow(const FilterTreeNode *node, int i)
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = node->index();
|
||||
if(idx >= 0)
|
||||
if (idx >= 0)
|
||||
beginInsertRows(createIndex(idx, 0, (void *) node), i, i);
|
||||
}
|
||||
|
||||
void FilterListModel::proxyEndInsertRow(const FilterListNode *node, int)
|
||||
void FilterTreeModel::proxyEndInsertRow(const FilterTreeNode *node, int)
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = node->index();
|
||||
if(idx >= 0)
|
||||
if (idx >= 0)
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void FilterListModel::proxyBeginRemoveRow(const FilterListNode *node, int i)
|
||||
void FilterTreeModel::proxyBeginRemoveRow(const FilterTreeNode *node, int i)
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = node->index();
|
||||
if(idx >= 0)
|
||||
if (idx >= 0)
|
||||
beginRemoveRows(createIndex(idx, 0, (void *) node), i, i);
|
||||
}
|
||||
|
||||
void FilterListModel::proxyEndRemoveRow(const FilterListNode *node, int)
|
||||
void FilterTreeModel::proxyEndRemoveRow(const FilterTreeNode *node, int)
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = node->index();
|
||||
if(idx >= 0)
|
||||
if (idx >= 0)
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
FilterListNode *FilterListModel::indexToNode(const QModelIndex &idx) const
|
||||
FilterTreeNode *FilterTreeModel::indexToNode(const QModelIndex &idx) const
|
||||
{
|
||||
void *ip;
|
||||
FilterListNode *node;
|
||||
FilterTreeNode *node;
|
||||
|
||||
if(!idx.isValid())
|
||||
return fList;
|
||||
if (!idx.isValid())
|
||||
return fTree;
|
||||
|
||||
ip = idx.internalPointer();
|
||||
if(ip == NULL)
|
||||
return fList;
|
||||
if (ip == NULL)
|
||||
return fTree;
|
||||
|
||||
node = static_cast<FilterListNode *>(ip);
|
||||
node = static_cast<FilterTreeNode *>(ip);
|
||||
return node;
|
||||
}
|
||||
|
||||
void FilterListModel::addFilter(const CardFilter *f)
|
||||
void FilterTreeModel::addFilter(const CardFilter *f)
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
fList->termNode(f);
|
||||
fTree->termNode(f);
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
int FilterListModel::rowCount(const QModelIndex &parent) const
|
||||
int FilterTreeModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
const FilterListNode *node;
|
||||
const FilterTreeNode *node;
|
||||
int result;
|
||||
|
||||
if(parent.column() > 0)
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
node = indexToNode(parent);
|
||||
if(node)
|
||||
if (node)
|
||||
result = node->childCount();
|
||||
else
|
||||
result = 0;
|
||||
|
@ -102,14 +102,14 @@ int FilterListModel::rowCount(const QModelIndex &parent) const
|
|||
return result;
|
||||
}
|
||||
|
||||
int FilterListModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
int FilterTreeModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant FilterListModel::data(const QModelIndex &index, int role) const
|
||||
QVariant FilterTreeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
const FilterListNode *node;
|
||||
const FilterTreeNode *node;
|
||||
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
@ -117,12 +117,12 @@ QVariant FilterListModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
|
||||
node = indexToNode(index);
|
||||
if(node == NULL)
|
||||
if (node == NULL)
|
||||
return QVariant();
|
||||
|
||||
switch (role) {
|
||||
case Qt::FontRole:
|
||||
if(!node->isLeaf()) {
|
||||
if (!node->isLeaf()) {
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
return f;
|
||||
|
@ -135,7 +135,7 @@ QVariant FilterListModel::data(const QModelIndex &index, int role) const
|
|||
case Qt::WhatsThisRole:
|
||||
return node->text();
|
||||
case Qt::CheckStateRole:
|
||||
if(node->isEnabled())
|
||||
if (node->isEnabled())
|
||||
return Qt::Checked;
|
||||
else
|
||||
return Qt::Unchecked;
|
||||
|
@ -146,10 +146,10 @@ QVariant FilterListModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
bool FilterListModel::setData(const QModelIndex &index,
|
||||
bool FilterTreeModel::setData(const QModelIndex &index,
|
||||
const QVariant &value, int role)
|
||||
{
|
||||
FilterListNode *node;
|
||||
FilterTreeNode *node;
|
||||
|
||||
if (!index.isValid())
|
||||
return false;
|
||||
|
@ -159,33 +159,33 @@ bool FilterListModel::setData(const QModelIndex &index,
|
|||
return false;
|
||||
|
||||
node = indexToNode(index);
|
||||
if(node == NULL || node == fList)
|
||||
if (node == NULL || node == fTree)
|
||||
return false;
|
||||
|
||||
Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
|
||||
if(state == Qt::Checked)
|
||||
if (state == Qt::Checked)
|
||||
node->enable();
|
||||
else
|
||||
else
|
||||
node->disable();
|
||||
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::ItemFlags FilterListModel::flags(const QModelIndex &index) const
|
||||
Qt::ItemFlags FilterTreeModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
const FilterListNode *node;
|
||||
const FilterTreeNode *node;
|
||||
Qt::ItemFlags result;
|
||||
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
node = indexToNode(index);
|
||||
if(node == NULL)
|
||||
if (node == NULL)
|
||||
return 0;
|
||||
|
||||
result = Qt::ItemIsEnabled;
|
||||
if(node == fList)
|
||||
if (node == fTree)
|
||||
return result;
|
||||
|
||||
result |= Qt::ItemIsSelectable;
|
||||
|
@ -194,9 +194,9 @@ Qt::ItemFlags FilterListModel::flags(const QModelIndex &index) const
|
|||
return result;
|
||||
}
|
||||
|
||||
QModelIndex FilterListModel::nodeIndex(const FilterListNode *node, int row, int column) const
|
||||
QModelIndex FilterTreeModel::nodeIndex(const FilterTreeNode *node, int row, int column) const
|
||||
{
|
||||
FilterListNode *child;
|
||||
FilterTreeNode *child;
|
||||
|
||||
if (column > 0 || row >= node->childCount())
|
||||
return QModelIndex();
|
||||
|
@ -205,25 +205,25 @@ QModelIndex FilterListModel::nodeIndex(const FilterListNode *node, int row, int
|
|||
return createIndex(row, column, child);
|
||||
}
|
||||
|
||||
QModelIndex FilterListModel::index(int row, int column,
|
||||
QModelIndex FilterTreeModel::index(int row, int column,
|
||||
const QModelIndex &parent) const
|
||||
{
|
||||
const FilterListNode *node;
|
||||
const FilterTreeNode *node;
|
||||
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
node = indexToNode(parent);
|
||||
if(node == NULL)
|
||||
if (node == NULL)
|
||||
return QModelIndex();
|
||||
|
||||
return nodeIndex(node, row, column);
|
||||
}
|
||||
|
||||
QModelIndex FilterListModel::parent(const QModelIndex &ind) const
|
||||
QModelIndex FilterTreeModel::parent(const QModelIndex &ind) const
|
||||
{
|
||||
const FilterListNode *node;
|
||||
FilterListNode *parent;
|
||||
const FilterTreeNode *node;
|
||||
FilterTreeNode *parent;
|
||||
int row;
|
||||
QModelIndex idx;
|
||||
|
||||
|
@ -231,13 +231,13 @@ QModelIndex FilterListModel::parent(const QModelIndex &ind) const
|
|||
return QModelIndex();
|
||||
|
||||
node = indexToNode(ind);
|
||||
if(node == NULL || node == fList)
|
||||
if (node == NULL || node == fTree)
|
||||
return QModelIndex();
|
||||
|
||||
parent = node->parent();
|
||||
if(parent) {
|
||||
if (parent) {
|
||||
row = parent->index();
|
||||
if(row < 0)
|
||||
if (row < 0)
|
||||
return QModelIndex();
|
||||
idx = createIndex(row, 0, parent);
|
||||
return idx;
|
||||
|
@ -246,9 +246,9 @@ QModelIndex FilterListModel::parent(const QModelIndex &ind) const
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
bool FilterListModel::removeRows(int row, int count, const QModelIndex & parent)
|
||||
bool FilterTreeModel::removeRows(int row, int count, const QModelIndex & parent)
|
||||
{
|
||||
FilterListNode *node;
|
||||
FilterTreeNode *node;
|
||||
int i, last;
|
||||
|
||||
last = row+count-1;
|
||||
|
@ -256,18 +256,18 @@ bool FilterListModel::removeRows(int row, int count, const QModelIndex & parent)
|
|||
return false;
|
||||
|
||||
node = indexToNode(parent);
|
||||
if(node == NULL || last >= node->childCount())
|
||||
if (node == NULL || last >= node->childCount())
|
||||
return false;
|
||||
|
||||
printf("delete children in %s\n", node->textCStr());
|
||||
fflush(stdout);
|
||||
for(i = 0; i < count; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
printf(" delete %d\n", i);
|
||||
fflush(stdout);
|
||||
node->deleteAt(row);
|
||||
}
|
||||
|
||||
if(node != fList && node->childCount() < 1)
|
||||
if (node != fTree && node->childCount() < 1)
|
||||
return removeRow(parent.row(), parent.parent());
|
||||
|
||||
return true;
|
|
@ -1,34 +1,34 @@
|
|||
#ifndef FILTERLISTMODEL_H
|
||||
#define FILTERLISTMODEL_H
|
||||
#ifndef FILTERTREEMODEL_H
|
||||
#define FILTERTREEMODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class FilterList;
|
||||
class FilterTree;
|
||||
class CardFilter;
|
||||
class FilterListNode;
|
||||
class FilterTreeNode;
|
||||
|
||||
class FilterListModel : public QAbstractItemModel {
|
||||
class FilterTreeModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
private:
|
||||
FilterList *fList;
|
||||
FilterTree *fTree;
|
||||
|
||||
public slots:
|
||||
void addFilter(const CardFilter *f);
|
||||
|
||||
private slots:
|
||||
void proxyBeginInsertRow(const FilterListNode *, int);
|
||||
void proxyEndInsertRow(const FilterListNode *, int);
|
||||
void proxyBeginRemoveRow(const FilterListNode *, int);
|
||||
void proxyEndRemoveRow(const FilterListNode *, int);
|
||||
void proxyBeginInsertRow(const FilterTreeNode *, int);
|
||||
void proxyEndInsertRow(const FilterTreeNode *, int);
|
||||
void proxyBeginRemoveRow(const FilterTreeNode *, int);
|
||||
void proxyEndRemoveRow(const FilterTreeNode *, int);
|
||||
|
||||
private:
|
||||
FilterListNode *indexToNode(const QModelIndex &idx) const;
|
||||
QModelIndex nodeIndex(const FilterListNode *node, int row, int column) const;
|
||||
FilterTreeNode *indexToNode(const QModelIndex &idx) const;
|
||||
QModelIndex nodeIndex(const FilterTreeNode *node, int row, int column) const;
|
||||
|
||||
public:
|
||||
FilterListModel(QObject *parent = 0);
|
||||
~FilterListModel();
|
||||
const FilterList *filterList() const { return fList; }
|
||||
FilterTreeModel(QObject *parent = 0);
|
||||
~FilterTreeModel();
|
||||
const FilterTree *filterTree() const { return fTree; }
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
|
@ -42,12 +42,11 @@
|
|||
#include <QDesktopWidget>
|
||||
#include "cardframe.h"
|
||||
#include "filterbuilder.h"
|
||||
#include "carditem.h"
|
||||
#include "carddatabase.h"
|
||||
//#include "carditem.h"
|
||||
//#include "carddatabase.h"
|
||||
#include "main.h"
|
||||
#include "settingscache.h"
|
||||
#include "filterlistmodel.h"
|
||||
#include "filterlist.h"
|
||||
#include "filtertreemodel.h"
|
||||
|
||||
void SearchLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
|
@ -169,8 +168,8 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
|||
searchAndButtons->addLayout(searchLayout, 0, 1);
|
||||
botFrame->addLayout(searchAndButtons);
|
||||
|
||||
filterModel = new FilterListModel();
|
||||
databaseDisplayModel->setFilterList(filterModel->filterList());
|
||||
filterModel = new FilterTreeModel();
|
||||
databaseDisplayModel->setFilterTree(filterModel->filterTree());
|
||||
filterView = new QTreeView;
|
||||
filterView->setModel(filterModel);
|
||||
filterView->setMaximumWidth(250);
|
||||
|
@ -663,7 +662,7 @@ void TabDeckEditor::filterViewCustomContextMenu(const QPoint &point) {
|
|||
QModelIndex idx;
|
||||
|
||||
idx = filterView->indexAt(point);
|
||||
if(!idx.isValid())
|
||||
if (!idx.isValid())
|
||||
return;
|
||||
|
||||
action = menu.addAction(QString("delete"));
|
||||
|
@ -679,7 +678,7 @@ void TabDeckEditor::filterRemove(QAction *action) {
|
|||
|
||||
point = action->data().toPoint();
|
||||
idx = filterView->indexAt(point);
|
||||
if(!idx.isValid())
|
||||
if (!idx.isValid())
|
||||
return;
|
||||
|
||||
filterModel->removeRow(idx.row(), idx.parent());
|
||||
|
|
|
@ -16,7 +16,7 @@ class DlgCardSearch;
|
|||
class QLabel;
|
||||
class DeckLoader;
|
||||
class Response;
|
||||
class FilterListModel;
|
||||
class FilterTreeModel;
|
||||
|
||||
class SearchLineEdit : public QLineEdit {
|
||||
private:
|
||||
|
@ -84,7 +84,7 @@ private:
|
|||
QLabel *hashLabel1;
|
||||
QLabel *hashLabel;
|
||||
DlgCardSearch *dlgCardSearch;
|
||||
FilterListModel *filterModel;
|
||||
FilterTreeModel *filterModel;
|
||||
QTreeView *filterView;
|
||||
|
||||
QMenu *deckMenu, *dbMenu;
|
||||
|
|
Loading…
Reference in a new issue