Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
cd4d04be
Commit
cd4d04be
authored
Mar 25, 2014
by
sylvanbasilisk
Browse files
change tabs into 4 spaces in new files
parent
07706262
Changes
16
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/cardfilter.cpp
View file @
cd4d04be
...
...
@@ -2,36 +2,36 @@
const
char
*
CardFilter
::
typeName
(
Type
t
)
{
switch
(
t
)
{
case
TypeAnd
:
return
"and"
;
case
TypeOr
:
return
"or"
;
case
TypeAndNot
:
return
"and not"
;
case
TypeOrNot
:
return
"or not"
;
default:
return
""
;
}
switch
(
t
)
{
case
TypeAnd
:
return
"and"
;
case
TypeOr
:
return
"or"
;
case
TypeAndNot
:
return
"and not"
;
case
TypeOrNot
:
return
"or not"
;
default:
return
""
;
}
}
const
char
*
CardFilter
::
attrName
(
Attr
a
)
{
switch
(
a
)
{
case
AttrName
:
return
"name"
;
case
AttrType
:
return
"type"
;
case
AttrColor
:
return
"color"
;
case
AttrText
:
return
"text"
;
case
AttrSet
:
return
"set"
;
case
AttrManaCost
:
return
"mana cost"
;
default:
return
""
;
}
switch
(
a
)
{
case
AttrName
:
return
"name"
;
case
AttrType
:
return
"type"
;
case
AttrColor
:
return
"color"
;
case
AttrText
:
return
"text"
;
case
AttrSet
:
return
"set"
;
case
AttrManaCost
:
return
"mana cost"
;
default:
return
""
;
}
}
cockatrice/src/cardfilter.h
View file @
cd4d04be
...
...
@@ -5,40 +5,40 @@
class
CardFilter
{
public:
enum
Type
{
TypeAnd
=
0
,
TypeOr
,
TypeAndNot
,
TypeOrNot
,
TypeEnd
};
/* if you add an atribute here you also need to
* add its string representation in attrName */
enum
Attr
{
AttrName
=
0
,
AttrType
,
AttrColor
,
AttrText
,
AttrSet
,
AttrManaCost
,
AttrEnd
};
enum
Type
{
TypeAnd
=
0
,
TypeOr
,
TypeAndNot
,
TypeOrNot
,
TypeEnd
};
/* if you add an atribute here you also need to
* add its string representation in attrName */
enum
Attr
{
AttrName
=
0
,
AttrType
,
AttrColor
,
AttrText
,
AttrSet
,
AttrManaCost
,
AttrEnd
};
private:
enum
Type
t
;
enum
Attr
a
;
QString
trm
;
enum
Type
t
;
enum
Attr
a
;
QString
trm
;
public:
CardFilter
(
QString
term
,
Type
type
,
Attr
attr
)
:
trm
(
term
),
t
(
type
),
a
(
attr
)
{};
CardFilter
(
QString
term
,
Type
type
,
Attr
attr
)
:
trm
(
term
),
t
(
type
),
a
(
attr
)
{};
Type
type
()
const
{
return
t
;
}
const
QString
&
term
()
const
{
return
trm
;
}
Attr
attr
()
const
{
return
a
;
}
Type
type
()
const
{
return
t
;
}
const
QString
&
term
()
const
{
return
trm
;
}
Attr
attr
()
const
{
return
a
;
}
static
const
char
*
typeName
(
Type
t
);
static
const
char
*
attrName
(
Attr
a
);
static
const
char
*
typeName
(
Type
t
);
static
const
char
*
attrName
(
Attr
a
);
};
#endif
cockatrice/src/cardframe.cpp
View file @
cd4d04be
...
...
@@ -7,53 +7,53 @@
#include
"cardinfotext.h"
CardFrame
::
CardFrame
(
int
width
,
int
height
,
const
QString
&
cardName
,
QWidget
*
parent
)
:
QStackedWidget
(
parent
)
,
info
(
0
)
,
cardTextOnly
(
false
)
const
QString
&
cardName
,
QWidget
*
parent
)
:
QStackedWidget
(
parent
)
,
info
(
0
)
,
cardTextOnly
(
false
)
{
setFrameStyle
(
QFrame
::
Panel
|
QFrame
::
Raised
);
setMaximumWidth
(
width
);
setMinimumWidth
(
width
);
setMaximumHeight
(
height
);
setMinimumHeight
(
height
);
pic
=
new
CardInfoPicture
(
width
);
addWidget
(
pic
);
text
=
new
CardInfoText
();
addWidget
(
text
);
connect
(
pic
,
SIGNAL
(
hasPictureChanged
()),
this
,
SLOT
(
hasPictureChanged
()));
setCard
(
db
->
getCard
(
cardName
));
setFrameStyle
(
QFrame
::
Panel
|
QFrame
::
Raised
);
setMaximumWidth
(
width
);
setMinimumWidth
(
width
);
setMaximumHeight
(
height
);
setMinimumHeight
(
height
);
pic
=
new
CardInfoPicture
(
width
);
addWidget
(
pic
);
text
=
new
CardInfoText
();
addWidget
(
text
);
connect
(
pic
,
SIGNAL
(
hasPictureChanged
()),
this
,
SLOT
(
hasPictureChanged
()));
setCard
(
db
->
getCard
(
cardName
));
}
void
CardFrame
::
setCard
(
CardInfo
*
card
)
{
if
(
info
)
disconnect
(
info
,
0
,
this
,
0
);
info
=
card
;
connect
(
info
,
SIGNAL
(
destroyed
()),
this
,
SLOT
(
clear
()));
text
->
setCard
(
info
);
pic
->
setCard
(
info
);
if
(
info
)
disconnect
(
info
,
0
,
this
,
0
);
info
=
card
;
connect
(
info
,
SIGNAL
(
destroyed
()),
this
,
SLOT
(
clear
()));
text
->
setCard
(
info
);
pic
->
setCard
(
info
);
}
void
CardFrame
::
setCard
(
const
QString
&
cardName
)
{
setCard
(
db
->
getCard
(
cardName
));
setCard
(
db
->
getCard
(
cardName
));
}
void
CardFrame
::
setCard
(
AbstractCardItem
*
card
)
{
setCard
(
card
->
getInfo
());
setCard
(
card
->
getInfo
());
}
void
CardFrame
::
clear
()
{
setCard
(
db
->
getCard
());
setCard
(
db
->
getCard
());
}
void
CardFrame
::
hasPictureChanged
()
{
if
(
pic
->
hasPicture
()
&&
!
cardTextOnly
)
setCurrentWidget
(
pic
);
else
setCurrentWidget
(
text
);
if
(
pic
->
hasPicture
()
&&
!
cardTextOnly
)
setCurrentWidget
(
pic
);
else
setCurrentWidget
(
text
);
}
cockatrice/src/cardframe.h
View file @
cd4d04be
...
...
@@ -9,28 +9,28 @@ class CardInfoPicture;
class
CardInfoText
;
class
CardFrame
:
public
QStackedWidget
{
Q_OBJECT
Q_OBJECT
private:
CardInfo
*
info
;
CardInfoPicture
*
pic
;
CardInfoText
*
text
;
bool
cardTextOnly
;
CardInfo
*
info
;
CardInfoPicture
*
pic
;
CardInfoText
*
text
;
bool
cardTextOnly
;
public:
CardFrame
(
int
width
,
int
height
,
const
QString
&
cardName
=
QString
(),
QWidget
*
parent
=
0
);
void
setCardTextOnly
(
bool
status
)
{
cardTextOnly
=
status
;
hasPictureChanged
();
}
CardFrame
(
int
width
,
int
height
,
const
QString
&
cardName
=
QString
(),
QWidget
*
parent
=
0
);
void
setCardTextOnly
(
bool
status
)
{
cardTextOnly
=
status
;
hasPictureChanged
();
}
public
slots
:
void
setCard
(
CardInfo
*
card
);
void
setCard
(
const
QString
&
cardName
);
void
setCard
(
AbstractCardItem
*
card
);
void
clear
();
void
setCard
(
CardInfo
*
card
);
void
setCard
(
const
QString
&
cardName
);
void
setCard
(
AbstractCardItem
*
card
);
void
clear
();
private
slots
:
void
hasPictureChanged
();
void
toggleCardTextOnly
()
{
setCardTextOnly
(
!
cardTextOnly
);
}
void
hasPictureChanged
();
void
toggleCardTextOnly
()
{
setCardTextOnly
(
!
cardTextOnly
);
}
};
#endif
cockatrice/src/cardinfopicture.cpp
View file @
cd4d04be
...
...
@@ -6,48 +6,48 @@
#include
"main.h"
CardInfoPicture
::
CardInfoPicture
(
int
maximumWidth
,
QWidget
*
parent
)
:
QLabel
(
parent
)
,
info
(
0
)
,
noPicture
(
true
)
:
QLabel
(
parent
)
,
info
(
0
)
,
noPicture
(
true
)
{
setMaximumWidth
(
maximumWidth
);
setMaximumWidth
(
maximumWidth
);
}
void
CardInfoPicture
::
setNoPicture
(
bool
status
)
{
if
(
noPicture
!=
status
)
{
noPicture
=
status
;
emit
hasPictureChanged
();
}
if
(
noPicture
!=
status
)
{
noPicture
=
status
;
emit
hasPictureChanged
();
}
}
void
CardInfoPicture
::
setCard
(
CardInfo
*
card
)
{
if
(
info
)
disconnect
(
info
,
0
,
this
,
0
);
info
=
card
;
connect
(
info
,
SIGNAL
(
pixmapUpdated
()),
this
,
SLOT
(
updatePixmap
()));
if
(
info
)
disconnect
(
info
,
0
,
this
,
0
);
info
=
card
;
connect
(
info
,
SIGNAL
(
pixmapUpdated
()),
this
,
SLOT
(
updatePixmap
()));
updatePixmap
();
updatePixmap
();
}
void
CardInfoPicture
::
updatePixmap
()
{
qreal
aspectRatio
=
(
qreal
)
CARD_HEIGHT
/
(
qreal
)
CARD_WIDTH
;
qreal
pixmapWidth
=
this
->
width
();
if
(
pixmapWidth
==
0
)
{
setNoPicture
(
true
);
return
;
}
QPixmap
*
resizedPixmap
=
info
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapWidth
*
aspectRatio
));
if
(
resizedPixmap
)
{
setNoPicture
(
false
);
this
->
setPixmap
(
*
resizedPixmap
);
}
else
{
setNoPicture
(
true
);
this
->
setPixmap
(
*
(
db
->
getCard
()
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapWidth
*
aspectRatio
))));
}
qreal
aspectRatio
=
(
qreal
)
CARD_HEIGHT
/
(
qreal
)
CARD_WIDTH
;
qreal
pixmapWidth
=
this
->
width
();
if
(
pixmapWidth
==
0
)
{
setNoPicture
(
true
);
return
;
}
QPixmap
*
resizedPixmap
=
info
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapWidth
*
aspectRatio
));
if
(
resizedPixmap
)
{
setNoPicture
(
false
);
this
->
setPixmap
(
*
resizedPixmap
);
}
else
{
setNoPicture
(
true
);
this
->
setPixmap
(
*
(
db
->
getCard
()
->
getPixmap
(
QSize
(
pixmapWidth
,
pixmapWidth
*
aspectRatio
))));
}
}
cockatrice/src/cardinfopicture.h
View file @
cd4d04be
...
...
@@ -7,27 +7,27 @@ class AbstractCardItem;
class
CardInfo
;
class
CardInfoPicture
:
public
QLabel
{
Q_OBJECT
Q_OBJECT
signals:
void
hasPictureChanged
();
void
hasPictureChanged
();
private:
CardInfo
*
info
;
bool
noPicture
;
CardInfo
*
info
;
bool
noPicture
;
public:
CardInfoPicture
(
int
maximumWidth
,
QWidget
*
parent
=
0
);
bool
hasPicture
()
const
{
return
!
noPicture
;
}
CardInfoPicture
(
int
maximumWidth
,
QWidget
*
parent
=
0
);
bool
hasPicture
()
const
{
return
!
noPicture
;
}
private:
void
setNoPicture
(
bool
status
);
void
setNoPicture
(
bool
status
);
public
slots
:
void
setCard
(
CardInfo
*
card
);
void
setCard
(
CardInfo
*
card
);
private
slots
:
void
updatePixmap
();
void
updatePixmap
();
};
...
...
cockatrice/src/cardinfotext.cpp
View file @
cd4d04be
...
...
@@ -8,60 +8,60 @@
#include
"main.h"
CardInfoText
::
CardInfoText
(
QWidget
*
parent
)
:
QFrame
(
parent
)
,
info
(
0
)
:
QFrame
(
parent
)
,
info
(
0
)
{
nameLabel1
=
new
QLabel
;
nameLabel2
=
new
QLabel
;
nameLabel2
->
setWordWrap
(
true
);
manacostLabel1
=
new
QLabel
;
manacostLabel2
=
new
QLabel
;
manacostLabel2
->
setWordWrap
(
true
);
cardtypeLabel1
=
new
QLabel
;
cardtypeLabel2
=
new
QLabel
;
cardtypeLabel2
->
setWordWrap
(
true
);
powtoughLabel1
=
new
QLabel
;
powtoughLabel2
=
new
QLabel
;
loyaltyLabel1
=
new
QLabel
;
loyaltyLabel2
=
new
QLabel
;
nameLabel1
=
new
QLabel
;
nameLabel2
=
new
QLabel
;
nameLabel2
->
setWordWrap
(
true
);
manacostLabel1
=
new
QLabel
;
manacostLabel2
=
new
QLabel
;
manacostLabel2
->
setWordWrap
(
true
);
cardtypeLabel1
=
new
QLabel
;
cardtypeLabel2
=
new
QLabel
;
cardtypeLabel2
->
setWordWrap
(
true
);
powtoughLabel1
=
new
QLabel
;
powtoughLabel2
=
new
QLabel
;
loyaltyLabel1
=
new
QLabel
;
loyaltyLabel2
=
new
QLabel
;
textLabel
=
new
QTextEdit
();
textLabel
->
setReadOnly
(
true
);
textLabel
=
new
QTextEdit
();
textLabel
->
setReadOnly
(
true
);
QGridLayout
*
grid
=
new
QGridLayout
(
this
);
int
row
=
0
;
grid
->
addWidget
(
nameLabel1
,
row
,
0
);
grid
->
addWidget
(
nameLabel2
,
row
++
,
1
);
grid
->
addWidget
(
manacostLabel1
,
row
,
0
);
grid
->
addWidget
(
manacostLabel2
,
row
++
,
1
);
grid
->
addWidget
(
cardtypeLabel1
,
row
,
0
);
grid
->
addWidget
(
cardtypeLabel2
,
row
++
,
1
);
grid
->
addWidget
(
powtoughLabel1
,
row
,
0
);
grid
->
addWidget
(
powtoughLabel2
,
row
++
,
1
);
grid
->
addWidget
(
loyaltyLabel1
,
row
,
0
);
grid
->
addWidget
(
loyaltyLabel2
,
row
++
,
1
);
grid
->
addWidget
(
textLabel
,
row
,
0
,
-
1
,
2
);
grid
->
setRowStretch
(
row
,
1
);
grid
->
setColumnStretch
(
1
,
1
);
QGridLayout
*
grid
=
new
QGridLayout
(
this
);
int
row
=
0
;
grid
->
addWidget
(
nameLabel1
,
row
,
0
);
grid
->
addWidget
(
nameLabel2
,
row
++
,
1
);
grid
->
addWidget
(
manacostLabel1
,
row
,
0
);
grid
->
addWidget
(
manacostLabel2
,
row
++
,
1
);
grid
->
addWidget
(
cardtypeLabel1
,
row
,
0
);
grid
->
addWidget
(
cardtypeLabel2
,
row
++
,
1
);
grid
->
addWidget
(
powtoughLabel1
,
row
,
0
);
grid
->
addWidget
(
powtoughLabel2
,
row
++
,
1
);
grid
->
addWidget
(
loyaltyLabel1
,
row
,
0
);
grid
->
addWidget
(
loyaltyLabel2
,
row
++
,
1
);
grid
->
addWidget
(
textLabel
,
row
,
0
,
-
1
,
2
);
grid
->
setRowStretch
(
row
,
1
);
grid
->
setColumnStretch
(
1
,
1
);
retranslateUi
();
retranslateUi
();
}
void
CardInfoText
::
setCard
(
CardInfo
*
card
)
{
nameLabel2
->
setText
(
card
->
getName
());
manacostLabel2
->
setText
(
card
->
getManaCost
());
cardtypeLabel2
->
setText
(
card
->
getCardType
());
powtoughLabel2
->
setText
(
card
->
getPowTough
());
loyaltyLabel2
->
setText
(
card
->
getLoyalty
()
>
0
?
QString
::
number
(
card
->
getLoyalty
())
:
QString
());
textLabel
->
setText
(
card
->
getText
());
nameLabel2
->
setText
(
card
->
getName
());
manacostLabel2
->
setText
(
card
->
getManaCost
());
cardtypeLabel2
->
setText
(
card
->
getCardType
());
powtoughLabel2
->
setText
(
card
->
getPowTough
());
loyaltyLabel2
->
setText
(
card
->
getLoyalty
()
>
0
?
QString
::
number
(
card
->
getLoyalty
())
:
QString
());
textLabel
->
setText
(
card
->
getText
());
}
void
CardInfoText
::
retranslateUi
()
{
nameLabel1
->
setText
(
tr
(
"Name:"
));
manacostLabel1
->
setText
(
tr
(
"Mana cost:"
));
cardtypeLabel1
->
setText
(
tr
(
"Card type:"
));
powtoughLabel1
->
setText
(
tr
(
"P / T:"
));
loyaltyLabel1
->
setText
(
tr
(
"Loyalty:"
));
nameLabel1
->
setText
(
tr
(
"Name:"
));
manacostLabel1
->
setText
(
tr
(
"Mana cost:"
));
cardtypeLabel1
->
setText
(
tr
(
"Card type:"
));
powtoughLabel1
->
setText
(
tr
(
"P / T:"
));
loyaltyLabel1
->
setText
(
tr
(
"Loyalty:"
));
}
cockatrice/src/cardinfotext.h
View file @
cd4d04be
...
...
@@ -8,24 +8,24 @@ class QTextEdit;
class
CardInfo
;
class
CardInfoText
:
public
QFrame
{
Q_OBJECT
Q_OBJECT
private:
QLabel
*
nameLabel1
,
*
nameLabel2
;
QLabel
*
manacostLabel1
,
*
manacostLabel2
;
QLabel
*
cardtypeLabel1
,
*
cardtypeLabel2
;
QLabel
*
powtoughLabel1
,
*
powtoughLabel2
;
QLabel
*
loyaltyLabel1
,
*
loyaltyLabel2
;
QTextEdit
*
textLabel
;
QLabel
*
nameLabel1
,
*
nameLabel2
;
QLabel
*
manacostLabel1
,
*
manacostLabel2
;
QLabel
*
cardtypeLabel1
,
*
cardtypeLabel2
;
QLabel
*
powtoughLabel1
,
*
powtoughLabel2
;
QLabel
*
loyaltyLabel1
,
*
loyaltyLabel2
;
QTextEdit
*
textLabel
;
CardInfo
*
info
;
CardInfo
*
info
;
public:
CardInfoText
(
QWidget
*
parent
=
0
);
void
retranslateUi
();
CardInfoText
(
QWidget
*
parent
=
0
);
void
retranslateUi
();
public
slots
:
void
setCard
(
CardInfo
*
card
);
void
setCard
(
CardInfo
*
card
);
};
#endif
cockatrice/src/filterbuilder.cpp
View file @
cd4d04be
...
...
@@ -8,77 +8,77 @@
#include
"cardfilter.h"
FilterBuilder
::
FilterBuilder
(
QWidget
*
parent
)
:
QFrame
(
parent
)
{
int
i
;
QVBoxLayout
*
layout
=
new
QVBoxLayout
;
QHBoxLayout
*
addFilter
=
new
QHBoxLayout
;
filterCombo
=
new
QComboBox
;
for
(
i
=
0
;
i
<
CardFilter
::
AttrEnd
;
i
++
)
filterCombo
->
addItem
(
tr
(
CardFilter
::
attrName
(
static_cast
<
CardFilter
::
Attr
>
(
i
))),
QVariant
(
i
)
);
typeCombo
=
new
QComboBox
;
for
(
i
=
0
;
i
<
CardFilter
::
TypeEnd
;
i
++
)
typeCombo
->
addItem
(
tr
(
CardFilter
::
typeName
(
static_cast
<
CardFilter
::
Type
>
(
i
))),
QVariant
(
i
)
);
QPushButton
*
ok
=
new
QPushButton
(
"+"
);
ok
->
setMaximumSize
(
20
,
20
);
addFilter
->
addWidget
(
ok
);
addFilter
->
addWidget
(
typeCombo
);
addFilter
->
addWidget
(
filterCombo
,
Qt
::
AlignLeft
);
edit
=
new
QLineEdit
;
edit
->
setSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Fixed
);
layout
->
addLayout
(
addFilter
);
layout
->
addWidget
(
edit
);
setFrameStyle
(
QFrame
::
Panel
|
QFrame
::
Raised
);
layout
->
setAlignment
(
Qt
::
AlignTop
);
setLayout
(
layout
);
connect
(
edit
,
SIGNAL
(
returnPressed
()),
this
,
SLOT
(
emit_add
()));
connect
(
ok
,
SIGNAL
(
released
()),
this
,
SLOT
(
emit_add
()));
connect
(
filterCombo
,
SIGNAL
(
currentIndexChanged
(
int
)),
edit
,
SLOT
(
clear
()));
fltr
=
NULL
;
:
QFrame
(
parent
)
{
int
i
;
QVBoxLayout
*
layout
=
new
QVBoxLayout
;
QHBoxLayout
*
addFilter
=
new
QHBoxLayout
;
filterCombo
=
new
QComboBox
;
for
(
i
=
0
;
i
<
CardFilter
::
AttrEnd
;
i
++
)
filterCombo
->
addItem
(
tr
(
CardFilter
::
attrName
(
static_cast
<
CardFilter
::
Attr
>
(
i
))),
QVariant
(
i
)
);
typeCombo
=
new
QComboBox
;
for
(
i
=
0
;
i
<
CardFilter
::
TypeEnd
;
i
++
)
typeCombo
->
addItem
(
tr
(
CardFilter
::
typeName
(
static_cast
<
CardFilter
::
Type
>
(
i
))),
QVariant
(
i
)
);
QPushButton
*
ok
=
new
QPushButton
(
"+"
);
ok
->
setMaximumSize
(
20
,
20
);
addFilter
->
addWidget
(
ok
);
addFilter
->
addWidget
(
typeCombo
);
addFilter
->
addWidget
(
filterCombo
,
Qt
::
AlignLeft
);
edit
=
new
QLineEdit
;
edit
->
setSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Fixed
);
layout
->
addLayout
(
addFilter
);
layout
->
addWidget
(
edit
);
setFrameStyle
(
QFrame
::
Panel
|
QFrame
::
Raised
);
layout
->
setAlignment
(
Qt
::
AlignTop
);
setLayout
(
layout
);
connect
(
edit
,
SIGNAL
(
returnPressed
()),
this
,
SLOT
(
emit_add
()));
connect
(
ok
,
SIGNAL
(
released
()),
this
,
SLOT
(
emit_add
()));
connect
(
filterCombo
,
SIGNAL
(
currentIndexChanged
(
int
)),
edit
,
SLOT
(
clear
()));
fltr
=
NULL
;
}
FilterBuilder
::~
FilterBuilder
()
{
destroyFilter
();
destroyFilter
();
}
void
FilterBuilder
::
destroyFilter
()
{
if
(
fltr
)
delete
fltr
;
if
(
fltr
)
delete
fltr
;
}
static
int
comboCurrentIntData
(
const
QComboBox
*
combo
)
{
return
combo
->
itemData
(
combo
->
currentIndex
()).
toInt
();
return
combo
->
itemData
(
combo
->
currentIndex
()).
toInt
();
}
void
FilterBuilder
::
emit_add
()
{
QString
txt
;
txt
=
edit
->
text
();
if
(
txt
.
length
()
<
1
)
return
;
destroyFilter
();
fltr
=
new
CardFilter
(
txt
,
static_cast
<
CardFilter
::
Type
>
(
comboCurrentIntData
(
typeCombo
)),
static_cast
<
CardFilter
::
Attr
>
(
comboCurrentIntData
(
filterCombo
)));
emit
add
(
fltr
);
edit
->
clear
();
QString
txt
;
txt
=
edit
->
text
();
if
(
txt
.
length
()
<
1
)
return
;
destroyFilter
();
fltr
=
new
CardFilter
(
txt
,
static_cast
<
CardFilter
::
Type
>
(
comboCurrentIntData
(
typeCombo
)),
static_cast
<
CardFilter
::
Attr
>
(
comboCurrentIntData
(
filterCombo
)));
emit
add
(
fltr
);
edit
->
clear
();
}
cockatrice/src/filterbuilder.h
View file @
cd4d04be
...
...
@@ -9,26 +9,26 @@ class QLineEdit;
class
CardFilter
;
class
FilterBuilder
:
public
QFrame
{
Q_OBJECT
Q_OBJECT
private:
QComboBox
*
typeCombo
;
QComboBox
*
filterCombo
;
QLineEdit
*
edit
;
CardFilter
*
fltr
;
QComboBox
*
typeCombo
;
QComboBox
*
filterCombo
;
QLineEdit
*
edit
;
CardFilter
*
fltr
;
void
destroyFilter
();
void
destroyFilter
();
public:
FilterBuilder
(
QWidget
*
parent
=
0
);
~
FilterBuilder
();
FilterBuilder
(
QWidget
*
parent
=
0
);
~
FilterBuilder
();
signals:
void
add
(
const
CardFilter
*
f
);
public
slots
:
private
slots
:
void
emit_add
();
void
emit_add
();
protected:
};
...
...
cockatrice/src/filtertree.cpp
View file @
cd4d04be
...
...
@@ -7,223 +7,223 @@
template
<
class
T
>
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
>
void
FilterTreeBranch
<
T
>::
deleteAt
(
int
i
)
{
preRemoveChild
(
this
,
i
);
delete
childNodes
.
takeAt
(
i
);
postRemoveChild
(
this
,
i
);
nodeChanged
();
preRemoveChild
(
this
,
i
);
delete
childNodes
.
takeAt
(
i
);
postRemoveChild
(
this
,
i
);
nodeChanged
();
}
template
<
class
T
>
int
FilterTreeBranch
<
T
>::
childIndex
(
const
FilterTreeNode
*
node
)
const
{
FilterTreeNode
*
unconst
;
T
downcasted
;
/* to do the dynamic cast to T we will lose const'ness, but we can
* trust QList::indexOf */
unconst
=
(
FilterTreeNode
*
)
node
;
downcasted
=
dynamic_cast
<
T
>
(
unconst
);
if
(
downcasted
==
NULL
)
return
-
1
;
return
childNodes
.
indexOf
(
downcasted
);
FilterTreeNode
*
unconst
;
T
downcasted
;
/* to do the dynamic cast to T we will lose const'ness, but we can
* trust QList::indexOf */
unconst
=
(
FilterTreeNode
*
)
node
;
downcasted
=
dynamic_cast
<
T
>
(
unconst
);
if
(
downcasted
==
NULL
)
return
-
1
;
return
childNodes
.
indexOf
(
downcasted
);
}
template
<
class
T
>
FilterTreeBranch
<
T
>::~
FilterTreeBranch
()
{
while
(
!
childNodes
.
isEmpty
())
delete
childNodes
.
takeFirst
();
while
(
!
childNodes
.
isEmpty
())
delete
childNodes
.
takeFirst
();
}
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
++
)
if
((
*
i
)
->
type
==
type
)
return
*
i
;
for
(
i
=
childNodes
.
constBegin
();
i
!=
childNodes
.
constEnd
();
i
++
)
if
((
*
i
)
->
type
==
type
)
return
*
i
;
return
NULL
;
return
NULL
;
}
FilterItemList
*
LogicMap
::
typeList
(
CardFilter
::
Type
type
)
{
QList
<
FilterItemList
*>::
iterator
i
;
int
count
;
count
=
0
;
for
(
i
=
childNodes
.
begin
();
i
!=
childNodes
.
end
();
i
++
)
{
if
((
*
i
)
->
type
==
type
)
break
;
count
++
;
}
if
(
i
==
childNodes
.
end
())
{
preInsertChild
(
this
,
count
);
i
=
childNodes
.
insert
(
i
,
new
FilterItemList
(
type
,
this
));
postInsertChild
(
this
,
count
);
nodeChanged
();
}
return
*
i
;
QList
<
FilterItemList
*>::
iterator
i
;
int
count
;
count
=
0
;
for
(
i
=
childNodes
.
begin
();
i
!=
childNodes
.
end
();
i
++
)
{
if
((
*
i
)
->
type
==
type
)
break
;
count
++
;
}
if
(
i
==
childNodes
.
end
())
{
preInsertChild
(
this
,
count
);
i
=
childNodes
.
insert
(
i
,
new
FilterItemList
(
type
,
this
));
postInsertChild
(
this
,
count
);
nodeChanged
();
}
return
*
i
;
}
FilterTreeNode
*
LogicMap
::
parent
()
const
{
return
p
;
return
p
;
}
int
FilterItemList
::
termIndex
(
const
QString
&
term
)
const
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
childNodes
.
count
();
i
++
)
if
((
childNodes
.
at
(
i
))
->
term
==
term
)
return
i
;
for
(
i
=
0
;
i
<
childNodes
.
count
();
i
++
)
if
((
childNodes
.
at
(
i
))
->
term
==
term
)
return
i
;
return
-
1
;
return
-
1
;
}
FilterTreeNode
*
FilterItemList
::
termNode
(
const
QString
&
term
)
{
int
i
,
count
;
FilterItem
*
fi
;
i
=
termIndex
(
term
);
if
(
i
<
0
)
{
fi
=
new
FilterItem
(
term
,
this
);
count
=
childNodes
.
count
();
preInsertChild
(
this
,
count
);
childNodes
.
append
(
fi
);
postInsertChild
(
this
,
count
);
nodeChanged
();
return
fi
;
}
return
childNodes
.
at
(
i
);
int
i
,
count
;
FilterItem
*
fi
;
i
=
termIndex
(
term
);
if
(
i
<
0
)
{
fi
=
new
FilterItem
(
term
,
this
);
count
=
childNodes
.
count
();
preInsertChild
(
this
,
count
);
childNodes
.
append
(
fi
);
postInsertChild
(
this
,
count
);
nodeChanged
();
return
fi
;
}
return
childNodes
.
at
(
i
);
}
bool
FilterItemList
::
testTypeAnd
(
const
CardInfo
*
info
,
CardFilter
::
Attr
attr
)
const
{
QList
<
FilterItem
*>::
const_iterator
i
;
QList
<
FilterItem
*>::
const_iterator
i
;
for
(
i
=
childNodes
.
constBegin
();
i
!=
childNodes
.
constEnd
();
i
++
)
if
(
!
(
*
i
)
->
acceptCardAttr
(
info
,
attr
))
return
false
;
for
(
i
=
childNodes
.
constBegin
();
i
!=
childNodes
.
constEnd
();
i
++
)
if
(
!
(
*
i
)
->
acceptCardAttr
(
info
,
attr
))
return
false
;
return
true
;
return
true
;
}
bool
FilterItemList
::
testTypeAndNot
(
const
CardInfo
*
info
,
CardFilter
::
Attr
attr
)
const
{
// if any one in the list is true, return false
return
!
testTypeOr
(
info
,
attr
);
// if any one in the list is true, return false
return
!
testTypeOr
(
info
,
attr
);
}
bool
FilterItemList
::
testTypeOr
(
const
CardInfo
*
info
,
CardFilter
::
Attr
attr
)
const
{
QList
<
FilterItem
*>::
const_iterator
i
;
QList
<
FilterItem
*>::
const_iterator
i
;
for
(
i
=
childNodes
.
constBegin
();
i
!=
childNodes
.
constEnd
();
i
++
)
if
((
*
i
)
->
acceptCardAttr
(
info
,
attr
))
return
true
;
for
(
i
=
childNodes
.
constBegin
();
i
!=
childNodes
.
constEnd
();
i
++
)
if
((
*
i
)
->
acceptCardAttr
(
info
,
attr
))
return
true
;
return
false
;
return
false
;
}
bool
FilterItemList
::
testTypeOrNot
(
const
CardInfo
*
info
,
CardFilter
::
Attr
attr
)
const
{
// if any one in the list is false, return true
return
!
testTypeAnd
(
info
,
attr
);
// if any one in the list is false, return true
return
!
testTypeAnd
(
info
,
attr
);
}
bool
FilterItem
::
acceptName
(
const
CardInfo
*
info
)
const
{
return
info
->
getName
().
contains
(
term
,
Qt
::
CaseInsensitive
);
return
info
->
getName
().
contains
(
term
,
Qt
::
CaseInsensitive
);
}
bool
FilterItem
::
acceptType
(
const
CardInfo
*
info
)
const
{
return
info
->
getCardType
().
contains
(
term
,
Qt
::
CaseInsensitive
);
return
info
->
getCardType
().
contains
(
term
,
Qt
::
CaseInsensitive
);
}
bool
FilterItem
::
acceptColor
(
const
CardInfo
*
info
)
const
{
QStringList
::
const_iterator
i
;
bool
status
;
QStringList
::
const_iterator
i
;
bool
status
;
status
=
false
;
for
(
i
=
info
->
getColors
().
constBegin
();
i
!=
info
->
getColors
().
constEnd
();
i
++
)
if
((
*
i
).
contains
(
term
,
Qt
::
CaseInsensitive
))
{
status
=
true
;
break
;
}
status
=
false
;
for
(
i
=
info
->
getColors
().
constBegin
();
i
!=
info
->
getColors
().
constEnd
();
i
++
)
if
((
*
i
).
contains
(
term
,
Qt
::
CaseInsensitive
))
{
status
=
true
;
break
;
}
return
status
;
return
status
;
}
bool
FilterItem
::
acceptText
(
const
CardInfo
*
info
)
const
{
return
info
->
getText
().
contains
(
term
,
Qt
::
CaseInsensitive
);
return
info
->
getText
().
contains
(
term
,
Qt
::
CaseInsensitive
);
}
bool
FilterItem
::
acceptSet
(
const
CardInfo
*
info
)
const
{
SetList
::
const_iterator
i
;
bool
status
;
status
=
false
;
for
(
i
=
info
->
getSets
().
constBegin
();
i
!=
info
->
getSets
().
constEnd
();
i
++
)
if
((
*
i
)
->
getShortName
()
==
term
||
(
*
i
)
->
getLongName
().
contains
(
term
,
Qt
::
CaseInsensitive
))
{
status
=
true
;
break
;
}
return
status
;
SetList
::
const_iterator
i
;
bool
status
;
status
=
false
;
for
(
i
=
info
->
getSets
().
constBegin
();
i
!=
info
->
getSets
().
constEnd
();
i
++
)
if
((
*
i
)
->
getShortName
()
==
term
||
(
*
i
)
->
getLongName
().
contains
(
term
,
Qt
::
CaseInsensitive
))
{
status
=
true
;
break
;
}
return
status
;
}
bool
FilterItem
::
acceptManaCost
(
const
CardInfo
*
info
)
const
{
return
(
info
->
getManaCost
()
==
term
);
return
(
info
->
getManaCost
()
==
term
);
}
bool
FilterItem
::
acceptCardAttr
(
const
CardInfo
*
info
,
CardFilter
::
Attr
attr
)
const
{
bool
status
;
if
(
!
isEnabled
())
return
true
;
switch
(
attr
)
{
case
CardFilter
::
AttrName
:
status
=
acceptName
(
info
);
break
;
case
CardFilter
::
AttrType
:
status
=
acceptType
(
info
);
break
;
case
CardFilter
::
AttrColor
:
status
=
acceptColor
(
info
);
break
;
case
CardFilter
::
AttrText
:
status
=
acceptText
(
info
);
break
;
case
CardFilter
::
AttrSet
:
status
=
acceptSet
(
info
);
break
;
case
CardFilter
::
AttrManaCost
:
status
=
acceptManaCost
(
info
);
break
;
default:
status
=
true
;
/* ignore this attribute */
}
return
status
;
bool
status
;
if
(
!
isEnabled
())
return
true
;
switch
(
attr
)
{
case
CardFilter
::
AttrName
:
status
=
acceptName
(
info
);
break
;
case
CardFilter
::
AttrType
:
status
=
acceptType
(
info
);
break
;
case
CardFilter
::
AttrColor
:
status
=
acceptColor
(
info
);
break
;
case
CardFilter
::
AttrText
:
status
=
acceptText
(
info
);
break
;
case
CardFilter
::
AttrSet
:
status
=
acceptSet
(
info
);
break
;
case
CardFilter
::
AttrManaCost
:
status
=
acceptManaCost
(
info
);
break
;
default:
status
=
true
;
/* ignore this attribute */
}
return
status
;
}
/* need to define these here to make QT happy, otherwise
...
...
@@ -234,103 +234,103 @@ FilterTree::~FilterTree() {}
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
)
break
;
count
++
;
}
if
(
i
==
childNodes
.
end
())
{
preInsertChild
(
this
,
count
);
i
=
childNodes
.
insert
(
i
,
new
LogicMap
(
attr
,
this
));
postInsertChild
(
this
,
count
);
nodeChanged
();
}
return
*
i
;
QList
<
LogicMap
*>::
iterator
i
;
int
count
;
count
=
0
;
for
(
i
=
childNodes
.
begin
();
i
!=
childNodes
.
end
();
i
++
)
{
if
((
*
i
)
->
attr
==
attr
)
break
;
count
++
;
}
if
(
i
==
childNodes
.
end
())
{
preInsertChild
(
this
,
count
);
i
=
childNodes
.
insert
(
i
,
new
LogicMap
(
attr
,
this
));
postInsertChild
(
this
,
count
);
nodeChanged
();
}
return
*
i
;
}
FilterItemList
*
FilterTree
::
attrTypeList
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
)
CardFilter
::
Type
type
)
{
return
attrLogicMap
(
attr
)
->
typeList
(
type
);
return
attrLogicMap
(
attr
)
->
typeList
(
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
FilterTree
::
findTermIndex
(
const
CardFilter
*
f
)
{
return
findTermIndex
(
f
->
attr
(),
f
->
type
(),
f
->
term
());
return
findTermIndex
(
f
->
attr
(),
f
->
type
(),
f
->
term
());
}
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
);
}
FilterTreeNode
*
FilterTree
::
termNode
(
const
CardFilter
*
f
)
{
return
termNode
(
f
->
attr
(),
f
->
type
(),
f
->
term
());
return
termNode
(
f
->
attr
(),
f
->
type
(),
f
->
term
());
}
FilterTreeNode
*
FilterTree
::
attrTypeNode
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
)
CardFilter
::
Type
type
)
{
return
attrTypeList
(
attr
,
type
);
return
attrTypeList
(
attr
,
type
);
}
bool
FilterTree
::
testAttr
(
const
CardInfo
*
info
,
const
LogicMap
*
lm
)
const
{
const
FilterItemList
*
fil
;
bool
status
;
const
FilterItemList
*
fil
;
bool
status
;
status
=
true
;
status
=
true
;
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeAnd
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
()
&&
!
fil
->
testTypeAnd
(
info
,
lm
->
attr
))
return
false
;
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeAnd
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
()
&&
!
fil
->
testTypeAnd
(
info
,
lm
->
attr
))
return
false
;
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeAndNot
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
()
&&
!
fil
->
testTypeAndNot
(
info
,
lm
->
attr
))
return
false
;
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeAndNot
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
()
&&
!
fil
->
testTypeAndNot
(
info
,
lm
->
attr
))
return
false
;
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeOr
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
())
{
status
=
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
;
}
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeOr
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
())
{
status
=
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
;
}
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeOrNot
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
()
&&
fil
->
testTypeOrNot
(
info
,
lm
->
attr
))
return
true
;
fil
=
lm
->
findTypeList
(
CardFilter
::
TypeOrNot
);
if
(
fil
!=
NULL
&&
fil
->
isEnabled
()
&&
fil
->
testTypeOrNot
(
info
,
lm
->
attr
))
return
true
;
return
status
;
return
status
;
}
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
++
)
if
((
*
i
)
->
isEnabled
()
&&
!
testAttr
(
info
,
*
i
))
return
false
;
for
(
i
=
childNodes
.
constBegin
();
i
!=
childNodes
.
constEnd
();
i
++
)
if
((
*
i
)
->
isEnabled
()
&&
!
testAttr
(
info
,
*
i
))
return
false
;
return
true
;
return
true
;
}
void
FilterTree
::
clear
()
{
while
(
childCount
()
>
0
)
deleteAt
(
0
);
while
(
childCount
()
>
0
)
deleteAt
(
0
);
}
cockatrice/src/filtertree.h
View file @
cd4d04be
...
...
@@ -11,48 +11,48 @@ class CardInfo;
class
FilterTreeNode
{
private:
bool
enabled
;
bool
enabled
;
public:
FilterTreeNode
()
:
enabled
(
true
)
{}
virtual
bool
isEnabled
()
const
{
return
enabled
;
}
virtual
void
enable
()
{
enabled
=
true
;
nodeChanged
();
}
virtual
void
disable
()
{
enabled
=
false
;
nodeChanged
();
}
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
FilterTreeNode
*
node
)
const
{
return
-
1
;
}
virtual
int
index
()
const
{
return
(
parent
()
!=
NULL
)
?
parent
()
->
childIndex
(
this
)
:
-
1
;
}
virtual
QString
text
()
const
{
return
QString
(
textCStr
());
}
virtual
bool
isLeaf
()
const
{
return
false
;
}
virtual
const
char
*
textCStr
()
const
{
return
""
;
}
virtual
void
nodeChanged
()
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
nodeChanged
();
}
virtual
void
preInsertChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
preInsertChild
(
p
,
i
);
}
virtual
void
postInsertChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
postInsertChild
(
p
,
i
);
}
virtual
void
preRemoveChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
preRemoveChild
(
p
,
i
);
}
virtual
void
postRemoveChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
postRemoveChild
(
p
,
i
);
}
FilterTreeNode
()
:
enabled
(
true
)
{}
virtual
bool
isEnabled
()
const
{
return
enabled
;
}
virtual
void
enable
()
{
enabled
=
true
;
nodeChanged
();
}
virtual
void
disable
()
{
enabled
=
false
;
nodeChanged
();
}
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
FilterTreeNode
*
node
)
const
{
return
-
1
;
}
virtual
int
index
()
const
{
return
(
parent
()
!=
NULL
)
?
parent
()
->
childIndex
(
this
)
:
-
1
;
}
virtual
QString
text
()
const
{
return
QString
(
textCStr
());
}
virtual
bool
isLeaf
()
const
{
return
false
;
}
virtual
const
char
*
textCStr
()
const
{
return
""
;
}
virtual
void
nodeChanged
()
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
nodeChanged
();
}
virtual
void
preInsertChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
preInsertChild
(
p
,
i
);
}
virtual
void
postInsertChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
postInsertChild
(
p
,
i
);
}
virtual
void
preRemoveChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
preRemoveChild
(
p
,
i
);
}
virtual
void
postRemoveChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
if
(
parent
()
!=
NULL
)
parent
()
->
postRemoveChild
(
p
,
i
);
}
};
template
<
class
T
>
class
FilterTreeBranch
:
public
FilterTreeNode
{
protected:
QList
<
T
>
childNodes
;
QList
<
T
>
childNodes
;
public:
~
FilterTreeBranch
();
FilterTreeNode
*
nodeAt
(
int
i
)
const
;
void
deleteAt
(
int
i
);
int
childCount
()
const
{
return
childNodes
.
size
();
}
int
childIndex
(
const
FilterTreeNode
*
node
)
const
;
~
FilterTreeBranch
();
FilterTreeNode
*
nodeAt
(
int
i
)
const
;
void
deleteAt
(
int
i
);
int
childCount
()
const
{
return
childNodes
.
size
();
}
int
childIndex
(
const
FilterTreeNode
*
node
)
const
;
};
class
FilterItemList
;
...
...
@@ -60,104 +60,104 @@ class FilterTree;
class
LogicMap
:
public
FilterTreeBranch
<
FilterItemList
*>
{
private:
FilterTree
*
const
p
;
FilterTree
*
const
p
;
public:
const
CardFilter
::
Attr
attr
;
LogicMap
(
CardFilter
::
Attr
a
,
FilterTree
*
parent
)
:
attr
(
a
),
p
(
parent
)
{}
const
FilterItemList
*
findTypeList
(
CardFilter
::
Type
type
)
const
;
FilterItemList
*
typeList
(
CardFilter
::
Type
type
);
FilterTreeNode
*
parent
()
const
;
const
char
*
textCStr
()
const
{
return
CardFilter
::
attrName
(
attr
);
}
const
CardFilter
::
Attr
attr
;
LogicMap
(
CardFilter
::
Attr
a
,
FilterTree
*
parent
)
:
attr
(
a
),
p
(
parent
)
{}
const
FilterItemList
*
findTypeList
(
CardFilter
::
Type
type
)
const
;
FilterItemList
*
typeList
(
CardFilter
::
Type
type
);
FilterTreeNode
*
parent
()
const
;
const
char
*
textCStr
()
const
{
return
CardFilter
::
attrName
(
attr
);
}
};
class
FilterItem
;
class
FilterItemList
:
public
FilterTreeBranch
<
FilterItem
*>
{
private:
LogicMap
*
const
p
;
LogicMap
*
const
p
;
public:
const
CardFilter
::
Type
type
;
FilterItemList
(
CardFilter
::
Type
t
,
LogicMap
*
parent
)
:
type
(
t
),
p
(
parent
)
{}
CardFilter
::
Attr
attr
()
const
{
return
p
->
attr
;
}
FilterTreeNode
*
parent
()
const
{
return
p
;
}
int
termIndex
(
const
QString
&
term
)
const
;
FilterTreeNode
*
termNode
(
const
QString
&
term
);
const
char
*
textCStr
()
const
{
return
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
;
const
CardFilter
::
Type
type
;
FilterItemList
(
CardFilter
::
Type
t
,
LogicMap
*
parent
)
:
type
(
t
),
p
(
parent
)
{}
CardFilter
::
Attr
attr
()
const
{
return
p
->
attr
;
}
FilterTreeNode
*
parent
()
const
{
return
p
;
}
int
termIndex
(
const
QString
&
term
)
const
;
FilterTreeNode
*
termNode
(
const
QString
&
term
);
const
char
*
textCStr
()
const
{
return
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
FilterTreeNode
{
private:
FilterItemList
*
const
p
;
FilterItemList
*
const
p
;
public:
const
QString
term
;
FilterItem
(
QString
trm
,
FilterItemList
*
parent
)
:
p
(
parent
),
term
(
trm
)
{}
CardFilter
::
Attr
attr
()
const
{
return
p
->
attr
();
}
CardFilter
::
Type
type
()
const
{
return
p
->
type
;
}
FilterTreeNode
*
parent
()
const
{
return
p
;
}
QString
text
()
const
{
return
term
;
}
const
char
*
textCStr
()
const
{
return
term
.
toStdString
().
c_str
();
}
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
;
const
QString
term
;
FilterItem
(
QString
trm
,
FilterItemList
*
parent
)
:
p
(
parent
),
term
(
trm
)
{}
CardFilter
::
Attr
attr
()
const
{
return
p
->
attr
();
}
CardFilter
::
Type
type
()
const
{
return
p
->
type
;
}
FilterTreeNode
*
parent
()
const
{
return
p
;
}
QString
text
()
const
{
return
term
;
}
const
char
*
textCStr
()
const
{
return
term
.
toStdString
().
c_str
();
}
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
FilterTree
:
public
QObject
,
public
FilterTreeBranch
<
LogicMap
*>
{
Q_OBJECT
Q_OBJECT
signals:
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
;
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:
LogicMap
*
attrLogicMap
(
CardFilter
::
Attr
attr
);
FilterItemList
*
attrTypeList
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
);
LogicMap
*
attrLogicMap
(
CardFilter
::
Attr
attr
);
FilterItemList
*
attrTypeList
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
);
bool
testAttr
(
const
CardInfo
*
info
,
const
LogicMap
*
lm
)
const
;
bool
testAttr
(
const
CardInfo
*
info
,
const
LogicMap
*
lm
)
const
;
void
nodeChanged
()
const
{
emit
changed
();
}
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
{
emit
preRemoveRow
(
p
,
i
);
}
void
postRemoveChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
emit
postRemoveRow
(
p
,
i
);
}
void
nodeChanged
()
const
{
emit
changed
();
}
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
{
emit
preRemoveRow
(
p
,
i
);
}
void
postRemoveChild
(
const
FilterTreeNode
*
p
,
int
i
)
const
{
emit
postRemoveRow
(
p
,
i
);
}
public:
FilterTree
();
~
FilterTree
();
int
findTermIndex
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
,
const
QString
&
term
);
int
findTermIndex
(
const
CardFilter
*
f
);
FilterTreeNode
*
termNode
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
,
const
QString
&
term
);
FilterTreeNode
*
termNode
(
const
CardFilter
*
f
);
FilterTreeNode
*
attrTypeNode
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
);
const
char
*
textCStr
()
{
return
"root"
;
}
int
index
()
const
{
return
0
;
}
bool
acceptsCard
(
const
CardInfo
*
info
)
const
;
void
clear
();
FilterTree
();
~
FilterTree
();
int
findTermIndex
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
,
const
QString
&
term
);
int
findTermIndex
(
const
CardFilter
*
f
);
FilterTreeNode
*
termNode
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
,
const
QString
&
term
);
FilterTreeNode
*
termNode
(
const
CardFilter
*
f
);
FilterTreeNode
*
attrTypeNode
(
CardFilter
::
Attr
attr
,
CardFilter
::
Type
type
);
const
char
*
textCStr
()
{
return
"root"
;
}
int
index
()
const
{
return
0
;
}
bool
acceptsCard
(
const
CardInfo
*
info
)
const
;
void
clear
();
};
#endif
cockatrice/src/filtertreemodel.cpp
View file @
cd4d04be
...
...
@@ -4,269 +4,269 @@
#include
"cardfilter.h"
FilterTreeModel
::
FilterTreeModel
(
QObject
*
parent
)
:
QAbstractItemModel
(
parent
)
:
QAbstractItemModel
(
parent
)
{
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
)));
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
)));
}
FilterTreeModel
::~
FilterTreeModel
()
{
delete
fTree
;
delete
fTree
;
}
void
FilterTreeModel
::
proxyBeginInsertRow
(
const
FilterTreeNode
*
node
,
int
i
)
{
int
idx
;
int
idx
;
idx
=
node
->
index
();
if
(
idx
>=
0
)
beginInsertRows
(
createIndex
(
idx
,
0
,
(
void
*
)
node
),
i
,
i
);
idx
=
node
->
index
();
if
(
idx
>=
0
)
beginInsertRows
(
createIndex
(
idx
,
0
,
(
void
*
)
node
),
i
,
i
);
}
void
FilterTreeModel
::
proxyEndInsertRow
(
const
FilterTreeNode
*
node
,
int
)
{
int
idx
;
int
idx
;
idx
=
node
->
index
();
if
(
idx
>=
0
)
endInsertRows
();
idx
=
node
->
index
();
if
(
idx
>=
0
)
endInsertRows
();
}
void
FilterTreeModel
::
proxyBeginRemoveRow
(
const
FilterTreeNode
*
node
,
int
i
)
{
int
idx
;
int
idx
;
idx
=
node
->
index
();
if
(
idx
>=
0
)
beginRemoveRows
(
createIndex
(
idx
,
0
,
(
void
*
)
node
),
i
,
i
);
idx
=
node
->
index
();
if
(
idx
>=
0
)
beginRemoveRows
(
createIndex
(
idx
,
0
,
(
void
*
)
node
),
i
,
i
);
}
void
FilterTreeModel
::
proxyEndRemoveRow
(
const
FilterTreeNode
*
node
,
int
)
{
int
idx
;
int
idx
;
idx
=
node
->
index
();
if
(
idx
>=
0
)
endRemoveRows
();
idx
=
node
->
index
();
if
(
idx
>=
0
)
endRemoveRows
();
}
FilterTreeNode
*
FilterTreeModel
::
indexToNode
(
const
QModelIndex
&
idx
)
const
{
void
*
ip
;
FilterTreeNode
*
node
;
void
*
ip
;
FilterTreeNode
*
node
;
if
(
!
idx
.
isValid
())
return
fTree
;
if
(
!
idx
.
isValid
())
return
fTree
;
ip
=
idx
.
internalPointer
();
if
(
ip
==
NULL
)
return
fTree
;
ip
=
idx
.
internalPointer
();
if
(
ip
==
NULL
)
return
fTree
;
node
=
static_cast
<
FilterTreeNode
*>
(
ip
);
return
node
;
node
=
static_cast
<
FilterTreeNode
*>
(
ip
);
return
node
;
}
void
FilterTreeModel
::
addFilter
(
const
CardFilter
*
f
)
{
emit
layoutAboutToBeChanged
();
fTree
->
termNode
(
f
);
emit
layoutChanged
();
emit
layoutAboutToBeChanged
();
fTree
->
termNode
(
f
);
emit
layoutChanged
();
}
int
FilterTreeModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
const
FilterTreeNode
*
node
;
int
result
;
const
FilterTreeNode
*
node
;
int
result
;
if
(
parent
.
column
()
>
0
)
return
0
;
if
(
parent
.
column
()
>
0
)
return
0
;
node
=
indexToNode
(
parent
);
if
(
node
)
result
=
node
->
childCount
();
else
result
=
0
;
node
=
indexToNode
(
parent
);
if
(
node
)
result
=
node
->
childCount
();
else
result
=
0
;
return
result
;
return
result
;
}
int
FilterTreeModel
::
columnCount
(
const
QModelIndex
&
/*parent*/
)
const
{
return
1
;
return
1
;
}
QVariant
FilterTreeModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
const
FilterTreeNode
*
node
;
if
(
!
index
.
isValid
())
return
QVariant
();
if
(
index
.
column
()
>=
columnCount
())
return
QVariant
();
node
=
indexToNode
(
index
);
if
(
node
==
NULL
)
return
QVariant
();
switch
(
role
)
{
case
Qt
::
FontRole
:
if
(
!
node
->
isLeaf
())
{
QFont
f
;
f
.
setBold
(
true
);
return
f
;
}
break
;
case
Qt
::
DisplayRole
:
case
Qt
::
EditRole
:
case
Qt
::
ToolTipRole
:
case
Qt
::
StatusTipRole
:
case
Qt
::
WhatsThisRole
:
if
(
!
node
->
isLeaf
())
return
tr
(
node
->
textCStr
());
else
return
node
->
text
();
case
Qt
::
CheckStateRole
:
if
(
node
->
isEnabled
())
return
Qt
::
Checked
;
else
return
Qt
::
Unchecked
;
default:
return
QVariant
();
}
return
QVariant
();
const
FilterTreeNode
*
node
;
if
(
!
index
.
isValid
())
return
QVariant
();
if
(
index
.
column
()
>=
columnCount
())
return
QVariant
();
node
=
indexToNode
(
index
);
if
(
node
==
NULL
)
return
QVariant
();
switch
(
role
)
{
case
Qt
::
FontRole
:
if
(
!
node
->
isLeaf
())
{
QFont
f
;
f
.
setBold
(
true
);
return
f
;
}
break
;
case
Qt
::
DisplayRole
:
case
Qt
::
EditRole
:
case
Qt
::
ToolTipRole
:
case
Qt
::
StatusTipRole
:
case
Qt
::
WhatsThisRole
:
if
(
!
node
->
isLeaf
())
return
tr
(
node
->
textCStr
());
else
return
node
->
text
();
case
Qt
::
CheckStateRole
:
if
(
node
->
isEnabled
())
return
Qt
::
Checked
;
else
return
Qt
::
Unchecked
;
default:
return
QVariant
();
}
return
QVariant
();
}
bool
FilterTreeModel
::
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
const
QVariant
&
value
,
int
role
)
{
FilterTreeNode
*
node
;
if
(
!
index
.
isValid
())
return
false
;
if
(
index
.
column
()
>=
columnCount
())
return
false
;
if
(
role
!=
Qt
::
CheckStateRole
)
return
false
;
node
=
indexToNode
(
index
);
if
(
node
==
NULL
||
node
==
fTree
)
return
false
;
Qt
::
CheckState
state
=
static_cast
<
Qt
::
CheckState
>
(
value
.
toInt
());
if
(
state
==
Qt
::
Checked
)
node
->
enable
();
else
node
->
disable
();
emit
dataChanged
(
index
,
index
);
return
true
;
}
FilterTreeNode
*
node
;
if
(
!
index
.
isValid
())
return
false
;
if
(
index
.
column
()
>=
columnCount
())
return
false
;
if
(
role
!=
Qt
::
CheckStateRole
)
return
false
;
node
=
indexToNode
(
index
);
if
(
node
==
NULL
||
node
==
fTree
)
return
false
;
Qt
::
CheckState
state
=
static_cast
<
Qt
::
CheckState
>
(
value
.
toInt
());
if
(
state
==
Qt
::
Checked
)
node
->
enable
();
else
node
->
disable
();
emit
dataChanged
(
index
,
index
);
return
true
;
}
Qt
::
ItemFlags
FilterTreeModel
::
flags
(
const
QModelIndex
&
index
)
const
{
const
FilterTreeNode
*
node
;
Qt
::
ItemFlags
result
;
const
FilterTreeNode
*
node
;
Qt
::
ItemFlags
result
;
if
(
!
index
.
isValid
())
return
0
;
if
(
!
index
.
isValid
())
return
0
;
node
=
indexToNode
(
index
);
if
(
node
==
NULL
)
return
0
;
node
=
indexToNode
(
index
);
if
(
node
==
NULL
)
return
0
;
result
=
Qt
::
ItemIsEnabled
;
if
(
node
==
fTree
)
return
result
;
result
=
Qt
::
ItemIsEnabled
;
if
(
node
==
fTree
)
return
result
;
result
|=
Qt
::
ItemIsSelectable
;
result
|=
Qt
::
ItemIsUserCheckable
;
result
|=
Qt
::
ItemIsSelectable
;
result
|=
Qt
::
ItemIsUserCheckable
;
return
result
;
return
result
;
}
QModelIndex
FilterTreeModel
::
nodeIndex
(
const
FilterTreeNode
*
node
,
int
row
,
int
column
)
const
{
FilterTreeNode
*
child
;
FilterTreeNode
*
child
;
if
(
column
>
0
||
row
>=
node
->
childCount
())
return
QModelIndex
();
if
(
column
>
0
||
row
>=
node
->
childCount
())
return
QModelIndex
();
child
=
node
->
nodeAt
(
row
);
return
createIndex
(
row
,
column
,
child
);
child
=
node
->
nodeAt
(
row
);
return
createIndex
(
row
,
column
,
child
);
}
QModelIndex
FilterTreeModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
const
QModelIndex
&
parent
)
const
{
const
FilterTreeNode
*
node
;
const
FilterTreeNode
*
node
;
if
(
!
hasIndex
(
row
,
column
,
parent
))
return
QModelIndex
();
if
(
!
hasIndex
(
row
,
column
,
parent
))
return
QModelIndex
();
node
=
indexToNode
(
parent
);
if
(
node
==
NULL
)
return
QModelIndex
();
node
=
indexToNode
(
parent
);
if
(
node
==
NULL
)
return
QModelIndex
();
return
nodeIndex
(
node
,
row
,
column
);
return
nodeIndex
(
node
,
row
,
column
);
}
QModelIndex
FilterTreeModel
::
parent
(
const
QModelIndex
&
ind
)
const
{
const
FilterTreeNode
*
node
;
FilterTreeNode
*
parent
;
int
row
;
QModelIndex
idx
;
if
(
!
ind
.
isValid
())
return
QModelIndex
();
node
=
indexToNode
(
ind
);
if
(
node
==
NULL
||
node
==
fTree
)
return
QModelIndex
();
parent
=
node
->
parent
();
if
(
parent
)
{
row
=
parent
->
index
();
if
(
row
<
0
)
return
QModelIndex
();
idx
=
createIndex
(
row
,
0
,
parent
);
return
idx
;
}
return
QModelIndex
();
const
FilterTreeNode
*
node
;
FilterTreeNode
*
parent
;
int
row
;
QModelIndex
idx
;
if
(
!
ind
.
isValid
())
return
QModelIndex
();
node
=
indexToNode
(
ind
);
if
(
node
==
NULL
||
node
==
fTree
)
return
QModelIndex
();
parent
=
node
->
parent
();
if
(
parent
)
{
row
=
parent
->
index
();
if
(
row
<
0
)
return
QModelIndex
();
idx
=
createIndex
(
row
,
0
,
parent
);
return
idx
;
}
return
QModelIndex
();
}
bool
FilterTreeModel
::
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
)
{
FilterTreeNode
*
node
;
int
i
,
last
;
FilterTreeNode
*
node
;
int
i
,
last
;
last
=
row
+
count
-
1
;
if
(
!
parent
.
isValid
()
||
count
<
1
||
row
<
0
)
return
false
;
last
=
row
+
count
-
1
;
if
(
!
parent
.
isValid
()
||
count
<
1
||
row
<
0
)
return
false
;
node
=
indexToNode
(
parent
);
if
(
node
==
NULL
||
last
>=
node
->
childCount
())
return
false
;
node
=
indexToNode
(
parent
);
if
(
node
==
NULL
||
last
>=
node
->
childCount
())
return
false
;
for
(
i
=
0
;
i
<
count
;
i
++
)
node
->
deleteAt
(
row
);
for
(
i
=
0
;
i
<
count
;
i
++
)
node
->
deleteAt
(
row
);
if
(
node
!=
fTree
&&
node
->
childCount
()
<
1
)
return
removeRow
(
parent
.
row
(),
parent
.
parent
());
if
(
node
!=
fTree
&&
node
->
childCount
()
<
1
)
return
removeRow
(
parent
.
row
(),
parent
.
parent
());
return
true
;
return
true
;
}
cockatrice/src/filtertreemodel.h
View file @
cd4d04be
...
...
@@ -8,37 +8,37 @@ class CardFilter;
class
FilterTreeNode
;
class
FilterTreeModel
:
public
QAbstractItemModel
{
Q_OBJECT
Q_OBJECT
private:
FilterTree
*
fTree
;
FilterTree
*
fTree
;
public
slots
:
void
addFilter
(
const
CardFilter
*
f
);
void
addFilter
(
const
CardFilter
*
f
);
private
slots
:
void
proxyBeginInsertRow
(
const
FilterTreeNode
*
,
int
);
void
proxyEndInsertRow
(
const
FilterTreeNode
*
,
int
);
void
proxyBeginRemoveRow
(
const
FilterTreeNode
*
,
int
);
void
proxyEndRemoveRow
(
const
FilterTreeNode
*
,
int
);
void
proxyBeginInsertRow
(
const
FilterTreeNode
*
,
int
);
void
proxyEndInsertRow
(
const
FilterTreeNode
*
,
int
);
void
proxyBeginRemoveRow
(
const
FilterTreeNode
*
,
int
);
void
proxyEndRemoveRow
(
const
FilterTreeNode
*
,
int
);
private:
FilterTreeNode
*
indexToNode
(
const
QModelIndex
&
idx
)
const
;
QModelIndex
nodeIndex
(
const
FilterTreeNode
*
node
,
int
row
,
int
column
)
const
;
FilterTreeNode
*
indexToNode
(
const
QModelIndex
&
idx
)
const
;
QModelIndex
nodeIndex
(
const
FilterTreeNode
*
node
,
int
row
,
int
column
)
const
;
public:
FilterTreeModel
(
QObject
*
parent
=
0
);
~
FilterTreeModel
();
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
;
bool
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
=
Qt
::
EditRole
);
Qt
::
ItemFlags
flags
(
const
QModelIndex
&
index
)
const
;
QModelIndex
parent
(
const
QModelIndex
&
ind
)
const
;
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
;
bool
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
);
FilterTreeModel
(
QObject
*
parent
=
0
);
~
FilterTreeModel
();
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
;
bool
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
=
Qt
::
EditRole
);
Qt
::
ItemFlags
flags
(
const
QModelIndex
&
index
)
const
;
QModelIndex
parent
(
const
QModelIndex
&
ind
)
const
;
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
;
bool
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
);
};
#endif
cockatrice/src/keysignals.cpp
View file @
cd4d04be
...
...
@@ -2,48 +2,48 @@
#include
<QKeyEvent>
bool
KeySignals
::
eventFilter
(
QObject
*
/*object*/
,
QEvent
*
event
)
{
QKeyEvent
*
kevent
;
QKeyEvent
*
kevent
;
if
(
event
->
type
()
!=
QEvent
::
KeyPress
)
return
false
;
if
(
event
->
type
()
!=
QEvent
::
KeyPress
)
return
false
;
kevent
=
static_cast
<
QKeyEvent
*>
(
event
);
switch
(
kevent
->
key
())
{
case
Qt
::
Key_Return
:
case
Qt
::
Key_Enter
:
if
(
kevent
->
modifiers
()
&
Qt
::
ControlModifier
)
emit
onCtrlEnter
();
else
emit
onEnter
();
break
;
case
Qt
::
Key_Right
:
if
(
kevent
->
modifiers
()
&
Qt
::
ControlModifier
)
emit
onCtrlRight
();
else
emit
onRight
();
kevent
=
static_cast
<
QKeyEvent
*>
(
event
);
switch
(
kevent
->
key
())
{
case
Qt
::
Key_Return
:
case
Qt
::
Key_Enter
:
if
(
kevent
->
modifiers
()
&
Qt
::
ControlModifier
)
emit
onCtrlEnter
();
else
emit
onEnter
();
break
;
case
Qt
::
Key_Right
:
if
(
kevent
->
modifiers
()
&
Qt
::
ControlModifier
)
emit
onCtrlRight
();
else
emit
onRight
();
if
(
!
filterLROn
)
return
false
;
break
;
case
Qt
::
Key_Left
:
if
(
kevent
->
modifiers
()
&
Qt
::
ControlModifier
)
emit
onCtrlLeft
();
else
emit
onLeft
();
if
(
!
filterLROn
)
return
false
;
break
;
case
Qt
::
Key_Left
:
if
(
kevent
->
modifiers
()
&
Qt
::
ControlModifier
)
emit
onCtrlLeft
();
else
emit
onLeft
();
if
(
!
filterLROn
)
return
false
;
break
;
case
Qt
::
Key_Delete
:
case
Qt
::
Key_Backspace
:
emit
onDelete
();
if
(
!
filterLROn
)
return
false
;
break
;
case
Qt
::
Key_Delete
:
case
Qt
::
Key_Backspace
:
emit
onDelete
();
if
(
!
filterDeleteOn
)
return
false
;
break
;
default:
return
false
;
}
if
(
!
filterDeleteOn
)
return
false
;
break
;
default:
return
false
;
}
return
true
;
return
true
;
}
cockatrice/src/keysignals.h
View file @
cd4d04be
...
...
@@ -2,29 +2,29 @@
#include
<QEvent>
class
KeySignals
:
public
QObject
{
Q_OBJECT
Q_OBJECT
private:
bool
filterDeleteOn
;
bool
filterLROn
;
bool
filterDeleteOn
;
bool
filterLROn
;
signals:
void
onEnter
();
void
onCtrlEnter
();
void
onLeft
();
void
onCtrlLeft
();
void
onRight
();
void
onCtrlRight
();
void
onDelete
();
void
onEnter
();
void
onCtrlEnter
();
void
onLeft
();
void
onCtrlLeft
();
void
onRight
();
void
onCtrlRight
();
void
onDelete
();
protected:
virtual
bool
eventFilter
(
QObject
*
,
QEvent
*
event
);
virtual
bool
eventFilter
(
QObject
*
,
QEvent
*
event
);
public:
KeySignals
()
:
filterDeleteOn
(
true
)
,
filterLROn
(
true
)
{}
void
filterDelete
(
bool
on
)
{
filterDeleteOn
=
on
;
}
void
filterLeftRight
(
bool
on
)
{
filterLROn
=
on
;
}
KeySignals
()
:
filterDeleteOn
(
true
)
,
filterLROn
(
true
)
{}
void
filterDelete
(
bool
on
)
{
filterDeleteOn
=
on
;
}
void
filterLeftRight
(
bool
on
)
{
filterLROn
=
on
;
}
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment