?? qtableview.cpp
字號:
Sets the auto-update option of the table view to \e enable. If \e enable is TRUE (this is the default) then the view updates itself automatically whenever it has changed in some way (for example when a \link setTableFlags() flag\endlink is changed). If \e enable is FALSE, the view does NOT repaint itself, or update its internal state variables itself when it is changed. This can be useful to avoid flicker during large changes, and is singularly useless otherwise: Disable auto-update, do the changes, re-enable auto-update, and call repaint(). \warning Do not leave the view in this state for a long time (i.e. between events ). If, for example, the user interacts with the view when auto-update is off, strange things can happen. Setting auto-update to TRUE does not repaint the view, you must call repaint() to do this. \sa autoUpdate(), repaint()*/void QTableView::setAutoUpdate( bool enable ){ if ( isUpdatesEnabled() == enable ) return; setUpdatesEnabled( enable ); if ( enable ) { showOrHideScrollBars(); updateScrollBars(); }}/*! Repaints the cell at row \e row, column \e col if it is inside the view. If \e erase is TRUE, the relevant part of the view is cleared to the background color/pixmap before the contents are repainted. \sa isVisible()*/void QTableView::updateCell( int row, int col, bool erase ){ int xPos, yPos; if ( !colXPos( col, &xPos ) ) return; if ( !rowYPos( row, &yPos ) ) return; QRect uR = QRect( xPos, yPos, cellW ? cellW : cellWidth(col), cellH ? cellH : cellHeight(row) ); repaint( uR.intersect(viewRect()), erase );}/*! \fn QRect QTableView::cellUpdateRect() const This function should only be called from the paintCell() function in subclasses. It returns the portion of a cell that actually needs to be updated, in \e cell coordinates. This is only useful for non-trivial paintCell().*//*! Returns the rectangle which is the actual table, excluding any frame, in \e widget coordinates.*/QRect QTableView::viewRect() const{ return QRect( frameWidth(), frameWidth(), viewWidth(), viewHeight() );}/*! Returns the index of the last (bottom) row in the view. The index of the first row is 0. If no rows are visible it returns -1. This can happen if the view is too small for the first row and Tbl_cutCellsV is set. \sa lastColVisible()*/int QTableView::lastRowVisible() const{ int cellMaxY; int row = findRawRow( maxViewY(), &cellMaxY ); if ( row == -1 || row >= nRows ) { // maxViewY() past end? row = nRows - 1; // yes: return last row } else { if ( testTableFlags(Tbl_cutCellsV) && cellMaxY > maxViewY() ) { if ( row == yCellOffs ) // cut by right margin? return -1; // yes, nothing in the view else row = row - 1; // cut by margin, one back } } return row;}/*! Returns the index of the last (right) column in the view. The index of the first column is 0. If no columns are visible it returns -1. This can happen if the view is too narrow for the first column and Tbl_cutCellsH is set. \sa lastRowVisible()*/int QTableView::lastColVisible() const{ int cellMaxX; int col = findRawCol( maxViewX(), &cellMaxX ); if ( col == -1 || col >= nCols ) { // maxViewX() past end? col = nCols - 1; // yes: return last col } else { if ( testTableFlags(Tbl_cutCellsH) && cellMaxX > maxViewX() ) { if ( col == xCellOffs ) // cut by bottom margin? return -1; // yes, nothing in the view else col = col - 1; // cell by margin, one back } } return col;}/*! Returns TRUE if \e row is at least partially visible. \sa colIsVisible()*/bool QTableView::rowIsVisible( int row ) const{ return rowYPos( row, 0 );}/*! Returns TRUE if \e col is at least partially visible. \sa rowIsVisible()*/bool QTableView::colIsVisible( int col ) const{ return colXPos( col, 0 );}/*! \internal Called when both scroll bars are active at the same time. Covers the bottom left corner between the two scroll bars with an empty widget.*/void QTableView::coverCornerSquare( bool enable ){ coveringCornerSquare = enable; if ( !cornerSquare && enable ) { cornerSquare = new QCornerSquare( this ); CHECK_PTR( cornerSquare ); cornerSquare->setGeometry( maxViewX() + 1, maxViewY() + 1, VSBEXT, HSBEXT); } if ( autoUpdate() && cornerSquare ) { if ( enable ) cornerSquare->show(); else cornerSquare->hide(); }}/*! \internal Scroll the view to a position such that: If \e horizontal is TRUE, the leftmost column shown fits snugly with the left edge of the view. If \e vertical is TRUE, the top row shown fits snugly with the top of the view. You can achieve the same effect automatically by setting any of the \link setTableFlags() Tbl_snapTo*Grid \endlink table flags.*/void QTableView::snapToGrid( bool horizontal, bool vertical ){ int newXCell = -1; int newYCell = -1; if ( horizontal && xCellDelta != 0 ) { int w = cellW ? cellW : cellWidth( xCellOffs ); if ( xCellDelta >= w/2 ) newXCell = xCellOffs + 1; else newXCell = xCellOffs; } if ( vertical && yCellDelta != 0 ) { int h = cellH ? cellH : cellHeight( yCellOffs ); if ( yCellDelta >= h/2 ) newYCell = yCellOffs + 1; else newYCell = yCellOffs; } setTopLeftCell( newYCell, newXCell ); //row,column}/*! \internal This internal slot is connected to the horizontal scroll bar's QScrollBar::valueChanged() signal. Moves the table horizontally to offset \e val without updating the scroll bar.*/void QTableView::horSbValue( int val ){ if ( horSliding ) { horSliding = FALSE; if ( horSnappingOff ) { horSnappingOff = FALSE; tFlags |= Tbl_snapToHGrid; } } setOffset( val, yOffs, FALSE );}/*! \internal This internal slot is connected to the horizontal scroll bar's QScrollBar::sliderMoved() signal. Scrolls the table smoothly horizontally even if \c Tbl_snapToHGrid is set.*/void QTableView::horSbSliding( int val ){ if ( testTableFlags(Tbl_snapToHGrid) && testTableFlags(Tbl_smoothHScrolling) ) { tFlags &= ~Tbl_snapToHGrid; // turn off snapping while sliding setOffset( val, yOffs, FALSE ); tFlags |= Tbl_snapToHGrid; // turn on snapping again } else { setOffset( val, yOffs, FALSE ); }}/*! \internal This internal slot is connected to the horizontal scroll bar's QScrollBar::sliderReleased() signal.*/void QTableView::horSbSlidingDone( ){ if ( testTableFlags(Tbl_snapToHGrid) && testTableFlags(Tbl_smoothHScrolling) ) snapToGrid( TRUE, FALSE );}/*! \internal This internal slot is connected to the vertical scroll bar's QScrollBar::valueChanged() signal. Moves the table vertically to offset \e val without updating the scroll bar.*/void QTableView::verSbValue( int val ){ if ( verSliding ) { verSliding = FALSE; if ( verSnappingOff ) { verSnappingOff = FALSE; tFlags |= Tbl_snapToVGrid; } } setOffset( xOffs, val, FALSE );}/*! \internal This internal slot is connected to the vertical scroll bar's QScrollBar::sliderMoved() signal. Scrolls the table smoothly vertically even if \c Tbl_snapToVGrid is set.*/void QTableView::verSbSliding( int val ){ if ( testTableFlags(Tbl_snapToVGrid) && testTableFlags(Tbl_smoothVScrolling) ) { tFlags &= ~Tbl_snapToVGrid; // turn off snapping while sliding setOffset( xOffs, val, FALSE ); tFlags |= Tbl_snapToVGrid; // turn on snapping again } else { setOffset( xOffs, val, FALSE ); }}/*! \internal This internal slot is connected to the vertical scroll bar's QScrollBar::sliderReleased() signal.*/void QTableView::verSbSlidingDone( ){ if ( testTableFlags(Tbl_snapToVGrid) && testTableFlags(Tbl_smoothVScrolling) ) snapToGrid( FALSE, TRUE );}/*! This virtual function is called before painting of table cells is started. It can be reimplemented by subclasses that want to to set up the painter in a special way and that do not want to do so for each cell.*/void QTableView::setupPainter( QPainter * ){}/*! \fn void QTableView::paintCell( QPainter *p, int row, int col ) This pure virtual function is called to paint the single cell at \e (row,col) using \e p, which is open when paintCell() is called and must remain open. The coordinate system is \link QPainter::translate() translated \endlink such that the origin is at the top left corner of the cell to be painted; i.e. \e cell coordinates. Do not scale or shear the coordinate system (or if you do, restore the transformation matrix before you return). By default, the painter is not clipped, for maximum efficiency. For safety, call setTableFlags(Tbl_clipCellPainting) to enable clipping. \sa paintEvent(), QPainter(), setTableFlags() *//*! Handles paint events for the table view. Calls paintCell() for the cells that needs to be repainted.*/void QTableView::paintEvent( QPaintEvent *e ){ QRect updateR = e->rect(); // update rectangle if ( sbDirty ) { bool e = eraseInPaint; updateScrollBars(); eraseInPaint = e; } QPainter paint( this ); if ( !contentsRect().contains( updateR ) ) {// update frame ? paint.save(); QRegion cr(updateR.intersect(frameRect())); cr -= contentsRect(); paint.setClipRegion( cr ); if ( inherits( "QMultiLineEdit" ) ){#ifdef QT_KEYPAD_MODE if ( !qt_modalEditingEnabled || isModalEditing() )#endif { paint.eraseRect(updateR); } if (!hasFocus()){ // clear the frame and margin QBrush brush(colorGroup().brush(QColorGroup::Base));#ifdef QT_KEYPAD_MODE if( qt_modalEditingEnabled ) brush = colorGroup().brush(QColorGroup::Background);#endif paint.fillRect(0, 0, width(), height(), brush); } } drawFrame( &paint ); if ( updateR.left() < frameWidth() ) //### updateR.setLeft( frameWidth() ); if ( updateR.top() < frameWidth() ) updateR.setTop( frameWidth() ); paint.restore(); } int maxWX = maxViewX(); int maxWY = maxViewY();#ifdef QT_KEYPAD_MODE if (qt_modalEditingEnabled && isModalEditing()){ paint.fillRect(maxWX+1+margin(), 1, width(), height(), colorGroup().brush(QColorGroup::Background)); // fill gap around scrollbars paint.fillRect(lineWidth(), maxWY+1+margin(), width()-2*lineWidth(), height() - maxWY, colorGroup().brush(QColorGroup::Background)); }#endif if ( updateR.right() > maxWX ) updateR.setRight( maxWX ); if ( updateR.bottom() > maxWY ) updateR.setBottom( maxWY ); setupPainter( &paint ); // prepare for painting table int firstRow = findRow( updateR.y() ); int firstCol = findCol( updateR.x() ); int xStart, yStart; if ( !colXPos( firstCol, &xStart ) || !rowYPos( firstRow, &yStart ) ) { // erase area outside cells but in view if ( inherits( "QMultiLineEdit" ) ) { const QColorGroup g = colorGroup();#ifdef QT_KEYPAD_MODE if ( qt_modalEditingEnabled && !isModalEditing() ) paint.fillRect( updateR, g.brush(QColorGroup::Background) ); else#endif paint.fillRect( updateR, g.brush(QColorGroup::Base) ); } else { paint.eraseRect( updateR ); } return; } int maxX = updateR.right(); int maxY = updateR.bottom(); int row = firstRow; int col; int yPos = yStart; int xPos = maxX+1; // in case the while() is empty int nextX; int nextY; QRect winR = viewRect(); QRect cellR; QRect cellUR;#ifndef QT_NO_TRANSFORMATIONS QWMatrix matrix;#endif while ( yPos <= maxY && row < nRows ) { nextY = yPos + (cellH ? cellH : cellHeight( row )); if ( testTableFlags( Tbl_cutCellsV ) && nextY > ( maxWY + 1 ) ) break; col = firstCol; xPos = xStart; while ( xPos <= maxX && col < nCols ) { nextX = xPos + (cellW ? cellW : cellWidth( col )); if ( testTableFlags( Tbl_cutCellsH ) && nextX > ( maxWX + 1 ) ) break; cellR.setRect( xPos, yPos, cellW ? cellW : cellWidth(col), cellH ? cellH : cellHeight(row) ); cellUR = cellR.intersect( updateR ); if ( cellUR.isValid() ) { cellUpdateR = cellUR; cellUpdateR.moveBy( -xPos, -yPos ); // cell coordinates if ( eraseInPaint ) paint.eraseRect( cellUR );#ifndef QT_NO_TRANSFORMATIONS
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -