feat: bring back categories
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user