mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 15:43:54 -07:00
fix set sorting (#6630)
This commit is contained in:
parent
f978407a19
commit
e57ee8e9c9
3 changed files with 22 additions and 20 deletions
|
|
@ -20,8 +20,6 @@
|
||||||
#include <libcockatrice/card/database/card_database_manager.h>
|
#include <libcockatrice/card/database/card_database_manager.h>
|
||||||
#include <libcockatrice/models/database/card_set/card_sets_model.h>
|
#include <libcockatrice/models/database/card_set/card_sets_model.h>
|
||||||
|
|
||||||
#define SORT_RESET -1
|
|
||||||
|
|
||||||
WndSets::WndSets(QWidget *parent) : QMainWindow(parent)
|
WndSets::WndSets(QWidget *parent) : QMainWindow(parent)
|
||||||
{
|
{
|
||||||
setOrderIsSorted = false;
|
setOrderIsSorted = false;
|
||||||
|
|
@ -97,7 +95,6 @@ WndSets::WndSets(QWidget *parent) : QMainWindow(parent)
|
||||||
view->setDropIndicatorShown(true);
|
view->setDropIndicatorShown(true);
|
||||||
view->setDragDropMode(QAbstractItemView::InternalMove);
|
view->setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
|
|
||||||
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
|
||||||
view->setColumnHidden(SetsModel::SortKeyCol, true);
|
view->setColumnHidden(SetsModel::SortKeyCol, true);
|
||||||
view->setColumnHidden(SetsModel::IsKnownCol, true);
|
view->setColumnHidden(SetsModel::IsKnownCol, true);
|
||||||
view->setColumnHidden(SetsModel::PriorityCol, true);
|
view->setColumnHidden(SetsModel::PriorityCol, true);
|
||||||
|
|
@ -196,10 +193,10 @@ WndSets::WndSets(QWidget *parent) : QMainWindow(parent)
|
||||||
auto headerState = SettingsCache::instance().layouts().getSetsDialogHeaderState();
|
auto headerState = SettingsCache::instance().layouts().getSetsDialogHeaderState();
|
||||||
if (!headerState.isEmpty()) {
|
if (!headerState.isEmpty()) {
|
||||||
view->header()->restoreState(headerState);
|
view->header()->restoreState(headerState);
|
||||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
|
||||||
} else {
|
} else {
|
||||||
view->header()->resizeSections(QHeaderView::ResizeToContents);
|
view->header()->resizeSections(QHeaderView::ResizeToContents);
|
||||||
}
|
}
|
||||||
|
resetSort();
|
||||||
connect(view->header(), &QHeaderView::geometriesChanged, this, &WndSets::saveHeaderState);
|
connect(view->header(), &QHeaderView::geometriesChanged, this, &WndSets::saveHeaderState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,6 +236,13 @@ void WndSets::rebuildMainLayout(int actionToTake)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WndSets::resetSort()
|
||||||
|
{
|
||||||
|
view->sortByColumn(SetsModel::SortKeyCol, Qt::AscendingOrder);
|
||||||
|
sortIndex = -1;
|
||||||
|
sortWarning->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
void WndSets::includeRebalancedCardsChanged(bool _includeRebalancedCards)
|
void WndSets::includeRebalancedCardsChanged(bool _includeRebalancedCards)
|
||||||
{
|
{
|
||||||
includeRebalancedCards = _includeRebalancedCards;
|
includeRebalancedCards = _includeRebalancedCards;
|
||||||
|
|
@ -260,9 +264,9 @@ void WndSets::actRestore()
|
||||||
|
|
||||||
void WndSets::actRestoreOriginalOrder()
|
void WndSets::actRestoreOriginalOrder()
|
||||||
{
|
{
|
||||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
|
||||||
model->restoreOriginalOrder();
|
model->restoreOriginalOrder();
|
||||||
sortWarning->setVisible(false);
|
view->selectionModel()->reset();
|
||||||
|
resetSort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WndSets::actDisableResetButton(const QString &filterString)
|
void WndSets::actDisableResetButton(const QString &filterString)
|
||||||
|
|
@ -288,11 +292,12 @@ void WndSets::actSort(int index)
|
||||||
sortIndex = index;
|
sortIndex = index;
|
||||||
sortWarning->setVisible(true);
|
sortWarning->setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
resetSort();
|
||||||
sortIndex = -1;
|
|
||||||
sortWarning->setVisible(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!view->selectionModel()->selection().empty()) {
|
||||||
|
view->scrollTo(view->selectionModel()->selectedRows().first());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WndSets::actIgnoreWarning()
|
void WndSets::actIgnoreWarning()
|
||||||
|
|
@ -301,23 +306,18 @@ void WndSets::actIgnoreWarning()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
model->sort(sortIndex, sortOrder);
|
model->sort(sortIndex, sortOrder);
|
||||||
view->header()->setSortIndicator(SORT_RESET, Qt::DescendingOrder);
|
resetSort();
|
||||||
sortIndex = -1;
|
|
||||||
sortWarning->setVisible(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WndSets::actDisableSortButtons(int index)
|
void WndSets::actDisableSortButtons(int index)
|
||||||
{
|
{
|
||||||
if (index != SORT_RESET) {
|
if (index != SetsModel::SortKeyCol) {
|
||||||
view->setDragEnabled(false);
|
view->setDragEnabled(false);
|
||||||
setOrderIsSorted = true;
|
setOrderIsSorted = true;
|
||||||
} else {
|
} else {
|
||||||
setOrderIsSorted = false;
|
setOrderIsSorted = false;
|
||||||
view->setDragEnabled(true);
|
view->setDragEnabled(true);
|
||||||
}
|
}
|
||||||
if (!view->selectionModel()->selection().empty()) {
|
|
||||||
view->scrollTo(view->selectionModel()->selectedRows().first());
|
|
||||||
}
|
|
||||||
actToggleButtons(view->selectionModel()->selection(), QItemSelection());
|
actToggleButtons(view->selectionModel()->selection(), QItemSelection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,6 @@ private:
|
||||||
QHBoxLayout *filterBox;
|
QHBoxLayout *filterBox;
|
||||||
int sortIndex;
|
int sortIndex;
|
||||||
Qt::SortOrder sortOrder;
|
Qt::SortOrder sortOrder;
|
||||||
void closeEvent(QCloseEvent *ev) override;
|
|
||||||
void saveHeaderState();
|
|
||||||
void rebuildMainLayout(int actionToTake);
|
|
||||||
bool setOrderIsSorted;
|
bool setOrderIsSorted;
|
||||||
bool includeRebalancedCards;
|
bool includeRebalancedCards;
|
||||||
enum
|
enum
|
||||||
|
|
@ -56,6 +53,11 @@ private:
|
||||||
SOME_SETS_SELECTED
|
SOME_SETS_SELECTED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void closeEvent(QCloseEvent *ev) override;
|
||||||
|
void saveHeaderState();
|
||||||
|
void rebuildMainLayout(int actionToTake);
|
||||||
|
void resetSort();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WndSets(QWidget *parent = nullptr);
|
explicit WndSets(QWidget *parent = nullptr);
|
||||||
~WndSets() override;
|
~WndSets() override;
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ QVariant SetsModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case SortKeyCol:
|
case SortKeyCol:
|
||||||
return QString("%1").arg(set->getSortKey(), 8, 10, QChar('0'));
|
return QString("%1").arg(index.row(), 8, 10, QChar('0'));
|
||||||
case IsKnownCol:
|
case IsKnownCol:
|
||||||
return set->getIsKnown();
|
return set->getIsKnown();
|
||||||
case SetTypeCol:
|
case SetTypeCol:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue