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

📄 qtableview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  currently on the top edge of the view.  \sa setYOffset(), xOffset(), topCell()*//*!  Scrolls the table such that \e y becomes the top pixel in the view.  The \e y parameter is in \e table coordinates.  The interaction with \link setTableFlags() Tbl_snapToVGrid  \endlink is tricky.  \sa yOffset(), setXOffset(), setOffset(), setTopCell()*/void QTableView::setYOffset( int y ){    setOffset( xOffset(), y );}/*!  Scrolls the table such that \e (x,y) becomes the top left pixel  in the view. Parameters \e (x,y) are in \e table coordinates.  The interaction with \link setTableFlags() Tbl_snapTo*Grid \endlink  is tricky.  If \e updateScrBars is TRUE, the scroll bars are  updated.  \sa xOffset(), yOffset(), setXOffset(), setYOffset(), setTopLeftCell()*/void QTableView::setOffset( int x, int y, bool updateScrBars ){    if ( (!testTableFlags(Tbl_snapToHGrid) || xCellDelta == 0) &&	 (!testTableFlags(Tbl_snapToVGrid) || yCellDelta == 0) &&	 (x == xOffs && y == yOffs) )	return;    if ( x < 0 )	x = 0;    if ( y < 0 )	y = 0;    if ( cellW ) {	if ( x > maxXOffset() )	    x = maxXOffset();	xCellOffs = x / cellW;	if ( !testTableFlags(Tbl_snapToHGrid) ) {	    xCellDelta	= (short)(x % cellW);	} else {	    x		= xCellOffs*cellW;	    xCellDelta	= 0;	}    } else {	int xn=0, xcd=0, col = 0;	while ( col < nCols-1 && x >= xn+(xcd=cellWidth(col)) ) {	    xn += xcd;	    col++;	}	xCellOffs = col;	if ( testTableFlags(Tbl_snapToHGrid) ) {	    xCellDelta = 0;	    x = xn;	} else {	    xCellDelta = (short)(x-xn);	}    }    if ( cellH ) {	if ( y > maxYOffset() )	    y = maxYOffset();	yCellOffs = y / cellH;	if ( !testTableFlags(Tbl_snapToVGrid) ) {	    yCellDelta	= (short)(y % cellH);	} else {	    y		= yCellOffs*cellH;	    yCellDelta	= 0;	}    } else {	int yn=0, yrd=0, row=0;	while ( row < nRows-1 && y >= yn+(yrd=cellHeight(row)) ) {	    yn += yrd;	    row++;	}	yCellOffs = row;	if ( testTableFlags(Tbl_snapToVGrid) ) {	    yCellDelta = 0;	    y = yn;	} else {	    yCellDelta = (short)(y-yn);	}    }    int dx = (x - xOffs);    int dy = (y - yOffs);    xOffs = x;    yOffs = y;    if ( autoUpdate() && isVisible() )	scroll( dx, dy );    if ( updateScrBars )	updateScrollBars( verValue | horValue );}/*!  \fn int QTableView::cellWidth() const  Returns the column width, in pixels.	Returns 0 if the columns have  variable widths.  \sa setCellWidth(), cellHeight()*//*!  Returns the width of column \e col, in pixels.  This function is virtual and must be reimplemented by subclasses that  have variable cell widths. Note that if the total table width  changes, updateTableSize() must be called.  \sa setCellWidth(), cellHeight(), totalWidth(), updateTableSize()*/int QTableView::cellWidth( int ){    return cellW;}/*!  Sets the width in pixels of the table cells to \e cellWidth.  Setting it to zero means that the column width is variable.  When  set to 0 (this is the default) QTableView calls the virtual function  cellWidth() to get the width.  \sa cellWidth(), setCellHeight(), totalWidth(), numCols()*/void QTableView::setCellWidth( int cellWidth ){    if ( cellW == cellWidth )	return;#if defined(CHECK_RANGE)    if ( cellWidth < 0 || cellWidth > SHRT_MAX ) {	qWarning( "QTableView::setCellWidth: (%s) Argument out of range (%d)",		 name( "unnamed" ), cellWidth );	return;    }#endif    cellW = (short)cellWidth;    updateScrollBars( horSteps | horRange );    if ( autoUpdate() && isVisible() )	repaint();}/*!  \fn int QTableView::cellHeight() const  Returns the row height, in pixels.  Returns 0 if the rows have  variable heights.  \sa setCellHeight(), cellWidth()*//*!  Returns the height of row \e row, in pixels.  This function is virtual and must be reimplemented by subclasses that  have variable cell heights.  Note that if the total table height  changes, updateTableSize() must be called.  \sa setCellHeight(), cellWidth(), totalHeight()*/int QTableView::cellHeight( int ){    return cellH;}/*!  Sets the height in pixels of the table cells to \e cellHeight.  Setting it to zero means that the row height is variable.  When set  to 0 (this is the default) QTableView calls the virtual function  cellHeight() to get the height.  \sa cellHeight(), setCellWidth(), totalHeight(), numRows()*/void QTableView::setCellHeight( int cellHeight ){    if ( cellH == cellHeight )	return;#if defined(CHECK_RANGE)    if ( cellHeight < 0 || cellHeight > SHRT_MAX ) {	qWarning( "QTableView::setCellHeight: (%s) Argument out of range (%d)",		 name( "unnamed" ), cellHeight );	return;    }#endif    cellH = (short)cellHeight;    if ( autoUpdate() && isVisible() )	repaint();    updateScrollBars( verSteps | verRange );}/*!  Returns the total width of the table in pixels.  This function is virtual and should be reimplemented by subclasses that  have variable cell widths and a non-trivial cellWidth() function, or a  large number of columns in the table.  The default implementation may be slow for very wide tables.  \sa cellWidth(), totalHeight() */int QTableView::totalWidth(){    if ( cellW ) {	return cellW*nCols;    } else {	int tw = 0;	for( int i = 0 ; i < nCols ; i++ )	    tw += cellWidth( i );	return tw;    }}/*!  Returns the total height of the table in pixels.  This function is virtual and should be reimplemented by subclasses that  have variable cell heights and a non-trivial cellHeight() function, or a  large number of rows in the table.  The default implementation may be slow for very tall tables.  \sa cellHeight(), totalWidth()*/int QTableView::totalHeight(){    if ( cellH ) {	return cellH*nRows;    } else {	int th = 0;	for( int i = 0 ; i < nRows ; i++ )	    th += cellHeight( i );	return th;    }}/*!  \fn uint QTableView::tableFlags() const  Returns the union of the table flags that are currently set.  \sa setTableFlags(), clearTableFlags(), testTableFlags()*//*!  \fn bool QTableView::testTableFlags( uint f ) const  Returns TRUE if any of the table flags in \e f are currently set,  otherwise FALSE.  \sa setTableFlags(), clearTableFlags(), tableFlags()*//*!  Sets the table flags to \e f.  If a flag setting changes the appearance of the table the table is  repainted if and only if autoUpdate() is TRUE.  The table flags are mostly single bits, though there are some multibit  flags for convenience. Here is a complete list:  <dl compact>  <dt> Tbl_vScrollBar <dd> The table has a vertical scroll bar.  <dt> Tbl_hScrollBar <dd> The table has a horizontal scroll bar.  <dt> Tbl_autoVScrollBar <dd> The table has a vertical scroll bar if  and only if the table is taller than the view.  <dt> Tbl_autoHScrollBar <dd> The table has a horizontal scroll bar if  and only if the table is wider than the view.  <dt> Tbl_autoScrollBars <dd> The union of the previous two flags.  <dt> Tbl_clipCellPainting <dd> The table uses QPainter::setClipRect() to  make sure that paintCell() will not draw outside the cell  boundaries.  <dt> Tbl_cutCellsV <dd> The table will never show part of a  cell at the bottom of the table; if there is not space for all of  a cell the space is left blank.  <dt> Tbl_cutCellsH <dd> The table will never show part of a  cell at the right side of the table; if there is not space for all of  a cell the space is left blank.  <dt> Tbl_cutCells <dd> The union of the previous two flags.  <dt> Tbl_scrollLastHCell <dd> When the user scrolls horizontally,  let him/her scroll the last cell leftward until it is at the left  edge of the view.  If this flag is not set, the user can only scroll  to the point where last cell is completely visible.  <dt> Tbl_scrollLastVCell <dd> When the user scrolls vertically, let  him/her scroll the last cell upward until it is at the top edge of  the view.  If this flag is not set, the user can only scroll to the  point where last cell is completely visible.  <dt> Tbl_scrollLastCell <dd> The union of the previous two flags.  <dt> Tbl_smoothHScrolling <dd> The table scrolls as smoothly as  possible when the user scrolls horizontally. When this flag is not  set scrolling is done one cell at a time.  <dt> Tbl_smoothVScrolling <dd> The table scrolls as smoothly as  possible when scrolling vertically. When this flag is not set  scrolling is done one cell at a time.  <dt> Tbl_smoothScrolling <dd> The union of of previous two flags.  <dt> Tbl_snapToHGrid <dd> Except when the user is actually scrolling,  the leftmost column shown snaps to the leftmost edge of the view.  <dt> Tbl_snapToVGrid <dd> Except when the user is actually  scrolling, the top row snaps to the top edge of the view.  <dt> Tbl_snapToGrid <dd> The union of the previous two flags.  </dl>  You can specify more than one flag at a time using bitwise OR.  Example:  \code    setTableFlags( Tbl_smoothScrolling | Tbl_autoScrollBars );  \endcode  \warning The cutCells options (\c Tbl_cutCells, \c Tbl_cutCellsH and  Tbl_cutCellsV) may cause painting problems when scrollbars are  enabled. Do not combine cutCells and scrollbars.  \sa clearTableFlags(), testTableFlags(), tableFlags()*/void QTableView::setTableFlags( uint f ){    f = (f ^ tFlags) & f;			// clear flags already set    tFlags |= f;    bool updateOn = autoUpdate();    setAutoUpdate( FALSE );    uint repaintMask = Tbl_cutCellsV | Tbl_cutCellsH;    if ( f & Tbl_vScrollBar ) {	setVerScrollBar( TRUE );    }    if ( f & Tbl_hScrollBar ) {	setHorScrollBar( TRUE );    }    if ( f & Tbl_autoVScrollBar ) {	updateScrollBars( verRange );    }    if ( f & Tbl_autoHScrollBar ) {	updateScrollBars( horRange );    }    if ( f & Tbl_scrollLastHCell ) {	updateScrollBars( horRange );    }    if ( f & Tbl_scrollLastVCell ) {	updateScrollBars( verRange );    }    if ( f & Tbl_snapToHGrid ) {	updateScrollBars( horRange );    }    if ( f & Tbl_snapToVGrid ) {	updateScrollBars( verRange );    }    if ( f & Tbl_snapToGrid ) {			// Note: checks for 2 flags	if ( (f & Tbl_snapToHGrid) != 0 && xCellDelta != 0 || //have to scroll?	     (f & Tbl_snapToVGrid) != 0 && yCellDelta != 0 ) {	    snapToGrid( (f & Tbl_snapToHGrid) != 0,	// do snapping			(f & Tbl_snapToVGrid) != 0 );	    repaintMask |= Tbl_snapToGrid;	// repaint table	}    }    if ( updateOn ) {	setAutoUpdate( TRUE );	updateScrollBars();	if ( isVisible() && (f & repaintMask) )	    repaint();    }}/*!  Clears the \link setTableFlags() table flags\endlink that are set  in \e f.  Example (clears a single flag):  \code    clearTableFlags( Tbl_snapToGrid );  \endcode  The default argument clears all flags.  \sa setTableFlags(), testTableFlags(), tableFlags()*/void QTableView::clearTableFlags( uint f ){    f = (f ^ ~tFlags) & f;		// clear flags that are already 0    tFlags &= ~f;    bool updateOn = autoUpdate();    setAutoUpdate( FALSE );    uint repaintMask = Tbl_cutCellsV | Tbl_cutCellsH;    if ( f & Tbl_vScrollBar ) {	setVerScrollBar( FALSE );    }    if ( f & Tbl_hScrollBar ) {	setHorScrollBar( FALSE );    }    if ( f & Tbl_scrollLastHCell ) {	int maxX = maxXOffset();	if ( xOffs > maxX ) {	    setOffset( maxX, yOffs );	    repaintMask |= Tbl_scrollLastHCell;	}	updateScrollBars( horRange );    }    if ( f & Tbl_scrollLastVCell ) {	int maxY = maxYOffset();	if ( yOffs > maxY ) {	    setOffset( xOffs, maxY );	    repaintMask |= Tbl_scrollLastVCell;	}	updateScrollBars( verRange );    }    if ( f & Tbl_smoothScrolling ) {	      // Note: checks for 2 flags	if ((f & Tbl_smoothHScrolling) != 0 && xCellDelta != 0 ||//must scroll?	    (f & Tbl_smoothVScrolling) != 0 && yCellDelta != 0 ) {	    snapToGrid( (f & Tbl_smoothHScrolling) != 0,      // do snapping			(f & Tbl_smoothVScrolling) != 0 );	    repaintMask |= Tbl_smoothScrolling;		     // repaint table	}    }    if ( f & Tbl_snapToHGrid ) {	updateScrollBars( horRange );    }    if ( f & Tbl_snapToVGrid ) {	updateScrollBars( verRange );    }    if ( updateOn ) {	setAutoUpdate( TRUE );	updateScrollBars();	     // returns immediately if nothing to do	if ( isVisible() && (f & repaintMask) )	    repaint();    }}/*!  \fn bool QTableView::autoUpdate() const  Returns TRUE if the view updates itself automatically whenever it  is changed in some way.  \sa setAutoUpdate()*//*!

⌨️ 快捷键说明

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