MiniQtHelper: upgrade ComboBox widget

Added interface functions:
    - GetComboBoxCount() the function returns the number of
      combo box options currently set,
    - SelectComboBoxOption() - selects an active combo box
      option by name from the list of set options.

Updated interface functions:
    - Changed SetComboOptions() to SetComboBoxOptions to keep
      consistency in naming.
This commit is contained in:
Artur Wojcik
2022-11-17 19:22:40 +01:00
committed by Baldur Karlsson
parent e2f3426dc6
commit e630515813
4 changed files with 53 additions and 6 deletions
+19 -2
View File
@@ -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<rdcstr> &options) = 0;
virtual void SetComboBoxOptions(QWidget *combo, const rdcarray<rdcstr> &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("");
+19 -1
View File
@@ -686,7 +686,7 @@ QWidget *MiniQtHelper::CreateComboBox(bool editable, WidgetCallback changed)
return w;
}
void MiniQtHelper::SetComboOptions(QWidget *combo, const rdcarray<rdcstr> &options)
void MiniQtHelper::SetComboBoxOptions(QWidget *combo, const rdcarray<rdcstr> &options)
{
if(!combo)
return;
@@ -700,3 +700,21 @@ void MiniQtHelper::SetComboOptions(QWidget *combo, const rdcarray<rdcstr> &optio
comb->clear();
comb->addItems(texts);
}
size_t MiniQtHelper::GetComboBoxCount(QWidget *combo)
{
if(!combo)
return 0;
const QComboBox *comb = qobject_cast<const QComboBox *>(combo);
return comb->count();
}
void MiniQtHelper::SelectComboBoxOption(QWidget *combo, const rdcstr &option)
{
if(!combo)
return;
QComboBox *comb = qobject_cast<QComboBox *>(combo);
comb->setCurrentText(option);
}
+3 -1
View File
@@ -115,7 +115,9 @@ public:
QWidget *CreateComboBox(bool editable, WidgetCallback changed) override;
void SetComboOptions(QWidget *combo, const rdcarray<rdcstr> &options) override;
void SetComboBoxOptions(QWidget *combo, const rdcarray<rdcstr> &options) override;
size_t GetComboBoxCount(QWidget *combo) override;
void SelectComboBoxOption(QWidget *combo, const rdcstr &option) override;
private:
ICaptureContext &m_Ctx;
+12 -2
View File
@@ -298,9 +298,19 @@ struct MiniQtInvoker : ObjectForwarder<IMiniQtHelper>
return InvokeRetFunction<QWidget *>(&IMiniQtHelper::CreateComboBox, editable, changed);
}
void SetComboOptions(QWidget *combo, const rdcarray<rdcstr> &options)
void SetComboBoxOptions(QWidget *combo, const rdcarray<rdcstr> &options)
{
InvokeVoidFunction(&IMiniQtHelper::SetComboOptions, combo, options);
InvokeVoidFunction(&IMiniQtHelper::SetComboBoxOptions, combo, options);
}
size_t GetComboBoxCount(QWidget *combo)
{
return InvokeRetFunction<size_t>(&IMiniQtHelper::GetComboBoxCount, combo);
}
void SelectComboBoxOption(QWidget *combo, const rdcstr &option)
{
InvokeVoidFunction(&IMiniQtHelper::SelectComboBoxOption, combo, option);
}
};