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