Eneboo - Documentación para desarrolladores
src/qt/include/qtable.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 **
00003 ** Definition of QTable widget class
00004 **
00005 ** Created : 000607
00006 **
00007 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00008 **
00009 ** This file is part of the table module of the Qt GUI Toolkit.
00010 **
00011 ** This file may be distributed under the terms of the Q Public License
00012 ** as defined by Trolltech ASA of Norway and appearing in the file
00013 ** LICENSE.QPL included in the packaging of this file.
00014 **
00015 ** This file may be distributed and/or modified under the terms of the
00016 ** GNU General Public License version 2 as published by the Free Software
00017 ** Foundation and appearing in the file LICENSE.GPL included in the
00018 ** packaging of this file.
00019 **
00020 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00021 ** file in accordance with the Qt Commercial License Agreement provided
00022 ** with the Software.
00023 **
00024 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00025 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00026 **
00027 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00028 **   information about Qt Commercial License Agreements.
00029 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00030 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00031 **
00032 ** Contact info@trolltech.com if any conditions of this licensing are
00033 ** not clear to you.
00034 **
00035 **********************************************************************/
00036 
00037 #ifndef QTABLE_H
00038 #define QTABLE_H
00039 
00040 #ifndef QT_H
00041 #include "qscrollview.h"
00042 #include "qpixmap.h"
00043 #include "qptrvector.h"
00044 #include "qheader.h"
00045 #include "qmemarray.h"
00046 #include "qptrlist.h"
00047 #include "qguardedptr.h"
00048 #include "qshared.h"
00049 #include "qintdict.h"
00050 #include "qstringlist.h"
00051 #endif // QT_H
00052 
00053 
00054 #ifndef QT_NO_TABLE
00055 
00056 #if !defined( QT_MODULE_TABLE ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_TABLE )
00057 #define QM_EXPORT_TABLE
00058 #ifndef QM_TEMPLATE_EXTERN_TABLE
00059 #   define QM_TEMPLATE_EXTERN_TABLE
00060 #endif
00061 #else
00062 #define QM_EXPORT_TABLE Q_EXPORT
00063 #define QM_TEMPLATE_EXTERN_TABLE Q_TEMPLATE_EXTERN
00064 #endif
00065 
00066 class QTableHeader;
00067 class QValidator;
00068 class QTable;
00069 class QPaintEvent;
00070 class QTimer;
00071 class QResizeEvent;
00072 class QComboBox;
00073 class QCheckBox;
00074 class QDragObject;
00075 
00076 struct QTablePrivate;
00077 struct QTableHeaderPrivate;
00078 
00079 
00080 class QM_EXPORT_TABLE QTableSelection
00081 {
00082 public:
00083     QTableSelection();
00084     QTableSelection( int start_row, int start_col, int end_row, int end_col );
00085     void init( int row, int col );
00086     void expandTo( int row, int col );
00087     bool operator==( const QTableSelection &s ) const;
00088     bool operator!=( const QTableSelection &s ) const { return !(operator==(s)); }
00089 
00090     int topRow() const { return tRow; }
00091     int bottomRow() const { return bRow; }
00092     int leftCol() const { return lCol; }
00093     int rightCol() const { return rCol; }
00094     int anchorRow() const { return aRow; }
00095     int anchorCol() const { return aCol; }
00096     int numRows() const;
00097     int numCols() const;
00098 
00099     bool isActive() const { return active; }
00100     bool isEmpty() const { return numRows() == 0; }
00101 
00102 private:
00103     uint active : 1;
00104     uint inited : 1;
00105     int tRow, lCol, bRow, rCol;
00106     int aRow, aCol;
00107 };
00108 
00109 #define Q_DEFINED_QTABLE_SELECTION
00110 #include "qwinexport.h"
00111 
00112 class QM_EXPORT_TABLE QTableItem : public Qt
00113 {
00114     friend class QTable;
00115 
00116 public:
00117     enum EditType { Never, OnTyping, WhenCurrent, Always };
00118 
00119     QTableItem( QTable *table, EditType et );
00120     QTableItem( QTable *table, EditType et, const QString &text );
00121     QTableItem( QTable *table, EditType et, const QString &text,
00122                 const QPixmap &p );
00123     virtual ~QTableItem();
00124 
00125     virtual QPixmap pixmap() const;
00126     virtual QString text() const;
00127     virtual void setPixmap( const QPixmap &p );
00128     virtual void setText( const QString &t );
00129     QTable *table() const { return t; }
00130 
00131     virtual int alignment() const;
00132     virtual void setWordWrap( bool b );
00133     bool wordWrap() const;
00134 
00135     EditType editType() const;
00136     virtual QWidget *createEditor() const;
00137     virtual void setContentFromEditor( QWidget *w );
00138     virtual void setReplaceable( bool );
00139     bool isReplaceable() const;
00140 
00141     virtual QString key() const;
00142     virtual QSize sizeHint() const;
00143 
00144     virtual void setSpan( int rs, int cs );
00145     int rowSpan() const;
00146     int colSpan() const;
00147 
00148     virtual void setRow( int r );
00149     virtual void setCol( int c );
00150     int row() const;
00151     int col() const;
00152 
00153     virtual void paint( QPainter *p, const QColorGroup &cg,
00154                         const QRect &cr, bool selected );
00155 
00156     void updateEditor( int oldRow, int oldCol );
00157 
00158     virtual void setEnabled( bool b );
00159     bool isEnabled() const;
00160 
00161     virtual int rtti() const;
00162     static int RTTI;
00163 
00164 private:
00165     QString txt;
00166     QPixmap pix;
00167     QTable *t;
00168     EditType edType;
00169     uint wordwrap : 1;
00170     uint tcha : 1;
00171     uint enabled : 1;
00172     int rw, cl;
00173     int rowspan, colspan;
00174 #if (QT_VERSION >= 0x040000)
00175 #error "Add a setAlignment() function in 4.0 (but no d pointer)"
00176 #endif
00177 };
00178 
00179 #define Q_DEFINED_QTABLE_ITEM
00180 #include "qwinexport.h"
00181 
00182 class QM_EXPORT_TABLE QComboTableItem : public QTableItem
00183 {
00184 public:
00185     QComboTableItem( QTable *table, const QStringList &list, bool editable = FALSE );
00186     ~QComboTableItem();
00187     virtual QWidget *createEditor() const;
00188     virtual void setContentFromEditor( QWidget *w );
00189     virtual void paint( QPainter *p, const QColorGroup &cg,
00190                         const QRect &cr, bool selected );
00191     virtual void setCurrentItem( int i );
00192     virtual void setCurrentItem( const QString &i );
00193     int currentItem() const;
00194     QString currentText() const;
00195     int count() const;
00196 #if !defined(Q_NO_USING_KEYWORD)
00197     using QTableItem::text;
00198 #endif
00199     QString text( int i ) const;
00200     virtual void setEditable( bool b );
00201     bool isEditable() const;
00202     virtual void setStringList( const QStringList &l );
00203 
00204     int rtti() const;
00205     static int RTTI;
00206 
00207     QSize sizeHint() const;
00208 
00209 private:
00210     QComboBox *cb;
00211     QStringList entries;
00212     int current;
00213     bool edit;
00214     static QComboBox *fakeCombo;
00215     static QWidget *fakeComboWidget;
00216     static int fakeRef;
00217 
00218 };
00219 
00220 class QM_EXPORT_TABLE QCheckTableItem : public QTableItem
00221 {
00222 public:
00223     QCheckTableItem( QTable *table, const QString &txt );
00224     void setText( const QString &t );
00225     virtual QWidget *createEditor() const;
00226     virtual void setContentFromEditor( QWidget *w );
00227     virtual void paint( QPainter *p, const QColorGroup &cg,
00228                         const QRect &cr, bool selected );
00229     virtual void setChecked( bool b );
00230     bool isChecked() const;
00231 
00232     int rtti() const;
00233     static int RTTI;
00234 
00235     QSize sizeHint() const;
00236 
00237 private:
00238     QCheckBox *cb;
00239     bool checked;
00240 
00241 };
00242 
00243 class QM_EXPORT_TABLE QTable : public QScrollView
00244 {
00245     Q_OBJECT
00246     Q_ENUMS( SelectionMode FocusStyle )
00247     Q_PROPERTY( int numRows READ numRows WRITE setNumRows )
00248     Q_PROPERTY( int numCols READ numCols WRITE setNumCols )
00249     Q_PROPERTY( bool showGrid READ showGrid WRITE setShowGrid )
00250     Q_PROPERTY( bool rowMovingEnabled READ rowMovingEnabled WRITE setRowMovingEnabled )
00251     Q_PROPERTY( bool columnMovingEnabled READ columnMovingEnabled WRITE setColumnMovingEnabled )
00252     Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
00253     Q_PROPERTY( bool sorting READ sorting WRITE setSorting )
00254     Q_PROPERTY( SelectionMode selectionMode READ selectionMode WRITE setSelectionMode )
00255     Q_PROPERTY( FocusStyle focusStyle READ focusStyle WRITE setFocusStyle )
00256     Q_PROPERTY( int numSelections READ numSelections )
00257 
00258     friend class QTableHeader;
00259     friend class QComboTableItem;
00260     friend class QCheckTableItem;
00261     friend class QTableItem;
00262 
00263 public:
00264     QTable( QWidget* parent=0, const char* name=0 );
00265     QTable( int numRows, int numCols,
00266             QWidget* parent=0, const char* name=0 );
00267     ~QTable();
00268 
00269     QHeader *horizontalHeader() const;
00270     QHeader *verticalHeader() const;
00271 
00272     enum SelectionMode { Single, Multi, SingleRow, MultiRow, NoSelection };
00273     virtual void setSelectionMode( SelectionMode mode );
00274     SelectionMode selectionMode() const;
00275 
00276     virtual void setItem( int row, int col, QTableItem *item );
00277     virtual void setText( int row, int col, const QString &text );
00278     virtual void setPixmap( int row, int col, const QPixmap &pix );
00279     virtual QTableItem *item( int row, int col ) const;
00280     virtual QString text( int row, int col ) const;
00281     virtual QPixmap pixmap( int row, int col ) const;
00282     virtual void clearCell( int row, int col );
00283 
00284     virtual QRect cellGeometry( int row, int col ) const;
00285     virtual int columnWidth( int col ) const;
00286     virtual int rowHeight( int row ) const;
00287     virtual int columnPos( int col ) const;
00288     virtual int rowPos( int row ) const;
00289     virtual int columnAt( int x ) const;
00290     virtual int rowAt( int y ) const;
00291 
00292     virtual int numRows() const;
00293     virtual int numCols() const;
00294 
00295     void updateCell( int row, int col );
00296 
00297     bool eventFilter( QObject * o, QEvent * );
00298 
00299     int currentRow() const { return curRow; }
00300     int currentColumn() const { return curCol; }
00301     void ensureCellVisible( int row, int col );
00302 
00303     bool isSelected( int row, int col ) const;
00304     bool isRowSelected( int row, bool full = FALSE ) const;
00305     bool isColumnSelected( int col, bool full = FALSE ) const;
00306     int numSelections() const;
00307     QTableSelection selection( int num ) const;
00308     virtual int addSelection( const QTableSelection &s );
00309     virtual void removeSelection( const QTableSelection &s );
00310     virtual void removeSelection( int num );
00311     virtual int currentSelection() const;
00312 
00313     void selectCells( int start_row, int start_col, int end_row, int end_col );
00314     void selectRow( int row );
00315     void selectColumn( int col );
00316 
00317     bool showGrid() const;
00318 
00319     bool columnMovingEnabled() const;
00320     bool rowMovingEnabled() const;
00321 
00322     virtual void sortColumn( int col, bool ascending = TRUE,
00323                              bool wholeRows = FALSE );
00324     bool sorting() const;
00325 
00326     virtual void takeItem( QTableItem *i );
00327 
00328     virtual void setCellWidget( int row, int col, QWidget *e );
00329     virtual QWidget *cellWidget( int row, int col ) const;
00330     virtual void clearCellWidget( int row, int col );
00331 
00332     virtual QRect cellRect( int row, int col ) const;
00333 
00334     virtual void paintCell( QPainter *p, int row, int col,
00335                             const QRect &cr, bool selected );
00336     virtual void paintCell( QPainter *p, int row, int col,
00337                             const QRect &cr, bool selected, const QColorGroup &cg );
00338     virtual void paintFocus( QPainter *p, const QRect &r );
00339     QSize sizeHint() const;
00340 
00341     bool isReadOnly() const;
00342     bool isRowReadOnly( int row ) const;
00343     bool isColumnReadOnly( int col ) const;
00344 
00345     void setEnabled( bool b );
00346 
00347     void repaintSelections();
00348 
00349     enum FocusStyle { FollowStyle, SpreadSheet };
00350     virtual void setFocusStyle( FocusStyle fs );
00351     FocusStyle focusStyle() const;
00352 
00353     void updateHeaderStates();
00354 
00355 public slots:
00356     virtual void setNumRows( int r );
00357     virtual void setNumCols( int r );
00358     virtual void setShowGrid( bool b );
00359     virtual void hideRow( int row );
00360     virtual void hideColumn( int col );
00361     virtual void showRow( int row );
00362     virtual void showColumn( int col );
00363     bool isRowHidden( int row ) const;
00364     bool isColumnHidden( int col ) const;
00365 
00366     virtual void setColumnWidth( int col, int w );
00367     virtual void setRowHeight( int row, int h );
00368 
00369     virtual void adjustColumn( int col );
00370     virtual void adjustRow( int row );
00371 
00372     virtual void setColumnStretchable( int col, bool stretch );
00373     virtual void setRowStretchable( int row, bool stretch );
00374     bool isColumnStretchable( int col ) const;
00375     bool isRowStretchable( int row ) const;
00376     virtual void setSorting( bool b );
00377     virtual void swapRows( int row1, int row2, bool swapHeader = FALSE );
00378     virtual void swapColumns( int col1, int col2, bool swapHeader = FALSE );
00379     virtual void swapCells( int row1, int col1, int row2, int col2 );
00380 
00381     virtual void setLeftMargin( int m );
00382     virtual void setTopMargin( int m );
00383     virtual void setCurrentCell( int row, int col );
00384     void clearSelection( bool repaint = TRUE );
00385     virtual void setColumnMovingEnabled( bool b );
00386     virtual void setRowMovingEnabled( bool b );
00387 
00388     virtual void setReadOnly( bool b );
00389     virtual void setRowReadOnly( int row, bool ro );
00390     virtual void setColumnReadOnly( int col, bool ro );
00391 
00392     virtual void setDragEnabled( bool b );
00393     bool dragEnabled() const;
00394 
00395     virtual void insertRows( int row, int count = 1 );
00396     virtual void insertColumns( int col, int count = 1 );
00397     virtual void removeRow( int row );
00398     virtual void removeRows( const QMemArray<int> &rows );
00399     virtual void removeColumn( int col );
00400     virtual void removeColumns( const QMemArray<int> &cols );
00401 
00402     virtual void editCell( int row, int col, bool replace = FALSE );
00403 
00404     void setRowLabels( const QStringList &labels );
00405     void setColumnLabels( const QStringList &labels );
00406 
00407 protected:
00408     enum EditMode { NotEditing, Editing, Replacing };
00409     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00410     void contentsMousePressEvent( QMouseEvent* );
00411     void contentsMouseMoveEvent( QMouseEvent* );
00412     void contentsMouseDoubleClickEvent( QMouseEvent* );
00413     void contentsMouseReleaseEvent( QMouseEvent* );
00414     void contentsContextMenuEvent( QContextMenuEvent * e );
00415     void keyPressEvent( QKeyEvent* );
00416     void focusInEvent( QFocusEvent* );
00417     void focusOutEvent( QFocusEvent* );
00418     void viewportResizeEvent( QResizeEvent * );
00419     void showEvent( QShowEvent *e );
00420     void paintEvent( QPaintEvent *e );
00421     void setEditMode( EditMode mode, int row, int col );
00422 #ifndef QT_NO_DRAGANDDROP
00423     virtual void contentsDragEnterEvent( QDragEnterEvent *e );
00424     virtual void contentsDragMoveEvent( QDragMoveEvent *e );
00425     virtual void contentsDragLeaveEvent( QDragLeaveEvent *e );
00426     virtual void contentsDropEvent( QDropEvent *e );
00427     virtual QDragObject *dragObject();
00428     virtual void startDrag();
00429 #endif
00430 
00431     virtual void paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch );
00432     virtual void activateNextCell();
00433     virtual QWidget *createEditor( int row, int col, bool initFromCell ) const;
00434     virtual void setCellContentFromEditor( int row, int col );
00435     virtual QWidget *beginEdit( int row, int col, bool replace );
00436     virtual void endEdit( int row, int col, bool accept, bool replace );
00437 
00438     virtual void resizeData( int len );
00439     virtual void insertWidget( int row, int col, QWidget *w );
00440     int indexOf( int row, int col ) const;
00441 
00442     void windowActivationChange( bool );
00443     bool isEditing() const;
00444     EditMode editMode() const;
00445     int currEditRow() const;
00446     int currEditCol() const;
00447 
00448 protected slots:
00449     virtual void columnWidthChanged( int col );
00450     virtual void rowHeightChanged( int row );
00451     virtual void columnIndexChanged( int section, int fromIndex, int toIndex );
00452     virtual void rowIndexChanged( int section, int fromIndex, int toIndex );
00453     virtual void columnClicked( int col );
00454 
00455 signals:
00456     void currentChanged( int row, int col );
00457     void clicked( int row, int col, int button, const QPoint &mousePos );
00458     void doubleClicked( int row, int col, int button, const QPoint &mousePos );
00459     void pressed( int row, int col, int button, const QPoint &mousePos );
00460     void selectionChanged();
00461     void valueChanged( int row, int col );
00462     void contextMenuRequested( int row, int col, const QPoint &pos );
00463 #ifndef QT_NO_DRAGANDDROP
00464     void dropped( QDropEvent *e );
00465 #endif
00466 
00467 private slots:
00468     void doAutoScroll();
00469     void doValueChanged();
00470     void updateGeometriesSlot();
00471 
00472 private:
00473     void contentsMousePressEventEx( QMouseEvent* );
00474     void drawContents( QPainter* );
00475     void updateGeometries();
00476     void repaintSelections( QTableSelection *oldSelection,
00477                             QTableSelection *newSelection,
00478                             bool updateVertical = TRUE,
00479                             bool updateHorizontal = TRUE );
00480     QRect rangeGeometry( int topRow, int leftCol,
00481                          int bottomRow, int rightCol, bool &optimize );
00482     void fixRow( int &row, int y );
00483     void fixCol( int &col, int x );
00484 
00485     void init( int numRows, int numCols );
00486     QSize tableSize() const;
00487     void repaintCell( int row, int col );
00488     void contentsToViewport2( int x, int y, int& vx, int& vy );
00489     QPoint contentsToViewport2( const QPoint &p );
00490     void viewportToContents2( int vx, int vy, int& x, int& y );
00491     QPoint viewportToContents2( const QPoint &p );
00492 
00493     void updateRowWidgets( int row );
00494     void updateColWidgets( int col );
00495     bool isSelected( int row, int col, bool includeCurrent ) const;
00496     void setCurrentCell( int row, int col, bool updateSelections, bool ensureVisible = FALSE );
00497     void fixCell( int &row, int &col, int key );
00498     void delayedUpdateGeometries();
00499     struct TableWidget
00500     {
00501         TableWidget( QWidget *w, int r, int c ) : wid( w ), row( r ), col ( c ) {}
00502         QWidget *wid;
00503         int row, col;
00504     };
00505     void saveContents( QPtrVector<QTableItem> &tmp,
00506                        QPtrVector<TableWidget> &tmp2 );
00507     void updateHeaderAndResizeContents( QTableHeader *header,
00508                                         int num, int colRow,
00509                                         int width, bool &updateBefore );
00510     void restoreContents( QPtrVector<QTableItem> &tmp,
00511                           QPtrVector<TableWidget> &tmp2 );
00512     void finishContentsResze( bool updateBefore );
00513 
00514 private:
00515     QPtrVector<QTableItem> contents;
00516     QPtrVector<QWidget> widgets;
00517     int curRow;
00518     int curCol;
00519     QTableHeader *leftHeader, *topHeader;
00520     EditMode edMode;
00521     int editCol, editRow;
00522     QPtrList<QTableSelection> selections;
00523     QTableSelection *currentSel;
00524     QTimer *autoScrollTimer;
00525     int lastSortCol;
00526     bool sGrid : 1;
00527     bool mRows : 1;
00528     bool mCols : 1;
00529     bool asc : 1;
00530     bool doSort : 1;
00531     bool unused : 1;
00532     bool readOnly : 1;
00533     bool shouldClearSelection : 1;
00534     bool dEnabled : 1;
00535     bool context_menu : 1;
00536     bool drawActiveSelection : 1;
00537     bool was_visible : 1;
00538     SelectionMode selMode;
00539     int pressedRow, pressedCol;
00540     QTablePrivate *d;
00541     QIntDict<int> roRows;
00542     QIntDict<int> roCols;
00543     int startDragRow;
00544     int startDragCol;
00545     QPoint dragStartPos;
00546     int oldCurrentRow, oldCurrentCol;
00547     QWidget *unused_topLeftCorner; //### remove in 4.0
00548     FocusStyle focusStl;
00549     QSize unused_cachedSizeHint; // ### remove in 4.0
00550 
00551 #if defined(Q_DISABLE_COPY)
00552     QTable( const QTable & );
00553     QTable &operator=( const QTable & );
00554 #endif
00555 };
00556 
00557 #define Q_DEFINED_QTABLE
00558 #include "qwinexport.h"
00559 #endif // QT_NO_TABLE
00560 #endif // TABLE_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'