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
841b91bc
Commit
841b91bc
authored
Oct 12, 2009
by
Max-Wilhelm Bruker
Browse files
deck editor improvement
parent
9f353401
Changes
4
Show whitespace changes
Inline
Side-by-side
cockatrice/src/carddatabasemodel.cpp
View file @
841b91bc
...
...
@@ -63,29 +63,9 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
}
}
class
CardInfoCompare
{
private:
int
column
;
Qt
::
SortOrder
order
;
public:
CardInfoCompare
(
int
_column
,
Qt
::
SortOrder
_order
)
:
column
(
_column
),
order
(
_order
)
{
}
inline
bool
operator
()(
CardInfo
*
a
,
CardInfo
*
b
)
const
{
bool
result
;
switch
(
column
)
{
case
0
:
result
=
(
a
->
getName
()
<
b
->
getName
());
break
;
case
1
:
result
=
(
a
->
getSets
().
at
(
0
)
->
getShortName
()
<
b
->
getSets
().
at
(
0
)
->
getShortName
());
break
;
case
2
:
result
=
(
a
->
getManaCost
()
<
b
->
getManaCost
());
break
;
case
3
:
result
=
(
a
->
getCardType
()
<
b
->
getCardType
());
break
;
case
4
:
result
=
(
a
->
getPowTough
()
<
b
->
getPowTough
());
break
;
default:
result
=
false
;
}
return
(
order
==
Qt
::
AscendingOrder
)
^
result
;
}
};
void
CardDatabaseModel
::
sort
(
int
column
,
Qt
::
SortOrder
order
)
CardDatabaseDisplayModel
::
CardDatabaseDisplayModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
CardInfoCompare
cmp
(
column
,
order
);
q
Sort
(
cardList
.
begin
(),
cardList
.
end
(),
cmp
);
setFilterCaseSensitivity
(
Qt
::
CaseInsensitive
);
set
Sort
CaseSensitivity
(
Qt
::
CaseInsensitive
);
}
cockatrice/src/carddatabasemodel.h
View file @
841b91bc
...
...
@@ -2,6 +2,7 @@
#define CARDDATABASEMODEL_H
#include
<QAbstractListModel>
#include
<QSortFilterProxyModel>
#include
<QList>
#include
"carddatabase.h"
...
...
@@ -14,10 +15,15 @@ public:
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
=
Qt
::
DisplayRole
)
const
;
void
sort
(
int
column
,
Qt
::
SortOrder
order
=
Qt
::
AscendingOrder
);
private:
QList
<
CardInfo
*>
cardList
;
CardDatabase
*
db
;
};
class
CardDatabaseDisplayModel
:
public
QSortFilterProxyModel
{
Q_OBJECT
public:
CardDatabaseDisplayModel
(
QObject
*
parent
=
0
);
};
#endif
cockatrice/src/window_deckeditor.cpp
View file @
841b91bc
...
...
@@ -19,11 +19,15 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
searchLayout
->
addWidget
(
searchLabel
);
searchLayout
->
addWidget
(
searchEdit
);
databaseModel
=
new
CardDatabaseModel
(
db
);
databaseModel
=
new
CardDatabaseModel
(
db
,
this
);
databaseDisplayModel
=
new
CardDatabaseDisplayModel
(
this
);
databaseDisplayModel
->
setSourceModel
(
databaseModel
);
databaseDisplayModel
->
sort
(
0
,
Qt
::
AscendingOrder
);
databaseView
=
new
QTreeView
();
databaseView
->
setModel
(
databaseModel
);
databaseView
->
setModel
(
database
Display
Model
);
databaseView
->
setUniformRowHeights
(
true
);
databaseView
->
setSortingEnabled
(
true
);
databaseView
->
sortByColumn
(
0
,
Qt
::
AscendingOrder
);
databaseView
->
resizeColumnToContents
(
0
);
connect
(
databaseView
->
selectionModel
(),
SIGNAL
(
currentRowChanged
(
const
QModelIndex
&
,
const
QModelIndex
&
)),
this
,
SLOT
(
updateCardInfoLeft
(
const
QModelIndex
&
,
const
QModelIndex
&
)));
connect
(
databaseView
,
SIGNAL
(
doubleClicked
(
const
QModelIndex
&
)),
this
,
SLOT
(
actAddCard
()));
...
...
@@ -173,10 +177,7 @@ void WndDeckEditor::updateCardInfoRight(const QModelIndex ¤t, const QModel
void
WndDeckEditor
::
updateSearch
(
const
QString
&
search
)
{
QModelIndexList
matches
=
databaseModel
->
match
(
databaseModel
->
index
(
0
,
0
),
Qt
::
DisplayRole
,
search
);
if
(
matches
.
isEmpty
())
return
;
databaseView
->
selectionModel
()
->
setCurrentIndex
(
matches
[
0
],
QItemSelectionModel
::
SelectCurrent
);
databaseDisplayModel
->
setFilterRegExp
(
search
);
}
bool
WndDeckEditor
::
confirmClose
()
...
...
@@ -279,7 +280,7 @@ void WndDeckEditor::addCardHelper(const QString &zoneName)
const
QModelIndex
currentIndex
=
databaseView
->
selectionModel
()
->
currentIndex
();
if
(
!
currentIndex
.
isValid
())
return
;
const
QString
cardName
=
databaseModel
->
index
(
currentIndex
.
row
(),
0
).
data
().
toString
();
const
QString
cardName
=
currentIndex
.
sibling
(
currentIndex
.
row
(),
0
).
data
().
toString
();
QModelIndex
newCardIndex
=
deckModel
->
addCard
(
cardName
,
zoneName
);
recursiveExpand
(
newCardIndex
);
...
...
cockatrice/src/window_deckeditor.h
View file @
841b91bc
...
...
@@ -7,6 +7,7 @@
class
CardDatabase
;
class
CardDatabaseModel
;
class
CardDatabaseDisplayModel
;
class
DeckListModel
;
class
QTreeView
;
class
QTableView
;
...
...
@@ -46,6 +47,7 @@ private:
CardDatabase
*
db
;
CardDatabaseModel
*
databaseModel
;
CardDatabaseDisplayModel
*
databaseDisplayModel
;
DeckListModel
*
deckModel
;
QTreeView
*
databaseView
;
QTreeView
*
deckView
;
...
...
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