25 #include <QAbstractItemView>
28 #include <QMouseEvent>
29 #include <QStandardItem>
30 #include <QStandardItemModel>
31 #include <QStyledItemDelegate>
32 #include <QVBoxLayout>
42 void paint(QPainter* painter,
const QStyleOptionViewItem& option,
43 const QModelIndex& index)
const override
45 auto styleOption =
const_cast<QStyleOptionViewItem&
>(option);
46 styleOption.showDecorationSelected =
false;
47 QStyledItemDelegate::paint(painter, styleOption, index);
55 , m_box(new QComboBox)
57 , m_model(new QStandardItemModel(this))
59 setAutoFillBackground(
true);
60 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
63 m_box->view()->viewport()->installEventFilter(
this);
66 m_box->setEditable(
true);
67 m_box->lineEdit()->setReadOnly(
true);
68 m_box->lineEdit()->installEventFilter(
this);
69 connect(
m_box->lineEdit(), &QLineEdit::selectionChanged,
m_box->lineEdit(),
70 &QLineEdit::deselect);
76 auto layout =
new QVBoxLayout;
78 layout->setSpacing(0);
79 layout->addWidget(
m_box);
86 return m_box->sizeHint();
91 return m_box->minimumSizeHint();
102 const QVector<int>& roles)
104 #if QT_VERSION > QT_VERSION_CHECK(5, 9, 0)
110 auto item =
m_model->itemFromIndex(topLeft);
115 auto state = item->checkState() == Qt::Checked ? true :
false;
119 setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty));
126 if (
auto item =
m_model->itemFromIndex(index)) {
127 auto state = item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked;
128 item->setCheckState(state);
141 const auto mouseEvent =
static_cast<const QMouseEvent*
>(event);
142 auto index =
m_box->view()->indexAt(mouseEvent->pos());
153 return QObject::eventFilter(obj, event);
167 auto labels =
property.values();
168 auto selectedIndices =
property.selectedIndices();
170 for (
size_t i = 0; i < labels.size(); ++i) {
171 auto item =
new QStandardItem(QString::fromStdString(labels[i]));
172 m_model->invisibleRootItem()->appendRow(item);
173 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
174 item->setCheckable(
true);
176 auto state =
Utils::Contains(selectedIndices, i) ? Qt::Checked : Qt::Unchecked;
187 connect(
m_model, &QStandardItemModel::dataChanged,
this,
190 disconnect(
m_model, &QStandardItemModel::dataChanged,
this,
200 m_box->setCurrentText(QString::fromStdString(combo.
label()));
205 return obj ==
m_box->view()->viewport() &&
event->type() == QEvent::MouseButtonRelease;
210 return obj ==
m_box->lineEdit() &&
event->type() == QEvent::MouseButtonRelease;
Custom property to define list of string values with multiple selections.
std::string label() const
Returns the label to show.
void setSelected(int index, bool value=true)
Sets given index selection flag.
Base class for all custom variant editors.
void setDataIntern(const QVariant &data)
Saves the data as given by editor's internal components and notifies the model.
bool isClickToSelect(QObject *obj, QEvent *event) const
void update_components() override
Should update widget components from m_data, if necessary.
QStandardItemModel * m_model
bool isClickToExpand(QObject *obj, QEvent *event) const
QSize sizeHint() const override
bool is_persistent() const override
Returns true if editor should remains alive after editing finished.
void updateBoxLabel()
Update text on QComboBox with the label provided by combo property.
QSize minimumSizeHint() const override
WheelEventFilter * m_wheelEventFilter
SelectableComboBoxEditor(QWidget *parent=nullptr)
void setConnected(bool isConnected)
bool eventFilter(QObject *obj, QEvent *event) override
Handles mouse clicks on QComboBox elements.
void onModelDataChanged(const QModelIndex &, const QModelIndex &, const QVector< int > &)
Propagate check state from the model to ComboProperty.
void onClickedList(const QModelIndex &index)
Processes press event in QComboBox's underlying list view.
Event filter to install on combo boxes and spin boxes to ignore wheel events during scrolling.
Provides custom style delegate for QComboBox to allow checkboxes.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QCheckListStyledItemDelegate(QObject *parent=nullptr)
bool Contains(const A &container, const B &element)
Returns true if container contains a given element.
materialitems.h Collection of materials to populate MaterialModel.
QVariant CheckStateRole(const SessionItem &item)
Returns check state for given item.