📄 q3listview.cpp
字号:
renameBox = 0; } Q3ListView *lv = listView(); if (lv) { if (lv->d->oldFocusItem == this) lv->d->oldFocusItem = 0; if (lv->d->focusItem == this) lv->d->focusItem = 0; if (lv->d->highlighted == this) lv->d->highlighted = 0; if (lv->d->pressedItem == this) lv->d->pressedItem = 0; if (lv->d->selectAnchor == this) lv->d->selectAnchor = 0; for (int j = 0; j < lv->d->iterators.size(); ++j) { Q3ListViewItemIterator *i = lv->d->iterators.at(j); if (i->current() == this) i->currentRemoved(); } } if (parentItem) parentItem->takeItem(this); Q3ListViewItem * i = childItem; childItem = 0; while (i) { i->parentItem = 0; Q3ListViewItem * n = i->siblingItem; delete i; i = n; } delete (Q3ListViewPrivate::ItemColumnInfo *)columns;}/*! If \a b is true each of the item's columns may contain multiple lines of text; otherwise each of them may only contain a single line.*/void Q3ListViewItem::setMultiLinesEnabled(bool b){ mlenabled = b;}/*! Returns true if the item can display multiple lines of text in its columns; otherwise returns false.*/bool Q3ListViewItem::multiLinesEnabled() const{ return mlenabled;}/*! If \a allow is true, the list view starts a drag (see Q3ListView::dragObject()) when the user presses and moves the mouse on this item.*/void Q3ListViewItem::setDragEnabled(bool allow){ allow_drag = (uint)allow;}/*! If \a allow is true, the list view accepts drops onto the item; otherwise drops are not allowed.*/void Q3ListViewItem::setDropEnabled(bool allow){ allow_drop = (uint)allow;}/*! Returns true if this item can be dragged; otherwise returns false. \sa setDragEnabled()*/bool Q3ListViewItem::dragEnabled() const{ return (bool)allow_drag;}/*! Returns true if this item accepts drops; otherwise returns false. \sa setDropEnabled(), acceptDrop()*/bool Q3ListViewItem::dropEnabled() const{ return (bool)allow_drop;}/*! Returns true if the item can accept drops of type QMimeSource \a mime; otherwise returns false. The default implementation does nothing and returns false. A subclass must reimplement this to accept drops.*/bool Q3ListViewItem::acceptDrop(const QMimeSource *) const{ return false;}#ifndef QT_NO_DRAGANDDROP/*! This function is called when something was dropped on the item. \a e contains all the information about the drop. The default implementation does nothing, subclasses may need to reimplement this function.*/void Q3ListViewItem::dropped(QDropEvent *e){ Q_UNUSED(e);}#endif/*! This function is called when a drag enters the item's bounding rectangle. The default implementation does nothing, subclasses may need to reimplement this function.*/void Q3ListViewItem::dragEntered(){}/*! This function is called when a drag leaves the item's bounding rectangle. The default implementation does nothing, subclasses may need to reimplement this function.*/void Q3ListViewItem::dragLeft(){}/*! Inserts \a newChild into this list view item's list of children. You should not need to call this function; it is called automatically by the constructor of \a newChild. \warning If you are using \c Single selection mode, then you should only insert unselected items.*/void Q3ListViewItem::insertItem(Q3ListViewItem * newChild){ Q3ListView *lv = listView(); if (lv && lv->currentItem() && lv->currentItem()->renameBox) { if (lv->d->defRenameAction == Q3ListView::Reject) lv->currentItem()->cancelRename(lv->currentItem()->renameCol); else lv->currentItem()->okRename(lv->currentItem()->renameCol); } if (!newChild || newChild->parentItem == this) return; if (newChild->parentItem) newChild->parentItem->takeItem(newChild); if (open) invalidateHeight(); newChild->siblingItem = childItem; childItem = newChild; nChildren++; newChild->parentItem = this; lsc = Unsorted; newChild->ownHeight = 0; newChild->configured = false; if (lv && !lv->d->focusItem) { lv->d->focusItem = lv->firstChild(); lv->d->selectAnchor = lv->d->focusItem; lv->repaintItem(lv->d->focusItem); }}/*! \fn void Q3ListViewItem::removeItem(Q3ListViewItem *item) Removes the given \a item. Use takeItem() instead.*//*! Removes \a item from this object's list of children and causes an update of the screen display. The item is not deleted. You should not normally need to call this function because Q3ListViewItem::~Q3ListViewItem() calls it. The normal way to delete an item is to use \c delete. If you need to move an item from one place in the hierarchy to another you can use takeItem() to remove the item from the list view and then insertItem() to put the item back in its new position. If a taken item is part of a selection in \c Single selection mode, it is unselected and selectionChanged() is emitted. If a taken item is part of a selection in \c Multi or \c Extended selection mode, it remains selected. \warning This function leaves \a item and its children in a state where most member functions are unsafe. Only a few functions work correctly on an item in this state, most notably insertItem(). The functions that work on taken items are explicitly documented as such. \sa Q3ListViewItem::insertItem()*/void Q3ListViewItem::takeItem(Q3ListViewItem * item){ if (!item) return; Q3ListView *lv = listView(); if (lv && lv->currentItem() && lv->currentItem()->renameBox) { if (lv->d->defRenameAction == Q3ListView::Reject) lv->currentItem()->cancelRename(lv->currentItem()->renameCol); else lv->currentItem()->okRename(lv->currentItem()->renameCol); } bool emit_changed = false; if (lv && !lv->d->clearing) { if (lv->d->oldFocusItem == this) lv->d->oldFocusItem = 0; for (int j = 0; j < lv->d->iterators.size(); ++j) { Q3ListViewItemIterator *i = lv->d->iterators.at(j); if (i->current() == item) i->currentRemoved(); } invalidateHeight(); if (lv->d && !lv->d->drawables.isEmpty()) lv->d->drawables.clear(); if (!lv->d->dirtyItems.isEmpty()) { if (item->childItem) { lv->d->dirtyItems.clear(); lv->d->dirtyItemTimer->stop(); lv->triggerUpdate(); } else { lv->d->dirtyItems.removeAll(item); } } if (lv->d->focusItem) { const Q3ListViewItem * c = lv->d->focusItem; while(c && c != item) c = c->parentItem; if (c == item) { if (lv->selectedItem()) { // for Single, setSelected(false) when selectedItem() is taken lv->selectedItem()->setSelected(false); // we don't emit selectionChanged(0) emit lv->selectionChanged(); } if (item->nextSibling()) lv->d->focusItem = item->nextSibling(); else if (item->itemAbove()) lv->d->focusItem = item->itemAbove(); else lv->d->focusItem = 0; emit_changed = true; } } // reset anchors etc. if they are set to this or any child // items const Q3ListViewItem *ptr = lv->d->selectAnchor; while (ptr && ptr != item) ptr = ptr->parentItem; if (ptr == item) lv->d->selectAnchor = lv->d->focusItem; ptr = lv->d->startDragItem; while (ptr && ptr != item) ptr = ptr->parentItem; if (ptr == item) lv->d->startDragItem = 0; ptr = lv->d->pressedItem; while (ptr && ptr != item) ptr = ptr->parentItem; if (ptr == item) lv->d->pressedItem = 0; ptr = lv->d->highlighted; while (ptr && ptr != item) ptr = ptr->parentItem; if (ptr == item) lv->d->highlighted = 0; } nChildren--; Q3ListViewItem ** nextChild = &childItem; while(nextChild && *nextChild && item != *nextChild) nextChild = &((*nextChild)->siblingItem); if (nextChild && item == *nextChild) *nextChild = (*nextChild)->siblingItem; item->parentItem = 0; item->siblingItem = 0; item->ownHeight = 0; item->maybeTotalHeight = -1; item->configured = false; if (emit_changed) { emit lv->currentChanged(lv->d->focusItem);#ifndef QT_NO_ACCESSIBILITY QAccessible::updateAccessibility(lv->viewport(), 0, QAccessible::Focus);#endif }}/*! \fn QString Q3ListViewItem::key(int column, bool ascending) const Returns a key that can be used for sorting by column \a column. The default implementation returns text(). Derived classes may also incorporate the order indicated by \a ascending into this key, although this is not recommended. If you want to sort on non-alphabetical data, e.g. dates, numbers, etc., it is more efficient to reimplement compare(). \sa compare(), sortChildItems()*/QString Q3ListViewItem::key(int column, bool) const{ return text(column);}/*! Compares this list view item to \a i using the column \a col in \a ascending order. Returns \< 0 if this item is less than \a i, 0 if they are equal and \> 0 if this item is greater than \a i. This function is used for sorting. The default implementation compares the item keys (key()) using QString::localeAwareCompare(). A reimplementation can use different values and a different comparison function. Here is a reimplementation that uses plain Unicode comparison: \code int MyListViewItem::compare(Q3ListViewItem *i, int col, bool ascending) const { return key(col, ascending).compare(i->key(col, ascending)); } \endcode We don't recommend using \a ascending so your code can safely ignore it. \sa key() QString::localeAwareCompare() QString::compare()*/int Q3ListViewItem::compare(Q3ListViewItem *i, int col, bool ascending) const{ return key(col, ascending).localeAwareCompare(i->key(col, ascending));}/*! Sorts this item's children using column \a column. This is done in ascending order if \a ascending is true and in descending order if \a ascending is false. Asks some of the children to sort their children. (Q3ListView and Q3ListViewItem ensure that all on-screen objects are properly sorted but may avoid or defer sorting other objects in order to be more responsive.) \sa key() compare()*/void Q3ListViewItem::sortChildItems(int column, bool ascending){ // we try HARD not to sort. if we're already sorted, don't. if (column == (int)lsc && ascending == (bool)lso) return; if (column < 0) return; lsc = column; lso = ascending; const int nColumns = (listView() ? listView()->columns() : 0); // and don't sort if we already have the right sorting order if (column > nColumns || childItem == 0 || childItem->siblingItem == 0) return; // make an array for qHeapSort() Q3ListViewPrivate::SortableItem * siblings = new Q3ListViewPrivate::SortableItem[nChildren]; Q3ListViewItem * s = childItem; int i = 0; while (s && i < nChildren) { siblings[i].numCols = nColumns; siblings[i].col = column; siblings[i].asc = ascending; siblings[i].item = s; s = s->siblingItem; i++; } // and sort it. qHeapSort(siblings, siblings + nChildren); // build the linked list of siblings, in the appropriate // direction, and finally set this->childItem to the new top // child. if (ascending) { for(i = 0; i < nChildren - 1; i++) siblings[i].item->siblingItem = siblings[i+1].item; siblings[nChildren-1].item->siblingItem = 0; childItem = siblings[0].item; } else { for(i = nChildren - 1; i > 0; i--) siblings[i].item->siblingItem = siblings[i-1].item; siblings[0].item->siblingItem = 0; childItem = siblings[nChildren-1].item; } for (i = 0; i < nChildren; i++) { if (siblings[i].item->isOpen()) siblings[i].item->sort(); } delete[] siblings;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -