refactor: rename column enum
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
@@ -138,11 +138,11 @@ QVariant InstanceList::headerData(int section, Qt::Orientation orientation, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch(static_cast<Column>(section)) {
|
switch(static_cast<Column>(section)) {
|
||||||
case Icon: return tr("Icon");
|
case IconColumn: return tr("Icon");
|
||||||
case Name: return tr("Name");
|
case NameColumn: return tr("Name");
|
||||||
case GameVersion: return tr("Game Version");
|
case GameVersionColumn: return tr("Game Version");
|
||||||
case PlayTime: return tr("Play time");
|
case PlayTimeColumn: return tr("Play time");
|
||||||
case LastPlayed: return tr("Last played");
|
case LastPlayedColumn: return tr("Last played");
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,12 +154,12 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const {
|
|||||||
const InstancePtr inst = m_instances[index.row()];
|
const InstancePtr inst = m_instances[index.row()];
|
||||||
|
|
||||||
switch (static_cast<Column>(index.column())) {
|
switch (static_cast<Column>(index.column())) {
|
||||||
case Icon:
|
case IconColumn:
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole) {
|
||||||
return inst->iconKey();
|
return inst->iconKey();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Name:
|
case NameColumn:
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
||||||
return inst->name();
|
return inst->name();
|
||||||
if (role == Qt::AccessibleTextRole)
|
if (role == Qt::AccessibleTextRole)
|
||||||
@@ -167,12 +167,12 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const {
|
|||||||
if (role == Qt::ToolTipRole)
|
if (role == Qt::ToolTipRole)
|
||||||
return inst->instanceRoot();
|
return inst->instanceRoot();
|
||||||
break;
|
break;
|
||||||
case GameVersion: {
|
case GameVersionColumn: {
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
return inst->getMainVersion();
|
return inst->getMainVersion();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PlayTime: {
|
case PlayTimeColumn: {
|
||||||
QString foo = Time::prettifyDuration(inst->totalTimePlayed());
|
QString foo = Time::prettifyDuration(inst->totalTimePlayed());
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
return foo;
|
return foo;
|
||||||
@@ -180,7 +180,7 @@ QVariant InstanceList::data(const QModelIndex& index, int role) const {
|
|||||||
return tr("Total played for %1").arg(foo);
|
return tr("Total played for %1").arg(foo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LastPlayed: {
|
case LastPlayedColumn: {
|
||||||
QString foo = Time::prettifyDuration(inst->lastTimePlayed());
|
QString foo = Time::prettifyDuration(inst->lastTimePlayed());
|
||||||
QDateTime bar = QDateTime::fromMSecsSinceEpoch(inst->lastLaunch());
|
QDateTime bar = QDateTime::fromMSecsSinceEpoch(inst->lastLaunch());
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
@@ -222,7 +222,7 @@ Qt::ItemFlags InstanceList::flags(const QModelIndex& index) const
|
|||||||
Qt::ItemFlags f;
|
Qt::ItemFlags f;
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
f |= (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||||
if (index.column() == Name) {
|
if (index.column() == NameColumn) {
|
||||||
f |= Qt::ItemIsEditable; // FIXME: bad UX! User can only use rename, if they selected the name column
|
f |= Qt::ItemIsEditable; // FIXME: bad UX! User can only use rename, if they selected the name column
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
|
|||||||
if (changed) {
|
if (changed) {
|
||||||
m_groupNameCache.insert(name);
|
m_groupNameCache.insert(name);
|
||||||
auto idx = getInstIndex(inst.get());
|
auto idx = getInstIndex(inst.get());
|
||||||
emit dataChanged(index(idx, Name), index(idx, Name), { GroupRole });
|
emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), {GroupRole });
|
||||||
saveGroupList();
|
saveGroupList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ void InstanceList::deleteGroup(const QString& name)
|
|||||||
removed = true;
|
removed = true;
|
||||||
auto idx = getInstIndex(instance.get());
|
auto idx = getInstIndex(instance.get());
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
emit dataChanged(index(idx, Name), index(idx, Name), { GroupRole });
|
emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), {GroupRole });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -565,7 +565,7 @@ InstancePtr InstanceList::getInstanceByManagedName(const QString& managed_name)
|
|||||||
|
|
||||||
QModelIndex InstanceList::getInstanceIndexById(const QString &id) const
|
QModelIndex InstanceList::getInstanceIndexById(const QString &id) const
|
||||||
{
|
{
|
||||||
return index(getInstIndex(getInstanceById(id).get()), Name);
|
return index(getInstIndex(getInstanceById(id).get()), NameColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int InstanceList::getInstIndex(BaseInstance* inst) const
|
int InstanceList::getInstIndex(BaseInstance* inst) const
|
||||||
@@ -583,7 +583,7 @@ void InstanceList::propertiesChanged(BaseInstance* inst)
|
|||||||
{
|
{
|
||||||
int i = getInstIndex(inst);
|
int i = getInstIndex(inst);
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
emit dataChanged(index(i, Icon), index(i, ColumnCount - 1));
|
emit dataChanged(index(i, IconColumn), index(i, ColumnCount - 1));
|
||||||
updateTotalPlayTime();
|
updateTotalPlayTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ public:
|
|||||||
|
|
||||||
enum Column
|
enum Column
|
||||||
{
|
{
|
||||||
Icon = 0,
|
IconColumn = 0,
|
||||||
Name,
|
NameColumn,
|
||||||
GameVersion,
|
GameVersionColumn,
|
||||||
PlayTime,
|
PlayTimeColumn,
|
||||||
LastPlayed,
|
LastPlayedColumn,
|
||||||
|
|
||||||
ColumnCount
|
ColumnCount
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ InstanceDelegate::InstanceDelegate(QObject* parent) : QStyledItemDelegate(parent
|
|||||||
void InstanceDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
|
void InstanceDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QStyledItemDelegate::initStyleOption(option, index);
|
QStyledItemDelegate::initStyleOption(option, index);
|
||||||
if (index.column() == InstanceList::Icon) {
|
if (index.column() == InstanceList::IconColumn) {
|
||||||
// make decoration fill cell, subtract default margins
|
// make decoration fill cell, subtract default margins
|
||||||
option->decorationSize = option->rect.size().shrunkBy(QMargins(3, 1, 3, 1));
|
option->decorationSize = option->rect.size().shrunkBy(QMargins(3, 1, 3, 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ QVariant InstanceProxyModel::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case InstanceList::LastPlayed: {
|
case InstanceList::LastPlayedColumn: {
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
QDateTime foo = data.toDateTime();
|
QDateTime foo = data.toDateTime();
|
||||||
if (foo.isNull() || !foo.isValid() || foo.toMSecsSinceEpoch() == 0)
|
if (foo.isNull() || !foo.isValid() || foo.toMSecsSinceEpoch() == 0)
|
||||||
|
|||||||
@@ -80,16 +80,16 @@ void InstanceView::createTable()
|
|||||||
header->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("InstanceViewTableHeaderState").toByteArray()));
|
header->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("InstanceViewTableHeaderState").toByteArray()));
|
||||||
|
|
||||||
header->setSectionsMovable(true);
|
header->setSectionsMovable(true);
|
||||||
header->setSectionResizeMode(InstanceList::Icon, QHeaderView::Fixed);
|
header->setSectionResizeMode(InstanceList::IconColumn, QHeaderView::Fixed);
|
||||||
header->setSectionResizeMode(InstanceList::Name, QHeaderView::Stretch);
|
header->setSectionResizeMode(InstanceList::NameColumn, QHeaderView::Stretch);
|
||||||
header->setSectionResizeMode(InstanceList::GameVersion, QHeaderView::Interactive);
|
header->setSectionResizeMode(InstanceList::GameVersionColumn, QHeaderView::Interactive);
|
||||||
header->setSectionResizeMode(InstanceList::PlayTime, QHeaderView::Interactive);
|
header->setSectionResizeMode(InstanceList::PlayTimeColumn, QHeaderView::Interactive);
|
||||||
header->setSectionResizeMode(InstanceList::LastPlayed, QHeaderView::Interactive);
|
header->setSectionResizeMode(InstanceList::LastPlayedColumn, QHeaderView::Interactive);
|
||||||
m_table->setColumnWidth(InstanceList::Icon, m_rowHeight + 3 + 3); // padding left and right
|
m_table->setColumnWidth(InstanceList::IconColumn, m_rowHeight + 3 + 3); // padding left and right
|
||||||
m_table->verticalHeader()->setDefaultSectionSize(m_rowHeight + 1 + 1); // padding top and bottom
|
m_table->verticalHeader()->setDefaultSectionSize(m_rowHeight + 1 + 1); // padding top and bottom
|
||||||
|
|
||||||
if (!APPLICATION->settings()->contains("InstanceViewTableHeaderState"))
|
if (!APPLICATION->settings()->contains("InstanceViewTableHeaderState"))
|
||||||
m_table->sortByColumn(InstanceList::LastPlayed, Qt::AscendingOrder);
|
m_table->sortByColumn(InstanceList::LastPlayedColumn, Qt::AscendingOrder);
|
||||||
|
|
||||||
connect(m_table, &QTableView::doubleClicked, this, &InstanceView::activateInstance);
|
connect(m_table, &QTableView::doubleClicked, this, &InstanceView::activateInstance);
|
||||||
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstanceView::currentRowChanged);
|
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstanceView::currentRowChanged);
|
||||||
@@ -132,7 +132,7 @@ 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
|
||||||
m_table->setCurrentIndex(current.siblingAtColumn(InstanceList::Name));
|
m_table->setCurrentIndex(current.siblingAtColumn(InstanceList::NameColumn));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
void InstanceView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||||
|
|||||||
Reference in New Issue
Block a user