kexi

KexiTableViewData Class Reference

#include <kexitableviewdata.h>

List of all members.


Detailed Description

Reimplements QPtrList to allow configurable sorting and more. Original author: Till Busch. Reimplemented by Jaroslaw Staniek.

Definition at line 222 of file kexitableviewdata.h.


Public Types

typedef QPtrListIterator<
KexiTableItem
Iterator

Public Slots

void deleteLater ()

Signals

void destroying ()
void aboutToChangeCell (KexiTableItem *item, int colnum, QVariant &newValue, KexiDB::ResultInfo *result)
void aboutToInsertRow (KexiTableItem *item, KexiDB::ResultInfo *result, bool repaint)
void aboutToUpdateRow (KexiTableItem *item, KexiDB::RowEditBuffer *buffer, KexiDB::ResultInfo *result)
void rowUpdated (KexiTableItem *)
void rowInserted (KexiTableItem *, bool repaint)
void rowInserted (KexiTableItem *, uint index, bool repaint)
void aboutToDeleteRow (KexiTableItem &item, KexiDB::ResultInfo *result, bool repaint)
void rowDeleted ()
void rowsDeleted (const QValueList< int > &rowsToDelete)
void reloadRequested ()
void rowRepaintRequested (KexiTableItem &)

Public Member Functions

 KexiTableViewData ()
 KexiTableViewData (KexiDB::Cursor *c)
 KexiTableViewData (const QValueList< QVariant > &keys, const QValueList< QVariant > &values, KexiDB::Field::Type keyType=KexiDB::Field::Text, KexiDB::Field::Type valueType=KexiDB::Field::Text)
 KexiTableViewData (KexiDB::Field::Type keyType, KexiDB::Field::Type valueType)
virtual ~KexiTableViewData ()
void preloadAllRows ()
void setSorting (int column, bool ascending=true)
int sortedColumn () const
int sortingOrder () const
void addColumn (KexiTableViewColumn *col)
int globalColumnID (int visibleID)
int visibleColumnID (int globalID)
bool isDBAware ()
QString dbTableName () const
KexiDB::Cursorcursor () const
uint columnsCount () const
KexiTableViewColumncolumn (uint c)
virtual bool isReadOnly () const
virtual void setReadOnly (bool set)
virtual bool isInsertingEnabled () const
virtual void setInsertingEnabled (bool set)
void clearRowEditBuffer ()
bool updateRowEditBufferRef (KexiTableItem *item, int colnum, KexiTableViewColumn *col, QVariant &newval, bool allowSignals=true, QVariant *visibleValueForLookupField=0)
bool updateRowEditBuffer (KexiTableItem *item, int colnum, KexiTableViewColumn *col, QVariant newval, bool allowSignals=true)
bool updateRowEditBuffer (KexiTableItem *item, int colnum, QVariant newval, bool allowSignals=true)
KexiDB::RowEditBufferrowEditBuffer () const
KexiDB::ResultInforesult ()
bool saveRowChanges (KexiTableItem &item, bool repaint=false)
bool saveNewRow (KexiTableItem &item, bool repaint=false)
bool deleteRow (KexiTableItem &item, bool repaint=false)
void deleteRows (const QValueList< int > &rowsToDelete, bool repaint=false)
virtual bool deleteAllRows (bool repaint=false)
virtual void clearInternal ()
void insertRow (KexiTableItem &item, uint index, bool repaint=false)
int autoIncrementedColumn ()
void reload ()
KexiTableItemat (uint index)
virtual uint count () const
bool isEmpty () const
KexiTableItemfirst ()
KexiTableItemlast ()
int findRef (const KexiTableItem *item)
void sort ()
bool removeFirst ()
bool removeLast ()
void append (const KexiTableItem *item)
void prepend (const KexiTableItem *item)
Iterator iterator ()
IteratorcreateIterator ()
bool containsROWIDInfo () const
KexiTableItemcreateItem () const

Public Attributes

KexiTableViewColumn::List columns

Protected Member Functions

void init ()
void init (const QValueList< QVariant > &keys, const QValueList< QVariant > &values, KexiDB::Field::Type keyType, KexiDB::Field::Type valueType)
virtual int compareItems (Item item1, Item item2)
int cmpStr (Item item1, Item item2)
int cmpInt (Item item1, Item item2)
int cmpUInt (Item item1, Item item2)
int cmpLongLong (Item item1, Item item2)
int cmpULongLong (Item item1, Item item2)
int cmpDouble (Item item1, Item item2)
int cmpDate (Item item1, Item item2)
int cmpDateTime (Item item1, Item item2)
int cmpTime (Item item1, Item item2)
int cmpBLOB (Item item1, Item item2)
bool saveRow (KexiTableItem &item, bool insert, bool repaint)

Protected Attributes

int m_sortedColumn
int m_realSortedColumn
short m_order
short m_type
int m_itemSize
KexiDB::RowEditBufferm_pRowEditBuffer
QGuardedPtr< KexiDB::Cursorm_cursor
KexiDB::ResultInfo m_result
uint m_visibleColumnsCount
QValueVector< int > m_visibleColumnsIDs
QValueVector< int > m_globalColumnsIDs
bool m_readOnly: 1
bool m_insertingEnabled: 1
bool m_inside_acceptEditor: 1
bool m_containsROWIDInfo: 1
int m_autoIncrementedColumn
int(KexiTableViewData::* cmpFunc )(void *, void *)
QVariant m_leftTmp
QVariant m_rightTmp

Static Protected Attributes

static unsigned short charTable []

Constructor & Destructor Documentation

KexiTableViewData::KexiTableViewData (  ) 

not db-aware version

Definition at line 229 of file kexitableviewdata.cpp.

KexiTableViewData::KexiTableViewData ( KexiDB::Cursor c  ) 

db-aware version

Definition at line 237 of file kexitableviewdata.cpp.

KexiTableViewData::KexiTableViewData ( const QValueList< QVariant > &  keys,
const QValueList< QVariant > &  values,
KexiDB::Field::Type  keyType = KexiDB::Field::Text,
KexiDB::Field::Type  valueType = KexiDB::Field::Text 
)

Defines two-column table usually used with comboboxes. First column is invisible and contains key values. Second column and contains user-visible value.

Parameters:
keys a list of keys
values a list of text values (must be of the same length as keys list)
keyType a type for keys
valueType a type for values

Definition at line 274 of file kexitableviewdata.cpp.

KexiTableViewData::KexiTableViewData ( KexiDB::Field::Type  keyType,
KexiDB::Field::Type  valueType 
)

Like above constructor, but keys and values are not provided. You can do this later by calling append(KexiTableItem*) method. (KexiTableItem object must have exactly two columns)

Definition at line 283 of file kexitableviewdata.cpp.


Member Function Documentation

void KexiTableViewData::preloadAllRows (  ) 

Preloads all rows provided by cursor (only for db-aware version).

Todo:
change to bool and return false on error!

Definition at line 851 of file kexitableviewdata.cpp.

void KexiTableViewData::setSorting ( int  column,
bool  ascending = true 
)

Sets sorting for column. If column is -1, sorting is disabled.

TODO allow users to define BLOB sorting function?

Definition at line 386 of file kexitableviewdata.cpp.

int KexiTableViewData::sortedColumn (  )  const [inline]

Returns:
the column number by which the data is sorted, or -1 if sorting is disabled. In this case sortingOrder() will return 0. Initial sorted column number for data after instantiating object is -1.

Definition at line 268 of file kexitableviewdata.h.

int KexiTableViewData::sortingOrder (  )  const [inline]

Returns:
1 if ascending sort order is set, -1 id descending sort order is set, or 0 if no sorting is set. This is independent of whether data is sorted now. Initial sorting for data after instantiating object is 0.

Definition at line 273 of file kexitableviewdata.h.

void KexiTableViewData::addColumn ( KexiTableViewColumn col  ) 

Adds column col. Warning: col will be owned by this object, and deleted on its destruction.

Definition at line 351 of file kexitableviewdata.cpp.

bool KexiTableViewData::isDBAware (  )  [inline]

Returns:
true if this db-aware data set.

Definition at line 284 of file kexitableviewdata.h.

QString KexiTableViewData::dbTableName (  )  const

For db-aware data set only: table name is returned; equivalent to cursor()->query()->parentTable()->name().

Definition at line 379 of file kexitableviewdata.cpp.

bool KexiTableViewData::isReadOnly (  )  const [virtual]

Returns:
true if data is not editable. Can be set using setReadOnly() but it's still true if database cursor returned by cursor() is not 0 and has read-only connection.

Definition at line 871 of file kexitableviewdata.cpp.

void KexiTableViewData::setReadOnly ( bool  set  )  [virtual]

Sets readOnly flag for this data. If set is true, insertingEnabled flag will be cleared automatically.

See also:
isInsertingEnabled()

Definition at line 543 of file kexitableviewdata.cpp.

virtual bool KexiTableViewData::isInsertingEnabled (  )  const [inline, virtual]

Returns:
true if data inserting is enabled (the default).

Definition at line 310 of file kexitableviewdata.h.

void KexiTableViewData::setInsertingEnabled ( bool  set  )  [virtual]

Sets insertingEnabled flag. If true, empty row is available If set is true, read-only flag will be cleared automatically.

See also:
setReadOnly()

Definition at line 552 of file kexitableviewdata.cpp.

void KexiTableViewData::clearRowEditBuffer (  ) 

Clears and initializes internal row edit buffer for incoming editing. Creates buffer using KexiDB::RowEditBuffer(false) (false means not db-aware type) if our data is not db-aware, or db-aware buffer if data is db-aware (isDBAware()==true).

See also:
KexiDB::RowEditBuffer

Definition at line 561 of file kexitableviewdata.cpp.

bool KexiTableViewData::updateRowEditBufferRef ( KexiTableItem item,
int  colnum,
KexiTableViewColumn col,
QVariant &  newval,
bool  allowSignals = true,
QVariant *  visibleValueForLookupField = 0 
)

Updates internal row edit buffer: currently edited column col (number colnum) has now assigned new value of newval. Uses column's caption to address the column in buffer if the buffer is of simple type, or db-aware buffer if (isDBAware()==true). (then fields are addressed with KexiDB::Field, instead of caption strings). If allowSignals is true (the default), aboutToChangeCell() signal is emitted. visibleValueForLookupField allows to pass visible value (usually a text) for a lookup field (only reasonable if col->visibleLookupColumnInfo != 0). Note that newval may be changed in aboutToChangeCell() signal handler.

See also:
KexiDB::RowEditBuffer

Definition at line 570 of file kexitableviewdata.cpp.

bool KexiTableViewData::updateRowEditBuffer ( KexiTableItem item,
int  colnum,
KexiTableViewColumn col,
QVariant  newval,
bool  allowSignals = true 
) [inline]

Added for convenience. Like above but newval is passed by value.

Definition at line 340 of file kexitableviewdata.h.

bool KexiTableViewData::updateRowEditBuffer ( KexiTableItem item,
int  colnum,
QVariant  newval,
bool  allowSignals = true 
) [inline]

Added for convenience. Like above but it's assumed that item item's columns are ordered like in table view, not like in form view. Don't use this with form views.

Definition at line 349 of file kexitableviewdata.h.

KexiDB::ResultInfo* KexiTableViewData::result (  )  [inline]

Returns:
last operation's result information (always not null).

Definition at line 359 of file kexitableviewdata.h.

void KexiTableViewData::deleteRows ( const QValueList< int > &  rowsToDelete,
bool  repaint = false 
)

Deletes rows (by number) passed with rowsToDelete. Currently, this method is only for non data-aware tables.

Definition at line 777 of file kexitableviewdata.cpp.

bool KexiTableViewData::deleteAllRows ( bool  repaint = false  )  [virtual]

Deletes all rows. Works either for db-aware and non db-aware tables. Column's definition is not changed. For db-aware version, all rows are removed from a database. Row-edit buffer is cleared.

If repaint is true, reloadRequested() signal is emitted after deleting (if at least one row was deleted), so presenters can repaint their contents.

Returns:
true on success.

Definition at line 820 of file kexitableviewdata.cpp.

void KexiTableViewData::insertRow ( KexiTableItem item,
uint  index,
bool  repaint = false 
)

Inserts new item at index index. item will be owned by this data object. Note: Reasonable only for not not-db-aware version.

Definition at line 797 of file kexitableviewdata.cpp.

int KexiTableViewData::autoIncrementedColumn (  ) 

Todo:
what about multiple autoinc columns?

what about changing column order?

Definition at line 835 of file kexitableviewdata.cpp.

void KexiTableViewData::reload (  )  [inline]

Emits reloadRequested() signal to reload presenters.

Definition at line 403 of file kexitableviewdata.h.

bool KexiTableViewData::containsROWIDInfo (  )  const [inline]

Returns:
true if ROWID information is stored within every row. Only reasonable for db-aware version. ROWID information is available if DriverBehaviour::ROW_ID_FIELD_RETURNS_LAST_AUTOINCREMENTED_VALUE == false for a KexiDB database driver and a table has no primary key defined. Phisically, ROWID information is stored after last KexiTableItem's element, so every KexiTableItem's length is expanded by one.

Definition at line 425 of file kexitableviewdata.h.

void KexiTableViewData::aboutToChangeCell ( KexiTableItem item,
int  colnum,
QVariant &  newValue,
KexiDB::ResultInfo result 
) [signal]

Emitted before change of the single, currently edited cell. Connect this signal to your slot and set result->success to false to disallow this change. You can also change newValue to other value, or change other columns in item row.

void KexiTableViewData::aboutToInsertRow ( KexiTableItem item,
KexiDB::ResultInfo result,
bool  repaint 
) [signal]

Emited before inserting of a new, current row. Connect this signal to your slot and set result->success to false to disallow this inserting. You can also change columns in item row.

void KexiTableViewData::aboutToUpdateRow ( KexiTableItem item,
KexiDB::RowEditBuffer buffer,
KexiDB::ResultInfo result 
) [signal]

Emited before changing of an edited, current row. Connect this signal to your slot and set result->success to false to disallow this change. You can also change columns in item row.

void KexiTableViewData::rowUpdated ( KexiTableItem  )  [signal]

Current row has been updated.

void KexiTableViewData::rowInserted ( KexiTableItem ,
bool  repaint 
) [signal]

A row has been inserted.

void KexiTableViewData::rowInserted ( KexiTableItem ,
uint  index,
bool  repaint 
) [signal]

A row has been inserted at index position (not db-aware data only).

void KexiTableViewData::aboutToDeleteRow ( KexiTableItem item,
KexiDB::ResultInfo result,
bool  repaint 
) [signal]

Emited before deleting of a current row. Connect this signal to your slot and set result->success to false to disallow this deleting.

void KexiTableViewData::rowDeleted (  )  [signal]

Current row has been deleted.

void KexiTableViewData::rowsDeleted ( const QValueList< int > &  rowsToDelete  )  [signal]

Rows have been deleted.

void KexiTableViewData::reloadRequested (  )  [signal]

Displayed data needs to be reloaded in all presenters.

int KexiTableViewData::cmpBLOB ( Item  item1,
Item  item2 
) [protected]

Compare function for BLOB data (QByteArray). Uses size as the weight.

Definition at line 537 of file kexitableviewdata.cpp.

bool KexiTableViewData::saveRow ( KexiTableItem item,
bool  insert,
bool  repaint 
) [protected]

internal: for saveRowChanges() and saveNewRow()

Todo:
if there're multiple views for this data, we need multiple buffers!

Todo:
set m_result.column if possible

Definition at line 628 of file kexitableviewdata.cpp.


Member Data Documentation

Columns information

Definition at line 297 of file kexitableviewdata.h.

(logical) sorted column number, set by setSorting() can differ from m_realSortedColumn if there's lookup column used

Definition at line 503 of file kexitableviewdata.h.

real sorted column number, set by setSorting(), used by cmp*() methods

Definition at line 505 of file kexitableviewdata.h.

used to faster lookup columns of simple type (not dbaware)

Definition at line 516 of file kexitableviewdata.h.

Used in acceptEditor() to avoid infinite recursion, eg. when we're calling acceptRowEdit() during cell accepting phase.

Definition at line 526 of file kexitableviewdata.h.

See also:
containsROWIDInfo()

Definition at line 529 of file kexitableviewdata.h.

QVariant KexiTableViewData::m_leftTmp [protected]

Temporary, used in compare functions like cmpInt(), cmpString() to avoid memory allocations.

Definition at line 537 of file kexitableviewdata.h.


The documentation for this class was generated from the following files:
KDE Home | KDE Accessibility Home | Description of Access Keys