Skip to content

Commit

Permalink
create helper method QgsCheckableComboBox::addItemWithCheckState
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Sep 14, 2020
1 parent 4fe3d2f commit b516a49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/gui/auto_generated/qgscheckablecombobox.sip.in
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgscheckablecombobox.cpp
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgscheckablecombobox.h
Expand Up @@ -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()
Expand Down

0 comments on commit b516a49

Please sign in to comment.