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>
283 if (effectiveModel.userType() == qMetaTypeId<QJSValue>())
286 if (effectiveModel.isNull())
288 else if (
const auto qaim = qvariant_cast<QAbstractItemModel*>(effectiveModel))
291 qmlWarning(
q) <<
"TreeView only accepts a model of type QAbstractItemModel";
295 emit q->modelChanged();
319 auto item =
q->itemAtCell(cell);
333 const int row = cell.
y();
347 if (oldSelection == newSelection)
394 d->QQuickTableViewPrivate::setModelImpl(modelAsVariant);
398 this, &QQuickTreeView::rootIndexChanged);
408 const int row = cellAtPosition(tapHandler->point().pressPosition()).y();
419 return d_func()->m_treeModelToTableModel.rootIndex();
425 d->m_treeModelToTableModel.setRootIndex(
index);
432 d->m_treeModelToTableModel.resetRootIndex();
439 if (row < 0 || row >=
d->m_treeModelToTableModel.rowCount())
442 return d->m_treeModelToTableModel.depthAtRow(
row);
448 if (row < 0 || row >=
d->m_treeModelToTableModel.rowCount())
451 return d->m_treeModelToTableModel.isExpanded(
row);
457 expandRecursively(
row, 1);
460void QQuickTreeView::expandRecursively(
int row,
int depth)
463 if (
row >=
d->m_treeModelToTableModel.rowCount())
470 auto expandRowRecursively = [
this,
d,
depth](
int startRow) {
471 d->m_treeModelToTableModel.expandRecursively(startRow,
depth);
475 const QPoint treeNodeCell(
c, startRow);
477 d->setRequiredProperty(
"expanded",
true,
d->modelIndexAtCell(treeNodeCell),
item,
false);
483 const bool isExpanded =
d->m_treeModelToTableModel.isExpanded(
row);
486 expandRowRecursively(
row);
489 const auto model =
d->m_treeModelToTableModel.model();
490 for (
int r = 0;
r <
model->rowCount(); ++
r) {
491 const int rootRow =
d->m_treeModelToTableModel.itemIndex(
model->index(
r, 0));
493 expandRowRecursively(rootRow);
504 if (!
index.isValid()) {
509 if (
index.model() !=
d->m_treeModelToTableModel.model()) {
510 qmlWarning(
this) <<
"index doesn't belong to correct model: " <<
index;
514 if (rowAtIndex(
index) != -1) {
523 while (
parent.isValid()) {
526 d->m_treeModelToTableModel.expandRow(
row);
532 d->setRequiredProperty(
"expanded",
true,
d->modelIndexAtCell(treeNodeCell),
item,
false);
539 d->m_treeModelToTableModel.expand(
parent);
552 if (row < 0 || row >=
d->m_treeModelToTableModel.rowCount())
555 if (!
d->m_treeModelToTableModel.isExpanded(
row))
558 d_func()->m_treeModelToTableModel.collapseRow(
row);
563 d->setRequiredProperty(
"expanded",
false,
d->modelIndexAtCell(treeNodeCell),
item,
false);
569void QQuickTreeView::collapseRecursively(
int row)
572 if (
row >=
d->m_treeModelToTableModel.rowCount())
577 auto collapseRowRecursive = [
this,
d](
int startRow) {
580 d->m_treeModelToTableModel.collapseRecursively(startRow);
583 const QPoint treeNodeCell(
c, startRow);
585 d->setRequiredProperty(
"expanded",
false,
d->modelIndexAtCell(treeNodeCell),
item,
false);
590 collapseRowRecursive(
row);
593 const auto model =
d->m_treeModelToTableModel.model();
594 for (
int r = 0;
r <
model->rowCount(); ++
r) {
595 const int rootRow =
d->m_treeModelToTableModel.itemIndex(
model->index(
r, 0));
597 collapseRowRecursive(rootRow);
615 const QModelIndex tableIndex =
d->m_treeModelToTableModel.index(cell.
y(), cell.
x());
616 return d->m_treeModelToTableModel.mapToModel(tableIndex);
621 const QModelIndex tableIndex = d_func()->m_treeModelToTableModel.mapFromModel(
index);
625#if QT_DEPRECATED_SINCE(6, 4)
637 qmlWarning(
this) <<
"modelIndex(row, column) is deprecated. "
638 "Use index(row, column) instead. For more information, see "
639 "https://doc.qt.io/qt-6/qml-qtquick-tableview-obsolete.html";
655 switch (
event->key()) {
668 if (!
event->isAccepted())
674#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().
Q_CORE_EXPORT QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
Q_CORE_EXPORT void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
Q_CORE_EXPORT bool contains(const QModelIndex &index) const
Returns true if the selection contains the given index; otherwise returns false.
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)
QItemSelectionModel::SelectionFlag selectionFlag
virtual void initItemCallback(int modelIndex, QObject *item)
QAbstractItemModel * qaim(QVariant modelAsVariant) const
QItemSelection existingSelection
int modelIndexAtCell(const QPoint &cell) const
QPointer< QItemSelectionModel > selectionModel
void setRequiredProperty(const char *property, const QVariant &value, int serializedModelIndex, QObject *object, bool init)
bool keyNavigationEnabled
void setSelectionBehavior(SelectionBehavior selectionBehavior)
QItemSelectionModel * selectionModel
void setEditTriggers(EditTriggers editTriggers)
FINALEditTriggers editTriggers
bool pointerNavigationEnabled
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.
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, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
selection select(topLeft, bottomRight)