mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-25 15:16:22 +00:00
Add helper function for appending text to a textedit
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<TextWidget *>(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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -177,6 +177,10 @@ struct MiniQtInvoker : UIThreadInvoker<IMiniQtHelper>
|
||||
{
|
||||
InvokeVoidFunction(&IMiniQtHelper::SetWidgetText, widget, text);
|
||||
}
|
||||
void AppendText(QWidget *widget, const rdcstr &text)
|
||||
{
|
||||
InvokeVoidFunction(&IMiniQtHelper::AppendText, widget, text);
|
||||
}
|
||||
rdcstr GetWidgetText(QWidget *widget)
|
||||
{
|
||||
return InvokeRetFunction<rdcstr>(&IMiniQtHelper::GetWidgetText, widget);
|
||||
|
||||
Reference in New Issue
Block a user