#include <kexiblobbuffer.h>
Inherits TQObject.
Classes | |
| class | Handle |
Public Types | |
| typedef long | Id_t |
Public Member Functions | |
| Handle | insertPixmap (const KURL &url) |
| Handle | insertObject (const TQByteArray &data, const TQString &name, const TQString &caption, const TQString &mimeType, Id_t identifier=0) |
| Handle | insertPixmap (const TQPixmap &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 |
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...
Use this class by acessing to its singleton: KexiBLOBBuffer::self().
This class is used for buffering BLOB data, to avoid duplicating object's data in memory and a need for loading (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 needs 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 framework 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 TQByteArray 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.
Member Typedef Documentation
◆ Id_t
| typedef long KexiBLOBBuffer::Id_t |
long integer for unique identifying blobs
Definition at line 89 of file kexiblobbuffer.h.
Constructor & Destructor Documentation
◆ KexiBLOBBuffer()
| KexiBLOBBuffer::KexiBLOBBuffer | ( | ) |
Definition at line 173 of file kexiblobbuffer.cpp.
◆ ~KexiBLOBBuffer()
| KexiBLOBBuffer::~KexiBLOBBuffer | ( | ) |
Definition at line 182 of file kexiblobbuffer.cpp.
Member Function Documentation
◆ insertItem()
|
protected |
Inserts an object for a given id into the buffer.
Definition at line 351 of file kexiblobbuffer.cpp.
◆ insertObject()
| KexiBLOBBuffer::Handle KexiBLOBBuffer::insertObject | ( | const TQByteArray & | data, |
| const TQString & | name, | ||
| const TQString & | caption, | ||
| const TQString & | mimeType, | ||
| KexiBLOBBuffer::Id_t | identifier = 0 |
||
| ) |
Inserts a new BLOB data.
- Parameters
-
data The data for BLOB object. name The name for the object, usually a file name or empty caption The more friendly than name, can be based on file name or empty or defined by a user (this case is not yet used) mimeType The mimeType for the object for easier and mor accurate decoding. identifier Object's identifier. If positive, the "stored" flag for the data will be set to true with identifer, otherwise (the default) the BLOB data will have "stored" flag set to false, and a new temporary identifier will be assigned.
Definition at line 226 of file kexiblobbuffer.cpp.
◆ insertPixmap() [1/2]
| KexiBLOBBuffer::Handle KexiBLOBBuffer::insertPixmap | ( | const KURL & | url | ) |
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.
- Returns
- handle to the pixmap data or a null handle if such pixmap could not be loaded.
- Todo:
- what about searching by filename only and then compare data?
- Todo:
- download the file if remote, then set fileName properly
- Todo:
- err msg
- Todo:
- err msg
stored
Definition at line 187 of file kexiblobbuffer.cpp.
◆ insertPixmap() [2/2]
| KexiBLOBBuffer::Handle KexiBLOBBuffer::insertPixmap | ( | const TQPixmap & | pixmap | ) |
Inserts a new pixmap available in memory, e.g. coming from clipboard.
<
- Todo:
- OK? What about jpegs?
Definition at line 240 of file kexiblobbuffer.cpp.
◆ objectForId() [1/2]
| KexiBLOBBuffer::Handle KexiBLOBBuffer::objectForId | ( | Id_t | id | ) |
- Returns
- an object for a given id. First, unstored object is checked, then unstored, if stored was not found.
stored
Definition at line 320 of file kexiblobbuffer.cpp.
◆ objectForId() [2/2]
| KexiBLOBBuffer::Handle KexiBLOBBuffer::objectForId | ( | Id_t | id, |
| bool | stored | ||
| ) |
- Returns
- an object for a given id. If stored is true, stored BLOBs buffer is browsed, otherwise unstored (in memory) BLOBs buffer is browsed. If no object is cached for this id, null handle is returned.
- Todo:
- err msg
- Todo:
- use PreparedStatement
- Todo:
- err msg
Definition at line 259 of file kexiblobbuffer.cpp.
◆ removeItem()
|
protected |
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.
◆ self()
|
static |
Access to KexiBLOBBuffer singleton.
Definition at line 365 of file kexiblobbuffer.cpp.
◆ setConnection()
|
static |
Definition at line 360 of file kexiblobbuffer.cpp.
◆ takeItem()
|
protected |
Takes an object for a item out of the buffer.
Definition at line 342 of file kexiblobbuffer.cpp.
Friends And Related Symbol Documentation
◆ Handle
|
friend |
Definition at line 220 of file kexiblobbuffer.h.
The documentation for this class was generated from the following files:
