diff --git a/qrenderdoc/Code/Interface/Extensions.h b/qrenderdoc/Code/Interface/Extensions.h index 496aa8833..5ce9e2a3e 100644 --- a/qrenderdoc/Code/Interface/Extensions.h +++ b/qrenderdoc/Code/Interface/Extensions.h @@ -891,7 +891,7 @@ happen. DOCUMENT(R"(Create a drop-down combo box widget. When created there are no pre-defined entries in the drop-down section. This can be changed with -:meth:`SetComboOptions`. +:meth:`SetComboBoxOptions`. :param bool editable: ``True`` if the widget should allow the user to enter any text they wish as well as being able to select a pre-defined entry. @@ -908,7 +908,24 @@ passed nothing will happen. :param QWidget combo: The combo box. :param List[str] options: The new options for the combo box. )"); - virtual void SetComboOptions(QWidget *combo, const rdcarray &options) = 0; + virtual void SetComboBoxOptions(QWidget *combo, const rdcarray &options) = 0; + + DOCUMENT(R"(Get the number of options in a drop-down combo box. If another type of widget is +passed ``0`` will be returned. + +:param QWidget combo: The combo box. +:return: The current number of options. +:rtype: int +)") + virtual size_t GetComboBoxCount(QWidget *combo) = 0; + + DOCUMENT(R"(Select the current option in a drop-down combo box. If another type of widget or +an unknown option is passed, nothing will happen. + +:param QWidget combo: The combo box. +:param str option: The option to select. +)") + virtual void SelectComboBoxOption(QWidget *combo, const rdcstr &option) = 0; protected: DOCUMENT(""); diff --git a/qrenderdoc/Code/MiniQtHelper.cpp b/qrenderdoc/Code/MiniQtHelper.cpp index 1e12adb38..969336fe4 100644 --- a/qrenderdoc/Code/MiniQtHelper.cpp +++ b/qrenderdoc/Code/MiniQtHelper.cpp @@ -686,7 +686,7 @@ QWidget *MiniQtHelper::CreateComboBox(bool editable, WidgetCallback changed) return w; } -void MiniQtHelper::SetComboOptions(QWidget *combo, const rdcarray &options) +void MiniQtHelper::SetComboBoxOptions(QWidget *combo, const rdcarray &options) { if(!combo) return; @@ -700,3 +700,21 @@ void MiniQtHelper::SetComboOptions(QWidget *combo, const rdcarray &optio comb->clear(); comb->addItems(texts); } + +size_t MiniQtHelper::GetComboBoxCount(QWidget *combo) +{ + if(!combo) + return 0; + const QComboBox *comb = qobject_cast(combo); + + return comb->count(); +} + +void MiniQtHelper::SelectComboBoxOption(QWidget *combo, const rdcstr &option) +{ + if(!combo) + return; + QComboBox *comb = qobject_cast(combo); + + comb->setCurrentText(option); +} diff --git a/qrenderdoc/Code/MiniQtHelper.h b/qrenderdoc/Code/MiniQtHelper.h index c297e1398..ed812d6d3 100644 --- a/qrenderdoc/Code/MiniQtHelper.h +++ b/qrenderdoc/Code/MiniQtHelper.h @@ -115,7 +115,9 @@ public: QWidget *CreateComboBox(bool editable, WidgetCallback changed) override; - void SetComboOptions(QWidget *combo, const rdcarray &options) override; + void SetComboBoxOptions(QWidget *combo, const rdcarray &options) override; + size_t GetComboBoxCount(QWidget *combo) override; + void SelectComboBoxOption(QWidget *combo, const rdcstr &option) override; private: ICaptureContext &m_Ctx; diff --git a/qrenderdoc/Windows/PythonShell.cpp b/qrenderdoc/Windows/PythonShell.cpp index 8ddb43aca..5e1c12e94 100644 --- a/qrenderdoc/Windows/PythonShell.cpp +++ b/qrenderdoc/Windows/PythonShell.cpp @@ -298,9 +298,19 @@ struct MiniQtInvoker : ObjectForwarder return InvokeRetFunction(&IMiniQtHelper::CreateComboBox, editable, changed); } - void SetComboOptions(QWidget *combo, const rdcarray &options) + void SetComboBoxOptions(QWidget *combo, const rdcarray &options) { - InvokeVoidFunction(&IMiniQtHelper::SetComboOptions, combo, options); + InvokeVoidFunction(&IMiniQtHelper::SetComboBoxOptions, combo, options); + } + + size_t GetComboBoxCount(QWidget *combo) + { + return InvokeRetFunction(&IMiniQtHelper::GetComboBoxCount, combo); + } + + void SelectComboBoxOption(QWidget *combo, const rdcstr &option) + { + InvokeVoidFunction(&IMiniQtHelper::SelectComboBoxOption, combo, option); } };