create helper method QgsCheckableComboBox::addItemWithCheckState

This commit is contained in:
Denis Rouzaud 2020-09-11 10:57:22 +02:00
parent 4fe3d2f4e6
commit b516a49b9e
3 changed files with 23 additions and 0 deletions

View File

@ -62,6 +62,15 @@ no items selected.
:param text: default text
.. seealso:: :py:func:`defaultText`
%End
void addItemWithCheckState( const QString &text, Qt::CheckState state, const QVariant &userData = QVariant() );
%Docstring
Adds an item to the combobox with the given ``text``, check ``state``
and containing the specified ``userData`` (stored in the Qt.UserRole).
The item is appended to the list of existing items.
.. versionadded:: 3.16
%End
QStringList checkedItems() const;

View File

@ -134,6 +134,12 @@ void QgsCheckableComboBox::setDefaultText( const QString &text )
}
}
void QgsCheckableComboBox::addItemWithCheckState( const QString &text, Qt::CheckState state, const QVariant &userData )
{
QComboBox::addItem( text, userData );
setItemCheckState( count(), state );
}
QStringList QgsCheckableComboBox::checkedItems() const
{
QStringList items;

View File

@ -163,6 +163,14 @@ class GUI_EXPORT QgsCheckableComboBox : public QComboBox
*/
void setDefaultText( const QString &text );
/**
* Adds an item to the combobox with the given \a text, check \a state
* and containing the specified \a userData (stored in the Qt::UserRole).
* The item is appended to the list of existing items.
* \since QGIS 3.16
*/
void addItemWithCheckState( const QString &text, Qt::CheckState state, const QVariant &userData = QVariant() );
/**
* Returns currently checked items.
* \see setCheckedItems()