diff --git a/qrenderdoc/Code/Interface/Extensions.h b/qrenderdoc/Code/Interface/Extensions.h index e4a6608ec..20879fe2b 100644 --- a/qrenderdoc/Code/Interface/Extensions.h +++ b/qrenderdoc/Code/Interface/Extensions.h @@ -687,6 +687,17 @@ add text next to it. )"); virtual void SetWidgetText(QWidget *widget, const rdcstr &text) = 0; + DOCUMENT(R"(Appends to the 'text' of a widget. For most widgets this will not be different from +getting the text with :meth:`GetWidgetText`, appending to the string, and setting with :meth:`SetWidgetText` +but for multi-line widgets like text edits this can give a better experience with better scrolling. + +This will also scroll to and move the cursor to the end of the text. + +:param QWidget widget: The widget to append text for. +:param str text: The text to append to the widget's text. +)"); + virtual void AppendText(QWidget *widget, const rdcstr &text) = 0; + DOCUMENT(R"(Return the current text of a widget. See :meth:`SetWidgetText`. :param QWidget widget: The widget to query. diff --git a/qrenderdoc/Code/MiniQtHelper.cpp b/qrenderdoc/Code/MiniQtHelper.cpp index 135f546c6..759de4753 100644 --- a/qrenderdoc/Code/MiniQtHelper.cpp +++ b/qrenderdoc/Code/MiniQtHelper.cpp @@ -365,6 +365,28 @@ void MiniQtHelper::SetWidgetText(QWidget *widget, const rdcstr &text) } } +void MiniQtHelper::AppendText(QWidget *widget, const rdcstr &text) +{ +#define APPEND_TEXT(TextWidget) \ + { \ + TextWidget *w = qobject_cast(widget); \ + if(w) \ + { \ + ScrollToBottom(widget); \ + w->moveCursor(QTextCursor::End); \ + w->insertPlainText(text); \ + return; \ + } \ + } + + APPEND_TEXT(RDTextEdit); + APPEND_TEXT(QTextEdit); + + rdcstr t = GetWidgetText(widget); + t += text; + SetWidgetText(widget, t); +} + rdcstr MiniQtHelper::GetWidgetText(QWidget *widget) { if(!widget) diff --git a/qrenderdoc/Code/MiniQtHelper.h b/qrenderdoc/Code/MiniQtHelper.h index 41056b81c..a57fb59f3 100644 --- a/qrenderdoc/Code/MiniQtHelper.h +++ b/qrenderdoc/Code/MiniQtHelper.h @@ -72,6 +72,7 @@ public: // widget manipulation void SetWidgetText(QWidget *widget, const rdcstr &text) override; + void AppendText(QWidget *widget, const rdcstr &text) override; rdcstr GetWidgetText(QWidget *widget) override; void ScrollToTop(QWidget *widget) override; diff --git a/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp b/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp index 34045ac9a..96f81f5b7 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonInvokers.cpp @@ -177,6 +177,10 @@ struct MiniQtInvoker : UIThreadInvoker { InvokeVoidFunction(&IMiniQtHelper::SetWidgetText, widget, text); } + void AppendText(QWidget *widget, const rdcstr &text) + { + InvokeVoidFunction(&IMiniQtHelper::AppendText, widget, text); + } rdcstr GetWidgetText(QWidget *widget) { return InvokeRetFunction(&IMiniQtHelper::GetWidgetText, widget);