2019-12-31 06:17:17 +00:00
|
|
|
#include "gamelistwidget.h"
|
2020-03-02 01:08:29 +00:00
|
|
|
#include "common/string_util.h"
|
2020-01-24 04:50:44 +00:00
|
|
|
#include "core/game_list.h"
|
2019-12-31 06:17:17 +00:00
|
|
|
#include "core/settings.h"
|
|
|
|
#include "qthostinterface.h"
|
|
|
|
#include "qtutils.h"
|
2020-01-08 05:01:04 +00:00
|
|
|
#include <QtCore/QSortFilterProxyModel>
|
2020-01-08 03:39:19 +00:00
|
|
|
#include <QtGui/QPixmap>
|
2019-12-31 06:17:17 +00:00
|
|
|
#include <QtWidgets/QHeaderView>
|
2020-03-02 01:08:25 +00:00
|
|
|
#include <QtWidgets/QMenu>
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-01-08 05:01:04 +00:00
|
|
|
class GameListModel final : public QAbstractTableModel
|
2019-12-31 06:17:17 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Column : int
|
|
|
|
{
|
2020-01-08 03:50:44 +00:00
|
|
|
Column_Type,
|
2019-12-31 06:17:17 +00:00
|
|
|
Column_Code,
|
|
|
|
Column_Title,
|
2020-03-02 01:08:25 +00:00
|
|
|
Column_FileTitle,
|
2019-12-31 06:17:17 +00:00
|
|
|
Column_Size,
|
2020-05-16 10:03:01 +00:00
|
|
|
Column_Region,
|
|
|
|
Column_Compatibility,
|
2019-12-31 06:17:17 +00:00
|
|
|
|
|
|
|
Column_Count
|
|
|
|
};
|
|
|
|
|
2020-03-02 01:08:29 +00:00
|
|
|
static inline constexpr std::array<const char*, Column_Count> s_column_names = {
|
2020-05-16 10:03:01 +00:00
|
|
|
{"Type", "Code", "Title", "File Title", "Size", "Region", "Compatibility"}};
|
2020-03-02 01:08:25 +00:00
|
|
|
|
2020-03-02 01:08:29 +00:00
|
|
|
static std::optional<Column> getColumnIdForName(std::string_view name)
|
|
|
|
{
|
|
|
|
for (int column = 0; column < Column_Count; column++)
|
|
|
|
{
|
|
|
|
if (name == s_column_names[column])
|
|
|
|
return static_cast<Column>(column);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2020-03-10 12:59:17 +00:00
|
|
|
GameListModel(GameList* game_list, QObject* parent = nullptr) : QAbstractTableModel(parent), m_game_list(game_list)
|
2019-12-31 06:17:17 +00:00
|
|
|
{
|
2020-01-08 03:39:19 +00:00
|
|
|
loadCommonImages();
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|
|
|
|
~GameListModel() = default;
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override
|
|
|
|
{
|
|
|
|
if (parent.isValid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return static_cast<int>(m_game_list->GetEntryCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override
|
|
|
|
{
|
|
|
|
if (parent.isValid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Column_Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
const int row = index.row();
|
|
|
|
if (row < 0 || row >= static_cast<int>(m_game_list->GetEntryCount()))
|
|
|
|
return {};
|
|
|
|
|
2020-01-24 04:50:44 +00:00
|
|
|
const GameListEntry& ge = m_game_list->GetEntries()[row];
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-01-08 03:39:19 +00:00
|
|
|
switch (role)
|
|
|
|
{
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
{
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case Column_Code:
|
|
|
|
return QString::fromStdString(ge.code);
|
|
|
|
|
|
|
|
case Column_Title:
|
|
|
|
return QString::fromStdString(ge.title);
|
|
|
|
|
2020-03-02 01:08:25 +00:00
|
|
|
case Column_FileTitle:
|
|
|
|
{
|
|
|
|
const std::string_view file_title(GameList::GetTitleForPath(ge.path.c_str()));
|
|
|
|
return QString::fromUtf8(file_title.data(), static_cast<int>(file_title.length()));
|
|
|
|
}
|
|
|
|
|
2020-01-08 03:39:19 +00:00
|
|
|
case Column_Size:
|
|
|
|
return QString("%1 MB").arg(static_cast<double>(ge.total_size) / 1048576.0, 0, 'f', 2);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 05:01:04 +00:00
|
|
|
case Qt::InitialSortOrderRole:
|
|
|
|
{
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case Column_Type:
|
|
|
|
return static_cast<int>(ge.type);
|
|
|
|
|
|
|
|
case Column_Code:
|
|
|
|
return QString::fromStdString(ge.code);
|
|
|
|
|
|
|
|
case Column_Title:
|
|
|
|
return QString::fromStdString(ge.title);
|
|
|
|
|
2020-03-02 01:08:25 +00:00
|
|
|
case Column_FileTitle:
|
|
|
|
{
|
|
|
|
const std::string_view file_title(GameList::GetTitleForPath(ge.path.c_str()));
|
|
|
|
return QString::fromUtf8(file_title.data(), static_cast<int>(file_title.length()));
|
|
|
|
}
|
|
|
|
|
2020-01-08 05:01:04 +00:00
|
|
|
case Column_Region:
|
|
|
|
return static_cast<int>(ge.region);
|
|
|
|
|
2020-05-16 10:03:01 +00:00
|
|
|
case Column_Compatibility:
|
|
|
|
return static_cast<int>(ge.compatibility_rating);
|
|
|
|
|
2020-01-08 05:01:04 +00:00
|
|
|
case Column_Size:
|
2020-01-08 22:46:52 +00:00
|
|
|
return static_cast<qulonglong>(ge.total_size);
|
2020-01-08 05:01:04 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 03:39:19 +00:00
|
|
|
case Qt::DecorationRole:
|
|
|
|
{
|
|
|
|
switch (index.column())
|
|
|
|
{
|
2020-01-08 03:50:44 +00:00
|
|
|
case Column_Type:
|
|
|
|
{
|
|
|
|
switch (ge.type)
|
|
|
|
{
|
2020-01-24 04:50:44 +00:00
|
|
|
case GameListEntryType::Disc:
|
2020-01-08 03:50:44 +00:00
|
|
|
return m_type_disc_pixmap;
|
2020-01-24 04:50:44 +00:00
|
|
|
case GameListEntryType::PSExe:
|
2020-01-08 03:50:44 +00:00
|
|
|
default:
|
|
|
|
return m_type_exe_pixmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 03:39:19 +00:00
|
|
|
case Column_Region:
|
|
|
|
{
|
|
|
|
switch (ge.region)
|
|
|
|
{
|
2020-03-12 03:51:29 +00:00
|
|
|
case DiscRegion::NTSC_J:
|
2020-01-08 03:39:19 +00:00
|
|
|
return m_region_jp_pixmap;
|
2020-03-12 03:51:29 +00:00
|
|
|
case DiscRegion::NTSC_U:
|
2020-01-08 03:39:19 +00:00
|
|
|
return m_region_us_pixmap;
|
2020-03-12 03:51:29 +00:00
|
|
|
case DiscRegion::PAL:
|
2020-01-08 03:39:19 +00:00
|
|
|
default:
|
|
|
|
return m_region_eu_pixmap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 10:03:01 +00:00
|
|
|
case Column_Compatibility:
|
|
|
|
{
|
|
|
|
return m_compatibiliy_pixmaps[static_cast<int>(
|
|
|
|
(ge.compatibility_rating >= GameListCompatibilityRating::Count) ? GameListCompatibilityRating::Unknown :
|
|
|
|
ge.compatibility_rating)];
|
|
|
|
}
|
|
|
|
|
2020-01-08 03:39:19 +00:00
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
|
|
|
|
{
|
2020-03-02 01:08:25 +00:00
|
|
|
if (orientation != Qt::Horizontal || role != Qt::DisplayRole || section < 0 || section >= Column_Count)
|
2019-12-31 06:17:17 +00:00
|
|
|
return {};
|
|
|
|
|
2020-03-02 01:08:25 +00:00
|
|
|
return tr(s_column_names[section]);
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void refresh()
|
|
|
|
{
|
2020-03-10 12:59:17 +00:00
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 05:01:04 +00:00
|
|
|
bool titlesLessThan(int left_row, int right_row, bool ascending) const
|
|
|
|
{
|
|
|
|
if (left_row < 0 || left_row >= static_cast<int>(m_game_list->GetEntryCount()) || right_row < 0 ||
|
|
|
|
right_row >= static_cast<int>(m_game_list->GetEntryCount()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-24 04:50:44 +00:00
|
|
|
const GameListEntry& left = m_game_list->GetEntries().at(left_row);
|
|
|
|
const GameListEntry& right = m_game_list->GetEntries().at(right_row);
|
2020-01-08 05:01:04 +00:00
|
|
|
return ascending ? (left.title < right.title) : (right.title < left.title);
|
|
|
|
}
|
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
private:
|
2020-01-08 03:39:19 +00:00
|
|
|
void loadCommonImages()
|
|
|
|
{
|
|
|
|
// TODO: Use svg instead of png
|
2020-01-08 03:50:44 +00:00
|
|
|
m_type_disc_pixmap.load(QStringLiteral(":/icons/media-optical-24.png"));
|
|
|
|
m_type_exe_pixmap.load(QStringLiteral(":/icons/applications-system-24.png"));
|
|
|
|
m_region_eu_pixmap.load(QStringLiteral(":/icons/flag-eu.png"));
|
2020-01-08 03:39:19 +00:00
|
|
|
m_region_jp_pixmap.load(QStringLiteral(":/icons/flag-jp.png"));
|
|
|
|
m_region_us_pixmap.load(QStringLiteral(":/icons/flag-us.png"));
|
|
|
|
m_region_eu_pixmap.load(QStringLiteral(":/icons/flag-eu.png"));
|
2020-05-16 10:03:01 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < static_cast<int>(GameListCompatibilityRating::Count); i++)
|
|
|
|
m_compatibiliy_pixmaps[i].load(QStringLiteral(":/icons/star-%1.png").arg(i));
|
2020-01-08 03:39:19 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
GameList* m_game_list;
|
2020-01-08 03:39:19 +00:00
|
|
|
|
2020-01-08 03:50:44 +00:00
|
|
|
QPixmap m_type_disc_pixmap;
|
|
|
|
QPixmap m_type_exe_pixmap;
|
|
|
|
|
2020-01-08 03:39:19 +00:00
|
|
|
QPixmap m_region_jp_pixmap;
|
|
|
|
QPixmap m_region_eu_pixmap;
|
|
|
|
QPixmap m_region_us_pixmap;
|
2020-05-16 10:03:01 +00:00
|
|
|
|
|
|
|
std::array<QPixmap, static_cast<int>(GameListCompatibilityRating::Count)> m_compatibiliy_pixmaps;
|
2019-12-31 06:17:17 +00:00
|
|
|
};
|
|
|
|
|
2020-01-08 05:01:04 +00:00
|
|
|
class GameListSortModel final : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GameListSortModel(GameListModel* parent) : QSortFilterProxyModel(parent), m_model(parent) {}
|
|
|
|
|
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
|
|
|
|
{
|
|
|
|
// TODO: Search
|
|
|
|
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override
|
|
|
|
{
|
|
|
|
const bool ascending = sortOrder() == Qt::AscendingOrder;
|
|
|
|
const QVariant left = source_left.data(Qt::InitialSortOrderRole);
|
|
|
|
const QVariant right = source_right.data(Qt::InitialSortOrderRole);
|
|
|
|
if (left != right)
|
2020-03-02 01:08:20 +00:00
|
|
|
return ascending ? (left < right) : (right > left);
|
2020-01-08 05:01:04 +00:00
|
|
|
|
|
|
|
// fallback to sorting by title for equal items
|
|
|
|
return m_model->titlesLessThan(source_left.row(), source_right.row(), ascending);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GameListModel* m_model;
|
|
|
|
};
|
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
GameListWidget::GameListWidget(QWidget* parent /* = nullptr */) : QStackedWidget(parent) {}
|
|
|
|
|
|
|
|
GameListWidget::~GameListWidget() = default;
|
|
|
|
|
|
|
|
void GameListWidget::initialize(QtHostInterface* host_interface)
|
|
|
|
{
|
|
|
|
m_host_interface = host_interface;
|
|
|
|
m_game_list = host_interface->getGameList();
|
|
|
|
|
|
|
|
connect(m_host_interface, &QtHostInterface::gameListRefreshed, this, &GameListWidget::onGameListRefreshed);
|
|
|
|
|
|
|
|
m_table_model = new GameListModel(m_game_list, this);
|
2020-01-08 05:01:04 +00:00
|
|
|
m_table_sort_model = new GameListSortModel(m_table_model);
|
|
|
|
m_table_sort_model->setSourceModel(m_table_model);
|
2019-12-31 06:17:17 +00:00
|
|
|
m_table_view = new QTableView(this);
|
2020-01-08 05:01:04 +00:00
|
|
|
m_table_view->setModel(m_table_sort_model);
|
|
|
|
m_table_view->setSortingEnabled(true);
|
2019-12-31 06:17:17 +00:00
|
|
|
m_table_view->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
m_table_view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
2020-03-02 01:08:16 +00:00
|
|
|
m_table_view->setContextMenuPolicy(Qt::CustomContextMenu);
|
2019-12-31 06:17:17 +00:00
|
|
|
m_table_view->setAlternatingRowColors(true);
|
|
|
|
m_table_view->setShowGrid(false);
|
|
|
|
m_table_view->setCurrentIndex({});
|
2020-01-08 03:38:31 +00:00
|
|
|
m_table_view->horizontalHeader()->setHighlightSections(false);
|
2020-03-02 01:08:25 +00:00
|
|
|
m_table_view->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
|
2019-12-31 06:17:17 +00:00
|
|
|
m_table_view->verticalHeader()->hide();
|
2020-01-08 03:39:19 +00:00
|
|
|
m_table_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-03-02 01:08:29 +00:00
|
|
|
loadTableViewColumnVisibilitySettings();
|
|
|
|
loadTableViewColumnSortSettings();
|
2020-03-02 01:08:20 +00:00
|
|
|
|
2020-01-24 04:49:46 +00:00
|
|
|
connect(m_table_view->selectionModel(), &QItemSelectionModel::currentChanged, this,
|
|
|
|
&GameListWidget::onSelectionModelCurrentChanged);
|
2020-03-02 01:08:16 +00:00
|
|
|
connect(m_table_view, &QTableView::doubleClicked, this, &GameListWidget::onTableViewItemDoubleClicked);
|
|
|
|
connect(m_table_view, &QTableView::customContextMenuRequested, this,
|
|
|
|
&GameListWidget::onTableViewContextMenuRequested);
|
2020-03-02 01:08:25 +00:00
|
|
|
connect(m_table_view->horizontalHeader(), &QHeaderView::customContextMenuRequested, this,
|
|
|
|
&GameListWidget::onTableViewHeaderContextMenuRequested);
|
2020-03-02 01:08:29 +00:00
|
|
|
connect(m_table_view->horizontalHeader(), &QHeaderView::sortIndicatorChanged, this,
|
|
|
|
&GameListWidget::onTableViewHeaderSortIndicatorChanged);
|
2019-12-31 06:17:17 +00:00
|
|
|
|
|
|
|
insertWidget(0, m_table_view);
|
|
|
|
setCurrentIndex(0);
|
2020-03-02 01:08:29 +00:00
|
|
|
|
|
|
|
resizeTableViewColumnsToFit();
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWidget::onGameListRefreshed()
|
|
|
|
{
|
|
|
|
m_table_model->refresh();
|
|
|
|
}
|
|
|
|
|
2020-03-02 01:08:16 +00:00
|
|
|
void GameListWidget::onSelectionModelCurrentChanged(const QModelIndex& current, const QModelIndex& previous)
|
2019-12-31 06:17:17 +00:00
|
|
|
{
|
2020-03-02 01:08:16 +00:00
|
|
|
const QModelIndex source_index = m_table_sort_model->mapToSource(current);
|
2020-01-24 04:49:44 +00:00
|
|
|
if (!source_index.isValid() || source_index.row() >= static_cast<int>(m_game_list->GetEntryCount()))
|
2020-03-02 01:08:16 +00:00
|
|
|
{
|
|
|
|
emit entrySelected(nullptr);
|
2019-12-31 06:17:17 +00:00
|
|
|
return;
|
2020-03-02 01:08:16 +00:00
|
|
|
}
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-01-24 04:50:44 +00:00
|
|
|
const GameListEntry& entry = m_game_list->GetEntries().at(source_index.row());
|
2020-03-02 01:08:16 +00:00
|
|
|
emit entrySelected(&entry);
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 01:08:16 +00:00
|
|
|
void GameListWidget::onTableViewItemDoubleClicked(const QModelIndex& index)
|
2020-01-24 04:49:46 +00:00
|
|
|
{
|
2020-03-02 01:08:16 +00:00
|
|
|
const QModelIndex source_index = m_table_sort_model->mapToSource(index);
|
2020-01-24 04:49:46 +00:00
|
|
|
if (!source_index.isValid() || source_index.row() >= static_cast<int>(m_game_list->GetEntryCount()))
|
|
|
|
return;
|
|
|
|
|
2020-01-24 04:50:44 +00:00
|
|
|
const GameListEntry& entry = m_game_list->GetEntries().at(source_index.row());
|
2020-03-02 01:08:16 +00:00
|
|
|
emit entryDoubleClicked(&entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWidget::onTableViewContextMenuRequested(const QPoint& point)
|
|
|
|
{
|
|
|
|
const GameListEntry* entry = getSelectedEntry();
|
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit entryContextMenuRequested(m_table_view->mapToGlobal(point), entry);
|
2020-01-24 04:49:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 01:08:25 +00:00
|
|
|
void GameListWidget::onTableViewHeaderContextMenuRequested(const QPoint& point)
|
|
|
|
{
|
|
|
|
QMenu menu;
|
|
|
|
|
|
|
|
for (int column = 0; column < GameListModel::Column_Count; column++)
|
|
|
|
{
|
|
|
|
QAction* action = menu.addAction(tr(GameListModel::s_column_names[column]));
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(!m_table_view->isColumnHidden(column));
|
|
|
|
connect(action, &QAction::toggled, [this, column](bool enabled) {
|
|
|
|
m_table_view->setColumnHidden(column, !enabled);
|
2020-03-02 01:08:29 +00:00
|
|
|
saveTableViewColumnVisibilitySettings(column);
|
2020-03-02 01:08:25 +00:00
|
|
|
resizeTableViewColumnsToFit();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.exec(m_table_view->mapToGlobal(point));
|
|
|
|
}
|
|
|
|
|
2020-03-02 01:08:29 +00:00
|
|
|
void GameListWidget::onTableViewHeaderSortIndicatorChanged(int, Qt::SortOrder)
|
|
|
|
{
|
|
|
|
saveTableViewColumnSortSettings();
|
|
|
|
}
|
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
void GameListWidget::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
QStackedWidget::resizeEvent(event);
|
2020-03-02 01:08:25 +00:00
|
|
|
resizeTableViewColumnsToFit();
|
|
|
|
}
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-03-02 01:08:25 +00:00
|
|
|
void GameListWidget::resizeTableViewColumnsToFit()
|
|
|
|
{
|
2020-05-16 10:03:01 +00:00
|
|
|
QtUtils::ResizeColumnsForTableView(m_table_view, {32, 80, -1, -1, 100, 60, 100});
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|
2020-03-02 01:08:16 +00:00
|
|
|
|
2020-03-02 01:08:29 +00:00
|
|
|
static QString getColumnVisibilitySettingsKeyName(int column)
|
|
|
|
{
|
|
|
|
return QStringLiteral("GameListTableView/Show%1").arg(GameListModel::s_column_names[column]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWidget::loadTableViewColumnVisibilitySettings()
|
|
|
|
{
|
|
|
|
static constexpr std::array<bool, GameListModel::Column_Count> DEFAULT_VISIBILITY = {
|
|
|
|
{true, true, true, false, true, true}};
|
|
|
|
|
|
|
|
for (int column = 0; column < GameListModel::Column_Count; column++)
|
|
|
|
{
|
|
|
|
const bool visible =
|
|
|
|
m_host_interface->getSettingValue(getColumnVisibilitySettingsKeyName(column), DEFAULT_VISIBILITY[column])
|
|
|
|
.toBool();
|
|
|
|
m_table_view->setColumnHidden(column, !visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWidget::saveTableViewColumnVisibilitySettings()
|
|
|
|
{
|
|
|
|
for (int column = 0; column < GameListModel::Column_Count; column++)
|
|
|
|
{
|
|
|
|
const bool visible = !m_table_view->isColumnHidden(column);
|
|
|
|
m_host_interface->putSettingValue(getColumnVisibilitySettingsKeyName(column), visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWidget::saveTableViewColumnVisibilitySettings(int column)
|
|
|
|
{
|
|
|
|
const bool visible = !m_table_view->isColumnHidden(column);
|
|
|
|
m_host_interface->putSettingValue(getColumnVisibilitySettingsKeyName(column), visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWidget::loadTableViewColumnSortSettings()
|
|
|
|
{
|
|
|
|
const GameListModel::Column DEFAULT_SORT_COLUMN = GameListModel::Column_Type;
|
|
|
|
const bool DEFAULT_SORT_DESCENDING = false;
|
|
|
|
|
|
|
|
const GameListModel::Column sort_column =
|
|
|
|
GameListModel::getColumnIdForName(
|
|
|
|
m_host_interface->getSettingValue(QStringLiteral("GameListTableView/SortColumn")).toString().toStdString())
|
|
|
|
.value_or(DEFAULT_SORT_COLUMN);
|
|
|
|
const bool sort_descending =
|
|
|
|
m_host_interface->getSettingValue(QStringLiteral("GameListTableView/SortDescending"), DEFAULT_SORT_DESCENDING)
|
|
|
|
.toBool();
|
|
|
|
m_table_sort_model->sort(sort_column, sort_descending ? Qt::DescendingOrder : Qt::AscendingOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListWidget::saveTableViewColumnSortSettings()
|
|
|
|
{
|
|
|
|
const int sort_column = m_table_view->horizontalHeader()->sortIndicatorSection();
|
|
|
|
const bool sort_descending = (m_table_view->horizontalHeader()->sortIndicatorOrder() == Qt::DescendingOrder);
|
|
|
|
|
|
|
|
if (sort_column >= 0 && sort_column < GameListModel::Column_Count)
|
|
|
|
{
|
|
|
|
m_host_interface->putSettingValue(QStringLiteral("GameListTableView/SortColumn"),
|
|
|
|
QString::fromUtf8(GameListModel::s_column_names[sort_column]));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_host_interface->putSettingValue(QStringLiteral("GameListTableView/SortDescending"), sort_descending);
|
|
|
|
}
|
|
|
|
|
2020-03-02 01:08:16 +00:00
|
|
|
const GameListEntry* GameListWidget::getSelectedEntry() const
|
|
|
|
{
|
|
|
|
const QItemSelectionModel* selection_model = m_table_view->selectionModel();
|
|
|
|
if (!selection_model->hasSelection())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const QModelIndexList selected_rows = selection_model->selectedRows();
|
|
|
|
if (selected_rows.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const QModelIndex source_index = m_table_sort_model->mapToSource(selected_rows[0]);
|
|
|
|
if (!source_index.isValid() || source_index.row() >= static_cast<int>(m_game_list->GetEntryCount()))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &m_game_list->GetEntries().at(source_index.row());
|
|
|
|
}
|