Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** 00003 ** Definition of QDataTable class 00004 ** 00005 ** Created : 2000-11-03 00006 ** 00007 ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved. 00008 ** 00009 ** This file is part of the sql 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 QDATATABLE_H 00038 #define QDATATABLE_H 00039 00040 #ifndef QT_H 00041 #include "qstring.h" 00042 #include "qvariant.h" 00043 #include "qtable.h" 00044 #include "qsql.h" 00045 #include "qsqlcursor.h" 00046 #include "qsqlindex.h" 00047 #include "qsqleditorfactory.h" 00048 #include "qiconset.h" 00049 #endif // QT_H 00050 00051 #if !defined( QT_MODULE_SQL ) || defined( QT_LICENSE_PROFESSIONAL ) 00052 #define QM_EXPORT_SQL 00053 #else 00054 #define QM_EXPORT_SQL Q_EXPORT 00055 #endif 00056 00057 #ifndef QT_NO_SQL_VIEW_WIDGETS 00058 00059 class QPainter; 00060 class QSqlField; 00061 class QSqlPropertyMap; 00062 class QDataTablePrivate; 00063 00064 class QM_EXPORT_SQL QDataTable : public QTable 00065 { 00066 Q_OBJECT 00067 00068 Q_PROPERTY( QString nullText READ nullText WRITE setNullText ) 00069 Q_PROPERTY( QString trueText READ trueText WRITE setTrueText ) 00070 Q_PROPERTY( QString falseText READ falseText WRITE setFalseText ) 00071 Q_PROPERTY( DateFormat dateFormat READ dateFormat WRITE setDateFormat ) 00072 Q_PROPERTY( bool confirmEdits READ confirmEdits WRITE setConfirmEdits ) 00073 Q_PROPERTY( bool confirmInsert READ confirmInsert WRITE setConfirmInsert ) 00074 Q_PROPERTY( bool confirmUpdate READ confirmUpdate WRITE setConfirmUpdate ) 00075 Q_PROPERTY( bool confirmDelete READ confirmDelete WRITE setConfirmDelete ) 00076 Q_PROPERTY( bool confirmCancels READ confirmCancels WRITE setConfirmCancels ) 00077 Q_PROPERTY( bool autoEdit READ autoEdit WRITE setAutoEdit ) 00078 Q_PROPERTY( QString filter READ filter WRITE setFilter ) 00079 Q_PROPERTY( QStringList sort READ sort WRITE setSort ) 00080 Q_PROPERTY( int numCols READ numCols ) 00081 Q_PROPERTY( int numRows READ numRows ) 00082 00083 public: 00084 QDataTable ( QWidget* parent=0, const char* name=0 ); 00085 QDataTable ( QSqlCursor* cursor, bool autoPopulate = FALSE, QWidget* parent=0, const char* name=0 ); 00086 ~QDataTable(); 00087 00088 virtual void addColumn( const QString& fieldName, 00089 const QString& label = QString::null, 00090 int width = -1, 00091 const QIconSet& iconset = QIconSet() ); 00092 virtual void removeColumn( uint col ); 00093 virtual void setColumn( uint col, const QString& fieldName, 00094 const QString& label = QString::null, 00095 int width = -1, 00096 const QIconSet& iconset = QIconSet() ); 00097 00098 QString nullText() const; 00099 QString trueText() const; 00100 QString falseText() const; 00101 DateFormat dateFormat() const; 00102 bool confirmEdits() const; 00103 bool confirmInsert() const; 00104 bool confirmUpdate() const; 00105 bool confirmDelete() const; 00106 bool confirmCancels() const; 00107 bool autoDelete() const; 00108 bool autoEdit() const; 00109 QString filter() const; 00110 QStringList sort() const; 00111 00112 virtual void setSqlCursor( QSqlCursor* cursor = 0, 00113 bool autoPopulate = FALSE, bool autoDelete = FALSE ); 00114 QSqlCursor* sqlCursor() const; 00115 00116 virtual void setNullText( const QString& nullText ); 00117 virtual void setTrueText( const QString& trueText ); 00118 virtual void setFalseText( const QString& falseText ); 00119 virtual void setDateFormat( const DateFormat f ); 00120 virtual void setConfirmEdits( bool confirm ); 00121 virtual void setConfirmInsert( bool confirm ); 00122 virtual void setConfirmUpdate( bool confirm ); 00123 virtual void setConfirmDelete( bool confirm ); 00124 virtual void setConfirmCancels( bool confirm ); 00125 virtual void setAutoDelete( bool enable ); 00126 virtual void setAutoEdit( bool autoEdit ); 00127 virtual void setFilter( const QString& filter ); 00128 virtual void setSort( const QStringList& sort ); 00129 virtual void setSort( const QSqlIndex& sort ); 00130 00131 enum Refresh { 00132 RefreshData = 1, 00133 RefreshColumns = 2, 00134 RefreshAll = 3 00135 }; 00136 void refresh( Refresh mode ); 00137 void sortColumn ( int col, bool ascending = TRUE, 00138 bool wholeRows = FALSE ); 00139 QString text ( int row, int col ) const; 00140 QVariant value ( int row, int col ) const; 00141 QSqlRecord* currentRecord() const; 00142 00143 void installEditorFactory( QSqlEditorFactory * f ); 00144 void installPropertyMap( QSqlPropertyMap* m ); 00145 00146 int numCols() const; 00147 int numRows() const; 00148 void setNumCols( int c ); 00149 void setNumRows ( int r ); 00150 bool findBuffer( const QSqlIndex& idx, int atHint = 0 ); 00151 00152 void hideColumn( int col ); 00153 void showColumn( int col ); 00154 signals: 00155 void currentChanged( QSqlRecord* record ); 00156 void primeInsert( QSqlRecord* buf ); 00157 void primeUpdate( QSqlRecord* buf ); 00158 void primeDelete( QSqlRecord* buf ); 00159 void beforeInsert( QSqlRecord* buf ); 00160 void beforeUpdate( QSqlRecord* buf ); 00161 void beforeDelete( QSqlRecord* buf ); 00162 void cursorChanged( QSql::Op mode ); 00163 00164 public slots: 00165 virtual void find( const QString & str, bool caseSensitive, 00166 bool backwards ); 00167 virtual void sortAscending( int col ); 00168 virtual void sortDescending( int col ); 00169 virtual void refresh(); 00170 void setColumnWidth( int col, int w ); 00171 void adjustColumn( int col ); 00172 void setColumnStretchable( int col, bool stretch ); 00173 void swapColumns( int col1, int col2, bool swapHeaders = FALSE ); 00174 00175 protected: 00176 virtual bool insertCurrent(); 00177 virtual bool updateCurrent(); 00178 virtual bool deleteCurrent(); 00179 00180 virtual QSql::Confirm confirmEdit( QSql::Op m ); 00181 virtual QSql::Confirm confirmCancel( QSql::Op m ); 00182 00183 virtual void handleError( const QSqlError& e ); 00184 00185 virtual bool beginInsert(); 00186 virtual QWidget* beginUpdate ( int row, int col, bool replace ); 00187 00188 bool eventFilter( QObject *o, QEvent *e ); 00189 void keyPressEvent( QKeyEvent* ); 00190 void resizeEvent ( QResizeEvent * ); 00191 void contentsMousePressEvent( QMouseEvent* e ); 00192 void contentsContextMenuEvent( QContextMenuEvent* e ); 00193 void endEdit( int row, int col, bool accept, bool replace ); 00194 QWidget * createEditor( int row, int col, bool initFromCell ) const; 00195 void activateNextCell(); 00196 int indexOf( uint i ) const; // ### make this public in 4.0 00197 void reset(); 00198 void setSize( QSqlCursor* sql ); 00199 void repaintCell( int row, int col ); 00200 void paintCell ( QPainter * p, int row, int col, const QRect & cr, 00201 bool selected, const QColorGroup &cg ); 00202 virtual void paintField( QPainter * p, const QSqlField* field, const QRect & cr, 00203 bool selected ); 00204 void drawContents( QPainter * p, int cx, int cy, int cw, int ch ); 00205 virtual int fieldAlignment( const QSqlField* field ); 00206 void columnClicked ( int col ); 00207 void resizeData ( int len ); 00208 00209 QTableItem * item ( int row, int col ) const; 00210 void setItem ( int row, int col, QTableItem * item ); 00211 void clearCell ( int row, int col ) ; 00212 void setPixmap ( int row, int col, const QPixmap & pix ); 00213 void takeItem ( QTableItem * i ); 00214 00215 private slots: 00216 void loadNextPage(); 00217 void setCurrentSelection( int row, int col ); 00218 void updateCurrentSelection(); 00219 void sliderPressed(); 00220 void sliderReleased(); 00221 void doInsertCurrent(); 00222 void doUpdateCurrent(); 00223 00224 private: 00225 QString fieldToString( const QSqlField * field ); 00226 void init(); 00227 QWidget* beginEdit ( int row, int col, bool replace ); 00228 void updateRow( int row ); 00229 void endInsert(); 00230 void endUpdate(); 00231 QDataTablePrivate* d; 00232 00233 #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator= 00234 QDataTable( const QDataTable & ); 00235 QDataTable &operator=( const QDataTable & ); 00236 #endif 00237 }; 00238 00239 #endif 00240 #endif