47 #include <private/qtreewidget_p.h>
48 #include <private/qwidgetitemdata_p.h>
49 #include <private/qtreewidgetitemiterator_p.h>
51 #include <QtCore/private/qduplicatetracker_p.h>
121 headerItem->view =
parent;
135 headerItem->view =
parent;
147 headerItem->view =
nullptr;
149 rootItem->view =
nullptr;
166 item->view =
nullptr;
169 rootItem->children.
clear();
170 sortPendingTimer.
stop();
187 headerItem->view =
view();
190 if (
count == columns)
195 headerItem->values.
resize(columns);
199 headerItem->values.
resize(columns);
200 for (
int i =
count;
i < columns; ++
i) {
218 if (!
index.isValid())
232 executePendingSort();
243 && par->children.
count() > guess
244 && par->children.
at(guess) == itm) {
263 executePendingSort();
293 if (!
child.isValid())
296 if (!itm || itm == rootItem)
365 if (!
index.isValid())
385 if (!
index.isValid())
402 const auto beginIter = itm->values.
at(
index.column()).
cbegin();
403 const auto endIter = itm->values.
at(
index.column()).
cend();
480 for (
int i = oldCount;
i < oldCount +
count; ++
i) {
492 if (
child->children.count())
516 child->view =
nullptr;
538 return headerItem->
data(section, role);
557 if (section < 0 || orientation != Qt::Horizontal || !headerItem || section >=
columnCount())
573 if (!
index.isValid())
574 return rootItem->
flags();
590 sortPendingTimer.
stop();
608 sortPendingTimer.
stop();
633 bool changed =
false;
636 int oldRow = sorting.
at(
i).second;
638 int tmpitepos = lit - lst.
begin();
640 if (tmpitepos > lst.
size())
642 lit = lst.
begin() + tmpitepos;
645 int newRow = qMax<qsizetype>(lit - lst.
begin(), 0);
647 if ((
newRow < oldRow) && !(*
item < *lst.
at(oldRow - 1)) && !(*lst.
at(oldRow - 1) < *
item ))
657 newPersistentIndexes = oldPersistentIndexes;
660 int otherRow = sorting.
at(
j).second;
661 if (oldRow < otherRow && newRow >= otherRow)
663 else if (oldRow > otherRow &&
newRow <= otherRow)
666 for (
int k = 0; k < newPersistentIndexes.
count(); ++k) {
670 int oldPersistentRow =
pi.row();
671 int newPersistentRow = oldPersistentRow;
672 if (oldPersistentRow == oldRow)
673 newPersistentRow =
newRow;
674 else if (oldRow < oldPersistentRow && newRow >= oldPersistentRow)
675 newPersistentRow = oldPersistentRow - 1;
676 else if (oldRow > oldPersistentRow &&
newRow <= oldPersistentRow)
677 newPersistentRow = oldPersistentRow + 1;
678 if (newPersistentRow != oldPersistentRow)
679 newPersistentIndexes[k] =
createIndex(newPersistentRow,
680 pi.column(),
pi.internalPointer());
739 return v->mimeTypes();
761 cachedIndexes = indexes;
763 cachedIndexes.
clear();
788 bool QTreeModel::isChanging()
const
791 return !
d->changes.isEmpty();
821 bottomRight = topLeft;
845 for (
int i = 0;
i < iterators.
count(); ++
i) {
848 iterators[
i]->d_func()->ensureValidIterator(
c);
867 for (
int i = 0;
i < sorting.
count(); ++
i) {
869 sorting[
i].second =
i;
879 for (
int r = 0;
r < sorting.
count(); ++
r) {
880 int oldRow = sorting.
at(
r).second;
885 for (
int c = 0;
c < colCount; ++
c) {
900 executePendingSort();
1057 if (
this ==
model->headerItem) {
1080 if (
this ==
model->headerItem)
1081 return view->
header()->isHidden();
1082 if (view->d_func()->hiddenIndexes.isEmpty())
1085 return view->d_func()->
isRowHidden(view->d_func()->index(
this));
1103 view->
setExpanded(view->d_func()->index(
this), expand);
1120 return view->
isExpanded(view->d_func()->index(
this));
1421 model->rootItem->addChild(
this);
1443 model->rootItem->addChild(
this);
1462 model->rootItem->insertChild(
i,
this);
1525 int i = par->children.
indexOf(
this);
1530 if (!par->children.
isEmpty() && par->children.
at(
i) ==
this)
1535 if (
this ==
model->headerItem) {
1536 model->headerItem =
nullptr;
1540 model->beginRemoveItems(
nullptr,
i, 1);
1545 model->endRemoveItems();
1551 for (
int i = 0;
i < children.
count(); ++
i) {
1554 child->par =
nullptr;
1556 child->view =
nullptr;
1574 parentStack.
push(0);
1595 for (
int i = 0;
i <
item->childCount(); ++
i) {
1597 parentStack.
push(copy);
1654 if (changedState && changedExplicit) {
1667 child->itemChanged();
1686 item->view->setRowHidden(
index.row(),
index.parent(), inserting);
1688 for (
int i = 0;
i <
parent->children.count(); ++
i) {
1704 if (!
parent->d->disabled) {
1705 Qt::ItemFlags oldFlags =
parent->itemFlags;
1710 if (
parent->itemFlags != oldFlags)
1714 for (
int i = 0;
i <
parent->children.count(); ++
i) {
1774 for (
int i = 0;
i < children.
count(); ++
i) {
1777 Qt::ItemFlags
f = itemFlags;
1789 for (
int i = 0;
i < column_values.
count(); ++
i) {
1790 if (column_values.
at(
i).
role == role) {
1836 return childrenCheckState(
column);
1841 for (
const auto &column_value : column_values) {
1842 if (column_value.role == role)
1843 return column_value.
value;
1863 #ifndef QT_NO_DATASTREAM
1916 itemFlags(
other.itemFlags)
1934 itemFlags =
other.itemFlags;
1963 if (
model->rootItem ==
this)
1964 child->par =
nullptr;
1969 if (!
model->sortPendingTimer.isActive())
1979 i->values.reserve(cols);
1980 for (
int c = 0;
c <
i->children.count(); ++
c)
1981 stack.
push(
i->children.at(
c));
1985 model->endInsertItems();
2016 model->skipPendingSort =
false;
2017 model->executePendingSort();
2023 item->par =
nullptr;
2029 for (
int c = 0;
c <
i->children.count(); ++
c)
2030 stack.
push(
i->children.at(
c));
2064 for (
int n = 0;
n < children.
count(); ++
n)
2071 for (
int n = 0;
n < children.
count(); ++
n) {
2076 if (view &&
model) {
2083 child->par =
nullptr;
2087 if (!itemsToInsert.
isEmpty()) {
2091 for (
int c = 0;
c <
i->children.count(); ++
c)
2092 stack.
push(
i->children.at(
c));
2095 for (
int n = 0;
n < itemsToInsert.
count(); ++
n) {
2114 if (children.
count() > 0) {
2121 model->executePendingSort();
2124 for (
int n = 0;
n < children.
count(); ++
n) {
2126 item->par =
nullptr;
2132 for (
int c = 0;
c <
i->children.count(); ++
c)
2133 stack.
push(
i->children.at(
c));
2153 for (;
it !=
q->children.end(); ++
it) {
2173 if (
model->isChanging())
2176 int oldSortColumn = view->d_func()->explicitSortColumn;
2177 view->d_func()->explicitSortColumn =
column;
2181 view->d_func()->explicitSortColumn = oldSortColumn;
2196 bool checkedChildren =
false;
2197 bool uncheckedChildren =
false;
2198 for (
const auto *
child : children) {
2200 if (!
value.isValid())
2206 uncheckedChildren =
true;
2209 checkedChildren =
true;
2216 if (uncheckedChildren && checkedChildren)
2220 if (uncheckedChildren)
2222 else if (checkedChildren)
2248 void QTreeWidgetItem::itemChanged()
2251 model->itemChanged(
this);
2257 void QTreeWidgetItem::executePendingSort()
const
2260 model->executePendingSort();
2271 return (
v ? qobject_cast<QTreeModel*>(
v->model()) :
nullptr);
2275 #ifndef QT_NO_DATASTREAM
2343 emit q->itemChanged(indexItem,
index.column());
2364 emit q->currentItemChanged(currentItem, previousItem);
2393 emit q->itemSelectionChanged();
2400 && !
treeModel()->sortPendingTimer.isActive()) {
2599 this,
SLOT(_q_sort()));
2622 return d->model->columnCount();
2634 d->treeModel()->setColumnCount(columns);
2651 return d->treeModel()->rootItem;
2664 return d->treeModel()->rootItem->child(
index);
2679 return d->treeModel()->rootItem->childCount();
2693 d->treeModel()->rootItem->insertChild(
index,
item);
2718 return d->treeModel()->rootItem->takeChild(
index);
2730 d->treeModel()->executePendingSort();
2731 return d->treeModel()->rootItem->children.indexOf(
item);
2746 d->treeModel()->rootItem->insertChildren(
index,
items);
2768 return d->treeModel()->headerItem;
2789 d->treeModel()->beginInsertColumns(
QModelIndex(), oldCount,
item->columnCount() - 1);
2790 else if (oldCount >
item->columnCount())
2791 d->treeModel()->beginRemoveColumns(
QModelIndex(),
item->columnCount(), oldCount - 1);
2792 delete d->treeModel()->headerItem;
2793 d->treeModel()->headerItem =
item;
2795 d->treeModel()->endInsertColumns();
2796 else if (oldCount >
item->columnCount())
2797 d->treeModel()->endRemoveColumns();
2816 for (
int i = 0;
i < labels.count(); ++
i)
2817 item->setText(
i, labels.at(
i));
2882 QItemSelectionModel::SelectionFlags command)
2885 d->selectionModel->setCurrentIndex(
d->index(
item,
column), command);
2937 return (
d->explicitSortColumn != -1
2938 ?
d->explicitSortColumn
2939 :
header()->sortIndicatorSection());
3061 for (
const auto &
index : indexes) {
3079 const int indexesSize = indexes.
size();
3081 for (
int i = 0;
i < indexesSize; ++
i)
3095 if (
item ==
d->treeModel()->headerItem)
3099 return d->item(above);
3110 if (
item ==
d->treeModel()->headerItem)
3114 return d->item(below);
3180 d->treeModel()->clear();
3191 return model()->QAbstractItemModel::mimeTypes();
3205 if (
d->treeModel()->cachedIndexes.isEmpty()) {
3209 qWarning(
"QTreeWidget::mimeData: Null-item passed");
3213 for (
int c = 0;
c <
item->values.count(); ++
c) {
3216 qWarning() <<
"QTreeWidget::mimeData: No index associated with item :" <<
item;
3222 return d->model->QAbstractItemModel::mimeData(indexes);
3224 return d->treeModel()->internalMimeData();
3279 #if QT_CONFIG(draganddrop)
3281 void QTreeWidget::dropEvent(QDropEvent *
event) {
3284 dragDropMode() == QAbstractItemView::InternalMove)) {
3289 if (!
event->isAccepted() &&
d->dropOn(
event, &
row, &col, &topIndex)) {
3292 const int indexesCount = idxs.
count();
3293 indexes.
reserve(indexesCount);
3294 for (
const auto &
idx : idxs)
3305 for (
const auto &
index : indexes) {
3315 for (
int i = 0;
i < indexes.count(); ++
i) {
3325 int r = dropRow.
row() >= 0 ? dropRow.
row() :
row;
3339 if (
event->isAccepted())
3340 d->dropEventMoved =
true;
3343 QTreeView::dropEvent(
event);
3353 Q_ASSERT(!
"QTreeWidget::setModel() - Changing the model of the QTreeWidget is not allowed.");
3363 d->treeModel()->executePendingSort();
3370 void QTreeModelPrivate::executePendingOperations()
const
3372 q_func()->executePendingSort();
3377 #include "moc_qtreewidget.cpp"
3378 #include "moc_qtreewidget_p.cpp"
small capitals from c petite p scientific i
[1]
The QAbstractItemModel class provides the abstract interface for item model classes.
QModelIndexList persistentIndexList() const
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
void layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
bool checkIndex(const QModelIndex &index, CheckIndexOptions options=CheckIndexOption::NoOption) const
void headerDataChanged(Qt::Orientation orientation, int first, int last)
void beginInsertColumns(const QModelIndex &parent, int first, int last)
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
void beginRemoveRows(const QModelIndex &parent, int first, int last)
virtual Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
void beginInsertRows(const QModelIndex &parent, int first, int last)
static bool variantLessThan(const QVariant &v1, const QVariant &v2)
struct QAbstractItemModelPrivate::Persistent persistent
QWidget * indexWidget(const QModelIndex &index) const
void activated(const QModelIndex &index)
QAbstractItemModel * model() const
void setCurrentIndex(const QModelIndex &index)
void doubleClicked(const QModelIndex &index)
bool event(QEvent *event) override
void entered(const QModelIndex &index)
QModelIndex currentIndex() const
bool isPersistentEditorOpen(const QModelIndex &index) const
void setIndexWidget(const QModelIndex &index, QWidget *widget)
void scheduleDelayedItemsLayout()
void openPersistentEditor(const QModelIndex &index)
void pressed(const QModelIndex &index)
void clicked(const QModelIndex &index)
void edit(const QModelIndex &index)
QItemSelectionModel * selectionModel() const
void closePersistentEditor(const QModelIndex &index)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int timerId() const noexcept
The QDataStream class provides serialization of binary data to a QIODevice.
The QEvent class is the base class of all event classes. Event objects contain event parameters.
The QItemSelection class manages information about selected items in a model.
Q_CORE_EXPORT QModelIndexList indexes() const
QModelIndexList selectedIndexes
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
qsizetype size() const noexcept
bool isEmpty() const noexcept
iterator erase(const_iterator begin, const_iterator end)
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
void reserve(qsizetype size)
void replace(qsizetype i, parameter_type t)
void resize(qsizetype size)
const_iterator cend() const noexcept
void append(parameter_type t)
const_iterator cbegin() const noexcept
iterator insert(const Key &key, const T &value)
The QMimeData class provides a container for data that records information about its MIME type.
The QModelIndex class is used to locate data in a data model.
constexpr int row() const noexcept
QModelIndex parent() const
constexpr int column() const noexcept
constexpr bool isValid() const noexcept
bool contains(const Key &key) const noexcept
const QObjectList & children() const
virtual void timerEvent(QTimerEvent *event)
bool signalsBlocked() const noexcept
QScopedPointer< QObjectData > d_ptr
The QPersistentModelIndex class is used to locate data in a data model.
The QPoint class defines a point in the plane using integer precision.
The QRect class defines a rectangle in the plane using integer precision.
T * data() const noexcept
int columnCount(const QModelIndex &parent=QModelIndex()) const override
The QStack class is a template class that provides a stack.
The QString class provides a Unicode character string.
static QString number(int, int base=10)
The QStringList class provides a list of strings.
The QTimerEvent class contains parameters that describe a timer event.
bool operator()(QTreeWidgetItem *i1, QTreeWidgetItem *i2) const
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override
void ensureSorted(int column, Qt::SortOrder order, int start, int end, const QModelIndex &parent)
int rowCount(const QModelIndex &parent) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
bool insertColumns(int column, int count, const QModelIndex &) override
void emitDataChanged(QTreeWidgetItem *item, int column, const QList< int > &roles)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void itemChanged(QTreeWidgetItem *item)
void setColumnCount(int columns)
friend class QTreeWidgetItem
bool insertRows(int row, int count, const QModelIndex &) override
void sortItems(QList< QTreeWidgetItem * > *items, int column, Qt::SortOrder order)
QMimeData * internalMimeData() const
QTreeWidgetItem * item(const QModelIndex &index) const
Qt::DropActions supportedDropActions() const override
QMimeData * mimeData(const QModelIndexList &indexes) const override
QTreeModel(int columns=0, QTreeWidget *parent=nullptr)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void sort(int column, Qt::SortOrder order) override
static bool itemLessThan(const QPair< QTreeWidgetItem *, int > &left, const QPair< QTreeWidgetItem *, int > &right)
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
bool clearItemData(const QModelIndex &index) override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
static QList< QTreeWidgetItem * >::iterator sortedInsertionIterator(const QList< QTreeWidgetItem * >::iterator &begin, const QList< QTreeWidgetItem * >::iterator &end, Qt::SortOrder order, QTreeWidgetItem *item)
QStringList mimeTypes() const override
QMap< int, QVariant > itemData(const QModelIndex &index) const override
QModelIndex index(const QTreeWidgetItem *item, int column) const
bool hasChildren(const QModelIndex &parent) const override
void timerEvent(QTimerEvent *) override
void beginRemoveItems(QTreeWidgetItem *parent, int row, int count)
void beginInsertItems(QTreeWidgetItem *parent, int row, int count)
static bool itemGreaterThan(const QPair< QTreeWidgetItem *, int > &left, const QPair< QTreeWidgetItem *, int > &right)
QTreeWidget * view() const
bool operator()(QTreeWidgetItem *i1, QTreeWidgetItem *i2) const
The QTreeView class provides a default model/view implementation of a tree view.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >()) override
bool isSortingEnabled() const
void expand(const QModelIndex &index)
void setSelectionModel(QItemSelectionModel *selectionModel) override
void collapse(const QModelIndex &index)
void setModel(QAbstractItemModel *model) override
QModelIndex indexBelow(const QModelIndex &index) const
bool isExpanded(const QModelIndex &index) const
QHeaderView * header() const
void setExpanded(const QModelIndex &index, bool expand)
QModelIndex indexAt(const QPoint &p) const override
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override
QModelIndex indexAbove(const QModelIndex &index) const
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span)
QModelIndexList selectedIndexes() const override
void collapsed(const QModelIndex &index)
void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible) override
void setRowHidden(int row, const QModelIndex &parent, bool hide)
bool isRowHidden(int row, const QModelIndex &parent) const
QRect visualRect(const QModelIndex &index) const override
bool isFirstColumnSpanned(int row, const QModelIndex &parent) const
void expanded(const QModelIndex &index)
The QVariant class acts like a union for the most common Qt data types.
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
constexpr struct q20::ranges::@310 all_of
std::pair< T1, T2 > QPair
EGLOutputLayerEXT EGLint EGLAttrib value
GLenum GLuint GLenum GLsizei length
GLint GLfloat GLfloat GLfloat v2
GLenum GLsizei GLsizei GLint * values
[16]
GLsizei const GLfloat * v
[13]
GLsizei const GLchar ** strings
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLsizei GLenum const void * indices
GLenum GLenum GLsizei void GLsizei void * column
GLuint GLenum GLenum transform
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void GLsizei void void * span
GLfixed GLfixed GLint GLint order
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QSqlQueryModel * model
[16]
QTextStream out(stdout)
[7]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
selection select(topLeft, bottomRight)
QMultiHash< QModelIndex, QPersistentModelIndexData * > indexes
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const noexcept
void compare(Input input, FnUnderTest fn_under_test, const QByteArray &output)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent