[196] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Definition of QDataTable class
|
---|
| 4 | **
|
---|
| 5 | ** Created : 2000-11-03
|
---|
| 6 | **
|
---|
| 7 | ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
|
---|
| 8 | **
|
---|
| 9 | ** This file is part of the sql module of the Qt GUI Toolkit.
|
---|
| 10 | **
|
---|
| 11 | ** This file may be distributed under the terms of the Q Public License
|
---|
| 12 | ** as defined by Trolltech ASA of Norway and appearing in the file
|
---|
| 13 | ** LICENSE.QPL included in the packaging of this file.
|
---|
| 14 | **
|
---|
| 15 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 16 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 17 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 18 | ** packaging of this file.
|
---|
| 19 | **
|
---|
| 20 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
---|
| 21 | ** file in accordance with the Qt Commercial License Agreement provided
|
---|
| 22 | ** with the Software.
|
---|
| 23 | **
|
---|
| 24 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 25 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 26 | **
|
---|
| 27 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 28 | ** information about Qt Commercial License Agreements.
|
---|
| 29 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
| 30 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 31 | **
|
---|
| 32 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 33 | ** not clear to you.
|
---|
| 34 | **
|
---|
| 35 | **********************************************************************/
|
---|
| 36 |
|
---|
| 37 | #ifndef QDATATABLE_H
|
---|
| 38 | #define QDATATABLE_H
|
---|
| 39 |
|
---|
| 40 | #ifndef QT_H
|
---|
| 41 | #include "qstring.h"
|
---|
| 42 | #include "qvariant.h"
|
---|
| 43 | #include "qtable.h"
|
---|
| 44 | #include "qsql.h"
|
---|
| 45 | #include "qsqlcursor.h"
|
---|
| 46 | #include "qsqlindex.h"
|
---|
| 47 | #include "qsqleditorfactory.h"
|
---|
| 48 | #include "qiconset.h"
|
---|
| 49 | #endif // QT_H
|
---|
| 50 |
|
---|
| 51 | #if !defined( QT_MODULE_SQL ) || defined( QT_LICENSE_PROFESSIONAL )
|
---|
| 52 | #define QM_EXPORT_SQL
|
---|
| 53 | #else
|
---|
| 54 | #define QM_EXPORT_SQL Q_EXPORT
|
---|
| 55 | #endif
|
---|
| 56 |
|
---|
| 57 | #ifndef QT_NO_SQL_VIEW_WIDGETS
|
---|
| 58 |
|
---|
| 59 | class QPainter;
|
---|
| 60 | class QSqlField;
|
---|
| 61 | class QSqlPropertyMap;
|
---|
| 62 | class QDataTablePrivate;
|
---|
| 63 |
|
---|
| 64 | class QM_EXPORT_SQL QDataTable : public QTable
|
---|
| 65 | {
|
---|
| 66 | Q_OBJECT
|
---|
| 67 |
|
---|
| 68 | Q_PROPERTY( QString nullText READ nullText WRITE setNullText )
|
---|
| 69 | Q_PROPERTY( QString trueText READ trueText WRITE setTrueText )
|
---|
| 70 | Q_PROPERTY( QString falseText READ falseText WRITE setFalseText )
|
---|
| 71 | Q_PROPERTY( DateFormat dateFormat READ dateFormat WRITE setDateFormat )
|
---|
| 72 | Q_PROPERTY( bool confirmEdits READ confirmEdits WRITE setConfirmEdits )
|
---|
| 73 | Q_PROPERTY( bool confirmInsert READ confirmInsert WRITE setConfirmInsert )
|
---|
| 74 | Q_PROPERTY( bool confirmUpdate READ confirmUpdate WRITE setConfirmUpdate )
|
---|
| 75 | Q_PROPERTY( bool confirmDelete READ confirmDelete WRITE setConfirmDelete )
|
---|
| 76 | Q_PROPERTY( bool confirmCancels READ confirmCancels WRITE setConfirmCancels )
|
---|
| 77 | Q_PROPERTY( bool autoEdit READ autoEdit WRITE setAutoEdit )
|
---|
| 78 | Q_PROPERTY( QString filter READ filter WRITE setFilter )
|
---|
| 79 | Q_PROPERTY( QStringList sort READ sort WRITE setSort )
|
---|
| 80 | Q_PROPERTY( int numCols READ numCols )
|
---|
| 81 | Q_PROPERTY( int numRows READ numRows )
|
---|
| 82 |
|
---|
| 83 | public:
|
---|
| 84 | QDataTable ( QWidget* parent=0, const char* name=0 );
|
---|
| 85 | QDataTable ( QSqlCursor* cursor, bool autoPopulate = FALSE, QWidget* parent=0, const char* name=0 );
|
---|
| 86 | ~QDataTable();
|
---|
| 87 |
|
---|
| 88 | virtual void addColumn( const QString& fieldName,
|
---|
| 89 | const QString& label = QString::null,
|
---|
| 90 | int width = -1,
|
---|
| 91 | const QIconSet& iconset = QIconSet() );
|
---|
| 92 | virtual void removeColumn( uint col );
|
---|
| 93 | virtual void setColumn( uint col, const QString& fieldName,
|
---|
| 94 | const QString& label = QString::null,
|
---|
| 95 | int width = -1,
|
---|
| 96 | const QIconSet& iconset = QIconSet() );
|
---|
| 97 |
|
---|
| 98 | QString nullText() const;
|
---|
| 99 | QString trueText() const;
|
---|
| 100 | QString falseText() const;
|
---|
| 101 | DateFormat dateFormat() const;
|
---|
| 102 | bool confirmEdits() const;
|
---|
| 103 | bool confirmInsert() const;
|
---|
| 104 | bool confirmUpdate() const;
|
---|
| 105 | bool confirmDelete() const;
|
---|
| 106 | bool confirmCancels() const;
|
---|
| 107 | bool autoDelete() const;
|
---|
| 108 | bool autoEdit() const;
|
---|
| 109 | QString filter() const;
|
---|
| 110 | QStringList sort() const;
|
---|
| 111 |
|
---|
| 112 | virtual void setSqlCursor( QSqlCursor* cursor = 0,
|
---|
| 113 | bool autoPopulate = FALSE, bool autoDelete = FALSE );
|
---|
| 114 | QSqlCursor* sqlCursor() const;
|
---|
| 115 |
|
---|
| 116 | virtual void setNullText( const QString& nullText );
|
---|
| 117 | virtual void setTrueText( const QString& trueText );
|
---|
| 118 | virtual void setFalseText( const QString& falseText );
|
---|
| 119 | virtual void setDateFormat( const DateFormat f );
|
---|
| 120 | virtual void setConfirmEdits( bool confirm );
|
---|
| 121 | virtual void setConfirmInsert( bool confirm );
|
---|
| 122 | virtual void setConfirmUpdate( bool confirm );
|
---|
| 123 | virtual void setConfirmDelete( bool confirm );
|
---|
| 124 | virtual void setConfirmCancels( bool confirm );
|
---|
| 125 | virtual void setAutoDelete( bool enable );
|
---|
| 126 | virtual void setAutoEdit( bool autoEdit );
|
---|
| 127 | virtual void setFilter( const QString& filter );
|
---|
| 128 | virtual void setSort( const QStringList& sort );
|
---|
| 129 | virtual void setSort( const QSqlIndex& sort );
|
---|
| 130 |
|
---|
| 131 | enum Refresh {
|
---|
| 132 | RefreshData = 1,
|
---|
| 133 | RefreshColumns = 2,
|
---|
| 134 | RefreshAll = 3
|
---|
| 135 | };
|
---|
| 136 | void refresh( Refresh mode );
|
---|
| 137 | void sortColumn ( int col, bool ascending = TRUE,
|
---|
| 138 | bool wholeRows = FALSE );
|
---|
| 139 | QString text ( int row, int col ) const;
|
---|
| 140 | QVariant value ( int row, int col ) const;
|
---|
| 141 | QSqlRecord* currentRecord() const;
|
---|
| 142 |
|
---|
| 143 | void installEditorFactory( QSqlEditorFactory * f );
|
---|
| 144 | void installPropertyMap( QSqlPropertyMap* m );
|
---|
| 145 |
|
---|
| 146 | int numCols() const;
|
---|
| 147 | int numRows() const;
|
---|
| 148 | void setNumCols( int c );
|
---|
| 149 | void setNumRows ( int r );
|
---|
| 150 | bool findBuffer( const QSqlIndex& idx, int atHint = 0 );
|
---|
| 151 |
|
---|
| 152 | void hideColumn( int col );
|
---|
| 153 | void showColumn( int col );
|
---|
| 154 | signals:
|
---|
| 155 | void currentChanged( QSqlRecord* record );
|
---|
| 156 | void primeInsert( QSqlRecord* buf );
|
---|
| 157 | void primeUpdate( QSqlRecord* buf );
|
---|
| 158 | void primeDelete( QSqlRecord* buf );
|
---|
| 159 | void beforeInsert( QSqlRecord* buf );
|
---|
| 160 | void beforeUpdate( QSqlRecord* buf );
|
---|
| 161 | void beforeDelete( QSqlRecord* buf );
|
---|
| 162 | void cursorChanged( QSql::Op mode );
|
---|
| 163 |
|
---|
| 164 | public slots:
|
---|
| 165 | virtual void find( const QString & str, bool caseSensitive,
|
---|
| 166 | bool backwards );
|
---|
| 167 | virtual void sortAscending( int col );
|
---|
| 168 | virtual void sortDescending( int col );
|
---|
| 169 | virtual void refresh();
|
---|
| 170 | void setColumnWidth( int col, int w );
|
---|
| 171 | void adjustColumn( int col );
|
---|
| 172 | void setColumnStretchable( int col, bool stretch );
|
---|
| 173 | void swapColumns( int col1, int col2, bool swapHeaders = FALSE );
|
---|
| 174 |
|
---|
| 175 | protected:
|
---|
| 176 | virtual bool insertCurrent();
|
---|
| 177 | virtual bool updateCurrent();
|
---|
| 178 | virtual bool deleteCurrent();
|
---|
| 179 |
|
---|
| 180 | virtual QSql::Confirm confirmEdit( QSql::Op m );
|
---|
| 181 | virtual QSql::Confirm confirmCancel( QSql::Op m );
|
---|
| 182 |
|
---|
| 183 | virtual void handleError( const QSqlError& e );
|
---|
| 184 |
|
---|
| 185 | virtual bool beginInsert();
|
---|
| 186 | virtual QWidget* beginUpdate ( int row, int col, bool replace );
|
---|
| 187 |
|
---|
| 188 | bool eventFilter( QObject *o, QEvent *e );
|
---|
| 189 | void keyPressEvent( QKeyEvent* );
|
---|
| 190 | void resizeEvent ( QResizeEvent * );
|
---|
| 191 | void contentsMousePressEvent( QMouseEvent* e );
|
---|
| 192 | void contentsContextMenuEvent( QContextMenuEvent* e );
|
---|
| 193 | void endEdit( int row, int col, bool accept, bool replace );
|
---|
| 194 | QWidget * createEditor( int row, int col, bool initFromCell ) const;
|
---|
| 195 | void activateNextCell();
|
---|
| 196 | int indexOf( uint i ) const; // ### make this public in 4.0
|
---|
| 197 | void reset();
|
---|
| 198 | void setSize( QSqlCursor* sql );
|
---|
| 199 | void repaintCell( int row, int col );
|
---|
| 200 | void paintCell ( QPainter * p, int row, int col, const QRect & cr,
|
---|
| 201 | bool selected, const QColorGroup &cg );
|
---|
| 202 | virtual void paintField( QPainter * p, const QSqlField* field, const QRect & cr,
|
---|
| 203 | bool selected );
|
---|
| 204 | void drawContents( QPainter * p, int cx, int cy, int cw, int ch );
|
---|
| 205 | virtual int fieldAlignment( const QSqlField* field );
|
---|
| 206 | void columnClicked ( int col );
|
---|
| 207 | void resizeData ( int len );
|
---|
| 208 |
|
---|
| 209 | QTableItem * item ( int row, int col ) const;
|
---|
| 210 | void setItem ( int row, int col, QTableItem * item );
|
---|
| 211 | void clearCell ( int row, int col ) ;
|
---|
| 212 | void setPixmap ( int row, int col, const QPixmap & pix );
|
---|
| 213 | void takeItem ( QTableItem * i );
|
---|
| 214 |
|
---|
| 215 | private slots:
|
---|
| 216 | void loadNextPage();
|
---|
| 217 | void setCurrentSelection( int row, int col );
|
---|
| 218 | void updateCurrentSelection();
|
---|
| 219 | void sliderPressed();
|
---|
| 220 | void sliderReleased();
|
---|
| 221 | void doInsertCurrent();
|
---|
| 222 | void doUpdateCurrent();
|
---|
| 223 |
|
---|
| 224 | private:
|
---|
| 225 | QString fieldToString( const QSqlField * field );
|
---|
| 226 | void init();
|
---|
| 227 | QWidget* beginEdit ( int row, int col, bool replace );
|
---|
| 228 | void updateRow( int row );
|
---|
| 229 | void endInsert();
|
---|
| 230 | void endUpdate();
|
---|
| 231 | QDataTablePrivate* d;
|
---|
| 232 |
|
---|
| 233 | #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator=
|
---|
| 234 | QDataTable( const QDataTable & );
|
---|
| 235 | QDataTable &operator=( const QDataTable & );
|
---|
| 236 | #endif
|
---|
| 237 | };
|
---|
| 238 |
|
---|
| 239 | #endif
|
---|
| 240 | #endif
|
---|