6#include <QtCore/qobject.h>
7#include <QtQml/qqmlcontext.h>
8#include <QtQuick/private/qquicktaphandler_p.h>
10#include <QtQmlModels/private/qqmltreemodeltotablemodel_p_p.h>
286 if (effectiveModel.
userType() == qMetaTypeId<QJSValue>())
289 if (effectiveModel.
isNull())
291 else if (
const auto qaim = qvariant_cast<QAbstractItemModel*>(effectiveModel))
294 qmlWarning(
q) <<
"TreeView only accepts a model of type QAbstractItemModel";
298 emit q->modelChanged();
322 auto item =
q->itemAtCell(cell);
336 const int row = cell.
y();
353 if (oldSelection == newSelection)
358 if (oldRect.
y() != -1 && oldRect.
y() <=
row &&
row <= oldRect.
y() + oldRect.
height())
365 if (oldRect.
x() != -1) {
413 d->QQuickTableViewPrivate::setModelImpl(modelAsVariant);
417 this, &QQuickTreeView::rootIndexChanged);
427 const int row = cellAtPosition(tapHandler->point().pressPosition()).y();
438 return d_func()->m_treeModelToTableModel.rootIndex();
444 d->m_treeModelToTableModel.setRootIndex(
index);
451 d->m_treeModelToTableModel.resetRootIndex();
458 if (row < 0 || row >=
d->m_treeModelToTableModel.rowCount())
461 return d->m_treeModelToTableModel.depthAtRow(
row);
467 if (row < 0 || row >=
d->m_treeModelToTableModel.rowCount())
470 return d->m_treeModelToTableModel.isExpanded(
row);
476 expandRecursively(
row, 1);
479void QQuickTreeView::expandRecursively(
int row,
int depth)
482 if (
row >=
d->m_treeModelToTableModel.rowCount())
489 auto expandRowRecursively = [
this,
d,
depth](
int startRow) {
490 d->m_treeModelToTableModel.expandRecursively(startRow,
depth);
494 const QPoint treeNodeCell(
c, startRow);
496 d->setRequiredProperty(
"expanded",
true,
d->modelIndexAtCell(treeNodeCell),
item,
false);
502 const bool isExpanded =
d->m_treeModelToTableModel.isExpanded(
row);
505 expandRowRecursively(
row);
508 const auto model =
d->m_treeModelToTableModel.model();
509 for (
int r = 0;
r <
model->rowCount(); ++
r) {
510 const int rootRow =
d->m_treeModelToTableModel.itemIndex(
model->index(
r, 0));
512 expandRowRecursively(rootRow);
523 if (!
index.isValid()) {
528 if (
index.model() !=
d->m_treeModelToTableModel.model()) {
529 qmlWarning(
this) <<
"index doesn't belong to correct model: " <<
index;
533 if (rowAtIndex(
index) != -1) {
542 while (
parent.isValid()) {
545 d->m_treeModelToTableModel.expandRow(
row);
551 d->setRequiredProperty(
"expanded",
true,
d->modelIndexAtCell(treeNodeCell),
item,
false);
558 d->m_treeModelToTableModel.expand(
parent);
571 if (row < 0 || row >=
d->m_treeModelToTableModel.rowCount())
574 if (!
d->m_treeModelToTableModel.isExpanded(
row))
577 d_func()->m_treeModelToTableModel.collapseRow(
row);
582 d->setRequiredProperty(
"expanded",
false,
d->modelIndexAtCell(treeNodeCell),
item,
false);
588void QQuickTreeView::collapseRecursively(
int row)
591 if (
row >=
d->m_treeModelToTableModel.rowCount())
596 auto collapseRowRecursive = [
this,
d](
int startRow) {
599 d->m_treeModelToTableModel.collapseRecursively(startRow);
602 const QPoint treeNodeCell(
c, startRow);
604 d->setRequiredProperty(
"expanded",
false,
d->modelIndexAtCell(treeNodeCell),
item,
false);
609 collapseRowRecursive(
row);
612 const auto model =
d->m_treeModelToTableModel.model();
613 for (
int r = 0;
r <
model->rowCount(); ++
r) {
614 const int rootRow =
d->m_treeModelToTableModel.itemIndex(
model->index(
r, 0));
616 collapseRowRecursive(rootRow);
634 const QModelIndex tableIndex =
d->m_treeModelToTableModel.index(cell.
y(), cell.
x());
635 return d->m_treeModelToTableModel.mapToModel(tableIndex);
640 const QModelIndex tableIndex = d_func()->m_treeModelToTableModel.mapFromModel(
index);
644#if QT_DEPRECATED_SINCE(6, 4)
656 qmlWarning(
this) <<
"modelIndex(row, column) is deprecated. "
657 "Use index(row, column) instead. For more information, see "
658 "https://doc.qt.io/qt-6/qml-qtquick-tableview-obsolete.html";
674 switch (
event->key()) {
687 if (!
event->isAccepted())
693#include "moc_qquicktreeview_p.cpp"
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
The QJSValue class acts as a container for Qt/JavaScript data types.
The QKeyEvent class describes a key event.
constexpr int row() const noexcept
Returns the row this model index refers to.
constexpr int column() const noexcept
Returns the column this model index refers to.
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
bool hasChildren(int row) const
void setModel(QAbstractItemModel *model)
int depthAtRow(int row) const
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
QQuickItem * parent
\qmlproperty Item QtQuick::Item::parent This property holds the visual parent of the item.
QPoint cellAtModelIndex(int modelIndex) const
virtual void itemReusedCallback(int modelIndex, QObject *object)
void scheduleRebuildTable(QQuickTableViewPrivate::RebuildOptions options)
virtual void initItemCallback(int modelIndex, QObject *item)
QAbstractItemModel * qaim(QVariant modelAsVariant) const
int modelIndexAtCell(const QPoint &cell) const
QPointer< QItemSelectionModel > selectionModel
void setRequiredProperty(const char *property, const QVariant &value, int serializedModelIndex, QObject *object, bool init)
void setSelectionBehavior(SelectionBehavior selectionBehavior)
FINALbool keyNavigationEnabled
void setEditTriggers(EditTriggers editTriggers)
FINALQItemSelectionModel * selectionModel
FINALbool pointerNavigationEnabled
FINALEditTriggers editTriggers
Q_INVOKABLE QQuickItem * itemAtCell(const QPoint &cell) const
Q_INVOKABLE void positionViewAtCell(const QPoint &cell, PositionMode mode, const QPointF &offset=QPointF(), const QRectF &subRect=QRectF())
void keyPressEvent(QKeyEvent *e) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
void doubleTapped(QEventPoint eventPoint, Qt::MouseButton)
void updateSelection(const QRect &oldSelection, const QRect &newSelection) override
QVariant modelImpl() const override
~QQuickTreeViewPrivate() override
void setModelImpl(const QVariant &newModel) override
QQmlTreeModelToTableModel m_treeModelToTableModel
void updateRequiredProperties(int serializedModelIndex, QObject *object, bool init)
void initItemCallback(int serializedModelIndex, QObject *object) override
void itemReusedCallback(int serializedModelIndex, QObject *object) override
void dataChangedCallback(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
Q_INVOKABLE void collapse(int row)
Q_INVOKABLE void expand(int row)
Q_INVOKABLE bool isExpanded(int row) const
void expanded(int row, int depth)
QQuickTreeView(QQuickItem *parent=nullptr)
Q_INVOKABLE void toggleExpanded(int row)
void keyPressEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
void setRootIndex(const QModelIndex &index)
void collapsed(int row, bool recursively)
Q_INVOKABLE QModelIndex modelIndex(const QPoint &cell) const override
~QQuickTreeView() override
Q_INVOKABLE QPoint cellAtIndex(const QModelIndex &index) const override
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
QRect normalized() const noexcept
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
bool isNull() const
Returns true if this is a null variant, false otherwise.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Combined button and popup list for selecting options.
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static const int kTreeColumn
\qmltype TreeView \inqmlmodule QtQuick
#define QStringLiteral(str)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols, V4ObjectSet *visitedObjects)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent