chore: fix formatting

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-10-01 19:38:40 +02:00
parent 6527604b93
commit 5c02265325
No known key found for this signature in database
GPG Key ID: C10411294912A422
5 changed files with 50 additions and 41 deletions

View File

@ -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

View File

@ -15,11 +15,12 @@
#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
@ -29,8 +30,7 @@ InstanceProxyModel::InstanceProxyModel(QObject *parent) : QSortFilterProxyModel(
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
}

View File

@ -15,11 +15,10 @@
#pragma once
#include <QSortFilterProxyModel>
#include <QCollator>
#include <QSortFilterProxyModel>
class InstanceProxyModel : public QSortFilterProxyModel
{
class InstanceProxyModel : public QSortFilterProxyModel {
Q_OBJECT
public:

View File

@ -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);
@ -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 &current, 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 &current, const QModelInd
emit currentInstanceChanged(inst1, inst2);
}
void InstanceView::selectNameColumn(const QModelIndex &current, 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);
}

View File

@ -17,8 +17,8 @@
*/
#pragma once
#include <QStackedWidget>
#include <QAbstractItemView>
#include <QStackedWidget>
#include <QTableView>
#include "BaseInstance.h"
@ -32,9 +32,7 @@ class InstanceView : public QStackedWidget {
public:
explicit InstanceView(QWidget* parent = nullptr, InstanceList* instances = nullptr);
QAbstractItemView* currentView() {
return m_table;
}
QAbstractItemView* currentView() { return m_table; }
InstancePtr currentInstance();