18#ifndef QGSCHECKABLECOMBOBOX_H
19#define QGSCHECKABLECOMBOBOX_H
23#include <QStandardItemModel>
24#include <QStyledItemDelegate>
59 Qt::ItemFlags
flags(
const QModelIndex &index )
const override;
67 QVariant
data(
const QModelIndex &index,
int role = Qt::DisplayRole )
const override;
76 bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole )
override;
114 void paint( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
128 Q_PROPERTY( QString separator READ separator WRITE setSeparator )
129 Q_PROPERTY( QString defaultText READ defaultText WRITE setDefaultText )
130 Q_PROPERTY( QStringList checkedItems READ checkedItems WRITE setCheckedItems )
143 QString separator()
const;
150 void setSeparator(
const QString &separator );
157 QString defaultText()
const;
165 void setDefaultText(
const QString &text );
173 void addItemWithCheckState(
const QString &text, Qt::CheckState state,
const QVariant &userData = QVariant() );
179 QStringList checkedItems()
const;
186 QVariantList checkedItemsData()
const;
194 Qt::CheckState itemCheckState(
int index )
const;
203 void setItemCheckState(
int index, Qt::CheckState state );
211 void toggleItemCheckState(
int index );
224 void hidePopup()
override;
229 bool eventFilter( QObject *
object, QEvent *event )
override;
245 void setCheckedItems(
const QStringList &items );
252 void resizeEvent( QResizeEvent *event )
override;
260 void showContextMenu( QPoint pos );
265 void selectAllOptions();
270 void deselectAllOptions();
276 void updateCheckedItems();
277 void updateDisplayText();
280 QString mDefaultText;
282 bool mSkipHide =
false;
284 QMenu *mContextMenu =
nullptr;
285 QAction *mSelectAllAction =
nullptr;
286 QAction *mDeselectAllAction =
nullptr;
QStyledItemDelegate subclass for QgsCheckableComboBox.
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.
QComboBox subclass which allows selecting multiple items.
void checkedItemsChanged(const QStringList &items)
Emitted whenever the checked items list changed.
QgsCheckableItemModel * model() const
Returns the custom item model which handles checking the 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.