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++)
|
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)
|
||||||
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));
|
||||||
|
}
|
||||||
|
|
|
@ -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:
|
||||||
|
|
||||||
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 {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SetsProxyModel(QObject *parent = 0);
|
SetsProxyModel(QObject *parent = 0);
|
||||||
|
void saveOrder();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
#include "setsmodel.h"
|
#include "setsmodel.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
#include <QHBoxLayout>
|
#include <QGridLayout>
|
||||||
#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)
|
||||||
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)
|
||||||
WndSets::~WndSets()
|
WndSets::~WndSets()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WndSets::actSave()
|
||||||
|
{
|
||||||
|
proxyModel->saveOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WndSets::actRestore()
|
||||||
|
{
|
||||||
|
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
||||||
|
}
|
||||||
|
|
|
@ -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:
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue