diff --git a/qrenderdoc/Windows/EventBrowser.cpp b/qrenderdoc/Windows/EventBrowser.cpp index f61e026c5..0a442d07f 100644 --- a/qrenderdoc/Windows/EventBrowser.cpp +++ b/qrenderdoc/Windows/EventBrowser.cpp @@ -24,6 +24,7 @@ #include "EventBrowser.h" #include +#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 &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); diff --git a/qrenderdoc/Windows/EventBrowser.h b/qrenderdoc/Windows/EventBrowser.h index ff6776e6a..b1dc7d0b2 100644 --- a/qrenderdoc/Windows/EventBrowser.h +++ b/qrenderdoc/Windows/EventBrowser.h @@ -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 &draws); void SetDrawcallTimes(QTreeWidgetItem *node, const rdctype::array &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 m_Bookmarks; + QList m_BookmarkButtons; + void RefreshIcon(QTreeWidgetItem *item); Ui::EventBrowser *ui; diff --git a/qrenderdoc/Windows/EventBrowser.ui b/qrenderdoc/Windows/EventBrowser.ui index c68cefcd4..f7e816966 100644 --- a/qrenderdoc/Windows/EventBrowser.ui +++ b/qrenderdoc/Windows/EventBrowser.ui @@ -118,7 +118,7 @@ - + @@ -411,69 +411,69 @@ - - - 3 + + + + 0 + 0 + 82 + 16 + - - 6 - - - 0 - - - 6 - - - 0 - - - - - - - - :/asterisk_orange.png - - - - - - - Bookmarks - - - Qt::PlainText - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 0 - - - - - - - Qt::Vertical - - - - - - - Qt::Horizontal - - - - 564 - 20 - - - - - + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + :/asterisk_orange.png + + + + + + + + 0 + 0 + + + + Bookmarks + + + Qt::PlainText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 0 + + + + + + + Qt::Vertical + + + + +