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
|
||||
ui/instanceview/InstanceProxyModel.cpp
|
||||
ui/instanceview/InstanceProxyModel.h
|
||||
ui/instanceview/InstanceView.cpp ui/instanceview/InstanceView.h)
|
||||
ui/instanceview/InstanceView.h
|
||||
ui/instanceview/InstanceView.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(LAUNCHER_SOURCES
|
||||
|
@ -15,24 +15,24 @@
|
||||
|
||||
#include "InstanceProxyModel.h"
|
||||
|
||||
#include "InstanceList.h"
|
||||
#include "Application.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.setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||
// FIXME: use loaded translation as source of locale instead, hook this up to translation changes
|
||||
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);
|
||||
if(role == Qt::DecorationRole)
|
||||
{
|
||||
if (role == Qt::DecorationRole) {
|
||||
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()) {
|
||||
|
@ -15,19 +15,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QCollator>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class InstanceProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
class InstanceProxyModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InstanceProxyModel(QObject *parent = 0);
|
||||
public:
|
||||
InstanceProxyModel(QObject* parent = 0);
|
||||
|
||||
protected:
|
||||
QVariant data(const QModelIndex & index, int role) const override;
|
||||
protected:
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
private:
|
||||
private:
|
||||
QCollator m_naturalSort;
|
||||
};
|
||||
|
@ -22,8 +22,8 @@
|
||||
* or later.
|
||||
*/
|
||||
|
||||
#include "Application.h"
|
||||
#include "InstanceView.h"
|
||||
#include "Application.h"
|
||||
|
||||
#include "InstanceList.h"
|
||||
#include "ui/instanceview/InstanceProxyModel.h"
|
||||
@ -31,7 +31,8 @@
|
||||
#include <QHeaderView>
|
||||
#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();
|
||||
createTable();
|
||||
|
||||
@ -39,19 +40,21 @@ InstanceView::InstanceView(QWidget *parent, InstanceList *instances) : QStackedW
|
||||
setCurrentWidget(m_table);
|
||||
}
|
||||
|
||||
void InstanceView::storeState() {
|
||||
void InstanceView::storeState()
|
||||
{
|
||||
APPLICATION->settings()->set("InstanceViewTableHeaderState", m_table->horizontalHeader()->saveState().toBase64());
|
||||
}
|
||||
|
||||
void InstanceView::prepareModel() {
|
||||
void InstanceView::prepareModel()
|
||||
{
|
||||
m_proxy = new InstanceProxyModel(this);
|
||||
m_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
m_proxy->setSourceModel(m_instances);
|
||||
connect(m_proxy, &InstanceProxyModel::dataChanged, this, &InstanceView::dataChanged);
|
||||
}
|
||||
|
||||
void InstanceView::createTable() {
|
||||
|
||||
void InstanceView::createTable()
|
||||
{
|
||||
m_table = new QTableView(this);
|
||||
m_table->setModel(m_proxy);
|
||||
|
||||
@ -71,7 +74,7 @@ void InstanceView::createTable() {
|
||||
|
||||
m_table->verticalHeader()->hide();
|
||||
|
||||
QHeaderView *header = m_table->horizontalHeader();
|
||||
QHeaderView* header = m_table->horizontalHeader();
|
||||
header->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("InstanceViewTableHeaderState").toByteArray()));
|
||||
|
||||
header->setSectionsMovable(true);
|
||||
@ -80,7 +83,7 @@ void InstanceView::createTable() {
|
||||
header->setSectionResizeMode(InstanceList::GameVersion, QHeaderView::Interactive);
|
||||
header->setSectionResizeMode(InstanceList::PlayTime, 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
|
||||
|
||||
if (!APPLICATION->settings()->contains("InstanceViewTableHeaderState"))
|
||||
@ -92,7 +95,8 @@ void InstanceView::createTable() {
|
||||
connect(m_table, &QWidget::customContextMenuRequested, this, &InstanceView::contextMenuRequested);
|
||||
}
|
||||
|
||||
InstancePtr InstanceView::currentInstance() {
|
||||
InstancePtr InstanceView::currentInstance()
|
||||
{
|
||||
auto current = m_table->selectionModel()->currentIndex();
|
||||
if (current.isValid()) {
|
||||
int row = mappedIndex(current).row();
|
||||
@ -101,14 +105,16 @@ InstancePtr InstanceView::currentInstance() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void InstanceView::activateInstance(const QModelIndex &index) {
|
||||
void InstanceView::activateInstance(const QModelIndex& index)
|
||||
{
|
||||
if (index.isValid()) {
|
||||
int row = mappedIndex(index).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;
|
||||
if (current.isValid()) {
|
||||
int row = mappedIndex(current).row();
|
||||
@ -121,12 +127,14 @@ void InstanceView::currentRowChanged(const QModelIndex ¤t, const QModelInd
|
||||
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
|
||||
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
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QStackedWidget>
|
||||
#include <QAbstractItemView>
|
||||
#include <QStackedWidget>
|
||||
#include <QTableView>
|
||||
|
||||
#include "BaseInstance.h"
|
||||
@ -29,32 +29,30 @@ class InstanceList;
|
||||
class InstanceView : public QStackedWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InstanceView(QWidget *parent = nullptr, InstanceList* instances = nullptr);
|
||||
public:
|
||||
explicit InstanceView(QWidget* parent = nullptr, InstanceList* instances = nullptr);
|
||||
|
||||
QAbstractItemView* currentView() {
|
||||
return m_table;
|
||||
}
|
||||
QAbstractItemView* currentView() { return m_table; }
|
||||
|
||||
InstancePtr currentInstance();
|
||||
|
||||
// save state of current view
|
||||
void storeState();
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void instanceActivated(InstancePtr inst);
|
||||
void currentInstanceChanged(InstancePtr current, InstancePtr previous);
|
||||
void showContextMenu(const QPoint pos, InstancePtr inst);
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void activateInstance(const QModelIndex& index);
|
||||
void currentRowChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||
void selectNameColumn(const QModelIndex& current, const QModelIndex& previous);
|
||||
// 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);
|
||||
|
||||
private:
|
||||
private:
|
||||
void createTable();
|
||||
void prepareModel();
|
||||
QModelIndex mappedIndex(const QModelIndex& index) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user