29 #include <QAccessible> 30 #include <QGuiApplication> 32 #include <QDesktopWidget> 33 #include <QHeaderView> 34 #include <QMouseEvent> 38 #include <QStandardItemModel> 81 painter->
drawLine(option.rect.left(), option.rect.center().y(), option.rect.right(), option.rect.center().y());
88 opt.font.setBold(
true);
89 opt.font.setItalic(
true);
114 m_skipNextHide(false)
131 if (!itemView || !(treeView = qobject_cast<QTreeView *>(itemView))) {
134 if (itemView && !treeView)
135 qWarning() <<
"TreeComboBox: Only QTreeView and derived classes are allowed, using default view instead.";
159 if (this->
model() == model)
180 index = qBound(0, index,
model()->rowCount(root));
193 if (root.
isValid() && m->itemFromIndex(root))
194 m->itemFromIndex(root)->insertRow(index, item);
196 m->insertRow(index, item);
199 else if (
model()->insertRows(index, 1, root)) {
221 return insertItem(index, values, parentIndex, reload);
226 for (
const QString &text : texts)
290 #ifndef QT_NO_ACCESSIBILITY 298 int idx =
findData(data, role, flags);
322 return QIcon(qvariant_cast<QPixmap>(decoration));
324 return qvariant_cast<QIcon>(decoration);
339 while (!result.isEmpty()) {
352 if (
model()->hasChildren(index) && !
view()->isExpanded(index)) {
363 if (
model()->hasChildren(index))
394 if (
event->delta() > 0)
396 else if (
event->delta() < 0)
415 switch (
event->key()) {
452 if (!
event->text().isEmpty())
466 if (
object ==
view()->viewport()) {
489 else if (
object ==
view()) {
495 switch (keyEvent->
key()) {
541 for (
int r=0; r < rows; ++r) {
548 if (
model()->hasChildren(index))
560 QModelIndexList parents;
562 for (
int r=0; r < rows; ++r) {
564 if (
model()->hasChildren(index)) {
566 if (parents.size() > 1)
570 if (!parents.size()) {
610 if (qobject_cast<TreeComboBoxView *>(
view())) {
641 const int aboveHeight = algnTop - screen.
y();
642 const int belowHeight = screen.
bottom() - algnBot;
650 listRect.
adjust(0, 0, 0, adjH);
660 if (listRect.
bottom() < algnTop)
664 if (listRect.
top() < screen.
top())
677 if (!boundToScreen || listRect.
height() > aboveHeight) {
679 if (boundToScreen && belowHeight < listRect.
height())
683 else if (listRect.
height() > belowHeight || listRect.
bottom() < algnTop || (listRect.
bottom() > algnTop && listRect.
top() < algnTop)) {
685 if (aboveHeight < listRect.
height())
void adjustPopupHeight()
Resize visible popup height when items are expanded/collapsed in the tree view.
void initStyleOption(QStyleOptionComboBox *option) const const
void setView(QAbstractItemView *itemView)
virtual int rowCount(const QModelIndex &parent) const const=0
An item rendering delegate to highlight parent items and draw better item separators.
QModelIndex indexBelow(QModelIndex index)
Find first valid item index which if after given index.
QAbstractItemModel * model() const const
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
QModelIndex lastIndex(const QModelIndex &index)
Find last (greatest) valid item index in a set (eg.
QTreeView subclass used to display the combo box popup items.
bool contains(const Key &key) const const
void setCurrentIndex(const QModelIndex &index)
void setRenderHint(QPainter::RenderHint hint, bool on)
void setWordWrap(bool on)
void setView(QAbstractItemView *itemView=Q_NULLPTR)
Like QComboBox::setView but only accepts QTreeView (and derived) view classes.
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
void setItemDelegate(QAbstractItemDelegate *delegate)
void collapsed(const QModelIndex &index)
QIcon itemIcon(int index) const
Reimplemented from superclass.
virtual void keyPressEvent(QKeyEvent *event) override
Reimplemented from superclass.
QModelIndex indexAbove(QModelIndex index)
Find first valid item index which if before given index.
static void setParent(QAbstractItemModel *model, const QModelIndex &index, const bool selectable=false)
virtual void keyPressEvent(QKeyEvent *e) override
QModelIndex indexBelow(const QModelIndex &index) const const
QVariant itemData(int index, int role=Qt::UserRole) const
Reimplemented from superclass.
void setRootModelIndex(const QModelIndex &index)
virtual QRect visualRect(const QModelIndex &index) const const override
void drawLine(const QLineF &line)
bool isEditable() const const
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QModelIndex insertItem(int index, const QMap< int, QVariant > &values=QMap< int, QVariant >(), const QModelIndex &parentIndex=QModelIndex(), const bool reload=true)
Insert an item at given index (row), with optional data values, under parent item indicated by parent...
QMap< int, QPersistentModelIndex > m_indexMap
static bool isParent(const QModelIndex &index)
virtual void keyboardSearch(const QString &search) override
virtual void hidePopup() override
Reimplemented from superclass.
virtual void setRootIndex(const QModelIndex &index) override
virtual void setData(const QVariant &value, int role)
bool isNull() const const
void clear()
Like QComboBox::clear() but does NOT remove any items from the current data model.
virtual bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles)
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const const
void setExpanded(const QModelIndex &index, bool expanded)
virtual bool event(QEvent *event) override
Qt::ItemFlags flags() const const
int currentIndex() const
Reimplemented from superclass.
bool isValid() const const
QRect boundingRect(QChar ch) const const
void setItemData(const QModelIndex &index, const QVariant &value, int role=Qt::UserRole)
Sets the data role for the item at index to the specified value.
void installEventFilter(QObject *filterObj)
virtual QSize minimumSizeHint() const const override
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
void keyboardSearchString(const QString &text)
Reimplemented from superclass.
QScreen * primaryScreen()
int modelColumn() const const
void resizeColumnToContents(int column)
QMapIterator::Item next()
void setPen(const QColor &color)
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const const override
AccessibleDescriptionRole
QModelIndex insertParentItem(int index, const QIcon &icon, const QString &text, const bool selectable=false, const QModelIndex &parentIndex=QModelIndex(), const QVariant &userData=QVariant())
Inserts an item and marks is as a "parent" type item.
void insertItems(int index, const QStringList &texts, const QModelIndex &parentIndex)
Inserts multiple items from a list as children of parentIndex.
virtual int styleHint(QStyle::StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const const=0
void activated(int index)
void setWidthF(qreal width)
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const const override
virtual QVariant data(const QModelIndex &index, int role) const const=0
void setAllColumnsShowFocus(bool enable)
static void setSeparator(QAbstractItemModel *model, const QModelIndex &index)
const Key & key() const const
void setColor(const QColor &color)
void rowsRemoved(const QModelIndex &parent, int first, int last)
void setIndentation(int i)
const T & value() const const
bool isExpanded(const QModelIndex &index) const const
bool signalsBlocked() const const
TreeComboBox(QWidget *parent=Q_NULLPTR)
virtual QModelIndex parent(const QModelIndex &index) const const=0
bool blockSignals(bool block)
void currentTextChanged(const QString &text)
bool isValid() const const
QModelIndex rootIndex() const const
QVariant currentData(int role=Qt::UserRole) const
Reimplemented from superclass.
void ensureCurrentExpanded()
Called before showing popup to make sure the initial view size is correct.
bool contains(const QRect &rectangle, bool proper) const const
bool usePopup(QStyleOptionComboBox *option=NULL)
Return true if style options are set to use a "popup" presentation style (typ.
static bool isSeparator(const QModelIndex &index)
QVariant data(int role) const const
int findData(const QVariant &data, int role=Qt::UserRole, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
Reimplemented from superclass.
void setModel(QAbstractItemModel *model)
QSize expandedTo(const QSize &otherSize) const const
virtual bool hasChildren(const QModelIndex &parent) const const
virtual void wheelEvent(QWheelEvent *event) override
Reimplemented from superclass.
bool isNull() const const
void setHeight(int height)
void adjustPopupWidth()
Make sure tree view has a reasonable width.
void setModel(QAbstractItemModel *model)
Reimplemented from superclass.
void adjust(int dx1, int dy1, int dx2, int dy2)
void setCurrentIndex(int index)
QModelIndex index() const const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
int buildMap(QModelIndex parent=QModelIndex(), int row=0)
Emitted along with currentIndexChanged() signals and if item has valid Qt::UserRole data.
void currentModelIndexChanged(const QModelIndex &index)
QString fromLatin1(const char *str, int size)
bool isValid() const const
virtual Qt::ItemFlags flags(const QModelIndex &index) const const
Qt::ItemFlags flags() const const
QMap< QPersistentModelIndex, int > m_rowMap
QMap::iterator insert(const Key &key, const T &value)
bool isEmpty() const const
void expanded(const QModelIndex &index)
virtual void showPopup() override
Reimplemented from superclass.
int setCurrentData(const QVariant &data, const int defaultIdx=-1, int role=Qt::UserRole, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchExactly|Qt::MatchCaseSensitive))
This is a shortcut to using setCurrentIndex(findData()), and also returns the new index (like findDat...
QAbstractItemModel * model() const const
QVariant::Type type() const const
QPersistentModelIndex m_currentIndex
QModelIndex currentIndex() const const
void rowsInserted(const QModelIndex &parent, int first, int last)
void setRootIsDecorated(bool show)
void setCurrentIndex(int index)
Reimplemented from superclass.
void setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy policy)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void updateAccessibility(QObject *object, int child, QAccessible::Event reason)
void setSize(const QSize &size)
void setMaxVisibleItems(int maxItems)
const QPen & pen() const const
QString toString() const const
void setItemsExpandable(bool enable)
QModelIndex indexAbove(const QModelIndex &index) const const
virtual QSize sizeHint() const const override
void removeEventFilter(QObject *obj)
virtual QModelIndex indexAt(const QPoint &point) const const override
void currentIndexChanged(int index)
bool hasNext() const const
const T value(const Key &key, const T &defaultValue) const const
void currentDataChanged(const QVariant &data)
virtual bool eventFilter(QObject *object, QEvent *event) override
Reimplemented from superclass.