Re-added save and restore buttons
This commit is contained in:
parent
e48a815d25
commit
36ed4480c2
4 changed files with 55 additions and 14 deletions
|
@ -97,30 +97,49 @@ void SetsModel::swapRows(int oldRow, int newRow)
|
||||||
sets.insert(newRow, temp);
|
sets.insert(newRow, temp);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
for (int i = 0; i < sets.size(); i++)
|
|
||||||
sets[i]->setSortKey(i);
|
|
||||||
|
|
||||||
sets.sortByKey();
|
|
||||||
|
|
||||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetsModel::sort(int column, Qt::SortOrder order)
|
void SetsModel::sort(int column, Qt::SortOrder order)
|
||||||
{
|
{
|
||||||
QMap<QString, CardSet *> setMap;
|
QMap<QVariant, CardSet *> setMap;
|
||||||
int numRows = rowCount();
|
int numRows = rowCount();
|
||||||
int row;
|
int row;
|
||||||
|
|
||||||
for(row = 0; row < numRows; ++row)
|
for(row = 0; row < numRows; ++row)
|
||||||
setMap.insertMulti(index(row, column).data().toString(), sets.at(row));
|
setMap.insertMulti(index(row, column).data(), sets.at(row));
|
||||||
|
|
||||||
row = (order == Qt::AscendingOrder) ? 0 : numRows - 1;
|
|
||||||
|
QList<CardSet *> tmp = setMap.values();
|
||||||
|
sets.clear();
|
||||||
|
if(order == Qt::AscendingOrder)
|
||||||
|
{
|
||||||
|
for(row = 0; row < tmp.size(); row++) {
|
||||||
|
sets.append(tmp.at(row));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(row = tmp.size() - 1; row >= 0; row--) {
|
||||||
|
sets.append(tmp.at(row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach(CardSet * set, setMap)
|
emit dataChanged(index(0, 0), index(numRows - 1, columnCount() - 1));
|
||||||
set->setSortKey((order == Qt::AscendingOrder) ? row++ : row--);
|
}
|
||||||
|
|
||||||
|
void SetsModel::save()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < sets.size(); i++)
|
||||||
|
sets[i]->setSortKey(i);
|
||||||
|
|
||||||
sets.sortByKey();
|
sets.sortByKey();
|
||||||
emit dataChanged(index(0, 0), index(numRows - 1, columnCount() - 1));
|
}
|
||||||
|
|
||||||
|
void SetsModel::restore(CardDatabase *db)
|
||||||
|
{
|
||||||
|
sets = db->getSetList();
|
||||||
|
sets.sortByKey();
|
||||||
|
|
||||||
|
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SetsModel::mimeTypes() const
|
QStringList SetsModel::mimeTypes() const
|
||||||
|
|
|
@ -40,6 +40,8 @@ public:
|
||||||
QStringList mimeTypes() const;
|
QStringList mimeTypes() const;
|
||||||
void swapRows(int oldRow, int newRow);
|
void swapRows(int oldRow, int newRow);
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
|
void save();
|
||||||
|
void restore(CardDatabase *db);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,8 +13,6 @@ WndSets::WndSets(QWidget *parent)
|
||||||
model = new SetsModel(db, this);
|
model = new SetsModel(db, this);
|
||||||
view = new QTreeView;
|
view = new QTreeView;
|
||||||
view->setModel(model);
|
view->setModel(model);
|
||||||
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
|
||||||
view->setColumnHidden(SetsModel::SortKeyCol, true);
|
|
||||||
|
|
||||||
view->setAlternatingRowColors(true);
|
view->setAlternatingRowColors(true);
|
||||||
view->setUniformRowHeights(true);
|
view->setUniformRowHeights(true);
|
||||||
|
@ -36,6 +34,13 @@ WndSets::WndSets(QWidget *parent)
|
||||||
view->header()->setSectionResizeMode(SetsModel::LongNameCol, QHeaderView::ResizeToContents);
|
view->header()->setSectionResizeMode(SetsModel::LongNameCol, QHeaderView::ResizeToContents);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
||||||
|
view->setColumnHidden(SetsModel::SortKeyCol, true);
|
||||||
|
|
||||||
|
saveButton = new QPushButton(tr("Save set ordering"));
|
||||||
|
connect(saveButton, SIGNAL(clicked()), this, SLOT(actSave()));
|
||||||
|
restoreButton = new QPushButton(tr("Restore saved set ordering"));
|
||||||
|
connect(restoreButton, SIGNAL(clicked()), this, SLOT(actRestore()));
|
||||||
upButton = new QPushButton(tr("Move selected set up"));
|
upButton = new QPushButton(tr("Move selected set up"));
|
||||||
connect(upButton, SIGNAL(clicked()), this, SLOT(actUp()));
|
connect(upButton, SIGNAL(clicked()), this, SLOT(actUp()));
|
||||||
downButton = new QPushButton(tr("Move selected set down"));
|
downButton = new QPushButton(tr("Move selected set down"));
|
||||||
|
@ -62,6 +67,9 @@ WndSets::WndSets(QWidget *parent)
|
||||||
mainLayout->addWidget(topButton, 1, 1, 1, 1);
|
mainLayout->addWidget(topButton, 1, 1, 1, 1);
|
||||||
mainLayout->addWidget(bottomButton, 2, 1, 1, 1);
|
mainLayout->addWidget(bottomButton, 2, 1, 1, 1);
|
||||||
|
|
||||||
|
mainLayout->addWidget(saveButton, 3, 0, 1, 1);
|
||||||
|
mainLayout->addWidget(restoreButton, 3, 1, 1, 1);
|
||||||
|
|
||||||
QWidget *centralWidget = new QWidget;
|
QWidget *centralWidget = new QWidget;
|
||||||
centralWidget->setLayout(mainLayout);
|
centralWidget->setLayout(mainLayout);
|
||||||
setCentralWidget(centralWidget);
|
setCentralWidget(centralWidget);
|
||||||
|
@ -74,6 +82,16 @@ WndSets::~WndSets()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WndSets::actSave()
|
||||||
|
{
|
||||||
|
model->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WndSets::actRestore()
|
||||||
|
{
|
||||||
|
model->restore(db);
|
||||||
|
}
|
||||||
|
|
||||||
void WndSets::actToggleButtons(const QItemSelection & selected, const QItemSelection &)
|
void WndSets::actToggleButtons(const QItemSelection & selected, const QItemSelection &)
|
||||||
{
|
{
|
||||||
bool disabled = selected.empty();
|
bool disabled = selected.empty();
|
||||||
|
|
|
@ -15,13 +15,15 @@ class WndSets : public QMainWindow {
|
||||||
private:
|
private:
|
||||||
SetsModel *model;
|
SetsModel *model;
|
||||||
QTreeView *view;
|
QTreeView *view;
|
||||||
QPushButton *upButton, *downButton, *bottomButton, *topButton;
|
QPushButton *saveButton, *restoreButton, *upButton, *downButton, *bottomButton, *topButton;
|
||||||
public:
|
public:
|
||||||
WndSets(QWidget *parent = 0);
|
WndSets(QWidget *parent = 0);
|
||||||
~WndSets();
|
~WndSets();
|
||||||
protected:
|
protected:
|
||||||
void selectRow(int row);
|
void selectRow(int row);
|
||||||
private slots:
|
private slots:
|
||||||
|
void actSave();
|
||||||
|
void actRestore();
|
||||||
void actUp();
|
void actUp();
|
||||||
void actDown();
|
void actDown();
|
||||||
void actTop();
|
void actTop();
|
||||||
|
|
Loading…
Reference in a new issue