22 #include <QMouseEvent>
23 #include <QStandardItem>
24 #include <QStandardItemModel>
25 #include <QVBoxLayout>
28 : QStyledItemDelegate(parent)
33 const QModelIndex& index)
const
35 QStyleOptionViewItem& styleOption =
const_cast<QStyleOptionViewItem&
>(option);
36 styleOption.showDecorationSelected =
false;
37 QStyledItemDelegate::paint(painter, styleOption, index);
48 , m_box(new QComboBox)
50 , m_model(new QStandardItemModel(this))
52 setAutoFillBackground(
true);
53 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
56 m_box->view()->viewport()->installEventFilter(
this);
59 m_box->setEditable(
true);
60 m_box->lineEdit()->setReadOnly(
true);
61 m_box->lineEdit()->installEventFilter(
this);
62 connect(
m_box->lineEdit(), &QLineEdit::selectionChanged,
m_box->lineEdit(),
63 &QLineEdit::deselect);
69 auto layout =
new QVBoxLayout;
71 layout->setSpacing(0);
72 layout->addWidget(
m_box);
79 return m_box->sizeHint();
84 return m_box->minimumSizeHint();
96 auto item =
m_model->itemFromIndex(topLeft);
101 auto state = item->checkState() == Qt::Checked;
105 setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty));
112 if (
auto item =
m_model->itemFromIndex(index)) {
113 auto state = item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked;
114 item->setCheckState(state);
127 const auto mouseEvent =
static_cast<const QMouseEvent*
>(event);
128 auto index =
m_box->view()->indexAt(mouseEvent->pos());
139 return QObject::eventFilter(obj, event);
153 auto labels =
property.getValues();
154 auto selectedIndices =
property.selectedIndices();
156 for (
int i = 0; i < labels.size(); ++i) {
157 auto item =
new QStandardItem(labels[i]);
158 m_model->invisibleRootItem()->appendRow(item);
159 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
160 item->setCheckable(
true);
162 auto state = selectedIndices.contains(i) ? Qt::Checked : Qt::Unchecked;
173 connect(
m_model, &QStandardItemModel::dataChanged,
this,
176 disconnect(
m_model, &QStandardItemModel::dataChanged,
this,
191 return obj ==
m_box->view()->viewport() &&
event->type() == QEvent::MouseButtonRelease;
196 return obj ==
m_box->lineEdit() &&
event->type() == QEvent::MouseButtonRelease;
Defines class ComboProperty.
Defines classes releted to event filtering.
Defines MultiComboPropertyEditor class.
Custom property to define list of string values with multiple selections.
void setSelected(int index, bool value=true)
Sets given index selection flag.
QString label() const
Returns the label to show.
Base class for all custom variants editors.
void setDataIntern(const QVariant &data)
Saves the data from the editor and informs external delegates.
MultiComboPropertyEditor(QWidget *parent=nullptr)
void onModelDataChanged(const QModelIndex &, const QModelIndex &, const QVector< int > &)
Propagate check state from the model to ComboProperty.
bool isClickToExpand(QObject *obj, QEvent *event) const
void updateBoxLabel()
Update text on QComboBox with the label provided by combo property.
void onClickedList(const QModelIndex &index)
Processes press event in QComboBox's underlying list view.
bool isClickToSelect(QObject *obj, QEvent *event) const
QSize minimumSizeHint() const
QStandardItemModel * m_model
bool eventFilter(QObject *obj, QEvent *event)
Handles mouse clicks on QComboBox elements.
class WheelEventEater * m_wheel_event_filter
void initEditor()
Inits editor widgets from m_data.
void setConnected(bool isConnected)
Provides custom style delegate for QComboBox to allow checkboxes.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
QCheckListStyledItemDelegate(QObject *parent=nullptr)
Event filter to install on combo boxes and spin boxes to not to react on wheel events during scrollin...
QVariant CheckStateRole(const SessionItem &item)
Returns check state for given item.