kexi
KexiBLOBBuffer Class Reference
#include <kexiblobbuffer.h>
Detailed Description
Application-wide buffer for local BLOB data like pixmaps.For now only pixmaps are supported
- Todo:
- support any KPart-compatible objects and more...
This class is used for buffering BLOB data, to avoid duplicating object's data in memory and a need for loding (decoding) the same object many times. The data is always local, what means database storage is not employed here.
Each BLOB instance is identified by an unsigned integer number (Id_t type), uniquely generated on BLOB loading. Each BLOB can have assigned source url it has been loaded from (the url can be empty though, e.g. for data coming from clipboard).
References to KexiBLOBBuffer are counted, so when last reference is lost, data is freed and the integer identifier is no longer pointing any valid data. KexiBLOBBuffer::Handle is value-based class that describes handle based in an identifier. Objects of this class are obtained e.g. from insertPixmap() method.
There are two kinds of identifiers:
- integers assigned for BLOBs already saved to a db backend, when KexiBLOBBuffer::Handle::stored() is true
- temporary integers assigned for new BLOBs not yet saved to a db backend, when KexiBLOBBuffer::Handle::stored() is false KexiBLOBBuffer::Handle::setStoredWidthID() can be used to switch from unstored to stored state. Among others, the state has effect on saving forms: only unstored BLOBs will be saved back to the database; when a BLOB need to be removed, only it will be physically removed only if it was stored.
KexiBLOBBuffer is also useful for two more reasons:
- Property editor's item for "image" property displays a preview of pixmap contents. Without buffering, it would be needed to load pixmap data again: what if the file it is loaded from is located remote and connection is slow? Memory would be also unnecessary doubled.
- Undo/Redo frameword requires to store previous property values. Having a reference defined by a single interger, memory can be handled more effectively.
Example use cases: A large pixmap file "abc.jpg" is loaded as QByteArray once and buffered: integer identifier is returned. Then, multiple image widgets are using "abc.jpg" for displaying. Duplicating an image widget means only duplicating it's properties like position and BLOB's id: BLOB itself (data of "abc.jpg")is not duplicated. Creating a new image widget and assiging the same "abc.jpg" pixmap, means only referencing KexiBLOBBuffer using the same identifier.
Definition at line 80 of file kexiblobbuffer.h.
Public Types | |
typedef long | Id_t |
Public Member Functions | |
KexiBLOBBuffer () | |
~KexiBLOBBuffer () | |
Handle | insertPixmap (const KURL &url) |
Handle | insertObject (const QByteArray &data, const QString &name, const QString &caption, const QString &mimeType, Id_t identifier=0) |
Handle | insertPixmap (const QPixmap &pixmap) |
Handle | objectForId (Id_t id, bool stored) |
Handle | objectForId (Id_t id) |
Static Public Member Functions | |
static KexiBLOBBuffer * | self () |
static void | setConnection (KexiDB::Connection *conn) |
Protected Member Functions | |
void | removeItem (Id_t id, bool stored) |
void | takeItem (Item *item) |
void | insertItem (Item *item) |
Friends | |
class | Handle |
Classes | |
class | Handle |
Object handle used by KexiBLOBBuffer. More... |
Member Typedef Documentation
|
Definition at line 85 of file kexiblobbuffer.h. |
Member Function Documentation
|
Inserts an object for a given id into the buffer. Definition at line 351 of file kexiblobbuffer.cpp. |
|
Inserts a new BLOB data.
Definition at line 226 of file kexiblobbuffer.cpp. |
|
Inserts a new pixmap available in memory, e.g. coming from clipboard. Definition at line 240 of file kexiblobbuffer.cpp. |
|
Inserts a new pixmap loaded from a file at url. If the same file has already been loaded before, it can be found in cache and returned instantly. It is assumed that the BLOB is unstored, because it is loaded from external source, so stored() will be equal to false for returned handle.
Definition at line 187 of file kexiblobbuffer.cpp. |
|
Definition at line 320 of file kexiblobbuffer.cpp. |
|
Definition at line 259 of file kexiblobbuffer.cpp. |
|
Removes an object for a given id. If stored is true, stored BLOB is removed, otherwise unstored (in memory) BLOB is removed. Definition at line 328 of file kexiblobbuffer.cpp. |
|
Access to KexiBLOBBuffer singleton.
Definition at line 365 of file kexiblobbuffer.cpp. |
|
Takes an object for a item out of the buffer. Definition at line 342 of file kexiblobbuffer.cpp. |
The documentation for this class was generated from the following files: