Changeset 561 for trunk/src/gui/itemviews/qtreewidget.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/itemviews/qtreewidget.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 76 76 77 77 \ingroup model-view 78 \mainclass 78 79 79 */ 80 80 … … 578 578 return; 579 579 580 //layoutAboutToBeChanged and layoutChanged will be called by sortChildren 580 //layoutAboutToBeChanged and layoutChanged will be called by sortChildren 581 581 rootItem->sortChildren(column, order, true); 582 582 } … … 623 623 lit = sortedInsertionIterator(lit, lst.end(), order, item); 624 624 int newRow = qMax(lit - lst.begin(), 0); 625 626 627 628 625 629 lit = lst.insert(lit, item); 626 630 if (newRow != oldRow) { … … 854 858 for (int c = 0; c < colCount; ++c) { 855 859 QModelIndex from = createIndex(oldRow, c, item); 856 if (static_cast<QAbstractItemModelPrivate *>(d_ptr )->persistent.indexes.contains(from)) {860 if (static_cast<QAbstractItemModelPrivate *>(d_ptr)->persistent.indexes.contains(from)) { 857 861 QModelIndex to = createIndex(r, c, item); 858 862 fromList << from; … … 1577 1581 return; 1578 1582 1579 view-> viewport()->update( view->d_func()->itemDecorationRect(view->d_func()->index(this)));1583 view->); 1580 1584 } 1581 1585 … … 1769 1773 if (children.count() && (itemFlags & Qt::ItemIsTristate)) 1770 1774 return childrenCheckState(column); 1775 1771 1776 default: 1772 1777 if (column >= 0 && column < values.size()) { … … 1788 1793 { 1789 1794 int column = view ? view->sortColumn() : 0; 1790 return text(column) < other.text(column); 1795 const QVariant v1 = data(column, Qt::DisplayRole); 1796 const QVariant v2 = other.data(column, Qt::DisplayRole); 1797 return QAbstractItemModelPrivate::variantLessThan(v1, v2); 1791 1798 } 1792 1799 … … 1828 1835 out << values << d->display; 1829 1836 } 1837 1830 1838 1831 1839 /*! … … 1863 1871 return *this; 1864 1872 } 1865 1866 #endif // QT_NO_DATASTREAM1867 1873 1868 1874 /*! … … 2072 2078 { 2073 2079 QTreeModel *model = (q->view ? qobject_cast<QTreeModel*>(q->view->model()) : 0); 2080 2081 2074 2082 model->sortItems(&q->children, column, order); 2075 2083 if (climb) { 2076 2084 QList<QTreeWidgetItem*>::iterator it = q->children.begin(); 2077 2085 for (; it != q->children.end(); ++it) { 2078 //here we call the private object's method to avoid emitting 2086 //here we call the private object's method to avoid emitting 2079 2087 //the layoutAboutToBeChanged and layoutChanged signals 2080 2088 (*it)->d->sortChildren(column, order, climb); … … 2278 2286 void QTreeWidgetPrivate::_q_sort() 2279 2287 { 2280 Q_Q(QTreeWidget);2281 2288 if (sortingEnabled) { 2282 int column = q->header()->sortIndicatorSection();2283 Qt::SortOrder order = q->header()->sortIndicatorOrder();2284 model()->sort(column, order);2289 int column = ->sortIndicatorSection(); 2290 Qt::SortOrder order = ->sortIndicatorOrder(); 2291 odel()->sort(column, order); 2285 2292 } 2286 2293 } … … 2291 2298 QModelIndexList indices = selected.indexes(); 2292 2299 int i; 2293 QTreeModel *m = model();2300 QTreeModel *m = odel(); 2294 2301 for (i = 0; i < indices.count(); ++i) { 2295 2302 QTreeWidgetItem *item = m->item(indices.at(i)); … … 2309 2316 const QModelIndex &bottomRight) 2310 2317 { 2311 Q_Q(QTreeWidget);2312 2318 if (sortingEnabled && topLeft.isValid() && bottomRight.isValid() 2313 && ! model()->sortPendingTimer.isActive()) {2314 int column = q->header()->sortIndicatorSection();2319 && !odel()->sortPendingTimer.isActive()) { 2320 int column = ->sortIndicatorSection(); 2315 2321 if (column >= topLeft.column() && column <= bottomRight.column()) { 2316 Qt::SortOrder order = q->header()->sortIndicatorOrder();2317 model()->ensureSorted(column, order, topLeft.row(),2322 Qt::SortOrder order = ->sortIndicatorOrder(); 2323 odel()->ensureSorted(column, order, topLeft.row(), 2318 2324 bottomRight.row(), topLeft.parent()); 2319 2325 } … … 2328 2334 2329 2335 \ingroup model-view 2330 \mainclass 2336 2331 2337 2332 2338 The QTreeWidget class is a convenience class that provides a standard … … 2437 2443 expandAll() is invoked. 2438 2444 2439 \sa isItemExpanded(), itemCollapsed(), expandItem()2445 \sa Expanded(), itemCollapsed(), expandItem() 2440 2446 */ 2441 2447 … … 2449 2455 collapseAll() is invoked. 2450 2456 2451 \sa isItemExpanded(), itemExpanded(), collapseItem()2457 \sa Expanded(), itemExpanded(), collapseItem() 2452 2458 */ 2453 2459 … … 2543 2549 { 2544 2550 Q_D(const QTreeWidget); 2545 return d->model ()->columnCount();2551 return d->model->columnCount(); 2546 2552 } 2547 2553 … … 2555 2561 if (columns < 0) 2556 2562 return; 2557 d-> model()->setColumnCount(columns);2563 d->odel()->setColumnCount(columns); 2558 2564 } 2559 2565 … … 2572 2578 { 2573 2579 Q_D(const QTreeWidget); 2574 return d-> model()->rootItem;2580 return d->odel()->rootItem; 2575 2581 } 2576 2582 … … 2585 2591 { 2586 2592 Q_D(const QTreeWidget); 2587 return d-> model()->rootItem->child(index);2593 return d->odel()->rootItem->child(index); 2588 2594 } 2589 2595 … … 2600 2606 { 2601 2607 Q_D(const QTreeWidget); 2602 return d-> model()->rootItem->childCount();2608 return d->odel()->rootItem->childCount(); 2603 2609 } 2604 2610 … … 2614 2620 { 2615 2621 Q_D(QTreeWidget); 2616 d-> model()->rootItem->insertChild(index, item);2622 d->odel()->rootItem->insertChild(index, item); 2617 2623 } 2618 2624 … … 2639 2645 { 2640 2646 Q_D(QTreeWidget); 2641 return d-> model()->rootItem->takeChild(index);2647 return d->odel()->rootItem->takeChild(index); 2642 2648 } 2643 2649 … … 2648 2654 { 2649 2655 Q_D(QTreeWidget); 2650 d-> model()->executePendingSort();2651 return d-> model()->rootItem->children.indexOf(item);2656 d->odel()->executePendingSort(); 2657 return d->odel()->rootItem->children.indexOf(item); 2652 2658 } 2653 2659 … … 2661 2667 { 2662 2668 Q_D(const QTreeWidget); 2663 d-> model()->executePendingSort();2664 return d-> model()->rootItem->children.indexOf(item);2669 d->odel()->executePendingSort(); 2670 return d->odel()->rootItem->children.indexOf(item); 2665 2671 } 2666 2672 … … 2677 2683 { 2678 2684 Q_D(QTreeWidget); 2679 d-> model()->rootItem->insertChildren(index, items);2685 d->odel()->rootItem->insertChildren(index, items); 2680 2686 } 2681 2687 … … 2699 2705 { 2700 2706 Q_D(const QTreeWidget); 2701 return d-> model()->headerItem;2707 return d->odel()->headerItem; 2702 2708 } 2703 2709 … … 2720 2726 int oldCount = columnCount(); 2721 2727 if (oldCount < item->columnCount()) 2722 d-> model()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount());2728 d->odel()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount()); 2723 2729 else 2724 d-> model()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount);2725 delete d-> model()->headerItem;2726 d-> model()->headerItem = item;2730 d->odel()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount); 2731 delete d->odel()->headerItem; 2732 d->odel()->headerItem = item; 2727 2733 if (oldCount < item->columnCount()) 2728 d-> model()->endInsertColumns();2734 d->odel()->endInsertColumns(); 2729 2735 else 2730 d-> model()->endRemoveColumns();2731 d-> model()->headerDataChanged(Qt::Horizontal, 0, oldCount);2736 d->odel()->endRemoveColumns(); 2737 d->odel()->headerDataChanged(Qt::Horizontal, 0, oldCount); 2732 2738 } 2733 2739 … … 2746 2752 if (columnCount() < labels.count()) 2747 2753 setColumnCount(labels.count()); 2748 QTreeModel *model = d->model(); 2749 QTreeWidgetItem *item = model->headerItem; 2754 QTreeWidgetItem *item = d->treeModel()->headerItem; 2750 2755 for (int i = 0; i < labels.count(); ++i) 2751 2756 item->setText(i, labels.at(i)); … … 2784 2789 Sets the current \a item in the tree widget. 2785 2790 2786 Depending on the current selection mode, the item may also be selected. 2791 Unless the selection mode is \l{QAbstractItemView::}{NoSelection}, 2792 the item is also be selected. 2787 2793 2788 2794 \sa currentItem(), currentItemChanged() … … 2846 2852 { 2847 2853 Q_D(const QTreeWidget); 2848 return visualRect(d->index(item)); 2854 //the visual rect for an item is across all columns. So we need to determine 2855 //what is the first and last column and get their visual index rects 2856 QModelIndex base = d->index(item); 2857 const int firstVisiblesection = header()->logicalIndexAt(- header()->offset()); 2858 const int lastVisibleSection = header()->logicalIndexAt(header()->length() - header()->offset() - 1); 2859 QModelIndex first = base.sibling(base.row(), header()->logicalIndex(firstVisiblesection)); 2860 QModelIndex last = base.sibling(base.row(), header()->logicalIndex(lastVisibleSection)); 2861 return visualRect(first) | visualRect(last); 2849 2862 } 2850 2863 … … 2875 2888 Q_D(QTreeWidget); 2876 2889 header()->setSortIndicator(column, order); 2877 d->model ()->sort(column, order);2890 d->model->sort(column, order); 2878 2891 } 2879 2892 … … 3042 3055 { 3043 3056 Q_D(const QTreeWidget); 3044 QModelIndexList indexes = d->model ()->match(model()->index(0, column, QModelIndex()),3057 QModelIndexList indexes = d->model->match(model()->index(0, column, QModelIndex()), 3045 3058 Qt::DisplayRole, text, -1, flags); 3046 3059 QList<QTreeWidgetItem*> items; … … 3060 3073 { 3061 3074 Q_D(const QTreeWidget); 3062 if (item == d-> model()->headerItem)3075 if (item == d->odel()->headerItem) 3063 3076 return header()->isHidden(); 3064 3077 if (d->hiddenIndexes.isEmpty()) 3065 3078 return false; 3066 QTreeModel::SkipSorting skipSorting(d-> model());3079 QTreeModel::SkipSorting skipSorting(d->odel()); 3067 3080 return d->isRowHidden(d->index(item)); 3068 3081 } … … 3080 3093 { 3081 3094 Q_D(QTreeWidget); 3082 if (item == d-> model()->headerItem) {3095 if (item == d->odel()->headerItem) { 3083 3096 header()->setHidden(hide); 3084 3097 } else { … … 3100 3113 { 3101 3114 Q_D(const QTreeWidget); 3102 QTreeModel::SkipSorting skipSorting(d-> model());3115 QTreeModel::SkipSorting skipSorting(d->odel()); 3103 3116 return isExpanded(d->index(item)); 3104 3117 } … … 3110 3123 \sa expandItem(), collapseItem(), itemExpanded() 3111 3124 3112 \obsolete3113 3114 This function is deprecated. Use \l{QTreeWidgetItem::setExpanded()} instead.3125 \obsolete 3126 3127 This function is deprecated. Use \l{QTreeWidgetItem::setExpanded()} instead. 3115 3128 */ 3116 3129 void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand) 3117 3130 { 3118 3131 Q_D(QTreeWidget); 3119 QTreeModel::SkipSorting skipSorting(d-> model());3132 QTreeModel::SkipSorting skipSorting(d->odel()); 3120 3133 setExpanded(d->index(item), expand); 3121 3134 } … … 3132 3145 { 3133 3146 Q_D(const QTreeWidget); 3134 if (item == d-> model()->headerItem)3147 if (item == d->odel()->headerItem) 3135 3148 return false; // We can't set the header items to spanning 3136 3149 const QModelIndex index = d->index(item); … … 3149 3162 { 3150 3163 Q_D(QTreeWidget); 3151 if (item == d-> model()->headerItem)3164 if (item == d->odel()->headerItem) 3152 3165 return; // We can't set header items to spanning 3153 3166 const QModelIndex index = d->index(item); … … 3163 3176 { 3164 3177 Q_D(const QTreeWidget); 3165 if (item == d-> model()->headerItem)3178 if (item == d->odel()->headerItem) 3166 3179 return 0; 3167 3180 const QModelIndex index = d->index(item); … … 3178 3191 { 3179 3192 Q_D(const QTreeWidget); 3180 if (item == d-> model()->headerItem)3193 if (item == d->odel()->headerItem) 3181 3194 return 0; 3182 3195 const QModelIndex index = d->index(item); … … 3218 3231 { 3219 3232 Q_D(QTreeWidget); 3220 QTreeModel::SkipSorting skipSorting(d-> model());3233 QTreeModel::SkipSorting skipSorting(d->odel()); 3221 3234 expand(d->index(item)); 3222 3235 } … … 3231 3244 { 3232 3245 Q_D(QTreeWidget); 3233 QTreeModel::SkipSorting skipSorting(d-> model());3246 QTreeModel::SkipSorting skipSorting(d->odel()); 3234 3247 collapse(d->index(item)); 3235 3248 } … … 3248 3261 Q_D(QTreeWidget); 3249 3262 selectionModel()->clear(); 3250 d-> model()->clear();3263 d->odel()->clear(); 3251 3264 } 3252 3265 … … 3273 3286 { 3274 3287 Q_D(const QTreeWidget); 3275 if (d-> model()->cachedIndexes.isEmpty()) {3288 if (d->odel()->cachedIndexes.isEmpty()) { 3276 3289 QList<QModelIndex> indexes; 3277 3290 for (int i = 0; i < items.count(); ++i) { … … 3281 3294 } 3282 3295 } 3283 return model()->QAbstractItemModel::mimeData(indexes);3284 } 3285 return d-> model()->internalMimeData();3296 return ->QAbstractItemModel::mimeData(indexes); 3297 } 3298 return d->odel()->internalMimeData(); 3286 3299 } 3287 3300 … … 3427 3440 Q_D(QTreeWidget); 3428 3441 if (e->type() == QEvent::Polish) 3429 d-> model()->executePendingSort();3442 d->odel()->executePendingSort(); 3430 3443 return QTreeView::event(e); 3431 3444 }
Note:
See TracChangeset
for help on using the changeset viewer.