Implement bookmark handling in the event browser

This commit is contained in:
baldurk
2017-02-13 14:29:13 +00:00
parent 801547ac16
commit 55e5bcca61
3 changed files with 204 additions and 73 deletions
+123 -9
View File
@@ -24,6 +24,7 @@
#include "EventBrowser.h"
#include <QTimer>
#include "3rdparty/flowlayout/FlowLayout.h"
#include "Code/CaptureContext.h"
#include "Code/QRDUtils.h"
#include "ui_EventBrowser.h"
@@ -47,6 +48,8 @@ EventBrowser::EventBrowser(CaptureContext &ctx, QWidget *parent)
m_Ctx.AddLogViewer(this);
clearBookmarks();
ui->events->header()->resizeSection(COL_EID, 45);
ui->events->header()->setSectionResizeMode(COL_NAME, QHeaderView::Stretch);
@@ -77,6 +80,13 @@ EventBrowser::EventBrowser(CaptureContext &ctx, QWidget *parent)
ui->findStrip->hide();
ui->bookmarkStrip->hide();
m_BookmarkStripLayout = new FlowLayout(ui->bookmarkStrip, 0, 3, 3);
m_BookmarkSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
ui->bookmarkStrip->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
m_BookmarkStripLayout->addWidget(ui->bookmarkStripHeader);
m_BookmarkStripLayout->addItem(m_BookmarkSpacer);
m_CurrentIcon.addFile(QStringLiteral(":/flag_green.png"), QSize(), QIcon::Normal, QIcon::Off);
m_FindIcon.addFile(QStringLiteral(":/find.png"), QSize(), QIcon::Normal, QIcon::Off);
m_BookmarkIcon.addFile(QStringLiteral(":/asterisk_orange.png"), QSize(), QIcon::Normal, QIcon::Off);
@@ -96,6 +106,8 @@ void EventBrowser::OnLogfileLoaded()
(QTreeWidget *)NULL,
QStringList{QString("Frame #%1").arg(m_Ctx.FrameInfo().frameNumber), "", ""});
clearBookmarks();
QTreeWidgetItem *framestart = new QTreeWidgetItem(frame, QStringList{"Frame Start", "0", ""});
framestart->setData(COL_EID, Qt::UserRole, QVariant(0));
framestart->setData(COL_CURRENT, Qt::UserRole, QVariant(false));
@@ -116,12 +128,15 @@ void EventBrowser::OnLogfileLoaded()
void EventBrowser::OnLogfileClosed()
{
clearBookmarks();
ui->events->clear();
}
void EventBrowser::OnEventChanged(uint32_t eventID)
{
SelectEvent(eventID);
highlightBookmarks();
}
uint EventBrowser::AddDrawcalls(QTreeWidgetItem *parent, const rdctype::array<FetchDrawcall> &draws)
@@ -199,7 +214,6 @@ void EventBrowser::on_find_clicked()
{
ui->jumpStrip->hide();
ui->findStrip->show();
ui->bookmarkStrip->hide();
ui->findEvent->setFocus();
}
@@ -207,15 +221,15 @@ void EventBrowser::on_gotoEID_clicked()
{
ui->jumpStrip->show();
ui->findStrip->hide();
ui->bookmarkStrip->hide();
ui->jumpToEID->setFocus();
}
void EventBrowser::on_toolButton_clicked()
void EventBrowser::on_bookmark_clicked()
{
ui->jumpStrip->hide();
ui->findStrip->hide();
ui->bookmarkStrip->show();
QTreeWidgetItem *n = ui->events->currentItem();
if(n)
toggleBookmark(n->data(COL_LAST_EID, Qt::UserRole).toUInt());
}
void EventBrowser::on_timeDraws_clicked()
@@ -250,6 +264,8 @@ void EventBrowser::on_events_currentItemChanged(QTreeWidgetItem *current, QTreeW
uint lastEID = current->data(COL_LAST_EID, Qt::UserRole).toUInt();
m_Ctx.SetEventID({this}, EID, lastEID);
highlightBookmarks();
}
void EventBrowser::on_HideFindJump()
@@ -326,21 +342,119 @@ void EventBrowser::on_findPrev_clicked()
Find(false);
}
void EventBrowser::clearBookmarks()
{
for(QToolButton *b : m_BookmarkButtons)
delete b;
m_Bookmarks.clear();
m_BookmarkButtons.clear();
ui->bookmarkStrip->setVisible(false);
}
void EventBrowser::toggleBookmark(uint32_t EID)
{
int index = m_Bookmarks.indexOf(EID);
QTreeWidgetItem *found = NULL;
FindEventNode(found, ui->events->topLevelItem(0), EID);
if(index >= 0)
{
delete m_BookmarkButtons.takeAt(index);
m_Bookmarks.removeAt(index);
if(found)
{
found->setData(COL_BOOKMARK, Qt::UserRole, QVariant(false));
RefreshIcon(found);
}
}
else
{
QToolButton *but = new QToolButton(this);
but->setText(QString::number(EID));
but->setCheckable(true);
but->setAutoRaise(true);
but->setProperty("eid", EID);
QObject::connect(but, &QToolButton::clicked, [this, but, EID]() {
but->setChecked(true);
SelectEvent(EID);
highlightBookmarks();
});
m_BookmarkButtons.push_back(but);
m_Bookmarks.push_back(EID);
highlightBookmarks();
if(found)
{
found->setData(COL_BOOKMARK, Qt::UserRole, QVariant(true));
RefreshIcon(found);
}
m_BookmarkStripLayout->removeItem(m_BookmarkSpacer);
m_BookmarkStripLayout->addWidget(but);
m_BookmarkStripLayout->addItem(m_BookmarkSpacer);
}
ui->bookmarkStrip->setVisible(!m_BookmarkButtons.isEmpty());
}
void EventBrowser::jumpToBookmark(int idx)
{
if(idx < 0 || idx >= m_Bookmarks.count() || !m_Ctx.LogLoaded())
return;
// don't exclude ourselves, so we're updated as normal
SelectEvent(m_Bookmarks[idx]);
}
void EventBrowser::highlightBookmarks()
{
for(QToolButton *b : m_BookmarkButtons)
{
if(b->property("eid").toUInt() == m_Ctx.CurEvent())
b->setChecked(true);
else
b->setChecked(false);
}
}
bool EventBrowser::hasBookmark(QTreeWidgetItem *node)
{
if(node)
return hasBookmark(node->data(COL_EID, Qt::UserRole).toUInt());
return false;
}
bool EventBrowser::hasBookmark(uint32_t EID)
{
return m_Bookmarks.contains(EID);
}
void EventBrowser::RefreshIcon(QTreeWidgetItem *item)
{
if(item->data(COL_CURRENT, Qt::UserRole).toBool())
item->setIcon(COL_NAME, m_CurrentIcon);
else if(item->data(COL_FIND, Qt::UserRole).toBool())
item->setIcon(COL_NAME, m_FindIcon);
else if(item->data(COL_BOOKMARK, Qt::UserRole).toBool())
item->setIcon(COL_NAME, m_BookmarkIcon);
else if(item->data(COL_FIND, Qt::UserRole).toBool())
item->setIcon(COL_NAME, m_FindIcon);
else
item->setIcon(COL_NAME, QIcon());
}
bool EventBrowser::FindEventNode(QTreeWidgetItem *&found, QTreeWidgetItem *parent, uint32_t eventID)
{
for(int i = 0; i < parent->childCount(); i++)
// do a reverse search to find the last match (in case of 'set' markers that
// inherit the event of the next real draw).
for(int i = parent->childCount() - 1; i >= 0; i--)
{
QTreeWidgetItem *n = parent->child(i);
+18 -1
View File
@@ -33,8 +33,11 @@ namespace Ui
class EventBrowser;
}
class QSpacerItem;
class QToolButton;
class QTreeWidgetItem;
class QTimer;
class FlowLayout;
class SizeDelegate;
class EventBrowser : public QFrame, public ILogViewerForm
@@ -56,7 +59,7 @@ private slots:
void on_find_clicked();
void on_gotoEID_clicked();
void on_timeDraws_clicked();
void on_toolButton_clicked();
void on_bookmark_clicked();
void on_HideFindJump();
void on_jumpToEID_returnPressed();
void on_findEvent_returnPressed();
@@ -68,6 +71,12 @@ private slots:
// manual slots
void findHighlight_timeout();
public slots:
void clearBookmarks();
bool hasBookmark(uint32_t EID);
void toggleBookmark(uint32_t EID);
void jumpToBookmark(int idx);
private:
uint AddDrawcalls(QTreeWidgetItem *parent, const rdctype::array<FetchDrawcall> &draws);
void SetDrawcallTimes(QTreeWidgetItem *node, const rdctype::array<CounterResult> &results);
@@ -83,6 +92,9 @@ private:
int SetFindIcons(QTreeWidgetItem *parent, QString filter);
int SetFindIcons(QString filter);
void highlightBookmarks();
bool hasBookmark(QTreeWidgetItem *node);
QTreeWidgetItem *FindNode(QTreeWidgetItem *parent, QString filter, uint32_t after);
int FindEvent(QTreeWidgetItem *parent, QString filter, uint32_t after, bool forward);
int FindEvent(QString filter, uint32_t after, bool forward);
@@ -95,6 +107,11 @@ private:
SizeDelegate *m_SizeDelegate;
QTimer *m_FindHighlight;
FlowLayout *m_BookmarkStripLayout;
QSpacerItem *m_BookmarkSpacer;
QList<int> m_Bookmarks;
QList<QToolButton *> m_BookmarkButtons;
void RefreshIcon(QTreeWidgetItem *item);
Ui::EventBrowser *ui;
+63 -63
View File
@@ -118,7 +118,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<widget class="QToolButton" name="bookmark">
<property name="text">
<string/>
</property>
@@ -411,69 +411,69 @@
</item>
<item>
<widget class="QWidget" name="bookmarkStrip" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="spacing">
<number>3</number>
<widget class="QWidget" name="bookmarkStripHeader" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>82</width>
<height>16</height>
</rect>
</property>
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../Resources/resources.qrc">:/asterisk_orange.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Bookmarks</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer name="bookmarkSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>564</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="bookmarkStripIcon">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../Resources/resources.qrc">:/asterisk_orange.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="bookmarkStripLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Bookmarks</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="Line" name="bookmarkStripLine">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>