mirror of
https://github.com/obhq/obliteration.git
synced 2024-05-31 19:17:40 -04:00
Add name sorting. (#347)
This commit is contained in:
parent
4fccc1ae08
commit
c090f9db38
|
@ -21,6 +21,11 @@ QPixmap Game::icon() const
|
|||
// Construct icon object.
|
||||
QPixmap icon(path.c_str());
|
||||
|
||||
// For games with large icon sizes.
|
||||
if (icon.width() != 512 || icon.height() != 512) {
|
||||
icon = icon.scaled(512, 512, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
icon.setDevicePixelRatio(2.0);
|
||||
|
||||
return icon;
|
||||
|
@ -42,6 +47,8 @@ void GameListModel::add(Game *game)
|
|||
beginInsertRows(QModelIndex(), m_items.size(), m_items.size());
|
||||
m_items.append(game);
|
||||
endInsertRows();
|
||||
|
||||
sort(0);
|
||||
}
|
||||
|
||||
void GameListModel::clear()
|
||||
|
@ -73,3 +80,22 @@ QVariant GameListModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void GameListModel::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
if (column != 0)
|
||||
return;
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
auto compare = [order](const Game* a, const Game* b) {
|
||||
if (order == Qt::AscendingOrder)
|
||||
return a->name().toLower() < b->name().toLower();
|
||||
else
|
||||
return a->name().toLower() > b->name().toLower();
|
||||
};
|
||||
|
||||
std::sort(m_items.begin(), m_items.end(), compare);
|
||||
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
void add(Game *game);
|
||||
Game *get(int i) const { return m_items[i]; }
|
||||
void clear();
|
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
|
||||
public:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
|
|
@ -157,6 +157,7 @@ bool MainWindow::loadGames()
|
|||
|
||||
// Load games
|
||||
progress.setLabelText("Loading games...");
|
||||
auto gameList = reinterpret_cast<GameListModel *>(m_games->model());
|
||||
|
||||
for (auto &gameId : games) {
|
||||
if (progress.wasCanceled() || !loadGame(gameId)) {
|
||||
|
@ -166,6 +167,8 @@ bool MainWindow::loadGames()
|
|||
progress.setValue(++step);
|
||||
}
|
||||
|
||||
gameList->sort(0, Qt::AscendingOrder); // TODO add ability to select descending order (button?)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -206,7 +209,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
// Allows the games list to resort if window is resized.
|
||||
if (m_games) {
|
||||
if (m_tab->currentIndex() == 0) {
|
||||
m_games->updateGeometry();
|
||||
m_games->doItemsLayout();
|
||||
}
|
||||
|
@ -214,10 +217,10 @@ void MainWindow::resizeEvent(QResizeEvent *event)
|
|||
QMainWindow::resizeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::tabChanged(int index)
|
||||
void MainWindow::tabChanged()
|
||||
{
|
||||
// Check if the Games tab is selected
|
||||
if (index == 0 && m_games) {
|
||||
// Update games list if window was resized on another tab.
|
||||
if (m_tab->currentIndex() == 0) {
|
||||
m_games->updateGeometry();
|
||||
m_games->doItemsLayout();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ protected:
|
|||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void tabChanged(int index);
|
||||
void tabChanged();
|
||||
void installPkg();
|
||||
void openSystemFolder();
|
||||
void reportIssue();
|
||||
|
|
Loading…
Reference in a new issue