chore: fix formatting
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
6527604b93
commit
5c02265325
@ -872,7 +872,9 @@ SET(LAUNCHER_SOURCES
|
|||||||
# GUI - instance group view
|
# GUI - instance group view
|
||||||
ui/instanceview/InstanceProxyModel.cpp
|
ui/instanceview/InstanceProxyModel.cpp
|
||||||
ui/instanceview/InstanceProxyModel.h
|
ui/instanceview/InstanceProxyModel.h
|
||||||
ui/instanceview/InstanceView.cpp ui/instanceview/InstanceView.h)
|
ui/instanceview/InstanceView.h
|
||||||
|
ui/instanceview/InstanceView.cpp
|
||||||
|
)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(LAUNCHER_SOURCES
|
set(LAUNCHER_SOURCES
|
||||||
|
@ -15,24 +15,24 @@
|
|||||||
|
|
||||||
#include "InstanceProxyModel.h"
|
#include "InstanceProxyModel.h"
|
||||||
|
|
||||||
#include "InstanceList.h"
|
|
||||||
#include "Application.h"
|
|
||||||
#include <icons/IconList.h>
|
#include <icons/IconList.h>
|
||||||
|
#include "Application.h"
|
||||||
|
#include "InstanceList.h"
|
||||||
|
|
||||||
InstanceProxyModel::InstanceProxyModel(QObject *parent) : QSortFilterProxyModel(parent) {
|
InstanceProxyModel::InstanceProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
m_naturalSort.setNumericMode(true);
|
m_naturalSort.setNumericMode(true);
|
||||||
m_naturalSort.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
m_naturalSort.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||||
// FIXME: use loaded translation as source of locale instead, hook this up to translation changes
|
// FIXME: use loaded translation as source of locale instead, hook this up to translation changes
|
||||||
m_naturalSort.setLocale(QLocale::system());
|
m_naturalSort.setLocale(QLocale::system());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant InstanceProxyModel::data(const QModelIndex & index, int role) const
|
QVariant InstanceProxyModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
QVariant data = QSortFilterProxyModel::data(index, role);
|
QVariant data = QSortFilterProxyModel::data(index, role);
|
||||||
if(role == Qt::DecorationRole)
|
if (role == Qt::DecorationRole) {
|
||||||
{
|
|
||||||
if (!data.toString().isEmpty())
|
if (!data.toString().isEmpty())
|
||||||
return APPLICATION->icons()->getIcon(data.toString()); //FIXME: Needs QStyledItemDelegate
|
return APPLICATION->icons()->getIcon(data.toString()); // FIXME: Needs QStyledItemDelegate
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
|
@ -15,19 +15,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
#include <QCollator>
|
#include <QCollator>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
class InstanceProxyModel : public QSortFilterProxyModel
|
class InstanceProxyModel : public QSortFilterProxyModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InstanceProxyModel(QObject *parent = 0);
|
InstanceProxyModel(QObject* parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant data(const QModelIndex & index, int role) const override;
|
QVariant data(const QModelIndex& index, int role) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QCollator m_naturalSort;
|
QCollator m_naturalSort;
|
||||||
};
|
};
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
* or later.
|
* or later.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Application.h"
|
|
||||||
#include "InstanceView.h"
|
#include "InstanceView.h"
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
#include "InstanceList.h"
|
#include "InstanceList.h"
|
||||||
#include "ui/instanceview/InstanceProxyModel.h"
|
#include "ui/instanceview/InstanceProxyModel.h"
|
||||||
@ -31,7 +31,8 @@
|
|||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
|
||||||
InstanceView::InstanceView(QWidget *parent, InstanceList *instances) : QStackedWidget(parent), m_instances(instances) {
|
InstanceView::InstanceView(QWidget* parent, InstanceList* instances) : QStackedWidget(parent), m_instances(instances)
|
||||||
|
{
|
||||||
prepareModel();
|
prepareModel();
|
||||||
createTable();
|
createTable();
|
||||||
|
|
||||||
@ -39,19 +40,21 @@ InstanceView::InstanceView(QWidget *parent, InstanceList *instances) : QStackedW
|
|||||||
setCurrentWidget(m_table);
|
setCurrentWidget(m_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::storeState() {
|
void InstanceView::storeState()
|
||||||
|
{
|
||||||
APPLICATION->settings()->set("InstanceViewTableHeaderState", m_table->horizontalHeader()->saveState().toBase64());
|
APPLICATION->settings()->set("InstanceViewTableHeaderState", m_table->horizontalHeader()->saveState().toBase64());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::prepareModel() {
|
void InstanceView::prepareModel()
|
||||||
|
{
|
||||||
m_proxy = new InstanceProxyModel(this);
|
m_proxy = new InstanceProxyModel(this);
|
||||||
m_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
|
m_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
m_proxy->setSourceModel(m_instances);
|
m_proxy->setSourceModel(m_instances);
|
||||||
connect(m_proxy, &InstanceProxyModel::dataChanged, this, &InstanceView::dataChanged);
|
connect(m_proxy, &InstanceProxyModel::dataChanged, this, &InstanceView::dataChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::createTable() {
|
void InstanceView::createTable()
|
||||||
|
{
|
||||||
m_table = new QTableView(this);
|
m_table = new QTableView(this);
|
||||||
m_table->setModel(m_proxy);
|
m_table->setModel(m_proxy);
|
||||||
|
|
||||||
@ -71,7 +74,7 @@ void InstanceView::createTable() {
|
|||||||
|
|
||||||
m_table->verticalHeader()->hide();
|
m_table->verticalHeader()->hide();
|
||||||
|
|
||||||
QHeaderView *header = m_table->horizontalHeader();
|
QHeaderView* header = m_table->horizontalHeader();
|
||||||
header->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("InstanceViewTableHeaderState").toByteArray()));
|
header->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("InstanceViewTableHeaderState").toByteArray()));
|
||||||
|
|
||||||
header->setSectionsMovable(true);
|
header->setSectionsMovable(true);
|
||||||
@ -80,7 +83,7 @@ void InstanceView::createTable() {
|
|||||||
header->setSectionResizeMode(InstanceList::GameVersion, QHeaderView::Interactive);
|
header->setSectionResizeMode(InstanceList::GameVersion, QHeaderView::Interactive);
|
||||||
header->setSectionResizeMode(InstanceList::PlayTime, QHeaderView::Interactive);
|
header->setSectionResizeMode(InstanceList::PlayTime, QHeaderView::Interactive);
|
||||||
header->setSectionResizeMode(InstanceList::LastPlayed, QHeaderView::Interactive);
|
header->setSectionResizeMode(InstanceList::LastPlayed, QHeaderView::Interactive);
|
||||||
m_table->setColumnWidth(InstanceList::Icon, m_rowHeight + 3 + 3); // padding left and right
|
m_table->setColumnWidth(InstanceList::Icon, m_rowHeight + 3 + 3); // padding left and right
|
||||||
m_table->verticalHeader()->setDefaultSectionSize(m_rowHeight + 1 + 1); // padding top and bottom
|
m_table->verticalHeader()->setDefaultSectionSize(m_rowHeight + 1 + 1); // padding top and bottom
|
||||||
|
|
||||||
if (!APPLICATION->settings()->contains("InstanceViewTableHeaderState"))
|
if (!APPLICATION->settings()->contains("InstanceViewTableHeaderState"))
|
||||||
@ -92,7 +95,8 @@ void InstanceView::createTable() {
|
|||||||
connect(m_table, &QWidget::customContextMenuRequested, this, &InstanceView::contextMenuRequested);
|
connect(m_table, &QWidget::customContextMenuRequested, this, &InstanceView::contextMenuRequested);
|
||||||
}
|
}
|
||||||
|
|
||||||
InstancePtr InstanceView::currentInstance() {
|
InstancePtr InstanceView::currentInstance()
|
||||||
|
{
|
||||||
auto current = m_table->selectionModel()->currentIndex();
|
auto current = m_table->selectionModel()->currentIndex();
|
||||||
if (current.isValid()) {
|
if (current.isValid()) {
|
||||||
int row = mappedIndex(current).row();
|
int row = mappedIndex(current).row();
|
||||||
@ -101,14 +105,16 @@ InstancePtr InstanceView::currentInstance() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::activateInstance(const QModelIndex &index) {
|
void InstanceView::activateInstance(const QModelIndex& index)
|
||||||
|
{
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
int row = mappedIndex(index).row();
|
int row = mappedIndex(index).row();
|
||||||
emit instanceActivated(m_instances->at(row));
|
emit instanceActivated(m_instances->at(row));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) {
|
void InstanceView::currentRowChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||||
|
{
|
||||||
InstancePtr inst1, inst2;
|
InstancePtr inst1, inst2;
|
||||||
if (current.isValid()) {
|
if (current.isValid()) {
|
||||||
int row = mappedIndex(current).row();
|
int row = mappedIndex(current).row();
|
||||||
@ -121,12 +127,14 @@ void InstanceView::currentRowChanged(const QModelIndex ¤t, const QModelInd
|
|||||||
emit currentInstanceChanged(inst1, inst2);
|
emit currentInstanceChanged(inst1, inst2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::selectNameColumn(const QModelIndex ¤t, const QModelIndex &previous) {
|
void InstanceView::selectNameColumn(const QModelIndex& current, const QModelIndex& previous)
|
||||||
|
{
|
||||||
// Make sure Name column is always selected
|
// Make sure Name column is always selected
|
||||||
m_table->setCurrentIndex(current.siblingAtColumn(InstanceList::Name));
|
m_table->setCurrentIndex(current.siblingAtColumn(InstanceList::Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
|
void InstanceView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||||
|
{
|
||||||
// Notify others if data of the current instance changed
|
// Notify others if data of the current instance changed
|
||||||
auto current = m_table->selectionModel()->currentIndex();
|
auto current = m_table->selectionModel()->currentIndex();
|
||||||
|
|
||||||
@ -138,7 +146,8 @@ void InstanceView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::contextMenuRequested(const QPoint pos) {
|
void InstanceView::contextMenuRequested(const QPoint pos)
|
||||||
|
{
|
||||||
QModelIndex index = m_table->indexAt(pos);
|
QModelIndex index = m_table->indexAt(pos);
|
||||||
|
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
@ -148,6 +157,7 @@ void InstanceView::contextMenuRequested(const QPoint pos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex InstanceView::mappedIndex(const QModelIndex& index) const {
|
QModelIndex InstanceView::mappedIndex(const QModelIndex& index) const
|
||||||
|
{
|
||||||
return m_proxy->mapToSource(index);
|
return m_proxy->mapToSource(index);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QStackedWidget>
|
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
|
#include <QStackedWidget>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
@ -29,32 +29,30 @@ class InstanceList;
|
|||||||
class InstanceView : public QStackedWidget {
|
class InstanceView : public QStackedWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit InstanceView(QWidget *parent = nullptr, InstanceList* instances = nullptr);
|
explicit InstanceView(QWidget* parent = nullptr, InstanceList* instances = nullptr);
|
||||||
|
|
||||||
QAbstractItemView* currentView() {
|
QAbstractItemView* currentView() { return m_table; }
|
||||||
return m_table;
|
|
||||||
}
|
|
||||||
|
|
||||||
InstancePtr currentInstance();
|
InstancePtr currentInstance();
|
||||||
|
|
||||||
// save state of current view
|
// save state of current view
|
||||||
void storeState();
|
void storeState();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void instanceActivated(InstancePtr inst);
|
void instanceActivated(InstancePtr inst);
|
||||||
void currentInstanceChanged(InstancePtr current, InstancePtr previous);
|
void currentInstanceChanged(InstancePtr current, InstancePtr previous);
|
||||||
void showContextMenu(const QPoint pos, InstancePtr inst);
|
void showContextMenu(const QPoint pos, InstancePtr inst);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void activateInstance(const QModelIndex& index);
|
void activateInstance(const QModelIndex& index);
|
||||||
void currentRowChanged(const QModelIndex& current, const QModelIndex& previous);
|
void currentRowChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||||
void selectNameColumn(const QModelIndex& current, const QModelIndex& previous);
|
void selectNameColumn(const QModelIndex& current, const QModelIndex& previous);
|
||||||
// emits currentRowChanged if a data update affected the current instance
|
// emits currentRowChanged if a data update affected the current instance
|
||||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||||
void contextMenuRequested(const QPoint pos);
|
void contextMenuRequested(const QPoint pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createTable();
|
void createTable();
|
||||||
void prepareModel();
|
void prepareModel();
|
||||||
QModelIndex mappedIndex(const QModelIndex& index) const;
|
QModelIndex mappedIndex(const QModelIndex& index) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user