summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews/qtreewidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/itemviews/qtreewidget.cpp')
-rw-r--r--src/gui/itemviews/qtreewidget.cpp110
1 files changed, 55 insertions, 55 deletions
diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp
index 0f2a27c..709c7b9 100644
--- a/src/gui/itemviews/qtreewidget.cpp
+++ b/src/gui/itemviews/qtreewidget.cpp
@@ -577,7 +577,7 @@ void QTreeModel::sort(int column, Qt::SortOrder order)
if (column < 0 || column >= columnCount())
return;
- //layoutAboutToBeChanged and layoutChanged will be called by sortChildren
+ //layoutAboutToBeChanged and layoutChanged will be called by sortChildren
rootItem->sortChildren(column, order, true);
}
@@ -1787,7 +1787,11 @@ QVariant QTreeWidgetItem::data(int column, int role) const
bool QTreeWidgetItem::operator<(const QTreeWidgetItem &other) const
{
int column = view ? view->sortColumn() : 0;
- return text(column) < other.text(column);
+ const QVariant v1 = data(column, Qt::DisplayRole);
+ const QVariant v2 = other.data(column, Qt::DisplayRole);
+ if (QAbstractItemModelPrivate::canConvertToDouble(v1) && QAbstractItemModelPrivate::canConvertToDouble(v2))
+ return v1.toDouble() < v2.toDouble();
+ return v1.toString() < v2.toString();
}
#ifndef QT_NO_DATASTREAM
@@ -1827,6 +1831,7 @@ void QTreeWidgetItem::write(QDataStream &out) const
{
out << values << d->display;
}
+#endif // QT_NO_DATASTREAM
/*!
\since 4.1
@@ -1863,8 +1868,6 @@ QTreeWidgetItem &QTreeWidgetItem::operator=(const QTreeWidgetItem &other)
return *this;
}
-#endif // QT_NO_DATASTREAM
-
/*!
Appends the \a child item to the list of children.
@@ -2075,7 +2078,7 @@ void QTreeWidgetItemPrivate::sortChildren(int column, Qt::SortOrder order, bool
if (climb) {
QList<QTreeWidgetItem*>::iterator it = q->children.begin();
for (; it != q->children.end(); ++it) {
- //here we call the private object's method to avoid emitting
+ //here we call the private object's method to avoid emitting
//the layoutAboutToBeChanged and layoutChanged signals
(*it)->d->sortChildren(column, order, climb);
}
@@ -2277,11 +2280,10 @@ void QTreeWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex &current,
void QTreeWidgetPrivate::_q_sort()
{
- Q_Q(QTreeWidget);
if (sortingEnabled) {
- int column = q->header()->sortIndicatorSection();
- Qt::SortOrder order = q->header()->sortIndicatorOrder();
- model()->sort(column, order);
+ int column = header->sortIndicatorSection();
+ Qt::SortOrder order = header->sortIndicatorOrder();
+ treeModel()->sort(column, order);
}
}
@@ -2290,7 +2292,7 @@ void QTreeWidgetPrivate::_q_selectionChanged(const QItemSelection &selected, con
Q_Q(QTreeWidget);
QModelIndexList indices = selected.indexes();
int i;
- QTreeModel *m = model();
+ QTreeModel *m = treeModel();
for (i = 0; i < indices.count(); ++i) {
QTreeWidgetItem *item = m->item(indices.at(i));
item->d->selected = true;
@@ -2308,13 +2310,12 @@ void QTreeWidgetPrivate::_q_selectionChanged(const QItemSelection &selected, con
void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight)
{
- Q_Q(QTreeWidget);
if (sortingEnabled && topLeft.isValid() && bottomRight.isValid()
- && !model()->sortPendingTimer.isActive()) {
- int column = q->header()->sortIndicatorSection();
+ && !treeModel()->sortPendingTimer.isActive()) {
+ int column = header->sortIndicatorSection();
if (column >= topLeft.column() && column <= bottomRight.column()) {
- Qt::SortOrder order = q->header()->sortIndicatorOrder();
- model()->ensureSorted(column, order, topLeft.row(),
+ Qt::SortOrder order = header->sortIndicatorOrder();
+ treeModel()->ensureSorted(column, order, topLeft.row(),
bottomRight.row(), topLeft.parent());
}
}
@@ -2542,7 +2543,7 @@ QTreeWidget::~QTreeWidget()
int QTreeWidget::columnCount() const
{
Q_D(const QTreeWidget);
- return d->model()->columnCount();
+ return d->model->columnCount();
}
/*
@@ -2554,7 +2555,7 @@ void QTreeWidget::setColumnCount(int columns)
Q_D(QTreeWidget);
if (columns < 0)
return;
- d->model()->setColumnCount(columns);
+ d->treeModel()->setColumnCount(columns);
}
/*!
@@ -2571,7 +2572,7 @@ void QTreeWidget::setColumnCount(int columns)
QTreeWidgetItem *QTreeWidget::invisibleRootItem() const
{
Q_D(const QTreeWidget);
- return d->model()->rootItem;
+ return d->treeModel()->rootItem;
}
/*!
@@ -2584,7 +2585,7 @@ QTreeWidgetItem *QTreeWidget::invisibleRootItem() const
QTreeWidgetItem *QTreeWidget::topLevelItem(int index) const
{
Q_D(const QTreeWidget);
- return d->model()->rootItem->child(index);
+ return d->treeModel()->rootItem->child(index);
}
/*!
@@ -2599,7 +2600,7 @@ QTreeWidgetItem *QTreeWidget::topLevelItem(int index) const
int QTreeWidget::topLevelItemCount() const
{
Q_D(const QTreeWidget);
- return d->model()->rootItem->childCount();
+ return d->treeModel()->rootItem->childCount();
}
/*!
@@ -2613,7 +2614,7 @@ int QTreeWidget::topLevelItemCount() const
void QTreeWidget::insertTopLevelItem(int index, QTreeWidgetItem *item)
{
Q_D(QTreeWidget);
- d->model()->rootItem->insertChild(index, item);
+ d->treeModel()->rootItem->insertChild(index, item);
}
/*!
@@ -2638,7 +2639,7 @@ void QTreeWidget::addTopLevelItem(QTreeWidgetItem *item)
QTreeWidgetItem *QTreeWidget::takeTopLevelItem(int index)
{
Q_D(QTreeWidget);
- return d->model()->rootItem->takeChild(index);
+ return d->treeModel()->rootItem->takeChild(index);
}
/*!
@@ -2647,8 +2648,8 @@ QTreeWidgetItem *QTreeWidget::takeTopLevelItem(int index)
int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item)
{
Q_D(QTreeWidget);
- d->model()->executePendingSort();
- return d->model()->rootItem->children.indexOf(item);
+ d->treeModel()->executePendingSort();
+ return d->treeModel()->rootItem->children.indexOf(item);
}
/*!
@@ -2660,8 +2661,8 @@ int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item)
int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item) const
{
Q_D(const QTreeWidget);
- d->model()->executePendingSort();
- return d->model()->rootItem->children.indexOf(item);
+ d->treeModel()->executePendingSort();
+ return d->treeModel()->rootItem->children.indexOf(item);
}
/*!
@@ -2676,7 +2677,7 @@ int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item) const
void QTreeWidget::insertTopLevelItems(int index, const QList<QTreeWidgetItem*> &items)
{
Q_D(QTreeWidget);
- d->model()->rootItem->insertChildren(index, items);
+ d->treeModel()->rootItem->insertChildren(index, items);
}
/*!
@@ -2698,7 +2699,7 @@ void QTreeWidget::addTopLevelItems(const QList<QTreeWidgetItem*> &items)
QTreeWidgetItem *QTreeWidget::headerItem() const
{
Q_D(const QTreeWidget);
- return d->model()->headerItem;
+ return d->treeModel()->headerItem;
}
/*!
@@ -2719,16 +2720,16 @@ void QTreeWidget::setHeaderItem(QTreeWidgetItem *item)
int oldCount = columnCount();
if (oldCount < item->columnCount())
- d->model()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount());
+ d->treeModel()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount());
else
- d->model()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount);
- delete d->model()->headerItem;
- d->model()->headerItem = item;
+ d->treeModel()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount);
+ delete d->treeModel()->headerItem;
+ d->treeModel()->headerItem = item;
if (oldCount < item->columnCount())
- d->model()->endInsertColumns();
+ d->treeModel()->endInsertColumns();
else
- d->model()->endRemoveColumns();
- d->model()->headerDataChanged(Qt::Horizontal, 0, oldCount);
+ d->treeModel()->endRemoveColumns();
+ d->treeModel()->headerDataChanged(Qt::Horizontal, 0, oldCount);
}
@@ -2745,8 +2746,7 @@ void QTreeWidget::setHeaderLabels(const QStringList &labels)
Q_D(QTreeWidget);
if (columnCount() < labels.count())
setColumnCount(labels.count());
- QTreeModel *model = d->model();
- QTreeWidgetItem *item = model->headerItem;
+ QTreeWidgetItem *item = d->treeModel()->headerItem;
for (int i = 0; i < labels.count(); ++i)
item->setText(i, labels.at(i));
}
@@ -2874,7 +2874,7 @@ void QTreeWidget::sortItems(int column, Qt::SortOrder order)
{
Q_D(QTreeWidget);
header()->setSortIndicator(column, order);
- d->model()->sort(column, order);
+ d->model->sort(column, order);
}
/*!
@@ -3041,7 +3041,7 @@ QList<QTreeWidgetItem*> QTreeWidget::selectedItems() const
QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFlags flags, int column) const
{
Q_D(const QTreeWidget);
- QModelIndexList indexes = d->model()->match(model()->index(0, column, QModelIndex()),
+ QModelIndexList indexes = d->model->match(model()->index(0, column, QModelIndex()),
Qt::DisplayRole, text, -1, flags);
QList<QTreeWidgetItem*> items;
for (int i = 0; i < indexes.size(); ++i)
@@ -3059,11 +3059,11 @@ QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFla
bool QTreeWidget::isItemHidden(const QTreeWidgetItem *item) const
{
Q_D(const QTreeWidget);
- if (item == d->model()->headerItem)
+ if (item == d->treeModel()->headerItem)
return header()->isHidden();
if (d->hiddenIndexes.isEmpty())
return false;
- QTreeModel::SkipSorting skipSorting(d->model());
+ QTreeModel::SkipSorting skipSorting(d->treeModel());
return d->isRowHidden(d->index(item));
}
@@ -3079,7 +3079,7 @@ bool QTreeWidget::isItemHidden(const QTreeWidgetItem *item) const
void QTreeWidget::setItemHidden(const QTreeWidgetItem *item, bool hide)
{
Q_D(QTreeWidget);
- if (item == d->model()->headerItem) {
+ if (item == d->treeModel()->headerItem) {
header()->setHidden(hide);
} else {
const QModelIndex index = d->index(item);
@@ -3099,7 +3099,7 @@ void QTreeWidget::setItemHidden(const QTreeWidgetItem *item, bool hide)
bool QTreeWidget::isItemExpanded(const QTreeWidgetItem *item) const
{
Q_D(const QTreeWidget);
- QTreeModel::SkipSorting skipSorting(d->model());
+ QTreeModel::SkipSorting skipSorting(d->treeModel());
return isExpanded(d->index(item));
}
@@ -3116,7 +3116,7 @@ bool QTreeWidget::isItemExpanded(const QTreeWidgetItem *item) const
void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand)
{
Q_D(QTreeWidget);
- QTreeModel::SkipSorting skipSorting(d->model());
+ QTreeModel::SkipSorting skipSorting(d->treeModel());
setExpanded(d->index(item), expand);
}
@@ -3131,7 +3131,7 @@ void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand)
bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const
{
Q_D(const QTreeWidget);
- if (item == d->model()->headerItem)
+ if (item == d->treeModel()->headerItem)
return false; // We can't set the header items to spanning
const QModelIndex index = d->index(item);
return isFirstColumnSpanned(index.row(), index.parent());
@@ -3148,7 +3148,7 @@ bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const
void QTreeWidget::setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span)
{
Q_D(QTreeWidget);
- if (item == d->model()->headerItem)
+ if (item == d->treeModel()->headerItem)
return; // We can't set header items to spanning
const QModelIndex index = d->index(item);
setFirstColumnSpanned(index.row(), index.parent(), span);
@@ -3162,7 +3162,7 @@ void QTreeWidget::setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool sp
QTreeWidgetItem *QTreeWidget::itemAbove(const QTreeWidgetItem *item) const
{
Q_D(const QTreeWidget);
- if (item == d->model()->headerItem)
+ if (item == d->treeModel()->headerItem)
return 0;
const QModelIndex index = d->index(item);
const QModelIndex above = indexAbove(index);
@@ -3177,7 +3177,7 @@ QTreeWidgetItem *QTreeWidget::itemAbove(const QTreeWidgetItem *item) const
QTreeWidgetItem *QTreeWidget::itemBelow(const QTreeWidgetItem *item) const
{
Q_D(const QTreeWidget);
- if (item == d->model()->headerItem)
+ if (item == d->treeModel()->headerItem)
return 0;
const QModelIndex index = d->index(item);
const QModelIndex below = indexBelow(index);
@@ -3217,7 +3217,7 @@ void QTreeWidget::scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::S
void QTreeWidget::expandItem(const QTreeWidgetItem *item)
{
Q_D(QTreeWidget);
- QTreeModel::SkipSorting skipSorting(d->model());
+ QTreeModel::SkipSorting skipSorting(d->treeModel());
expand(d->index(item));
}
@@ -3230,7 +3230,7 @@ void QTreeWidget::expandItem(const QTreeWidgetItem *item)
void QTreeWidget::collapseItem(const QTreeWidgetItem *item)
{
Q_D(QTreeWidget);
- QTreeModel::SkipSorting skipSorting(d->model());
+ QTreeModel::SkipSorting skipSorting(d->treeModel());
collapse(d->index(item));
}
@@ -3247,7 +3247,7 @@ void QTreeWidget::clear()
{
Q_D(QTreeWidget);
selectionModel()->clear();
- d->model()->clear();
+ d->treeModel()->clear();
}
/*!
@@ -3272,7 +3272,7 @@ QStringList QTreeWidget::mimeTypes() const
QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const
{
Q_D(const QTreeWidget);
- if (d->model()->cachedIndexes.isEmpty()) {
+ if (d->treeModel()->cachedIndexes.isEmpty()) {
QList<QModelIndex> indexes;
for (int i = 0; i < items.count(); ++i) {
QTreeWidgetItem *item = items.at(i);
@@ -3280,9 +3280,9 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const
indexes << indexFromItem(item, c);
}
}
- return model()->QAbstractItemModel::mimeData(indexes);
+ return d->model->QAbstractItemModel::mimeData(indexes);
}
- return d->model()->internalMimeData();
+ return d->treeModel()->internalMimeData();
}
/*!
@@ -3426,7 +3426,7 @@ bool QTreeWidget::event(QEvent *e)
{
Q_D(QTreeWidget);
if (e->type() == QEvent::Polish)
- d->model()->executePendingSort();
+ d->treeModel()->executePendingSort();
return QTreeView::event(e);
}