18#ifndef QGSCHECKABLECOMBOBOX_H
19#define QGSCHECKABLECOMBOBOX_H
27#include <QStandardItemModel>
28#include <QStyledItemDelegate>
57 Qt::ItemFlags
flags(
const QModelIndex &index )
const override;
65 QVariant
data(
const QModelIndex &index,
int role = Qt::DisplayRole )
const override;
74 bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole )
override;
110 void paint( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
167 void addItemWithCheckState( const QString &text, Qt::CheckState state, const QVariant &userData = QVariant() );
209 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
210 for (
int idx = 0; idx < metaEnum.keyCount(); ++idx )
212 setItemCheckState( findData( QVariant::fromValue( metaEnum.value( idx ) ) ), value.testFlag(
static_cast< T
>( metaEnum.value( idx ) ) ) ? Qt::CheckState::Checked : Qt::CheckState::Unchecked );
224 for (
int i = 0; i < count(); ++i )
228 res.setFlag( itemData( i ).value< T >(),
true );
242 void toggleItemCheckState(
int index );
255 void hidePopup()
override;
260 bool eventFilter( QObject *
object, QEvent *event )
override;
306 void updateCheckedItems();
307 void updateDisplayText();
310 QString mDefaultText;
312 bool mSkipHide =
false;
314 QMenu *mContextMenu =
nullptr;
315 QAction *mSelectAllAction =
nullptr;
316 QAction *mDeselectAllAction =
nullptr;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Renders the delegate using the given painter and style option for the item specified by index.
QgsCheckBoxDelegate(QObject *parent=nullptr)
Constructor for QgsCheckBoxDelegate.
void setSeparator(const QString &separator)
Set separator used to separate items in the display text.
void setItemCheckState(int index, Qt::CheckState state)
Sets the item check state to state.
void setCheckedItemsFromFlags(const QFlags< T > &value)
Sets item check state using a QFlags value.
void deselectAllOptions()
Removes selection from all items.
void selectAllOptions()
Selects all items.
void checkedItemsChanged(const QStringList &items)
Emitted whenever the checked items list changed.
void setCheckedItems(const QStringList &items)
Set items which should be checked/selected.
QgsCheckableComboBox(QWidget *parent=nullptr)
Constructor for QgsCheckableComboBox.
QVariantList checkedItemsData() const
Returns userData (stored in the Qt::UserRole) associated with currently checked items.
QgsCheckableItemModel * mModel
QgsCheckableItemModel * model() const
Returns the custom item model which handles checking the items.
Qt::CheckState itemCheckState(int index) const
Returns the checked state of the item identified by index.
void addItemWithCheckState(const QString &text, Qt::CheckState state, const QVariant &userData=QVariant())
Adds an item to the combobox with the given text, check state (stored in the Qt::CheckStateRole) and ...
void showContextMenu(QPoint pos)
Display context menu which allows selecting/deselecting all items at once.
void resizeEvent(QResizeEvent *event) override
Handler for widget resizing.
void setDefaultText(const QString &text)
Set default text which will be displayed in the widget when no items selected.
QFlags< T > flagsFromCheckedItems() const
Returns enum flags corresponding to the checked items.
QStandardItemModel subclass which makes all items checkable by default.
void itemCheckStateChanged(const QModelIndex &index)
Emitted whenever the item's checkstate has changed.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Sets the role data for the item at index to value.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns a combination of the item flags: items are enabled (ItemIsEnabled), selectable (ItemIsSelecta...
QgsCheckableItemModel(QObject *parent=nullptr)
Constructor for QgsCheckableItemModel.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.