00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef WDBTABLE_H
00032 #define WDBTABLE_H
00033
00034 #include <qsqlpropertymap.h>
00035 #include <qdatatable.h>
00036 #include <qdragobject.h>
00037 #include "acfg.h"
00038 #include "aobject.h"
00039 #include "awidget.h"
00040 #include "wfield.h"
00041
00042 class aDatabase;
00043 class wDBTable;
00044 class QDataTable;
00045
00046 class aSearchWidget : public QFrame
00047 {
00048 Q_OBJECT
00049 public:
00050 aSearchWidget( QWidget *parent, wDBTable *table );
00051 ~aSearchWidget();
00052 void search( const QString &t ="");
00053 public slots:
00054 void setText( const QString &t );
00055 protected:
00056
00057 bool eventFilter( QObject *obj, QEvent *ev );
00058 private:
00059 QString ftext;
00060 QLineEdit *l;
00061 wDBTable *t;
00062 };
00063
00064
00065
00077 class QT_WIDGET_PLUGIN_EXPORT wDBTable : public QDataTable
00078 {
00079 friend class aForm;
00080
00081 Q_OBJECT
00082 Q_PROPERTY( Q_ULLONG Id READ getId WRITE setId DESIGNABLE true )
00083 Q_PROPERTY( int DefaultColWidth READ getDefColWidth WRITE setDefColWidth DESIGNABLE true )
00084 Q_PROPERTY( int TableInd READ getTblInd WRITE setTblInd DESIGNABLE true )
00085 Q_PROPERTY( QStringList DefFields READ getDefFields WRITE setDefFields DESIGNABLE true )
00086 Q_PROPERTY( QStringList DefHeaders READ getDefHeaders WRITE setDefHeaders DESIGNABLE true )
00087 Q_PROPERTY( QStringList ColWidth READ getColWidth WRITE setColWidth DESIGNABLE true )
00088 Q_PROPERTY( QStringList DefIdList READ getDefIdList WRITE setDefIdList DESIGNABLE true )
00089
00090 Q_PROPERTY( QString editFormName READ getEditFormName WRITE setEditFormName DESIGNABLE true )
00091 public:
00092 aCfg* md;
00093 aDatabase* db;
00094 aEngine* engine;
00095
00096 QStringList list_available_tables;
00097 QStringList fname, hname, colWidth,idList;
00098 int defColWidth;
00099 int tableInd;
00100 aCfgItem tables;
00101 QSqlCursor* cur;
00102 bool searchMode;
00103 QString searchString;
00104 aSearchWidget *searchWidget;
00105
00106 wDBTable( QString objtype, QWidget *parent = 0, const char *name = 0);
00107 virtual ~wDBTable();
00108 void checkFields();
00109 void setFields(int numTable);
00110 QStringList getFields(int numTable, bool GetId=false);
00111 QString getFieldName(long idField);
00112 QString getFieldType(long idField);
00113 int getTableInd(int id);
00114 int getTableId(int ind);
00115
00116
00117 void init();
00118 void init(aDatabase *adb, aEngine *e = 0 );
00119 void OpenEditor();
00120
00121
00122
00123
00124 QStringList getDefFields() const;
00125 QStringList getDefHeaders() const;
00126 QStringList getColWidth() const;
00127 QStringList getDefIdList() const;
00128 Q_ULLONG getId() const;
00129 int getTblInd() const;
00130 bool getOpenEditor() const;
00131 int getDefColWidth() const;
00132
00133 void setDefFields(QStringList lst);
00134 void setDefHeaders(QStringList lst);
00135 void setColWidth(QStringList lst);
00136 void setDefIdList(QStringList lst);
00137 void setId( Q_ULLONG fn );
00138 void setTblInd( int ind );
00139 void setOpenEditor( bool fn );
00140 void setDefColWidth( int fn );
00141
00142 QString getEditFormName() const { return vEditFormName;};
00143 void setEditFormName( QString name) { vEditFormName = name; };
00144
00145 QString containerType() const { return container_type;};
00146 void setContainerType( QString name) { container_type = name; };
00147 QPixmap systemIcon();
00148 virtual int Select( ANANAS_UID db_uid );
00149 public slots:
00150 QValueList<int> getBindList();
00151 void setWFieldEditor();
00152 void setAvailableTables();
00153 void lineUpdate(QSql::Op mode);
00154 void newFilter(const QString & );
00155 void newDataId(const Q_ULLONG );
00156 QVariant Value( const QString &colname );
00157
00158 bool searchColumn( const QString &text, bool FromCurrent = FALSE, bool Forward = TRUE );
00159 void searchOpen( const QString &text = "" );
00160 void searchClose();
00161
00162 protected slots:
00163 void doubleClickEventHandler(int , int , int, const QPoint& );
00164 virtual void updateTableCellHandler(int, int);
00165 void dropped(QDropEvent *);
00166 signals:
00167
00175 void saveLine(QSqlRecord *rec);
00176
00184 void deleteLine(QSqlRecord *rec);
00192 void selected( Q_ULLONG uid );
00200 void selectRecord ( Q_ULLONG );
00208 void updateCurr(int row, int col);
00209
00210
00211
00212
00213
00214
00215
00229
00230 void insertRequest();
00234 void updateRequest();
00238 void deleteRequest();
00242 void viewRequest();
00243
00244
00245 private slots:
00246
00247 void lineChange(int, int);
00248 void lineInsert(QSqlRecord*);
00249 void updateItem( ANANAS_UID db_uid );
00250
00251 protected:
00252 virtual QDragObject * dragObject ();
00253 virtual void paintField ( QPainter * p, const QSqlField * field, const QRect & cr, bool selected );
00254 QWidget * beginUpdate ( int row, int col, bool replace );
00255 virtual bool updateCurrent();
00256 void contentsContextMenuEvent ( QContextMenuEvent * e );
00257
00258 virtual bool deleteCurrent();
00259
00260 virtual void keyPressEvent ( QKeyEvent *e );
00261 void EditElement();
00262 virtual void activateNextCell();
00263 virtual bool beginInsert ();
00264 virtual QSql::Confirm confirmEdit( QSql::Op m );
00265
00266 private:
00267
00268 QPixmap t_doc;
00269 QPixmap t_doc_d;
00270 QPixmap t_doc_t;
00271 QPixmap t_doc_m;
00272 QPixmap t_doc_tm;
00273 QPixmap t_cat_e;
00274 QPixmap t_cat_ed;
00275 QPixmap t_cat_g;
00276 QPixmap t_cat_gd;
00277
00278 int lastEditedRow;
00279 int lastEditedCol;
00280
00281 QString container_type;
00282 Q_ULLONG doc_id;
00283 Q_ULLONG cat_group_id;
00284 long journalFieldId(long);
00285 QString journalFieldName(long);
00286 bool inEditMode;
00287
00288
00289 QValueList<int> listBindings;
00290 aCfgItem obj;
00291 QString vName, vEditFormName;
00292 QString vDefineCols;
00293 Q_ULLONG oid;
00294 };
00295
00296
00304 class aEditorFactory: public QSqlEditorFactory
00305 {
00306 public:
00311 aEditorFactory(QObject * parent = 0, const char * name = 0):QSqlEditorFactory(parent,name) {};
00312 QWidget * createEditor (QWidget * parent, const QSqlField * field);
00313 void setMd(aCfg *md);
00314 private:
00315 aCfg * md;
00316 };
00317
00324 class aObjectDrag : public QDragObject
00325 {
00326 Q_OBJECT
00327 public:
00328 aObjectDrag(aObject * obj, QWidget * dragSource);
00329 ~aObjectDrag();
00330
00331 virtual void setObject(aObject* obj);
00332 aObject* object() { return fObj; };
00333 const char* format(int i) const;
00334 virtual QByteArray encodedData(const char*) const;
00335 private:
00336 aObject* fObj;
00337 };
00338
00339
00340 #endif