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

📄 qtableview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************ $Id: qt/src/widgets/qtableview.cpp   2.3.12   edited 2005-10-27 $**** Implementation of QTableView class**** Created : 941115**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of the widgets module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qtableview.h"#ifndef QT_NO_TABLEVIEW#include "qscrollbar.h"#include "qpainter.h"#include "qdrawutil.h"#include <limits.h>#ifdef QT_KEYPAD_MODEextern bool qt_modalEditingEnabled;#endifextern void qt_set_paintevent_clipping( QPaintDevice* dev, const QRegion& region);extern void qt_clear_paintevent_clipping();enum ScrollBarDirtyFlags {    verGeometry	  = 0x01,    verSteps	  = 0x02,    verRange	  = 0x04,    verValue	  = 0x08,    horGeometry	  = 0x10,    horSteps	  = 0x20,    horRange	  = 0x40,    horValue	  = 0x80,    verMask	  = 0x0F,    horMask	  = 0xF0};#define HSBEXT horizontalScrollBar()->sizeHint().height()#define VSBEXT verticalScrollBar()->sizeHint().width()class QCornerSquare : public QWidget		// internal class{public:    QCornerSquare( QWidget *, const char* = 0 );    void paintEvent( QPaintEvent * );};QCornerSquare::QCornerSquare( QWidget *parent, const char *name )	: QWidget( parent, name ){}void QCornerSquare::paintEvent( QPaintEvent * ){}// NOT REVISED/*!  \class QTableView qtableview.h  \brief This is an abstract base class for implementing tables  \ingroup abstractwidgets  A table view consists of a number of abstract cells organized in rows  and columns and a visible part called a view. The cells are identified  with a row index and a column index. The top left cell is in row 0,  column 0.  The behavior of the widget can be finely tuned using  setTableFlags(); a typical subclass will consist of little more than a  call to setTableFlags(), some table content manipulation, and an  implementation of paintCell().  Subclasses that need cells with  variable width or height must reimplement cellHeight() and/or  cellWidth(). Use updateTableSize() to tell QTableView when the  width or height has changed.  When you read this documentation, it is important to understand the  distinctions between the four pixel coordinate systems involved.  <ol>  <li> The \e cell coordinates.  (0,0) is the top left corner of a cell.  This is used by functions such as paintCell().  <li> The \e table coordinates.  (0,0) is the top left corner of the cell at  row 0 and column 0. These coordinates are absolute; that is, they are  independent of what part of the table is visible at the moment. This is  used by functions such as setXOffset() or maxYOffset().  <li> The \e widget coordinates. (0,0) is the top left corner of the widget,  \e including the frame.  This is used by functions such as repaint().  <li> The \e view coordinates.  (0,0) is the top left corner of the view, \e  excluding the frame.  This is the least-used coordinate system, used by  functions such as viewWidth().  </ol>  It is rather unfortunate that we have to use four different  coordinate systems, but if we were to provide a flexible and  powerful base class, there wasn't any way around it.  Note: The row,column indices are always given in that order,  i.e. first the vertical (row), then the horizontal (column). This is  the opposite order of all pixel operations, which take first the  horizontal (x), then the vertical (y).  <img src=qtablevw-m.png> <img src=qtablevw-w.png>  \warning the functions setNumRows(), setNumCols(), setCellHeight(),  setCellWidth(), setTableFlags() and clearTableFlags() may cause  virtual functions like cellWidth() and cellHeight() to be called,  even if autoUpdate() is FALSE.  This may cause errors if relevant  state variables are not initialized.  \warning Experience has shown that use of this widget tends to bring  more bugs than expected, and our analysis indicates that widget's  very flexibility is the problem.  If QScrollView or QListBox can  easily be made to do the job you need, we recommend subclassing  those widgets rather than QTableView. In addition, QScrollView makes  it easy to have child widgets inside tables, something QTableView  doesn't support at all.  \sa QScrollView  <a href="guibooks.html#fowler">GUI Design Handbook: Table</a>*//*!  Constructs a table view.  All the arguments are passed to the QFrame  constructor.  The \link setTableFlags() table flags\endlink are all cleared (set to zero).  Set \c Tbl_autoVScrollBar or \c Tbl_autoHScrollBar to get automatic scroll  bars and \c Tbl_clipCellPainting to get safe clipping.  The \link setCellHeight() cell height\endlink and \link setCellWidth()  cell width\endlink are set to 0.  Frame line shapes (QFrame::HLink and QFrame::VLine) are disallowed,  see QFrame::setFrameStyle().  Note that the \a f argument is \e not \link setTableFlags() table  flags \endlink but rather \link QWidget::QWidget() widget  flags. \endlink*/QTableView::QTableView( QWidget *parent, const char *name, WFlags f )    : QFrame( parent, name, f, FALSE ){    nRows		 = nCols      = 0;	// zero rows/cols    xCellOffs		 = yCellOffs  = 0;	// zero offset    xCellDelta		 = yCellDelta = 0;	// zero cell offset    xOffs		 = yOffs      = 0;	// zero total pixel offset    cellH		 = cellW      = 0;	// user defined cell size    tFlags		 = 0;    vScrollBar		 = hScrollBar = 0;	// no scroll bars    cornerSquare	 = 0;    sbDirty		 = 0;    eraseInPaint	 = FALSE;    verSliding		 = FALSE;    verSnappingOff	 = FALSE;    horSliding		 = FALSE;    horSnappingOff	 = FALSE;    coveringCornerSquare = FALSE;    inSbUpdate		 = FALSE;    setFontPropagation( SamePalette );    setPalettePropagation( SamePalette );}/*!  Destructs the table view.*/QTableView::~QTableView(){    delete vScrollBar;    delete hScrollBar;    delete cornerSquare;}/*!  \internal  Reimplements QWidget::setBackgroundColor() for binary compatibility.  \sa setPalette()*/void QTableView::setBackgroundColor( const QColor &c ){    QWidget::setBackgroundColor( c );}/*!\reimp*/void QTableView::setPalette( const QPalette &p ){    QWidget::setPalette( p );}/*!\reimp*/void QTableView::show(){    showOrHideScrollBars();    QWidget::show();}/*!  \overload void QTableView::repaint( bool erase )  Repaints the entire view.*//*!  Repaints the table view directly by calling paintEvent() directly,  unless updates are disabled.  Erases the view area \e (x,y,w,h) if \e erase is TRUE. Parameters \e  (x,y) are in \e widget coordinates.  If \e w is negative, it is replaced with <code>width() - x</code>.  If \e h is negative, it is replaced width <code>height() - y</code>.  Doing a repaint() usually is faster than doing an update(), but  calling update() many times in a row will generate a single paint  event.  At present, QTableView is the only widget that reimplements \link  QWidget::repaint() repaint()\endlink.	 It does this because by  clearing and then repainting one cell at at time, it can make the  screen flicker less than it would otherwise.  */void QTableView::repaint( int x, int y, int w, int h, bool erase ){    if ( !isVisible() || testWState(WState_BlockUpdates) )	return;    if ( w < 0 )	w = width()  - x;    if ( h < 0 )	h = height() - y;    QRect r( x, y, w, h );    if ( r.isEmpty() )	return; // nothing to do    QPaintEvent e( r );    if ( erase && backgroundMode() != NoBackground )	eraseInPaint = TRUE;			// erase when painting    qt_set_paintevent_clipping( this, r );    paintEvent( &e );    qt_clear_paintevent_clipping();    eraseInPaint = FALSE;}/*!  \overload void QTableView::repaint( const QRect &r, bool erase )*//*!  \fn int QTableView::numRows() const  Returns the number of rows in the table.  \sa numCols(), setNumRows()*//*!  Sets the number of rows of the table to \e rows (must be non-negative).  Does not change topCell().  The table repaints itself automatically if autoUpdate() is set.  \sa numCols(), setNumCols(), numRows()*/void QTableView::setNumRows( int rows ){    if ( rows < 0 ) {#if defined(CHECK_RANGE)	qWarning( "QTableView::setNumRows: (%s) Negative argument %d.",		 name( "unnamed" ), rows );#endif	return;    }    if ( nRows == rows )	return;    if ( autoUpdate() && isVisible() ) {	int oldLastVisible = lastRowVisible();	int oldTopCell = topCell();	nRows = rows;	if ( autoUpdate() && isVisible() &&	     ( oldLastVisible != lastRowVisible() || oldTopCell != topCell() ) )		repaint( oldTopCell != topCell() );    } else {	// Be more careful - if destructing, bad things might happen.	nRows = rows;    }    updateScrollBars( verRange );    updateFrameSize();}/*!  \fn int QTableView::numCols() const  Returns the number of columns in the table  \sa numRows(), setNumCols()*//*!  Sets the number of columns of the table to \e cols (must be non-negative).  Does not change leftCell().  The table repaints itself automatically if autoUpdate() is set.  \sa numCols(), numRows(), setNumRows()*/void QTableView::setNumCols( int cols ){    if ( cols < 0 ) {#if defined(CHECK_RANGE)	qWarning( "QTableView::setNumCols: (%s) Negative argument %d.",		 name( "unnamed" ), cols );#endif	return;    }    if ( nCols == cols )	return;    int oldCols = nCols;    nCols = cols;    if ( autoUpdate() && isVisible() ) {	int maxCol = lastColVisible();	if ( maxCol >= oldCols || maxCol >= nCols )	    repaint();    }    updateScrollBars( horRange );    updateFrameSize();}/*!  \fn int QTableView::topCell() const  Returns the index of the first row in the table that is visible in  the view.  The index of the very first row is 0.  \sa leftCell(), setTopCell()*//*!  Scrolls the table such that \e row becomes the top row.  The index of the very first row is 0.  \sa setYOffset(), setTopLeftCell(), setLeftCell()*/void QTableView::setTopCell( int row ){    setTopLeftCell( row, -1 );    return;}/*!  \fn int QTableView::leftCell() const  Returns the index of the first column in the table that is visible in  the view.  The index of the very leftmost column is 0.  \sa topCell(), setLeftCell()*//*!  Scrolls the table such that \e col becomes the leftmost  column.  The index of the very leftmost column is 0.  \sa setXOffset(), setTopLeftCell(), setTopCell()*/void QTableView::setLeftCell( int col ){    setTopLeftCell( -1, col );    return;}/*!  Scrolls the table such that the cell at row \e row and colum \e  col becomes the top left cell in the view.  The cell at the extreme  top left of the table is at position (0,0).  \sa setLeftCell(), setTopCell(), setOffset()*/void QTableView::setTopLeftCell( int row, int col ){    int newX = xOffs;    int newY = yOffs;    if ( col >= 0 ) {	if ( cellW ) {	    newX = col*cellW;	    if ( newX > maxXOffset() )		newX = maxXOffset();	} else {	    newX = 0;	    while ( col )		newX += cellWidth( --col );   // optimize using current! ###	}    }    if ( row >= 0 ) {	if ( cellH ) {	    newY = row*cellH;	    if ( newY > maxYOffset() )		newY = maxYOffset();	} else {	    newY = 0;	    while ( row )		newY += cellHeight( --row );   // optimize using current! ###	}    }    setOffset( newX, newY );}/*!  \fn int QTableView::xOffset() const  Returns the x coordinate in \e table coordinates of the pixel which is  currently on the left edge of the view.  \sa setXOffset(), yOffset(), leftCell() *//*!  Scrolls the table such that \e x becomes the leftmost pixel in the view.  The \e x parameter is in \e table coordinates.  The interaction with \link setTableFlags() Tbl_snapToHGrid  \endlink is tricky.  \sa xOffset(), setYOffset(), setOffset(), setLeftCell()*/void QTableView::setXOffset( int x ){    setOffset( x, yOffset() );}/*!  \fn int QTableView::yOffset() const  Returns the y coordinate in \e table coordinates of the pixel which is

⌨️ 快捷键说明

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