Skip to content

Commit c7265b1

Browse files
committed
Allow sorting and moving columns in counter results.
* We do a custom sort so that it's always in the right order even if the data isn't formatted exactly as a number.
1 parent b10a8ab commit c7265b1

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

qrenderdoc/Windows/PerformanceCounterViewer.cpp

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,66 @@
2626
#include "Windows/Dialogs/PerformanceCounterSelection.h"
2727
#include "ui_PerformanceCounterViewer.h"
2828

29+
struct SortValue
30+
{
31+
enum
32+
{
33+
Integer,
34+
Float
35+
} type;
36+
union
37+
{
38+
uint64_t u;
39+
double d;
40+
} val;
41+
42+
SortValue(uint32_t eventID)
43+
{
44+
type = Integer;
45+
val.u = eventID;
46+
}
47+
48+
SortValue(const CounterResult &result, const CounterDescription &description)
49+
{
50+
switch(description.resultType)
51+
{
52+
case CompType::Float:
53+
type = Float;
54+
val.d = result.value.f;
55+
break;
56+
case CompType::Double:
57+
type = Float;
58+
val.d = result.value.d;
59+
break;
60+
61+
case CompType::UInt:
62+
type = Integer;
63+
if(description.resultByteWidth == 8)
64+
val.u = result.value.u64;
65+
else
66+
val.u = result.value.u32;
67+
}
68+
}
69+
};
70+
71+
struct CustomSortedTableItem : public QTableWidgetItem
72+
{
73+
explicit CustomSortedTableItem(const QString &text, SortValue v)
74+
: QTableWidgetItem(text), sortVal(v)
75+
{
76+
}
77+
bool operator<(const QTableWidgetItem &other) const
78+
{
79+
const CustomSortedTableItem &customother = (const CustomSortedTableItem &)other;
80+
81+
if(sortVal.type == SortValue::Integer)
82+
return sortVal.val.u < customother.sortVal.val.u;
83+
return sortVal.val.d < customother.sortVal.val.d;
84+
}
85+
86+
SortValue sortVal;
87+
};
88+
2989
PerformanceCounterViewer::PerformanceCounterViewer(ICaptureContext &ctx, QWidget *parent)
3090
: QFrame(parent), ui(new Ui::PerformanceCounterViewer), m_Ctx(ctx)
3191
{
@@ -38,6 +98,8 @@ PerformanceCounterViewer::PerformanceCounterViewer(ICaptureContext &ctx, QWidget
3898

3999
ui->captureCounters->setEnabled(m_Ctx.LogLoaded());
40100
ui->saveCSV->setEnabled(m_Ctx.LogLoaded());
101+
102+
ui->counterResults->horizontalHeader()->setSectionsMovable(true);
41103
}
42104

43105
PerformanceCounterViewer::~PerformanceCounterViewer()
@@ -48,8 +110,8 @@ PerformanceCounterViewer::~PerformanceCounterViewer()
48110
delete ui;
49111
}
50112

51-
QString PerformanceCounterViewer::FormatCounterResult(const CounterResult &result,
52-
const CounterDescription &description)
113+
QTableWidgetItem *PerformanceCounterViewer::MakeCounterResultItem(const CounterResult &result,
114+
const CounterDescription &description)
53115
{
54116
QString returnValue;
55117

@@ -102,7 +164,7 @@ QString PerformanceCounterViewer::FormatCounterResult(const CounterResult &resul
102164
case CounterUnit::Ratio: break;
103165
}
104166

105-
return returnValue;
167+
return new CustomSortedTableItem(returnValue, SortValue(result, description));
106168
}
107169

108170
void PerformanceCounterViewer::CaptureCounters()
@@ -161,11 +223,14 @@ void PerformanceCounterViewer::CaptureCounters()
161223
for(int i = 0; i < (int)results.size(); ++i)
162224
{
163225
int row = eventIdToRow[results[i].eventID];
226+
164227
ui->counterResults->setItem(row, 0,
165-
new QTableWidgetItem(QString::number(results[i].eventID)));
166-
ui->counterResults->setItem(row, counterIndex[results[i].counterID] + 1,
167-
new QTableWidgetItem(FormatCounterResult(
168-
results[i], counterDescriptions[results[i].counterID])));
228+
new CustomSortedTableItem(QString::number(results[i].eventID),
229+
SortValue(results[i].eventID)));
230+
231+
ui->counterResults->setItem(
232+
row, counterIndex[results[i].counterID] + 1,
233+
MakeCounterResultItem(results[i], counterDescriptions[results[i].counterID]));
169234

170235
ui->counterResults->item(row, 0)->setData(Qt::UserRole, results[i].eventID);
171236
}

qrenderdoc/Windows/PerformanceCounterViewer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace Ui
3232
class PerformanceCounterViewer;
3333
}
3434

35+
class QTableWidgetItem;
36+
3537
class PerformanceCounterViewer : public QFrame, public IPerformanceCounterViewer, public ILogViewer
3638
{
3739
Q_OBJECT
@@ -53,7 +55,8 @@ private slots:
5355
void on_saveCSV_clicked();
5456

5557
private:
56-
QString FormatCounterResult(const CounterResult &result, const CounterDescription &description);
58+
QTableWidgetItem *MakeCounterResultItem(const CounterResult &result,
59+
const CounterDescription &description);
5760

5861
QList<GPUCounter> m_SelectedCounters;
5962

qrenderdoc/Windows/PerformanceCounterViewer.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121
<property name="selectionBehavior">
122122
<enum>QAbstractItemView::SelectRows</enum>
123123
</property>
124+
<property name="sortingEnabled">
125+
<bool>true</bool>
126+
</property>
124127
<attribute name="horizontalHeaderHighlightSections">
125128
<bool>false</bool>
126129
</attribute>

0 commit comments

Comments
 (0)