src/qt3support/sql/q3datatable.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3Support module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef Q3DATATABLE_H
       
    43 #define Q3DATATABLE_H
       
    44 
       
    45 #include <QtCore/qstring.h>
       
    46 #include <QtCore/qvariant.h>
       
    47 #include <Qt3Support/q3table.h>
       
    48 #include <QtSql/qsql.h>
       
    49 #include <Qt3Support/q3sqlcursor.h>
       
    50 #include <QtSql/qsqlindex.h>
       
    51 #include <Qt3Support/q3sqleditorfactory.h>
       
    52 #include <Qt3Support/qiconset.h>
       
    53 
       
    54 QT_BEGIN_HEADER
       
    55 
       
    56 QT_BEGIN_NAMESPACE
       
    57 
       
    58 QT_MODULE(Qt3Support)
       
    59 
       
    60 #ifndef QT_NO_SQL_VIEW_WIDGETS
       
    61 
       
    62 class QPainter;
       
    63 class QSqlField;
       
    64 class Q3SqlPropertyMap;
       
    65 class Q3DataTablePrivate;
       
    66 
       
    67 class Q_COMPAT_EXPORT Q3DataTable : public Q3Table
       
    68 {
       
    69     Q_OBJECT
       
    70 
       
    71     Q_PROPERTY( QString nullText READ nullText WRITE setNullText )
       
    72     Q_PROPERTY( QString trueText READ trueText WRITE setTrueText )
       
    73     Q_PROPERTY( QString falseText READ falseText WRITE setFalseText )
       
    74     Q_PROPERTY( Qt::DateFormat dateFormat READ dateFormat WRITE setDateFormat )
       
    75     Q_PROPERTY( bool confirmEdits READ confirmEdits WRITE setConfirmEdits )
       
    76     Q_PROPERTY( bool confirmInsert READ confirmInsert WRITE setConfirmInsert )
       
    77     Q_PROPERTY( bool confirmUpdate READ confirmUpdate WRITE setConfirmUpdate )
       
    78     Q_PROPERTY( bool confirmDelete READ confirmDelete WRITE setConfirmDelete )
       
    79     Q_PROPERTY( bool confirmCancels READ confirmCancels WRITE setConfirmCancels )
       
    80     Q_PROPERTY( bool autoEdit READ autoEdit WRITE setAutoEdit )
       
    81     Q_PROPERTY( QString filter READ filter WRITE setFilter )
       
    82     Q_PROPERTY( QStringList sort READ sort WRITE setSort )
       
    83     Q_PROPERTY( int numCols READ numCols )
       
    84     Q_PROPERTY( int numRows READ numRows )
       
    85 
       
    86 public:
       
    87     Q3DataTable ( QWidget* parent=0, const char* name=0 );
       
    88     Q3DataTable ( Q3SqlCursor* cursor, bool autoPopulate = false, QWidget* parent=0, const char* name=0 );
       
    89     ~Q3DataTable();
       
    90 
       
    91     virtual void addColumn( const QString& fieldName,
       
    92 			    const QString& label = QString(),
       
    93 			    int width = -1,
       
    94 			    const QIconSet& iconset = QIconSet() );
       
    95     virtual void removeColumn( int col );
       
    96     virtual void setColumn( uint col, const QString& fieldName,
       
    97 			    const QString& label = QString(),
       
    98 			    int width = -1,
       
    99 			    const QIconSet& iconset = QIconSet() );
       
   100 
       
   101     QString      nullText() const;
       
   102     QString      trueText() const;
       
   103     QString      falseText() const;
       
   104     Qt::DateFormat dateFormat() const;
       
   105     bool         confirmEdits() const;
       
   106     bool         confirmInsert() const;
       
   107     bool         confirmUpdate() const;
       
   108     bool         confirmDelete() const;
       
   109     bool         confirmCancels() const;
       
   110     bool         autoDelete() const;
       
   111     bool         autoEdit() const;
       
   112     QString      filter() const;
       
   113     QStringList  sort() const;
       
   114 
       
   115     virtual void setSqlCursor( Q3SqlCursor* cursor = 0,
       
   116 			    bool autoPopulate = false, bool autoDelete = false );
       
   117     Q3SqlCursor* sqlCursor() const;
       
   118 
       
   119     virtual void setNullText( const QString& nullText );
       
   120     virtual void setTrueText( const QString& trueText );
       
   121     virtual void setFalseText( const QString& falseText );
       
   122     virtual void setDateFormat( const Qt::DateFormat f );
       
   123     virtual void setConfirmEdits( bool confirm );
       
   124     virtual void setConfirmInsert( bool confirm );
       
   125     virtual void setConfirmUpdate( bool confirm );
       
   126     virtual void setConfirmDelete( bool confirm );
       
   127     virtual void setConfirmCancels( bool confirm );
       
   128     virtual void setAutoDelete( bool enable );
       
   129     virtual void setAutoEdit( bool autoEdit );
       
   130     virtual void setFilter( const QString& filter );
       
   131     virtual void setSort( const QStringList& sort );
       
   132     virtual void setSort( const QSqlIndex& sort );
       
   133 
       
   134     enum Refresh {
       
   135 	RefreshData = 1,
       
   136 	RefreshColumns = 2,
       
   137 	RefreshAll = 3
       
   138     };
       
   139     void         refresh( Refresh mode );
       
   140     void         sortColumn ( int col, bool ascending = true,
       
   141 			      bool wholeRows = false );
       
   142     QString      text ( int row, int col ) const;
       
   143     QVariant     value ( int row, int col ) const;
       
   144     QSqlRecord*  currentRecord() const;
       
   145 
       
   146     void         installEditorFactory( Q3SqlEditorFactory * f );
       
   147     void         installPropertyMap( Q3SqlPropertyMap* m );
       
   148 
       
   149     int          numCols() const;
       
   150     int          numRows() const;
       
   151     void         setNumCols( int c );
       
   152     void         setNumRows ( int r );
       
   153     bool         findBuffer( const QSqlIndex& idx, int atHint = 0 );
       
   154 
       
   155     void	 hideColumn( int col );
       
   156     void	 showColumn( int col );
       
   157     int          indexOf( uint i ) const;
       
   158     void selectRow(int row);
       
   159 
       
   160 Q_SIGNALS:
       
   161     void         currentChanged( QSqlRecord* record );
       
   162     void         primeInsert( QSqlRecord* buf );
       
   163     void         primeUpdate( QSqlRecord* buf );
       
   164     void         primeDelete( QSqlRecord* buf );
       
   165     void         beforeInsert( QSqlRecord* buf );
       
   166     void         beforeUpdate( QSqlRecord* buf );
       
   167     void         beforeDelete( QSqlRecord* buf );
       
   168     void         cursorChanged( QSql::Op mode );
       
   169 
       
   170 public Q_SLOTS:
       
   171     virtual void find( const QString & str, bool caseSensitive,
       
   172 			     bool backwards );
       
   173     virtual void sortAscending( int col );
       
   174     virtual void sortDescending( int col );
       
   175     virtual void refresh();
       
   176     void setColumnWidth( int col, int w );
       
   177     void adjustColumn( int col );
       
   178     void setColumnStretchable( int col, bool stretch );
       
   179     void swapColumns( int col1, int col2, bool swapHeaders = false );
       
   180 
       
   181 protected:
       
   182     virtual bool insertCurrent();
       
   183     virtual bool updateCurrent();
       
   184     virtual bool deleteCurrent();
       
   185 
       
   186     virtual QSql::Confirm confirmEdit( QSql::Op m );
       
   187     virtual QSql::Confirm confirmCancel( QSql::Op m );
       
   188 
       
   189     virtual void handleError( const QSqlError& e );
       
   190 
       
   191     virtual bool beginInsert();
       
   192     virtual QWidget* beginUpdate ( int row, int col, bool replace );
       
   193 
       
   194     bool         eventFilter( QObject *o, QEvent *e );
       
   195     void         keyPressEvent( QKeyEvent* );
       
   196     void         resizeEvent ( QResizeEvent * );
       
   197     void         contentsMousePressEvent( QMouseEvent* e );
       
   198     void         contentsContextMenuEvent( QContextMenuEvent* e );
       
   199     void         endEdit( int row, int col, bool accept, bool replace );
       
   200     QWidget *    createEditor( int row, int col, bool initFromCell ) const;
       
   201     void         activateNextCell();
       
   202     void         reset();
       
   203     void         setSize( Q3SqlCursor* sql );
       
   204     void         repaintCell( int row, int col );
       
   205     void         paintCell ( QPainter * p, int row, int col, const QRect & cr,
       
   206 			     bool selected, const QColorGroup &cg );
       
   207     virtual void paintField( QPainter * p, const QSqlField* field, const QRect & cr,
       
   208 			     bool selected );
       
   209     void	 drawContents( QPainter * p, int cx, int cy, int cw, int ch );
       
   210     virtual int  fieldAlignment( const QSqlField* field );
       
   211     void         columnClicked ( int col );
       
   212     void         resizeData ( int len );
       
   213 
       
   214     Q3TableItem * item ( int row, int col ) const;
       
   215     void         setItem ( int row, int col, Q3TableItem * item );
       
   216     void         clearCell ( int row, int col ) ;
       
   217     void         setPixmap ( int row, int col, const QPixmap & pix );
       
   218     void         takeItem ( Q3TableItem * i );
       
   219 
       
   220 private Q_SLOTS:
       
   221     void         loadNextPage();
       
   222     void         setCurrentSelection( int row, int col );
       
   223     void         updateCurrentSelection();
       
   224     void	 sliderPressed();
       
   225     void	 sliderReleased();
       
   226     void	 doInsertCurrent();
       
   227     void	 doUpdateCurrent();
       
   228 
       
   229 private:
       
   230     void         drawContents( QPainter *p);
       
   231     QString	 fieldToString( const QSqlField * field );
       
   232     void         init();
       
   233     QWidget*     beginEdit ( int row, int col, bool replace );
       
   234     void         updateRow( int row );
       
   235     void         endInsert();
       
   236     void         endUpdate();
       
   237     Q3DataTablePrivate* d;
       
   238 
       
   239 #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator=
       
   240     Q3DataTable( const Q3DataTable & );
       
   241     Q3DataTable &operator=( const Q3DataTable & );
       
   242 #endif
       
   243 };
       
   244 
       
   245 #endif // QT_NO_SQL_VIEW_WIDGETS
       
   246 
       
   247 QT_END_NAMESPACE
       
   248 
       
   249 QT_END_HEADER
       
   250 
       
   251 #endif // Q3DATATABLE_H