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
f48f386f
Commit
f48f386f
authored
Nov 19, 2014
by
Fabio Bas
Browse files
Sets window: implemented save and restore buttons
parent
ac43fa23
Changes
4
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/setsmodel.cpp
View file @
f48f386f
...
@@ -90,6 +90,10 @@ bool SetsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int r
...
@@ -90,6 +90,10 @@ bool SetsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int r
for
(
int
i
=
0
;
i
<
sets
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
sets
.
size
();
i
++
)
sets
[
i
]
->
setSortKey
(
i
);
sets
[
i
]
->
setSortKey
(
i
);
sets
.
sortByKey
();
emit
dataChanged
(
index
(
0
,
0
),
index
(
rowCount
()
-
1
,
columnCount
()
-
1
));
return
true
;
return
true
;
}
}
...
@@ -104,3 +108,17 @@ SetsProxyModel::SetsProxyModel(QObject *parent)
...
@@ -104,3 +108,17 @@ SetsProxyModel::SetsProxyModel(QObject *parent)
setDynamicSortFilter
(
true
);
setDynamicSortFilter
(
true
);
}
}
void
SetsProxyModel
::
saveOrder
()
{
int
numRows
=
rowCount
();
SetsModel
*
model
=
(
SetsModel
*
)
sourceModel
();
for
(
int
row
=
0
;
row
<
numRows
;
++
row
)
{
QModelIndex
idx
=
index
(
row
,
0
);
int
oldRow
=
data
(
idx
,
Qt
::
DisplayRole
).
toInt
();
CardSet
*
temp
=
model
->
sets
.
at
(
oldRow
);
temp
->
setSortKey
(
row
);
}
model
->
sets
.
sortByKey
();
emit
model
->
dataChanged
(
model
->
index
(
0
,
0
),
model
->
index
(
model
->
rowCount
()
-
1
,
model
->
columnCount
()
-
1
));
}
cockatrice/src/setsmodel.h
View file @
f48f386f
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
#include
<QMimeData>
#include
<QMimeData>
#include
"carddatabase.h"
#include
"carddatabase.h"
class
SetsProxyModel
;
class
SetsMimeData
:
public
QMimeData
{
class
SetsMimeData
:
public
QMimeData
{
Q_OBJECT
Q_OBJECT
private:
private:
...
@@ -18,6 +20,7 @@ public:
...
@@ -18,6 +20,7 @@ public:
class
SetsModel
:
public
QAbstractTableModel
{
class
SetsModel
:
public
QAbstractTableModel
{
Q_OBJECT
Q_OBJECT
friend
class
SetsProxyModel
;
private:
private:
static
const
int
NUM_COLS
=
5
;
static
const
int
NUM_COLS
=
5
;
SetList
sets
;
SetList
sets
;
...
@@ -42,5 +45,6 @@ class SetsProxyModel : public QSortFilterProxyModel {
...
@@ -42,5 +45,6 @@ class SetsProxyModel : public QSortFilterProxyModel {
Q_OBJECT
Q_OBJECT
public:
public:
SetsProxyModel
(
QObject
*
parent
=
0
);
SetsProxyModel
(
QObject
*
parent
=
0
);
void
saveOrder
();
};
};
#endif
#endif
cockatrice/src/window_sets.cpp
View file @
f48f386f
...
@@ -2,8 +2,9 @@
...
@@ -2,8 +2,9 @@
#include
"setsmodel.h"
#include
"setsmodel.h"
#include
"main.h"
#include
"main.h"
#include
<QTreeView>
#include
<QTreeView>
#include
<Q
HBox
Layout>
#include
<Q
Grid
Layout>
#include
<QHeaderView>
#include
<QHeaderView>
#include
<QPushButton>
WndSets
::
WndSets
(
QWidget
*
parent
)
WndSets
::
WndSets
(
QWidget
*
parent
)
:
QMainWindow
(
parent
)
:
QMainWindow
(
parent
)
...
@@ -30,8 +31,15 @@ WndSets::WndSets(QWidget *parent)
...
@@ -30,8 +31,15 @@ WndSets::WndSets(QWidget *parent)
view
->
header
()
->
setSectionResizeMode
(
SetsModel
::
LongNameCol
,
QHeaderView
::
ResizeToContents
);
view
->
header
()
->
setSectionResizeMode
(
SetsModel
::
LongNameCol
,
QHeaderView
::
ResizeToContents
);
#endif
#endif
QHBoxLayout
*
mainLayout
=
new
QHBoxLayout
;
saveButton
=
new
QPushButton
(
tr
(
"Save sets order"
));
mainLayout
->
addWidget
(
view
);
connect
(
saveButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actSave
()));
restoreButton
=
new
QPushButton
(
tr
(
"Restore saved sets order"
));
connect
(
restoreButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actRestore
()));
QGridLayout
*
mainLayout
=
new
QGridLayout
;
mainLayout
->
addWidget
(
view
,
0
,
0
,
1
,
2
);
mainLayout
->
addWidget
(
saveButton
,
1
,
0
,
1
,
1
);
mainLayout
->
addWidget
(
restoreButton
,
1
,
1
,
1
,
1
);
QWidget
*
centralWidget
=
new
QWidget
;
QWidget
*
centralWidget
=
new
QWidget
;
centralWidget
->
setLayout
(
mainLayout
);
centralWidget
->
setLayout
(
mainLayout
);
...
@@ -44,3 +52,13 @@ WndSets::WndSets(QWidget *parent)
...
@@ -44,3 +52,13 @@ WndSets::WndSets(QWidget *parent)
WndSets
::~
WndSets
()
WndSets
::~
WndSets
()
{
{
}
}
void
WndSets
::
actSave
()
{
proxyModel
->
saveOrder
();
}
void
WndSets
::
actRestore
()
{
view
->
sortByColumn
(
SetsModel
::
SortKeyCol
,
Qt
::
AscendingOrder
);
}
cockatrice/src/window_sets.h
View file @
f48f386f
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
class
SetsModel
;
class
SetsModel
;
class
SetsProxyModel
;
class
SetsProxyModel
;
class
QTreeView
;
class
QTreeView
;
class
QPushButton
;
class
CardDatabase
;
class
CardDatabase
;
class
WndSets
:
public
QMainWindow
{
class
WndSets
:
public
QMainWindow
{
...
@@ -14,9 +15,13 @@ private:
...
@@ -14,9 +15,13 @@ private:
SetsModel
*
model
;
SetsModel
*
model
;
SetsProxyModel
*
proxyModel
;
SetsProxyModel
*
proxyModel
;
QTreeView
*
view
;
QTreeView
*
view
;
QPushButton
*
saveButton
,
*
restoreButton
;
public:
public:
WndSets
(
QWidget
*
parent
=
0
);
WndSets
(
QWidget
*
parent
=
0
);
~
WndSets
();
~
WndSets
();
private
slots
:
void
actSave
();
void
actRestore
();
};
};
#endif
#endif
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