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
3502ec80
Commit
3502ec80
authored
Jun 01, 2009
by
Max-Wilhelm Bruker
Browse files
deck editor
parent
9a277ccc
Changes
8
Show whitespace changes
Inline
Side-by-side
cockatrice/src/carddatabase.cpp
View file @
3502ec80
...
...
@@ -28,6 +28,35 @@ CardInfo::~CardInfo()
delete
pixmap
;
}
QString
CardInfo
::
getMainCardType
()
const
{
QString
result
=
getCardType
();
/*
Legendary Artifact Creature - Golem
Instant // Instant
*/
int
pos
;
if
((
pos
=
result
.
indexOf
(
'-'
))
!=
-
1
)
result
.
remove
(
pos
,
result
.
length
());
if
((
pos
=
result
.
indexOf
(
"//"
))
!=
-
1
)
result
.
remove
(
pos
,
result
.
length
());
result
=
result
.
simplified
();
/*
Legendary Artifact Creature
Instant
*/
if
((
pos
=
result
.
lastIndexOf
(
' '
))
!=
-
1
)
result
=
result
.
mid
(
pos
+
1
);
/*
Creature
Instant
*/
return
result
;
}
void
CardInfo
::
addEdition
(
const
QString
&
edition
)
{
if
(
!
editions
.
contains
(
edition
))
...
...
cockatrice/src/carddatabase.h
View file @
3502ec80
...
...
@@ -28,6 +28,7 @@ public:
QString
getCardType
()
const
{
return
cardtype
;
}
QString
getPowTough
()
const
{
return
powtough
;
}
QStringList
getText
()
const
{
return
text
;
}
QString
getMainCardType
()
const
;
void
addEdition
(
const
QString
&
edition
);
QPixmap
*
getPixmap
();
void
saveToStream
(
QDataStream
&
stream
);
...
...
cockatrice/src/decklist.cpp
View file @
3502ec80
...
...
@@ -7,7 +7,19 @@
#include
"decklist.h"
#include
"carddatabase.h"
QString
DecklistZone
::
getVisibleName
()
const
AbstractDecklistNode
::
AbstractDecklistNode
(
InnerDecklistNode
*
_parent
)
:
parent
(
_parent
)
{
if
(
parent
)
parent
->
append
(
this
);
}
InnerDecklistNode
::~
InnerDecklistNode
()
{
clearTree
();
}
QString
InnerDecklistNode
::
getVisibleName
()
const
{
if
(
name
==
"main"
)
return
QObject
::
tr
(
"Maindeck"
);
...
...
@@ -17,15 +29,35 @@ QString DecklistZone::getVisibleName() const
return
QString
();
}
void
InnerDecklistNode
::
clearTree
()
{
for
(
int
i
=
0
;
i
<
size
();
i
++
)
delete
at
(
i
);
}
int
InnerDecklistNode
::
recursiveCount
()
const
{
int
result
=
0
;
for
(
int
i
=
0
;
i
<
size
();
i
++
)
{
InnerDecklistNode
*
node
=
dynamic_cast
<
InnerDecklistNode
*>
(
at
(
i
));
if
(
node
)
result
+=
node
->
recursiveCount
();
else
result
+=
1
;
}
return
result
;
}
DeckList
::
DeckList
(
CardDatabase
*
_db
,
QObject
*
parent
)
:
QObject
(
parent
),
db
(
_db
)
{
root
=
new
InnerDecklistNode
;
initZones
();
}
DeckList
::~
DeckList
()
{
cleanList
()
;
delete
root
;
}
bool
DeckList
::
loadFromFile_Native
(
QIODevice
*
device
)
...
...
@@ -43,15 +75,14 @@ bool DeckList::loadFromFile_Native(QIODevice *device)
else
if
(
xml
.
name
()
==
"comments"
)
comments
=
xml
.
readElementText
();
else
if
(
xml
.
name
()
==
"zone"
)
{
DecklistZone
*
zone
=
new
DecklistZone
(
xml
.
attributes
().
value
(
"name"
).
toString
());
zones
.
append
(
zone
);
InnerDecklistNode
*
node
=
new
InnerDecklistNode
(
xml
.
attributes
().
value
(
"name"
).
toString
(),
root
);
while
(
!
xml
.
atEnd
())
{
if
(
xml
.
readNext
()
==
QXmlStreamReader
::
EndElement
)
break
;
if
(
xml
.
name
()
==
"card"
)
{
const
int
number
=
xml
.
attributes
().
value
(
"number"
).
toString
().
toInt
();
const
QString
card
=
xml
.
attributes
().
value
(
"name"
).
toString
();
zone
->
append
(
new
DecklistRow
(
number
,
card
)
);
new
DecklistCardNode
(
card
,
number
,
node
);
while
(
!
xml
.
atEnd
())
if
(
xml
.
readNext
()
==
QXmlStreamReader
::
EndElement
)
break
;
...
...
@@ -66,7 +97,7 @@ bool DeckList::loadFromFile_Native(QIODevice *device)
bool
DeckList
::
saveToFile_Native
(
QIODevice
*
device
)
{
QXmlStreamWriter
xml
(
device
);
/*
QXmlStreamWriter xml(device);
xml.setAutoFormatting(true);
xml.writeStartDocument();
...
...
@@ -91,11 +122,11 @@ bool DeckList::saveToFile_Native(QIODevice *device)
xml.writeEndDocument();
return true;
}
*/
}
bool
DeckList
::
loadFromFile_Plain
(
QIODevice
*
device
)
{
initZones
();
/*
initZones();
QTextStream in(device);
while (!in.atEnd()) {
...
...
@@ -125,18 +156,18 @@ bool DeckList::loadFromFile_Plain(QIODevice *device)
zone->append(new DecklistRow(number, line.mid(i + 1)));
}
return true;
}
*/
}
bool
DeckList
::
saveToFile_Plain
(
QIODevice
*
device
)
{
QTextStream
out
(
device
);
/*
QTextStream out(device);
for (int i = 0; i < zones.size(); i++)
for (int j = 0; j < zones[i]->size(); j++) {
DecklistRow *r = zones[i]->at(j);
out << QString("%1%2 %3\n").arg(zones[i]->getName() == "side" ? "SB: " : "").arg(r->getNumber()).arg(r->getCard());
}
return true;
}
*/
}
bool
DeckList
::
loadFromFile
(
const
QString
&
fileName
,
FileFormat
fmt
,
QWidget
*
parent
)
{
...
...
@@ -151,8 +182,8 @@ bool DeckList::loadFromFile(const QString &fileName, FileFormat fmt, QWidget *pa
case
CockatriceFormat
:
result
=
loadFromFile_Native
(
&
file
);
break
;
}
if
(
result
)
{
cacheCardPictures
(
parent
);
emit
deckLoaded
();
cacheCardPictures
(
parent
);
}
return
result
;
}
...
...
@@ -225,39 +256,39 @@ bool DeckList::saveDialog(QWidget *parent)
return
false
;
}
void
DeckList
::
cacheCardPicturesHelper
(
InnerDecklistNode
*
item
,
QProgressDialog
*
progress
)
{
for
(
int
i
=
0
;
i
<
item
->
size
();
i
++
)
{
DecklistCardNode
*
node
=
dynamic_cast
<
DecklistCardNode
*>
(
item
->
at
(
i
));
if
(
node
)
{
db
->
getCard
(
node
->
getName
())
->
getPixmap
();
progress
->
setValue
(
progress
->
value
()
+
1
);
}
else
cacheCardPicturesHelper
(
dynamic_cast
<
InnerDecklistNode
*>
(
item
->
at
(
i
)),
progress
);
}
}
void
DeckList
::
cacheCardPictures
(
QWidget
*
parent
)
{
int
totalCards
=
0
;
for
(
int
i
=
0
;
i
<
zones
.
size
();
i
++
)
totalCards
+=
zones
[
i
]
->
size
();
int
totalCards
=
root
->
recursiveCount
();
QProgressDialog
progress
(
tr
(
"Caching card pictures..."
),
QString
(),
0
,
totalCards
,
parent
);
progress
.
setMinimumDuration
(
1000
);
progress
.
setWindowModality
(
Qt
::
WindowModal
);
for
(
int
i
=
0
;
i
<
zones
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
zones
[
i
]
->
size
();
j
++
)
{
db
->
getCard
(
zones
[
i
]
->
at
(
j
)
->
getCard
())
->
getPixmap
();
progress
.
setValue
(
progress
.
value
()
+
1
);
}
cacheCardPicturesHelper
(
root
,
&
progress
);
}
void
DeckList
::
cleanList
()
{
for
(
int
i
=
0
;
i
<
zones
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
zones
[
i
]
->
size
();
j
++
)
delete
zones
[
i
]
->
at
(
j
);
zones
[
i
]
->
clear
();
delete
zones
[
i
];
}
zones
.
clear
();
root
->
clearTree
();
setName
();
setComments
();
}
void
DeckList
::
initZones
()
{
// possibly Magic specific
/*
// possibly Magic specific
zones.append(new DecklistZone("main"));
zones.append(new DecklistZone("side"));
}
*/
}
cockatrice/src/decklist.h
View file @
3502ec80
...
...
@@ -6,26 +6,45 @@
class
CardDatabase
;
class
QIODevice
;
class
QProgressDialog
;
class
DecklistRow
{
class
InnerDecklistNode
;
class
AbstractDecklistNode
{
protected:
InnerDecklistNode
*
parent
;
public:
AbstractDecklistNode
(
InnerDecklistNode
*
_parent
=
0
);
virtual
bool
hasChildren
()
const
=
0
;
virtual
QString
getName
()
const
=
0
;
const
InnerDecklistNode
*
getParent
()
const
{
return
parent
;
}
};
class
InnerDecklistNode
:
public
AbstractDecklistNode
,
public
QList
<
AbstractDecklistNode
*>
{
private:
int
number
;
QString
card
;
QString
name
;
public:
DecklistRow
(
int
_number
=
1
,
const
QString
&
_card
=
QString
())
:
number
(
_number
),
card
(
_card
)
{
}
int
getNumber
()
const
{
return
number
;
}
void
setNumber
(
int
_number
)
{
number
=
_number
;
}
QString
getCard
()
const
{
return
card
;
}
void
setCard
(
const
QString
&
_card
)
{
card
=
_card
;
}
InnerDecklistNode
(
const
QString
&
_name
=
QString
(),
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistNode
(
_parent
),
name
(
_name
)
{
}
~
InnerDecklistNode
();
bool
hasChildren
()
const
{
return
true
;
}
QString
getName
()
const
{
return
name
;
}
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
virtual
QString
getVisibleName
()
const
;
void
clearTree
();
int
recursiveCount
()
const
;
};
class
Decklist
Zon
e
:
public
QList
<
Decklist
Row
*>
{
class
Decklist
CardNod
e
:
public
Abstract
Decklist
Node
{
private:
QString
name
;
int
number
;
public:
DecklistZone
(
const
QString
&
_name
)
:
name
(
_name
)
{
}
DecklistCardNode
(
const
QString
&
_name
=
QString
(),
int
_number
=
1
,
InnerDecklistNode
*
_parent
=
0
)
:
AbstractDecklistNode
(
_parent
),
name
(
_name
),
number
(
_number
)
{
}
bool
hasChildren
()
const
{
return
false
;
}
int
getNumber
()
const
{
return
number
;
}
void
setNumber
(
int
_number
)
{
number
=
_number
;
}
QString
getName
()
const
{
return
name
;
}
QString
getVisibleName
()
const
;
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
};
class
DeckList
:
public
QObject
{
...
...
@@ -39,7 +58,8 @@ private:
QString
name
,
comments
;
QString
lastFileName
;
FileFormat
lastFileFormat
;
QList
<
DecklistZone
*>
zones
;
InnerDecklistNode
*
root
;
void
cacheCardPicturesHelper
(
InnerDecklistNode
*
item
,
QProgressDialog
*
progress
);
signals:
void
deckLoaded
();
public
slots
:
...
...
@@ -65,8 +85,7 @@ public:
void
cleanList
();
void
initZones
();
int
zoneCount
()
const
{
return
zones
.
size
();
}
DecklistZone
*
getZoneByIndex
(
int
index
)
const
{
return
zones
[
index
];
}
InnerDecklistNode
*
getRoot
()
const
{
return
root
;
}
};
#endif
cockatrice/src/decklistmodel.cpp
View file @
3502ec80
...
...
@@ -9,31 +9,116 @@ DeckListModel::DeckListModel(CardDatabase *_db, QObject *parent)
:
QAbstractItemModel
(
parent
),
db
(
_db
)
{
deckList
=
new
DeckList
(
db
,
this
);
connect
(
deckList
,
SIGNAL
(
deckLoaded
()),
this
,
SLOT
(
resetModel
()));
connect
(
deckList
,
SIGNAL
(
deckLoaded
()),
this
,
SLOT
(
rebuildTree
()));
root
=
new
InnerDecklistNode
;
}
DeckListModel
::~
DeckListModel
()
{
}
void
DeckListModel
::
resetModel
()
void
DeckListModel
::
debugIndexInfo
(
const
QString
&
func
,
const
QModelIndex
&
index
)
const
{
quint32
id
=
index
.
internalId
();
// 32 bit int, from MSB to LSB:
int
zone
=
id
>>
30
;
// 2 bits - zone
int
cardtype
=
(
id
>>
25
)
&
0x1f
;
// 5 bits - card type
int
card
=
(
id
>>
3
)
&
0x3fffff
;
// 22 bits - card
int
column
=
id
&
0x7
;
// 3 bits - column
if
(
index
.
isValid
())
qDebug
(
QString
(
"index: function = %1, zone = %2, cardtype = %3, card = %4, column = %5"
).
arg
(
func
).
arg
(
zone
).
arg
(
cardtype
).
arg
(
card
).
arg
(
column
).
toLatin1
());
else
qDebug
(
QString
(
"index: function = %1, invalid"
).
arg
(
func
).
toLatin1
());
}
void
DeckListModel
::
debugShowTree
(
InnerDecklistNode
*
node
,
int
depth
)
const
{
for
(
int
i
=
0
;
i
<
node
->
size
();
i
++
)
{
DecklistModelCardNode
*
foo
=
dynamic_cast
<
DecklistModelCardNode
*>
(
node
->
at
(
i
));
if
(
!
foo
)
{
InnerDecklistNode
*
bar
=
dynamic_cast
<
InnerDecklistNode
*>
(
node
->
at
(
i
));
qDebug
(
QString
(
"%1%2"
).
arg
(
QString
(
depth
*
4
,
' '
)).
arg
(
bar
->
getName
()).
toLatin1
());
debugShowTree
(
bar
,
depth
+
1
);
}
else
qDebug
(
QString
(
"%1%2 %3"
).
arg
(
QString
(
depth
*
4
,
' '
)).
arg
(
foo
->
getNumber
()).
arg
(
foo
->
getName
()).
toLatin1
());
}
}
void
DeckListModel
::
rebuildTree
()
{
root
->
clearTree
();
InnerDecklistNode
*
listRoot
=
deckList
->
getRoot
();
for
(
int
i
=
0
;
i
<
listRoot
->
size
();
i
++
)
{
InnerDecklistNode
*
currentZone
=
dynamic_cast
<
InnerDecklistNode
*>
(
listRoot
->
at
(
i
));
InnerDecklistNode
*
node
=
new
InnerDecklistNode
(
currentZone
->
getName
(),
root
);
for
(
int
j
=
0
;
j
<
currentZone
->
size
();
j
++
)
{
DecklistCardNode
*
currentCard
=
dynamic_cast
<
DecklistCardNode
*>
(
currentZone
->
at
(
j
));
QString
cardType
=
db
->
getCard
(
currentCard
->
getName
())
->
getMainCardType
();
InnerDecklistNode
*
cardTypeNode
=
dynamic_cast
<
InnerDecklistNode
*>
(
findNode
(
cardType
,
node
));
if
(
!
cardTypeNode
)
cardTypeNode
=
new
InnerDecklistNode
(
cardType
,
node
);
DecklistModelCardNode
*
newCard
=
new
DecklistModelCardNode
(
currentCard
,
cardTypeNode
);
}
}
debugShowTree
(
root
,
0
);
reset
();
}
AbstractDecklistNode
*
DeckListModel
::
findNode
(
const
QString
&
name
,
InnerDecklistNode
*
root
)
const
{
for
(
int
i
=
0
;
i
<
root
->
size
();
i
++
)
if
(
root
->
at
(
i
)
->
getName
()
==
name
)
return
root
->
at
(
i
);
return
0
;
}
AbstractDecklistNode
*
DeckListModel
::
findNode
(
const
QModelIndex
&
index
)
const
{
// debugIndexInfo("findNode", index);
if
(
index
.
isValid
())
{
InnerDecklistNode
*
parentNode
=
dynamic_cast
<
InnerDecklistNode
*>
(
findNode
(
index
.
parent
()));
return
parentNode
->
at
(
index
.
row
());
}
else
return
root
;
}
int
DeckListModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
if
(
!
parent
.
isValid
())
// parent = root
return
deckList
->
zoneCount
();
else
if
(
!
parent
.
parent
().
isValid
())
// parent = zone root
return
deckList
->
getZoneByIndex
(
parent
.
row
())
->
size
();
else
// parent = card
// debugIndexInfo("rowCount", parent);
InnerDecklistNode
*
node
=
dynamic_cast
<
InnerDecklistNode
*>
(
findNode
(
parent
));
if
(
node
)
{
// qDebug(QString(" rowCount: return %1").arg(node->size()).toLatin1());
return
node
->
size
();
}
else
{
// qDebug(" rowCount: return const 0");
return
0
;
}
}
bool
DeckListModel
::
hasChildren
(
const
QModelIndex
&
parent
)
const
{
return
!
parent
.
parent
().
isValid
();
// debugIndexInfo("hasChildren", parent);
if
(
!
parent
.
isValid
()
&&
root
->
size
())
return
true
;
if
(
parent
.
column
()
!=
0
)
return
false
;
/*
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(findNode(parent));
if (!node)
qDebug("line 109: return false");
return false;
}
qDebug(QString("line 112: return %1").arg(node->size()).toLatin1());
return node->size();
if (!parent.isValid())
return true;
qDebug(QString(" hasChildren: return %1").arg((!parent.column() && (((parent.internalId() >> 3) & 0x3fffff) == 0x3fffff))).toLatin1());
*/
// An item (possibly) has children if its column is zero and its card is -1.
return
(
!
parent
.
column
()
&&
(((
parent
.
internalId
()
>>
3
)
&
0x3fffff
)
==
0x3fffff
));
}
int
DeckListModel
::
columnCount
(
const
QModelIndex
&
/*parent*/
)
const
...
...
@@ -43,14 +128,17 @@ int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
QVariant
DeckListModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
// debugIndexInfo("data", index);
if
(
!
index
.
isValid
())
return
QVariant
();
if
(
index
.
column
()
>=
2
)
return
QVariant
();
if
(
!
index
.
parent
().
isValid
())
{
if
(
index
.
row
()
>=
deckList
->
zoneCount
()
)
AbstractDecklistNode
*
tempNode
=
findNode
(
index
);
if
(
tempNode
==
root
)
return
QVariant
();
if
(
tempNode
->
hasChildren
())
{
switch
(
role
)
{
case
Qt
::
FontRole
:
{
QFont
f
;
...
...
@@ -59,10 +147,11 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
}
case
Qt
::
DisplayRole
:
case
Qt
::
EditRole
:
{
DecklistZone
*
zone
=
deckList
->
getZoneByIndex
(
index
.
row
());
switch
(
index
.
column
())
{
case
0
:
return
zone
->
getVisibleName
();
case
1
:
return
QVariant
();
case
0
:
{
InnerDecklistNode
*
node
=
dynamic_cast
<
InnerDecklistNode
*>
(
tempNode
);
return
node
->
getVisibleName
();
}
default:
return
QVariant
();
}
}
...
...
@@ -71,16 +160,13 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
default:
return
QVariant
();
}
}
else
{
DecklistZone
*
zone
=
deckList
->
getZoneByIndex
(
index
.
parent
().
row
());
if
(
index
.
row
()
>=
zone
->
size
())
return
QVariant
();
switch
(
role
)
{
case
Qt
::
DisplayRole
:
case
Qt
::
EditRole
:
{
Decklist
Row
*
r
=
zone
->
at
(
index
.
row
()
);
Decklist
ModelCardNode
*
node
=
dynamic_cast
<
DecklistModelCardNode
*>
(
tempNode
);
switch
(
index
.
column
())
{
case
0
:
return
r
->
getNumber
();
case
1
:
return
r
->
get
Card
();
case
0
:
return
node
->
getNumber
();
case
1
:
return
node
->
get
Name
();
default:
return
QVariant
();
}
}
...
...
@@ -108,26 +194,53 @@ QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int
QModelIndex
DeckListModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
{
int
id
;
if
(
!
parent
.
isValid
())
id
=
-
((
row
+
1
)
*
1000
+
column
);
else
id
=
parent
.
row
()
*
1000000
+
row
*
1000
+
column
;
return
createIndex
(
row
,
column
,
id
);
// debugIndexInfo("index", parent);
// for explanation of the bit shifting, look at parent()
int
indexZone
,
indexCardType
,
indexCard
;
if
(
!
parent
.
isValid
())
{
indexZone
=
row
;
indexCardType
=
0x1f
;
indexCard
=
0x3fffff
;
}
else
{
quint32
pid
=
parent
.
internalId
();
indexZone
=
pid
>>
30
;
int
pcardtype
=
(
pid
>>
25
)
&
0x1f
;
if
(
pcardtype
==
0x1f
)
{
indexCardType
=
row
;
indexCard
=
0x3fffff
;
}
else
{
indexCardType
=
pcardtype
;
indexCard
=
row
;
}
}
// qDebug(QString("index(): zone = %1, cardtype = %2, card = %3, column = %4").arg(indexZone).arg(indexCardType).arg(indexCard).arg(column).toLatin1());
return
createIndex
(
row
,
column
,
(
indexZone
<<
30
)
+
(
indexCardType
<<
25
)
+
(
indexCard
<<
3
)
+
column
);
}
QModelIndex
DeckListModel
::
parent
(
const
QModelIndex
&
ind
)
const
{
if
((
int
)
ind
.
internalId
()
<
0
)
// debugIndexInfo("parent", ind);
quint32
id
=
ind
.
internalId
();
// 32 bit int, from MSB to LSB:
int
zone
=
id
>>
30
;
// 2 bits - zone
int
cardtype
=
(
id
>>
25
)
&
0x1f
;
// 5 bits - card type
int
card
=
(
id
>>
3
)
&
0x3fffff
;
// 22 bits - card
// int column = id & 0x7; // 3 bits - column
if
(
cardtype
==
0x1f
)
return
QModelIndex
();
else
if
(
card
==
0x3fffff
)
return
index
(
zone
,
0
);
else
return
index
(
ind
.
internalId
()
/
1000000
,
0
);
return
index
(
cardtype
,
0
,
index
(
zone
,
0
)
)
;
}
Qt
::
ItemFlags
DeckListModel
::
flags
(
const
QModelIndex
&
index
)
const
{
Qt
::
ItemFlags
result
=
Qt
::
ItemIsEnabled
;
if
(
index
.
parent
().
isV
al
i
d
())
{
if
((
(
index
.
intern
al
I
d
()
>>
3
)
&
0x3fffff
)
!=
0x3fffff
)
{
result
|=
Qt
::
ItemIsSelectable
;
if
(
index
.
column
()
==
0
)
result
|=
Qt
::
ItemIsEditable
;
...
...
@@ -137,12 +250,13 @@ Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
bool
DeckListModel
::
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
{
if
(
!
index
.
isValid
()
||
!
index
.
parent
().
isValid
()
||
role
!=
Qt
::
EditRole
)
DecklistModelCardNode
*
node
=
dynamic_cast
<
DecklistModelCardNode
*>
(
findNode
(
index
));
if
(
!
node
||
(
role
!=
Qt
::
EditRole
))
return
false
;
switch
(
index
.
column
())
{
case
0
:
de
ckList
->
getZoneByIndex
(
index
.
parent
().
row
())
->
at
(
index
.
row
())
->
setNumber
(
value
.
toInt
());
break
;
case
1
:
de
ckList
->
getZoneByIndex
(
index
.
parent
().
row
())
->
at
(
index
.
row
())
->
set
Card
(
value
.
toString
());
break
;
case
0
:
no
de
->
setNumber
(
value
.
toInt
());
break
;
case
1
:
no
de
->
set
Name
(
value
.
toString
());
break
;
default:
return
false
;
}
emit
dataChanged
(
index
,
index
);
...
...
@@ -151,21 +265,30 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int
bool
DeckListModel
::
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
)
{
// Inserting zones is not supported.
if
(
!
parent
.
isValid
())
/* DecklistNode *node = findNode(parent);
if (
row + count > node->size
())
return false;
beginRemoveRows(parent, row, row + count - 1);
for (int i = 0; i < count; i++)
de
ckList
->
getZoneByIndex
(
parent
.
row
())
->
remov
eAt
(
row
);
de
lete node->tak
eAt(row);
endRemoveRows();
return true;
*/
}
/*
void DeckListModel::insertCard(...)
{
}
void DeckListModel::removeCard(...)
{
}
*/
bool
DeckListModel
::
insertRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
)
{
/*
// Inserting zones is not supported.
if (!parent.isValid())
return false;
...
...
@@ -177,7 +300,7 @@ bool DeckListModel::insertRows(int row, int count, const QModelIndex &parent)
endInsertRows();
return true;
}
*/
}
void
DeckListModel
::
cleanList
()
{
...
...
cockatrice/src/decklistmodel.h
View file @
3502ec80
...
...
@@ -7,10 +7,22 @@
class
CardDatabase
;
class
DecklistModelCardNode
:
public
AbstractDecklistNode
{
private:
DecklistCardNode
*
dataNode
;
public:
DecklistModelCardNode
(
DecklistCardNode
*
_dataNode
,
InnerDecklistNode
*
_parent
)
:
AbstractDecklistNode
(
_parent
),
dataNode
(
_dataNode
)
{
}
bool
hasChildren
()
const
{
return
false
;
}
inline
int
getNumber
()
const
{
return
dataNode
->
getNumber
();
}
inline
void
setNumber
(
int
_number
)
{
dataNode
->
setNumber
(
_number
);
}
inline
QString
getName
()
const
{
return
dataNode
->
getName
();
}
inline
void
setName
(
const
QString
&
_name
)
{
dataNode
->
setName
(
_name
);
}
};
class
DeckListModel
:
public
QAbstractItemModel
{
Q_OBJECT
private
slots
:
void
re
setModel
();
void
re
buildTree
();
public:
DeckListModel
(
CardDatabase
*
_db
,
QObject
*
parent
=
0
);
~
DeckListModel
();
...
...
@@ -27,11 +39,14 @@ public:
bool
insertRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
=
QModelIndex
());
void
cleanList
();
DeckList
*
getDeckList
()
const
{
return
deckList
;
}
bool
loadFromFile
(
const
QString
&
fileName
,
DeckList
::
FileFormat
fmt
);
bool
saveToFile
(
const
QString
&
fileName
,
DeckList
::
FileFormat
fmt
);
private:
CardDatabase
*
db
;
DeckList
*
deckList
;
InnerDecklistNode
*
root
;
AbstractDecklistNode
*
findNode
(
const
QString
&
name
,
InnerDecklistNode
*
root
)
const
;
AbstractDecklistNode
*
findNode
(
const
QModelIndex
&
index
)
const
;
void
debugIndexInfo
(
const
QString
&
func
,
const
QModelIndex
&
index
)
const
;
void
debugShowTree
(
InnerDecklistNode
*
node
,
int
depth
)
const
;
};
#endif
cockatrice/src/dlg_startgame.cpp
View file @
3502ec80
...
...
@@ -45,7 +45,7 @@ void DlgStartGame::actLoad()
QStringList
DlgStartGame
::
getDeckList
()
const
{
QStringList
result
;
DeckList
*
deckList
=
tableModel
->
getDeckList
();
/*
DeckList *deckList = tableModel->getDeckList();
for (int i = 0; i < deckList->zoneCount(); i++) {
DecklistZone *zone = deckList->getZoneByIndex(i);
for (int j = 0; j < zone->size(); j++) {
...
...
@@ -54,5 +54,5 @@ QStringList DlgStartGame::getDeckList() const
result << QString("%1%2").arg(zone->getName() == "side" ? "SB:" : "").arg(r->getCard());
}
}
return
result
;
*/
return
result
;
}
cockatrice/src/window_deckeditor.cpp
View file @
3502ec80
...
...
@@ -91,7 +91,7 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
aSaveDeck
->
setShortcuts
(
QKeySequence
::
Save
);
connect
(
aSaveDeck
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actSaveDeck
()));
aSaveDeckAs
=
new
QAction
(
tr
(
"&Save deck as..."
),
this
);
aSaveDeckAs
->
setShortcuts
(
QKeySequence
::
SaveAs
);
//
aSaveDeckAs->setShortcuts(QKeySequence::SaveAs);
connect
(
aSaveDeckAs
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actSaveDeckAs
()));
aClose
=
new
QAction
(
tr
(
"&Close"
),
this
);
aClose
->
setShortcut
(
tr
(
"Ctrl+Q"
));
...
...
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