⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlistview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			      QString label3,			      QString label4,			      QString label5,			      QString label6,			      QString label7,			      QString label8 ){    init();    parent->insertItem( this );    moveToJustAfter( after );    setText( 0, label1 );    setText( 1, label2 );    setText( 2, label3 );    setText( 3, label4 );    setText( 4, label5 );    setText( 5, label6 );    setText( 6, label7 );    setText( 7, label8 );}/*!  (Re)sorts all child items of this item using the last sorting  configuration (sort column and direction).  \sa enforceSortOrder()*/void QListViewItem::sort(){    if ( !listView() )	 return;    lsc = Unsorted;    enforceSortOrder();    listView()->triggerUpdate();}/*!  Performs the initializations that's common to the constructors. */void QListViewItem::init(){    ownHeight = 0;    maybeTotalHeight = -1;    open = FALSE;    nChildren = 0;    parentItem = 0;    siblingItem = childItem = 0;    columns = 0;    selected = 0;    lsc = Unsorted;    lso = TRUE; // unsorted in ascending order :)    configured = FALSE;    expandable = FALSE;    selectable = TRUE;    is_root = FALSE;}/*!  Destroys the item, deleting all its children, freeing up all  allocated resources.*/QListViewItem::~QListViewItem(){    QListView *lv = listView();    if ( lv ) {	if ( lv->d->iterators ) {	    QListViewItemIterator *i = lv->d->iterators->first();	    while ( i ) {		if ( i->current() == this )		    i->currentRemoved();		i = lv->d->iterators->next();	    }	}    }    if ( parentItem )	parentItem->takeItem( this );    QListViewItem * i = childItem;    childItem = 0;    while ( i ) {	i->parentItem = 0;	QListViewItem * n = i->siblingItem;	delete i;	i = n;    }    delete (QListViewPrivate::ItemColumnInfo *)columns;}/*!  Inserts \a newChild into its list of children.  You should not  need to call this function; it is called automatically by the  constructor of \a newChild.  This function works even if this item is not contained in a list view.*/void QListViewItem::insertItem( QListViewItem * newChild ){    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;    QListView *lv = listView();    if ( !lv )	return;    if ( lv && lv->hasFocus() && !lv->d->focusItem ) {	lv->d->focusItem = lv->firstChild();	lv->repaintItem( lv->d->focusItem );    }}/*!\obsolete  This function has been renamed takeItem().*/void QListViewItem::removeItem( QListViewItem * item ){    takeItem( item );}/*!  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 normally not  need to call this function, as QListViewItem::~QListViewItem() calls it.  The normal way to delete an item is \c delete.  \warning This function leaves \a item and its children in a state  where most member functions are unsafe.  Only the few functions that  are explicitly documented to work in this state may be used then.  \sa QListViewItem::insertItem()*/void QListViewItem::takeItem( QListViewItem * item ){    if ( !item )	return;    QListView *lv = listView();    bool was_selected = FALSE;    bool emit_changed = FALSE;    QListViewItem *oldCurrent = 0;    if ( lv && !lv->d->clearing ) {	if ( lv->d->iterators ) {	    QListViewItemIterator *i = lv->d->iterators->first();	    while ( i ) {		if ( i->current() == item )		    i->currentRemoved();		i = lv->d->iterators->next();	    }	}	invalidateHeight();	if ( lv->d && lv->d->drawables ) {	    delete lv->d->drawables;	    lv->d->drawables = 0;	}	if ( lv->d->dirtyItems ) {	    if ( item->childItem ) {		delete lv->d->dirtyItems;		lv->d->dirtyItems = 0;		lv->d->dirtyItemTimer->stop();		lv->triggerUpdate();	    } else {		lv->d->dirtyItems->take( (void *)item );	    }	}	was_selected = item->isSelected();	item->setSelected( FALSE );#if 0	// ##### do we really want that???	if ( lv->selectedItem() ) {	    QListViewItem * c = lv->selectedItem();	    while( c && c != item )		c = c->parentItem;	    if ( c == item ) {		emit lv->selectionChanged( 0 );	    }	}#endif	if ( lv->d->focusItem ) {	    const QListViewItem * c = lv->d->focusItem;	    while( c && c != item )		c = c->parentItem;	    if ( c == item ) {		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;		oldCurrent = lv->d->focusItem;	    }	}	if ( lv->d->selectAnchor == item )	    lv->d->selectAnchor = lv->d->focusItem;    }    nChildren--;    QListViewItem ** 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( oldCurrent );    if ( was_selected )	emit lv->selectionChanged();}/*!  \fn QString QListViewItem::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.  You can use this function to sort by non-alphabetic data.  This code  excerpt sort by file modification date, for example  \code    if ( column == 3 ) {	QDateTime epoch( QDate( 1980, 1, 1 ) );	tmpString.sprintf( "%08d", epoch.secsTo( myFile.lastModified() ) );    } else {	// ....    }    return tmpString;  \endcode  \sa sortChildItems()*/QString QListViewItem::key( int column, bool ) const{    return text( column );}#if defined(Q_C_CALLBACKS)extern "C" {#endifstatic int cmp( const void *n1, const void *n2 ){    if ( !n1 || !n2 )	return 0;    return ((QListViewPrivate::SortableItem *)n1)->key.	    compare( ((QListViewPrivate::SortableItem *)n2)->key );}#if defined(Q_C_CALLBACKS)}#endif/*!  Sorts the children of this item by the return values of  key(\a column, \a ascending), in ascending order if \a ascending  is TRUE and in descending order of \a descending is FALSE.  Asks some of the children to sort their children.  (QListView and  QListViewItem 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()*/void QListViewItem::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;    // and don't sort if we already have the right sorting order    if ( childItem == 0 || childItem->siblingItem == 0 )	return;    // make an array we can sort in a thread-safe way using qsort()    QListViewPrivate::SortableItem * siblings	= new QListViewPrivate::SortableItem[nChildren];    QListViewItem * s = childItem;    int i = 0;    while ( s && i<nChildren ) {	siblings[i].key = s->key( column, ascending );	siblings[i].i = s;	s = s->siblingItem;	i++;    }    // and do it.    qsort( siblings, nChildren,	   sizeof( QListViewPrivate::SortableItem ), cmp );    // 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].i->siblingItem = siblings[i+1].i;	siblings[nChildren-1].i->siblingItem = 0;	childItem = siblings[0].i;    } else {	for( i=nChildren-1; i >0; i-- )	    siblings[i].i->siblingItem = siblings[i-1].i;	siblings[0].i->siblingItem = 0;	childItem = siblings[nChildren-1].i;    }    // we don't want no steenking memory leaks.    delete[] siblings;}/*!  Sets this item's own height to \a height pixels.  This implicitly  changes totalHeight() too.  Note that e.g. a font change causes this height to be overwritten  unless you reimplement setup().  For best results in Windows style, we suggest using an even number  of pixels.  \sa height() totalHeight() isOpen();*/void QListViewItem::setHeight( int height ){    if ( ownHeight != height ) {	ownHeight = height;	invalidateHeight();    }}/*!  Invalidates the cached total height of this item including  all open children.  This function works even if this item is not contained in a list view.  \sa setHeight() height() totalHeight()*/void QListViewItem::invalidateHeight(){    if ( maybeTotalHeight < 0 )	return;    maybeTotalHeight = -1;    if ( parentItem && parentItem->isOpen() )	parentItem->invalidateHeight();}/*!  Sets this item to be open (its children are visible) if \a o is  TRUE, and to be closed (its children are not visible) if \a o is  FALSE.  Also does some bookkeeping.  \sa height() totalHeight()*/void QListViewItem::setOpen( bool o ){    if ( o == (bool)open )	return;    open = o;    QListView *lv = listView();    if ( lv && this != lv->d->r ) {	if ( o )	    emit lv->expanded( this );	else	    emit lv->collapsed( this );    }    if ( !nChildren )	return;    invalidateHeight();    if ( !configured ) {	QListViewItem * l = this;	QStack<QListViewItem> s;	while( l ) {	    if ( l->open && l->childItem ) {		s.push( l->childItem );	    } else if ( l->childItem ) {		// first invisible child is unconfigured		QListViewItem * c = l->childItem;		while( c ) {		    c->configured = FALSE;		    c = c->siblingItem;		}	    }	    l->configured = TRUE;	    l->setup();	    l = (l == this) ? 0 : l->siblingItem;	    if ( !l && !s.isEmpty() )		l = s.pop();	}    }    if ( !open )	return;    enforceSortOrder();}/*!  This virtual function is called before the first time QListView  needs to know the height or any other graphical attribute of this  object, and whenever the font, GUI style or colors of the list view  change.  The default calls widthChanged() and sets the item's height to the  height of a single line of text in the list view's font.  (If you  use icons, multi-line text etc. you will probably need to call  setHeight() yourself or reimplement this.)*/void QListViewItem::setup(){    widthChanged();    QListView * v = listView();    int ph = 0;    for ( uint i = 0; i < v->d->column.size(); ++i ) {	if ( pixmap( i ) )	    ph = QMAX( ph, pixmap( i )->height() );    }    int h = QMAX( v->d->fontMetricsHeight, ph ) + 2*v->itemMargin();    h = QMAX( h, QApplication::globalStrut().height());    if ( h % 2 > 0 )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -