home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qdatatable.h < prev    next >
C/C++ Source or Header  |  2001-10-09  |  8KB  |  224 lines

  1. /****************************************************************************
  2. **
  3. ** Definition of QDataTable class
  4. **
  5. ** Created : 2000-11-03
  6. **
  7. ** Copyright (C) 2000 Trolltech AS.  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 AS 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
  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. signals:
  153.     void         currentChanged( QSqlRecord* record );
  154.     void         primeInsert( QSqlRecord* buf );
  155.     void         primeUpdate( QSqlRecord* buf );
  156.     void         primeDelete( QSqlRecord* buf );
  157.     void         beforeInsert( QSqlRecord* buf );
  158.     void         beforeUpdate( QSqlRecord* buf );
  159.     void         beforeDelete( QSqlRecord* buf );
  160.     void         cursorChanged( QSql::Op mode );
  161.  
  162. public slots:
  163.     virtual void find( const QString & str, bool caseSensitive,
  164.                  bool backwards );
  165.     virtual void sortAscending( int col );
  166.     virtual void sortDescending( int col );
  167.     virtual void refresh();
  168.     void setColumnWidth( int col, int w );
  169.  
  170. protected:
  171.     virtual bool insertCurrent();
  172.     virtual bool updateCurrent();
  173.     virtual bool deleteCurrent();
  174.  
  175.     virtual QSql::Confirm confirmEdit( QSql::Op m );
  176.     virtual QSql::Confirm confirmCancel( QSql::Op m );
  177.  
  178.     virtual void handleError( const QSqlError& e );
  179.  
  180.     virtual bool beginInsert();
  181.     virtual QWidget* beginUpdate ( int row, int col, bool replace );
  182.  
  183.     bool         eventFilter( QObject *o, QEvent *e );
  184.     void         resizeEvent ( QResizeEvent * );
  185.     void         contentsMousePressEvent( QMouseEvent* e );
  186.     void         contentsContextMenuEvent( QContextMenuEvent* e );
  187.     void         endEdit( int row, int col, bool accept, bool replace );
  188.     QWidget *    createEditor( int row, int col, bool initFromCell ) const;
  189.     void         activateNextCell();
  190.     int          indexOf( uint i ) const;
  191.     void         reset();
  192.     void         setSize( QSqlCursor* sql );
  193.     void         repaintCell( int row, int col );
  194.     void         paintCell ( QPainter * p, int row, int col, const QRect & cr,
  195.                  bool selected, const QColorGroup &cg );
  196.     virtual void paintField( QPainter * p, const QSqlField* field, const QRect & cr,
  197.                  bool selected );
  198.     virtual int  fieldAlignment( const QSqlField* field );
  199.     void         columnClicked ( int col );
  200.     void         resizeData ( int len );
  201.  
  202.     QTableItem * item ( int row, int col ) const;
  203.     void         setItem ( int row, int col, QTableItem * item );
  204.     void         clearCell ( int row, int col ) ;
  205.     void         setPixmap ( int row, int col, const QPixmap & pix );
  206.     void         takeItem ( QTableItem * i );
  207.  
  208. private slots:
  209.     void         loadNextPage();
  210.     void         loadLine( int l );
  211.     void         setCurrentSelection( int row, int col );
  212.  
  213. private:
  214.     void         init();
  215.     QWidget*     beginEdit ( int row, int col, bool replace );
  216.     void         updateRow( int row );
  217.     void         endInsert();
  218.     void         endUpdate();
  219.     QDataTablePrivate* d;
  220. };
  221.  
  222. #endif
  223. #endif
  224.