Sets window: implemented save and restore buttons
This commit is contained in:
parent
ac43fa23b9
commit
f48f386f35
4 changed files with 48 additions and 3 deletions
|
@ -90,6 +90,10 @@ bool SetsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int r
|
|||
for (int i = 0; i < sets.size(); i++)
|
||||
sets[i]->setSortKey(i);
|
||||
|
||||
sets.sortByKey();
|
||||
|
||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -104,3 +108,17 @@ SetsProxyModel::SetsProxyModel(QObject *parent)
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <QMimeData>
|
||||
#include "carddatabase.h"
|
||||
|
||||
class SetsProxyModel;
|
||||
|
||||
class SetsMimeData : public QMimeData {
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
@ -18,6 +20,7 @@ public:
|
|||
|
||||
class SetsModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
friend class SetsProxyModel;
|
||||
private:
|
||||
static const int NUM_COLS = 5;
|
||||
SetList sets;
|
||||
|
@ -42,5 +45,6 @@ class SetsProxyModel : public QSortFilterProxyModel {
|
|||
Q_OBJECT
|
||||
public:
|
||||
SetsProxyModel(QObject *parent = 0);
|
||||
void saveOrder();
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
#include "setsmodel.h"
|
||||
#include "main.h"
|
||||
#include <QTreeView>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QPushButton>
|
||||
|
||||
WndSets::WndSets(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
|
@ -30,8 +31,15 @@ WndSets::WndSets(QWidget *parent)
|
|||
view->header()->setSectionResizeMode(SetsModel::LongNameCol, QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(view);
|
||||
saveButton = new QPushButton(tr("Save sets order"));
|
||||
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;
|
||||
centralWidget->setLayout(mainLayout);
|
||||
|
@ -44,3 +52,13 @@ WndSets::WndSets(QWidget *parent)
|
|||
WndSets::~WndSets()
|
||||
{
|
||||
}
|
||||
|
||||
void WndSets::actSave()
|
||||
{
|
||||
proxyModel->saveOrder();
|
||||
}
|
||||
|
||||
void WndSets::actRestore()
|
||||
{
|
||||
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
class SetsModel;
|
||||
class SetsProxyModel;
|
||||
class QTreeView;
|
||||
class QPushButton;
|
||||
class CardDatabase;
|
||||
|
||||
class WndSets : public QMainWindow {
|
||||
|
@ -14,9 +15,13 @@ private:
|
|||
SetsModel *model;
|
||||
SetsProxyModel *proxyModel;
|
||||
QTreeView *view;
|
||||
QPushButton *saveButton, *restoreButton;
|
||||
public:
|
||||
WndSets(QWidget *parent = 0);
|
||||
~WndSets();
|
||||
private slots:
|
||||
void actSave();
|
||||
void actRestore();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue