kexitableviewdata.h
1/* This file is part of the KDE project
2 Copyright (C) 2002 Lucijan Busch <lucijan@gmx.at>
3 Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
4 Copyright (C) 2003-2006 Jaroslaw Staniek <js@iidea.pl>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20
21 Original Author: Till Busch <till@bux.at>
22 Original Project: buX (www.bux.at)
23*/
24
25#ifndef KEXITABLEVIEWDATA_H
26#define KEXITABLEVIEWDATA_H
27
28#include <tqptrlist.h>
29#include <tqvariant.h>
30#include <tqvaluevector.h>
31#include <tqstring.h>
32#include <tqobject.h>
33
34#include "kexitableitem.h"
35
36#include <kexidb/error.h>
37
38namespace KexiDB {
39class Field;
40class QuerySchema;
41class RowEditBuffer;
42class Cursor;
43}
44
45namespace KexiUtils {
46class Validator;
47}
49
50
52class KEXIDATATABLE_EXPORT KexiTableViewColumn {
53 public:
54 typedef TQPtrList<KexiTableViewColumn> List;
55 typedef TQPtrListIterator<KexiTableViewColumn> ListIterator;
56
59 KexiTableViewColumn(KexiDB::Field& f, bool owner = false);
60
65 KexiTableViewColumn(const TQString& name, KexiDB::Field::Type ctype,
66 uint cconst = KexiDB::Field::NoConstraints,
67 uint options = KexiDB::Field::NoOptions,
68 uint length=0, uint precision=0,
69 TQVariant defaultValue=TQVariant(),
70 const TQString& caption = TQString(),
71 const TQString& description = TQString(),
72 uint width = 0);
73
75 KexiTableViewColumn(const TQString& name, KexiDB::Field::Type ctype, const TQString& caption,
76 const TQString& description = TQString());
77
80 KexiDB::QueryColumnInfo* aVisibleLookupColumnInfo = 0);
81
82 virtual ~KexiTableViewColumn();
83
84 virtual bool acceptsFirstChar(const TQChar& ch) const;
85
89 bool isReadOnly() const;
90
91//TODO: synchronize this with table view:
93 inline void setReadOnly(bool ro) { m_readOnly=ro; }
94
96 inline bool visible() const { return columnInfo ? columnInfo->visible : m_visible; }
97
99 inline void setVisible(bool v) {
100 if (columnInfo)
101 columnInfo->visible = v;
102 m_visible=v;
103 }
104
106 void setIcon(const TQIconSet& icon) { m_icon = icon; }
107
109 TQIconSet icon() const { return m_icon; }
110
113 void setHeaderTextVisible(bool visible) { m_headerTextVisible = visible; }
114
117 bool isHeaderTextVisible() const { return m_headerTextVisible; }
118
123 inline TQString captionAliasOrName() const { return m_captionAliasOrName; }
124
128 void setValidator( KexiUtils::Validator* v );
129
131 inline KexiUtils::Validator* validator() const { return m_validator; }
132
140 void setRelatedData(KexiTableViewData *data);
141
145 inline KexiTableViewData *relatedData() const { return m_relatedData; }
146
149 inline KexiDB::Field* field() const { return m_field; }
150
154 void setRelatedDataEditable(bool set);
155
159 inline bool relatedDataEditable() const { return m_relatedDataEditable; }
160
164
171
172 bool isDBAware : 1;
173
174/* TQString caption;
175 int type; //!< one of KexiDB::Field::Type
176 uint width;
177*/
178// bool isNull() const;
179
180/* virtual TQString caption() const;
181 virtual void setCaption(const TQString& c);
182 */
183 protected:
186
187 void init();
188
189 TQString m_captionAliasOrName;
190
191 TQIconSet m_icon;
192
193 KexiUtils::Validator* m_validator;
194
197
198 KexiTableViewData* m_relatedData;
199 uint m_relatedDataPKeyID;
200
201 KexiDB::Field* m_field;
202
203 bool m_readOnly : 1;
204 bool m_fieldOwned : 1;
205 bool m_visible : 1;
206 bool m_relatedDataEditable : 1;
207 bool m_headerTextVisible : 1;
208
209 friend class KexiTableViewData;
210};
211
212
214//typedef TQValueVector<KexiTableViewColumn> KexiTableViewColumnList;
215
216typedef TQPtrList<KexiTableItem> KexiTableViewDataBase;
217
222class KEXIDATATABLE_EXPORT KexiTableViewData : public TQObject, protected KexiTableViewDataBase
223{
224 TQ_OBJECT
225
226
227public:
228 typedef TQPtrListIterator<KexiTableItem> Iterator;
229
232
235
236//TODO: make this more generic: allow to add more columns!
246 const TQValueList<TQVariant> &keys, const TQValueList<TQVariant> &values,
249
255
256 virtual ~KexiTableViewData();
257//js void setSorting(int key, bool order=true, short type=1);
258
261 void preloadAllRows();
262
264 void setSorting(int column, bool ascending=true);
265
269 inline int sortedColumn() const { return m_sortedColumn; }
270
274 inline int sortingOrder() const { return m_order; }
275
278 void addColumn( KexiTableViewColumn* col );
279
280 inline int globalColumnID(int visibleID) { return m_globalColumnsIDs.at( visibleID ); }
281 inline int visibleColumnID(int globalID) { return m_visibleColumnsIDs.at( globalID ); }
282
283 /*virtual?*/
285 inline bool isDBAware() { return m_cursor; }
286
289 TQString dbTableName() const;
290
291 inline KexiDB::Cursor* cursor() const { return m_cursor; }
292
293 inline uint columnsCount() const { return columns.count(); }
294
295 inline KexiTableViewColumn* column(uint c) { return columns.at(c); }
296
298 KexiTableViewColumn::List columns;
299
303 virtual bool isReadOnly() const;
304
308 virtual void setReadOnly(bool set);
309
311 virtual bool isInsertingEnabled() const { return m_insertingEnabled; }
312
316 virtual void setInsertingEnabled(bool set);
317
324 void clearRowEditBuffer();
325
336 bool updateRowEditBufferRef(KexiTableItem *item,
337 int colnum, KexiTableViewColumn* col, TQVariant& newval, bool allowSignals = true,
338 TQVariant *visibleValueForLookupField = 0);
339
341 inline bool updateRowEditBuffer(KexiTableItem *item, int colnum, KexiTableViewColumn* col,
342 TQVariant newval, bool allowSignals = true)
343 {
344 TQVariant newv(newval);
345 return updateRowEditBufferRef(item, colnum, col, newv, allowSignals);
346 }
347
350 inline bool updateRowEditBuffer(KexiTableItem *item, int colnum,
351 TQVariant newval, bool allowSignals = true)
352 {
353 KexiTableViewColumn* col = columns.at(colnum);
354 return col ? updateRowEditBufferRef(item, colnum, col, newval, allowSignals) : false;
355 }
356
357 inline KexiDB::RowEditBuffer* rowEditBuffer() const { return m_pRowEditBuffer; }
358
360 inline KexiDB::ResultInfo* result() { return &m_result; }
361
362 bool saveRowChanges(KexiTableItem& item, bool repaint = false);
363
364 bool saveNewRow(KexiTableItem& item, bool repaint = false);
365
366 bool deleteRow(KexiTableItem& item, bool repaint = false);
367
370 void deleteRows( const TQValueList<int> &rowsToDelete, bool repaint = false );
371
382 virtual bool deleteAllRows(bool repaint = false);
383
388 virtual void clearInternal();
389
393 void insertRow(KexiTableItem& item, uint index, bool repaint = false);
394
395/*TODO: add this as well?
396 void insertRow(KexiTableItem& item, KexiTableItem& aboveItem); */
397
401 int autoIncrementedColumn();
402
404 void reload() { emit reloadRequested(); }
405
406 inline KexiTableItem* at( uint index ) { return KexiTableViewDataBase::at(index); }
407 inline virtual uint count() const { return KexiTableViewDataBase::count(); }
408 inline bool isEmpty () const { return KexiTableViewDataBase::isEmpty(); }
409 inline KexiTableItem* first() { return KexiTableViewDataBase::first(); }
410 inline KexiTableItem* last() { return KexiTableViewDataBase::last(); }
411 inline int findRef( const KexiTableItem* item ) { return KexiTableViewDataBase::findRef(item); }
412 inline void sort() { KexiTableViewDataBase::sort(); }
413 inline bool removeFirst() { return KexiTableViewDataBase::removeFirst(); }
414 inline bool removeLast() { return KexiTableViewDataBase::removeLast(); }
415 inline void append( const KexiTableItem* item ) { KexiTableViewDataBase::append(item); }
416 inline void prepend( const KexiTableItem* item ) { KexiTableViewDataBase::prepend(item); }
417 inline Iterator iterator() { return Iterator(*this); }
418 inline Iterator* createIterator() { return new Iterator(*this); }
419
426 inline bool containsROWIDInfo() const { return m_containsROWIDInfo; }
427
428 inline KexiTableItem* createItem() const
429 { return new KexiTableItem(m_itemSize); }
430
431public slots:
433 void deleteLater();
434
435signals:
436 void destroying();
437
442 void aboutToChangeCell(KexiTableItem *item, int colnum, TQVariant& newValue,
443 KexiDB::ResultInfo* result);
444
448 void aboutToInsertRow(KexiTableItem *item, KexiDB::ResultInfo* result, bool repaint);
449
453 void aboutToUpdateRow(KexiTableItem *item, KexiDB::RowEditBuffer* buffer,
454 KexiDB::ResultInfo* result);
455
456 void rowUpdated(KexiTableItem*);
457
458 void rowInserted(KexiTableItem*, bool repaint);
459
461 void rowInserted(KexiTableItem*, uint index, bool repaint);
462
466 void aboutToDeleteRow(KexiTableItem& item, KexiDB::ResultInfo* result, bool repaint);
467
469 void rowDeleted();
470
472 void rowsDeleted( const TQValueList<int> &rowsToDelete );
473
476
477 void rowRepaintRequested(KexiTableItem&);
478
479protected:
480 void init();
481 void init(
482 const TQValueList<TQVariant> &keys, const TQValueList<TQVariant> &values,
483 KexiDB::Field::Type keyType, KexiDB::Field::Type valueType);
484
485 virtual int compareItems(Item item1, Item item2);
486 int cmpStr(Item item1, Item item2);
487 int cmpInt(Item item1, Item item2);
488 int cmpUInt(Item item1, Item item2);
489 int cmpLongLong(Item item1, Item item2);
490 int cmpULongLong(Item item1, Item item2);
491 int cmpDouble(Item item1, Item item2);
492 int cmpDate(Item item1, Item item2);
493 int cmpDateTime(Item item1, Item item2);
494 int cmpTime(Item item1, Item item2);
495
497 int cmpBLOB(Item item1, Item item2);
498
500 bool saveRow(KexiTableItem& item, bool insert, bool repaint);
501
507 short m_order;
508 short m_type;
509 int m_itemSize;
510 static unsigned short charTable[];
511 KexiDB::RowEditBuffer *m_pRowEditBuffer;
512 TQGuardedPtr<KexiDB::Cursor> m_cursor;
513
515// TQDict<KexiTableViewColumn> *m_simpleColumnsByName;
516
518
519 uint m_visibleColumnsCount;
520 TQValueVector<int> m_visibleColumnsIDs, m_globalColumnsIDs;
521
522 bool m_readOnly : 1;
523 bool m_insertingEnabled : 1;
524
528
531
532 int m_autoIncrementedColumn;
533
534 int (KexiTableViewData::*cmpFunc)(void *, void *);
535
538 TQVariant m_leftTmp, m_rightTmp;
539};
540
541#endif
Provides database cursor functionality.
Definition cursor.h:67
Meta-data for a field.
Definition field.h:73
Helper class that assigns additional information for the column in a query.
Definition queryschema.h:49
KexiDB::QuerySchema provides information about database query.
provides data for single edited database row KexiDB::RowEditBuffer provides data for single edited ro...
KexiDB::Field * field() const
bool isHeaderTextVisible() const
void setHeaderTextVisible(bool visible)
void setIcon(const TQIconSet &icon)
bool isDBAware
true if data is stored in DB, not only in memeory
void setVisible(bool v)
Changes column visibility.
KexiTableViewData * m_data
Data that this column is assigned to.
bool visible() const
Column visibility. By default column is visible.
KexiUtils::Validator * validator() const
KexiDB::QueryColumnInfo * visibleLookupColumnInfo
KexiDB::QueryColumnInfo * columnInfo
TQIconSet icon() const
bool relatedDataEditable() const
TQString captionAliasOrName() const
void setReadOnly(bool ro)
forces readOnly flag to be set to ro
KexiTableViewData * relatedData() const
int m_realSortedColumn
real sorted column number, set by setSorting(), used by cmp*() methods
KexiTableViewColumn::List columns
void reload()
Emits reloadRequested() signal to reload presenters.
int m_sortedColumn
(logical) sorted column number, set by setSorting() can differ from m_realSortedColumn if there's loo...
KexiDB::ResultInfo m_result
used to faster lookup columns of simple type (not dbaware)
KexiDB::ResultInfo * result()
void rowInserted(KexiTableItem *, uint index, bool repaint)
A row has been inserted at index position (not db-aware data only)
virtual bool isInsertingEnabled() const
void rowUpdated(KexiTableItem *)
Current row has been updated.
void aboutToUpdateRow(KexiTableItem *item, KexiDB::RowEditBuffer *buffer, KexiDB::ResultInfo *result)
void rowInserted(KexiTableItem *, bool repaint)
A row has been inserted.
TQVariant m_leftTmp
Temporary, used in compare functions like cmpInt(), cmpString() to avoid memory allocations.
bool updateRowEditBuffer(KexiTableItem *item, int colnum, TQVariant newval, bool allowSignals=true)
void aboutToDeleteRow(KexiTableItem &item, KexiDB::ResultInfo *result, bool repaint)
void aboutToChangeCell(KexiTableItem *item, int colnum, TQVariant &newValue, KexiDB::ResultInfo *result)
void reloadRequested()
Displayed data needs to be reloaded in all presenters.
bool containsROWIDInfo() const
void rowsDeleted(const TQValueList< int > &rowsToDelete)
Rows have been deleted.
void aboutToInsertRow(KexiTableItem *item, KexiDB::ResultInfo *result, bool repaint)
void rowDeleted()
Current row has been deleted.
bool updateRowEditBuffer(KexiTableItem *item, int colnum, KexiTableViewColumn *col, TQVariant newval, bool allowSignals=true)
A validator extending TQValidator with offline-checking for value's validity.
Definition validator.h:46
High-level database connectivity library with database backend drivers.
General Utils.
Definition identifier.h:27