feat: bring back categories
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
9050230b01
commit
b6c35491d5
@ -146,6 +146,8 @@ QVariant InstanceList::headerData(int section, Qt::Orientation orientation, int
|
|||||||
switch (section) {
|
switch (section) {
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
return tr("Name");
|
return tr("Name");
|
||||||
|
case CategoryColumn:
|
||||||
|
return tr("Category");
|
||||||
case GameVersionColumn:
|
case GameVersionColumn:
|
||||||
return tr("Game Version");
|
return tr("Game Version");
|
||||||
case PlayTimeColumn:
|
case PlayTimeColumn:
|
||||||
@ -163,6 +165,10 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
const InstancePtr inst = m_instances[index.row()];
|
const InstancePtr inst = m_instances[index.row()];
|
||||||
|
|
||||||
|
QString instanceGroup = getInstanceGroup(inst->id());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DecorationRole: {
|
case Qt::DecorationRole: {
|
||||||
if (index.column() == NameColumn)
|
if (index.column() == NameColumn)
|
||||||
@ -174,6 +180,8 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
|||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
return inst->name();
|
return inst->name();
|
||||||
|
case CategoryColumn:
|
||||||
|
return instanceGroup;
|
||||||
case GameVersionColumn:
|
case GameVersionColumn:
|
||||||
return inst->getMainVersion();
|
return inst->getMainVersion();
|
||||||
case PlayTimeColumn:
|
case PlayTimeColumn:
|
||||||
@ -199,8 +207,11 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Qt::EditRole: {
|
case Qt::EditRole: {
|
||||||
if (index.column() == NameColumn)
|
switch (index.column()) {
|
||||||
return data(index, Qt::DisplayRole);
|
case NameColumn:
|
||||||
|
case CategoryColumn:
|
||||||
|
return data(index, Qt::DisplayRole);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +238,7 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
case GroupRole: {
|
case GroupRole: {
|
||||||
return getInstanceGroup(inst->id());
|
return instanceGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -242,12 +253,17 @@ bool InstanceList::setData(const QModelIndex& index, const QVariant& value, int
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
InstancePtr inst = m_instances.at(index.row());
|
InstancePtr inst = m_instances.at(index.row());
|
||||||
auto newName = value.toString();
|
auto newValue = value.toString();
|
||||||
if (inst->name() == newName) {
|
|
||||||
|
if (index.column() == NameColumn) {
|
||||||
|
setInstanceName(inst, newValue);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inst->setName(newName);
|
if (index.column() == CategoryColumn) {
|
||||||
return true;
|
setInstanceGroup(inst, newValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags InstanceList::flags(const QModelIndex& index) const
|
Qt::ItemFlags InstanceList::flags(const QModelIndex& index) const
|
||||||
@ -256,7 +272,7 @@ Qt::ItemFlags InstanceList::flags(const QModelIndex& index) const
|
|||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
f |= Qt::ItemIsSelectable;
|
f |= Qt::ItemIsSelectable;
|
||||||
|
|
||||||
if (index.column() == NameColumn) {
|
if (index.column() == NameColumn || index.column() == CategoryColumn) {
|
||||||
f |= Qt::ItemIsEditable; // NOTE: instance view forces focus on NameColumn
|
f |= Qt::ItemIsEditable; // NOTE: instance view forces focus on NameColumn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,7 +299,11 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
|
|||||||
qDebug() << "Attempt to set a null instance's group";
|
qDebug() << "Attempt to set a null instance's group";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setInstanceGroup(inst, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstanceList::setInstanceGroup(const InstancePtr inst, const GroupId& name)
|
||||||
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
auto iter = m_instanceGroupIndex.find(inst->id());
|
auto iter = m_instanceGroupIndex.find(inst->id());
|
||||||
if (iter != m_instanceGroupIndex.end()) {
|
if (iter != m_instanceGroupIndex.end()) {
|
||||||
@ -293,7 +313,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
changed = true;
|
changed = true;
|
||||||
m_instanceGroupIndex[id] = name;
|
m_instanceGroupIndex[inst->id()] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
@ -304,6 +324,23 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InstanceList::setInstanceName(const InstanceId& id, const QString name)
|
||||||
|
{
|
||||||
|
auto inst = getInstanceById(id);
|
||||||
|
if (!inst) {
|
||||||
|
qDebug() << "Attempt to set a null instance's name";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setInstanceName(inst, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstanceList::setInstanceName(const InstancePtr inst, const QString name)
|
||||||
|
{
|
||||||
|
if (inst->name() != name) {
|
||||||
|
inst->setName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QStringList InstanceList::getGroups()
|
QStringList InstanceList::getGroups()
|
||||||
{
|
{
|
||||||
return m_groupNameCache.values();
|
return m_groupNameCache.values();
|
||||||
|
@ -58,6 +58,7 @@ class InstanceList : public QAbstractTableModel {
|
|||||||
|
|
||||||
enum Column {
|
enum Column {
|
||||||
NameColumn,
|
NameColumn,
|
||||||
|
CategoryColumn,
|
||||||
GameVersionColumn,
|
GameVersionColumn,
|
||||||
PlayTimeColumn,
|
PlayTimeColumn,
|
||||||
LastPlayedColumn,
|
LastPlayedColumn,
|
||||||
@ -83,6 +84,10 @@ class InstanceList : public QAbstractTableModel {
|
|||||||
|
|
||||||
GroupId getInstanceGroup(const InstanceId& id) const;
|
GroupId getInstanceGroup(const InstanceId& id) const;
|
||||||
void setInstanceGroup(const InstanceId& id, const GroupId& name);
|
void setInstanceGroup(const InstanceId& id, const GroupId& name);
|
||||||
|
void setInstanceGroup(const InstancePtr inst, const GroupId& name);
|
||||||
|
|
||||||
|
void setInstanceName(const InstanceId& id, const QString name);
|
||||||
|
void setInstanceName(const InstancePtr inst, const QString name);
|
||||||
|
|
||||||
void deleteGroup(const GroupId& name);
|
void deleteGroup(const GroupId& name);
|
||||||
bool trashInstance(const InstanceId& id);
|
bool trashInstance(const InstanceId& id);
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "InstanceList.h"
|
#include "InstanceList.h"
|
||||||
|
|
||||||
|
#include <QFont>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
InstanceTableProxyModel::InstanceTableProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
InstanceTableProxyModel::InstanceTableProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
m_naturalSort.setNumericMode(true);
|
m_naturalSort.setNumericMode(true);
|
||||||
@ -30,20 +33,49 @@ InstanceTableProxyModel::InstanceTableProxyModel(QObject* parent) : QSortFilterP
|
|||||||
QVariant InstanceTableProxyModel::data(const QModelIndex& index, int role) const
|
QVariant InstanceTableProxyModel::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
QVariant data = QSortFilterProxyModel::data(index, role);
|
QVariant data = QSortFilterProxyModel::data(index, role);
|
||||||
if (role == Qt::DecorationRole) {
|
QVariant displayData = data;
|
||||||
if (!data.toString().isEmpty())
|
if (role != Qt::DisplayRole)
|
||||||
return APPLICATION->icons()->getIcon(data.toString());
|
displayData = QSortFilterProxyModel::data(index, Qt::DisplayRole);
|
||||||
}
|
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (role) {
|
||||||
case InstanceList::LastPlayedColumn: {
|
case Qt::DecorationRole: {
|
||||||
if (role == Qt::DisplayRole) {
|
if (!data.toString().isEmpty())
|
||||||
QDateTime foo = data.toDateTime();
|
return APPLICATION->icons()->getIcon(data.toString());
|
||||||
if (foo.isNull() || !foo.isValid() || foo.toMSecsSinceEpoch() == 0)
|
break;
|
||||||
return tr("Never");
|
}
|
||||||
|
case Qt::DisplayRole: {
|
||||||
|
switch (index.column()) {
|
||||||
|
case InstanceList::CategoryColumn: {
|
||||||
|
if (data.toString().isEmpty())
|
||||||
|
return tr("None");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case InstanceList::LastPlayedColumn: {
|
||||||
|
QDateTime foo = data.toDateTime();
|
||||||
|
if (foo.isNull() || !foo.isValid() || foo.toMSecsSinceEpoch() == 0)
|
||||||
|
return tr("Never");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Qt::FontRole: {
|
||||||
|
QFont font = data.value<QFont>();
|
||||||
|
switch (index.column()) {
|
||||||
|
case InstanceList::CategoryColumn: {
|
||||||
|
if (displayData.toString().isEmpty())
|
||||||
|
font.setItalic(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case InstanceList::LastPlayedColumn: {
|
||||||
|
QDateTime foo = data.toDateTime();
|
||||||
|
if (foo.isNull() || !foo.isValid() || foo.toMSecsSinceEpoch() == 0)
|
||||||
|
font.setItalic(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return font;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,11 @@ void InstanceView::switchDisplayMode(InstanceView::DisplayMode mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::editSelected()
|
void InstanceView::editSelected(InstanceList::Column targetColumn)
|
||||||
{
|
{
|
||||||
auto current = currentView()->selectionModel()->currentIndex();
|
auto current = currentView()->selectionModel()->currentIndex();
|
||||||
if (current.isValid()) {
|
if (current.isValid()) {
|
||||||
currentView()->edit(current);
|
currentView()->edit(current.siblingAtColumn(targetColumn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,8 @@ void InstanceView::currentRowChanged(const QModelIndex& current, const QModelInd
|
|||||||
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
|
// Make sure Name column is always selected
|
||||||
currentView()->setCurrentIndex(current.siblingAtColumn(InstanceList::NameColumn));
|
if (current.column() != InstanceList::NameColumn && current.column() != InstanceList::CategoryColumn)
|
||||||
|
currentView()->setCurrentIndex(current.siblingAtColumn(InstanceList::NameColumn));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
void InstanceView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
|
||||||
#include "BaseInstance.h"
|
#include "BaseInstance.h"
|
||||||
|
#include "InstanceList.h"
|
||||||
|
|
||||||
class InstanceTableProxyModel;
|
class InstanceTableProxyModel;
|
||||||
class InstanceGridProxyModel;
|
class InstanceGridProxyModel;
|
||||||
class InstanceList;
|
|
||||||
|
|
||||||
class InstanceView : public QStackedWidget {
|
class InstanceView : public QStackedWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -52,7 +52,7 @@ class InstanceView : public QStackedWidget {
|
|||||||
|
|
||||||
void setCatDisplayed(bool enabled);
|
void setCatDisplayed(bool enabled);
|
||||||
|
|
||||||
void editSelected();
|
void editSelected(InstanceList::Column targetColumn = InstanceList::NameColumn);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void instanceActivated(InstancePtr inst);
|
void instanceActivated(InstancePtr inst);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user