Skip to content

Commit

Permalink
Use an enum for pixel history column ids instead of magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
w-pearson committed Jul 28, 2023
1 parent 70b412d commit 33f4b4b
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions qrenderdoc/Windows/PixelHistoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ struct EventTag

Q_DECLARE_METATYPE(EventTag);

enum
{
COL_EVENT,
COL_SHADER_OUT,
COL_SHADER_OUT_COLOR,
COL_TEX_AFTER,
COL_TEX_AFTER_COLOR,
COL_COUNT,
};

class PixelHistoryItemModel : public QAbstractItemModel
{
public:
Expand Down Expand Up @@ -71,6 +81,16 @@ class PixelHistoryItemModel : public QAbstractItemModel
}
}

static bool isColorColumn(int column)
{
switch(column)
{
case COL_SHADER_OUT_COLOR:
case COL_TEX_AFTER_COLOR: return true;
default: return false;
}
}

void setHistory(const rdcarray<PixelModification> &history)
{
m_ModList.reserve(history.count());
Expand Down Expand Up @@ -144,7 +164,7 @@ class PixelHistoryItemModel : public QAbstractItemModel

return 0;
}
int columnCount(const QModelIndex &parent = QModelIndex()) const override { return 5; }
int columnCount(const QModelIndex &parent = QModelIndex()) const override { return COL_COUNT; }
Qt::ItemFlags flags(const QModelIndex &index) const override
{
if(!index.isValid())
Expand All @@ -155,11 +175,11 @@ class PixelHistoryItemModel : public QAbstractItemModel

QVariant headerData(int section, Qt::Orientation orientation, int role) const override
{
if(orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0)
if(orientation == Qt::Horizontal && role == Qt::DisplayRole && section == COL_EVENT)
return lit("Event");

// sizes for the colour previews
if(orientation == Qt::Horizontal && role == Qt::SizeHintRole && (section == 2 || section == 4))
if(orientation == Qt::Horizontal && role == Qt::SizeHintRole && isColorColumn(section))
return QSize(18, 0);

return QVariant();
Expand All @@ -172,15 +192,15 @@ class PixelHistoryItemModel : public QAbstractItemModel
int col = index.column();

// preview columns
if(col == 2 || col == 4)
if(isColorColumn(col))
{
if(role == Qt::SizeHintRole)
return QSize(16, 0);
}

if(m_Loading)
{
if(role == Qt::DisplayRole && col == 0)
if(role == Qt::DisplayRole && col == COL_EVENT)
return tr("Loading...");

return QVariant();
Expand All @@ -190,7 +210,7 @@ class PixelHistoryItemModel : public QAbstractItemModel
{
QString uavName = IsD3D(m_Ctx.APIProps().pipelineType) ? lit("UAV") : lit("Storage");
// main text
if(col == 0)
if(col == COL_EVENT)
{
if(isEvent(index))
{
Expand Down Expand Up @@ -292,7 +312,7 @@ class PixelHistoryItemModel : public QAbstractItemModel
}

// pre mod/shader out text
if(col == 1)
if(col == COL_SHADER_OUT)
{
if(isEvent(index))
{
Expand All @@ -310,7 +330,7 @@ class PixelHistoryItemModel : public QAbstractItemModel
}

// post mod text
if(col == 3)
if(col == COL_TEX_AFTER)
{
if(isEvent(index))
return tr("Tex After\n\n") + modString(getMods(index).last().postMod);
Expand All @@ -322,7 +342,7 @@ class PixelHistoryItemModel : public QAbstractItemModel
if(role == Qt::BackgroundRole && (m_IsDepth || m_IsFloat))
{
// pre mod color
if(col == 2)
if(col == COL_SHADER_OUT_COLOR)
{
if(isEvent(index))
{
Expand All @@ -336,7 +356,7 @@ class PixelHistoryItemModel : public QAbstractItemModel
return backgroundBrush(mod.shaderOut);
}
}
else if(col == 4)
else if(col == COL_TEX_AFTER_COLOR)
{
if(isEvent(index))
return backgroundBrush(getMods(index).last().postMod);
Expand All @@ -346,7 +366,7 @@ class PixelHistoryItemModel : public QAbstractItemModel
}

// text backgrounds marking pass/fail
if(role == Qt::BackgroundRole && (col == 0 || col == 1 || col == 3))
if(role == Qt::BackgroundRole && !isColorColumn(col))
{
// rest
if(isEvent(index))
Expand All @@ -373,7 +393,7 @@ class PixelHistoryItemModel : public QAbstractItemModel

// Since we change the background color for some cells, also change the foreground color to
// ensure contrast with all UI themes
if(role == Qt::ForegroundRole && (col == 0 || col == 1 || col == 3))
if(role == Qt::ForegroundRole && !isColorColumn(col))
{
QColor textColor =
contrastingColor(QColor::fromRgb(235, 235, 235), m_Palette.color(QPalette::Text));
Expand Down Expand Up @@ -639,11 +659,11 @@ PixelHistoryView::PixelHistoryView(ICaptureContext &ctx, ResourceId id, QPoint p

ui->events->hideBranches();

ui->events->header()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->events->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
ui->events->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
ui->events->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
ui->events->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
ui->events->header()->setSectionResizeMode(COL_EVENT, QHeaderView::Stretch);
ui->events->header()->setSectionResizeMode(COL_SHADER_OUT, QHeaderView::ResizeToContents);
ui->events->header()->setSectionResizeMode(COL_SHADER_OUT_COLOR, QHeaderView::ResizeToContents);
ui->events->header()->setSectionResizeMode(COL_TEX_AFTER, QHeaderView::ResizeToContents);
ui->events->header()->setSectionResizeMode(COL_TEX_AFTER_COLOR, QHeaderView::ResizeToContents);

m_Ctx.AddCaptureViewer(this);
}
Expand Down

0 comments on commit 33f4b4b

Please sign in to comment.