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) {
|
||||
case NameColumn:
|
||||
return tr("Name");
|
||||
case CategoryColumn:
|
||||
return tr("Category");
|
||||
case GameVersionColumn:
|
||||
return tr("Game Version");
|
||||
case PlayTimeColumn:
|
||||
@ -163,6 +165,10 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
||||
}
|
||||
const InstancePtr inst = m_instances[index.row()];
|
||||
|
||||
QString instanceGroup = getInstanceGroup(inst->id());
|
||||
|
||||
|
||||
|
||||
switch (role) {
|
||||
case Qt::DecorationRole: {
|
||||
if (index.column() == NameColumn)
|
||||
@ -174,6 +180,8 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
||||
switch (index.column()) {
|
||||
case NameColumn:
|
||||
return inst->name();
|
||||
case CategoryColumn:
|
||||
return instanceGroup;
|
||||
case GameVersionColumn:
|
||||
return inst->getMainVersion();
|
||||
case PlayTimeColumn:
|
||||
@ -199,8 +207,11 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
||||
}
|
||||
|
||||
case Qt::EditRole: {
|
||||
if (index.column() == NameColumn)
|
||||
return data(index, Qt::DisplayRole);
|
||||
switch (index.column()) {
|
||||
case NameColumn:
|
||||
case CategoryColumn:
|
||||
return data(index, Qt::DisplayRole);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -227,7 +238,7 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const
|
||||
}
|
||||
|
||||
case GroupRole: {
|
||||
return getInstanceGroup(inst->id());
|
||||
return instanceGroup;
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
@ -242,12 +253,17 @@ bool InstanceList::setData(const QModelIndex& index, const QVariant& value, int
|
||||
return false;
|
||||
}
|
||||
InstancePtr inst = m_instances.at(index.row());
|
||||
auto newName = value.toString();
|
||||
if (inst->name() == newName) {
|
||||
auto newValue = value.toString();
|
||||
|
||||
if (index.column() == NameColumn) {
|
||||
setInstanceName(inst, newValue);
|
||||
return true;
|
||||
}
|
||||
inst->setName(newName);
|
||||
return true;
|
||||
if (index.column() == CategoryColumn) {
|
||||
setInstanceGroup(inst, newValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags InstanceList::flags(const QModelIndex& index) const
|
||||
@ -256,7 +272,7 @@ Qt::ItemFlags InstanceList::flags(const QModelIndex& index) const
|
||||
if (index.isValid()) {
|
||||
f |= Qt::ItemIsSelectable;
|
||||
|
||||
if (index.column() == NameColumn) {
|
||||
if (index.column() == NameColumn || index.column() == CategoryColumn) {
|
||||
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";
|
||||
return;
|
||||
}
|
||||
setInstanceGroup(inst, name);
|
||||
}
|
||||
|
||||
void InstanceList::setInstanceGroup(const InstancePtr inst, const GroupId& name)
|
||||
{
|
||||
bool changed = false;
|
||||
auto iter = m_instanceGroupIndex.find(inst->id());
|
||||
if (iter != m_instanceGroupIndex.end()) {
|
||||
@ -293,7 +313,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
|
||||
}
|
||||
} else {
|
||||
changed = true;
|
||||
m_instanceGroupIndex[id] = name;
|
||||
m_instanceGroupIndex[inst->id()] = name;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return m_groupNameCache.values();
|
||||
|
@ -58,6 +58,7 @@ class InstanceList : public QAbstractTableModel {
|
||||
|
||||
enum Column {
|
||||
NameColumn,
|
||||
CategoryColumn,
|
||||
GameVersionColumn,
|
||||
PlayTimeColumn,
|
||||
LastPlayedColumn,
|
||||
@ -83,6 +84,10 @@ class InstanceList : public QAbstractTableModel {
|
||||
|
||||
GroupId getInstanceGroup(const InstanceId& id) const;
|
||||
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);
|
||||
bool trashInstance(const InstanceId& id);
|
||||
|
@ -19,6 +19,9 @@
|
||||
#include "Application.h"
|
||||
#include "InstanceList.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QVariant>
|
||||
|
||||
InstanceTableProxyModel::InstanceTableProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
|
||||
{
|
||||
m_naturalSort.setNumericMode(true);
|
||||
@ -30,20 +33,49 @@ InstanceTableProxyModel::InstanceTableProxyModel(QObject* parent) : QSortFilterP
|
||||
QVariant InstanceTableProxyModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
QVariant data = QSortFilterProxyModel::data(index, role);
|
||||
if (role == Qt::DecorationRole) {
|
||||
if (!data.toString().isEmpty())
|
||||
return APPLICATION->icons()->getIcon(data.toString());
|
||||
}
|
||||
QVariant displayData = data;
|
||||
if (role != Qt::DisplayRole)
|
||||
displayData = QSortFilterProxyModel::data(index, Qt::DisplayRole);
|
||||
|
||||
switch (index.column()) {
|
||||
case InstanceList::LastPlayedColumn: {
|
||||
if (role == Qt::DisplayRole) {
|
||||
QDateTime foo = data.toDateTime();
|
||||
if (foo.isNull() || !foo.isValid() || foo.toMSecsSinceEpoch() == 0)
|
||||
return tr("Never");
|
||||
switch (role) {
|
||||
case Qt::DecorationRole: {
|
||||
if (!data.toString().isEmpty())
|
||||
return APPLICATION->icons()->getIcon(data.toString());
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -58,11 +58,11 @@ void InstanceView::switchDisplayMode(InstanceView::DisplayMode mode)
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceView::editSelected()
|
||||
void InstanceView::editSelected(InstanceList::Column targetColumn)
|
||||
{
|
||||
auto current = currentView()->selectionModel()->currentIndex();
|
||||
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)
|
||||
{
|
||||
// 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)
|
||||
|
@ -23,10 +23,10 @@
|
||||
#include <QTableView>
|
||||
|
||||
#include "BaseInstance.h"
|
||||
#include "InstanceList.h"
|
||||
|
||||
class InstanceTableProxyModel;
|
||||
class InstanceGridProxyModel;
|
||||
class InstanceList;
|
||||
|
||||
class InstanceView : public QStackedWidget {
|
||||
Q_OBJECT
|
||||
@ -52,7 +52,7 @@ class InstanceView : public QStackedWidget {
|
||||
|
||||
void setCatDisplayed(bool enabled);
|
||||
|
||||
void editSelected();
|
||||
void editSelected(InstanceList::Column targetColumn = InstanceList::NameColumn);
|
||||
|
||||
signals:
|
||||
void instanceActivated(InstancePtr inst);
|
||||
|
Loading…
x
Reference in New Issue
Block a user