#include <digestdbmodel.h>
Inheritance diagram for DigestDbModel:

Public Member Functions | |
| DigestDbModel (const QSqlDatabase &database, QObject *parent=0) | |
| DigestDbController * | digestDbController () const |
| virtual const QByteArray & | key () const |
| virtual MvcModuleId_t | moduleId () const |
| const QSqlDatabase & | database () const |
| QHash< int, QString > | fetchClasses () const |
| QString | fetchClassLabel (int id) const |
| bool | classLabelExists (const QString &label) const |
| const IdSet & | lastInsertedClassIdSet () const |
| QHash< int, QString > | fetchCollections () const |
| QString | fetchCollectionLabel (int id) const |
| bool | collectionLabelExists (const QString &label) const |
| const IdSet & | lastInsertedCollectionIdSet () const |
| QHash< int, QString > | fetchExperimentsBasic () const |
| QString | fetchExperimentLabel (int id) const |
| DExperimentRecord | fetchExperiment (int id, bool *ok=0) const |
| const IdSet & | lastInsertedExperimentIdSet () const |
| int | gestureCount () const |
| DGestureRecord | fetchGesture (int id, bool *ok=0) const |
| const IdSet & | lastInsertedGestureIdSet () const |
| QHash< int, QString > | fetchTrainedRecogsBasic () const |
| QString | fetchTrainedRecogLabel (int id) const |
| DTrainedRecogRecord | fetchTrainedRecog (int id, bool *ok=0) const |
| const IdSet & | lastInsertedTrainedRecogIdSet () const |
| QString | classesToString (const QSet< int > &classes, const QString &joinSep=QString(", ")) const |
| QString | collectionsToString (const QSet< int > &collections, const QString &joinSep=QString(", ")) const |
Static Public Member Functions | |
| static const QByteArray & | classKey () |
| static MvcModuleId_t | classModuleId () |
| static bool | createTables (const QSqlDatabase &db) |
| static QString | idSetToString (const IdSet &idSet) |
Protected Member Functions | |
| virtual void | prepareQueries (const QSqlDatabase &db) |
| virtual void | customEvent (QEvent *e) |
| virtual void | dispatchEvent (MEvent *) |
| virtual void | changeControllerEvent (MChangeControllerEvent *event) |
| virtual void | classAddEvent (MClassAddEvent *) |
| virtual void | classUpdateEvent (MClassUpdateEvent *) |
| virtual void | classesRemoveEvent (MClassesRemoveEvent *) |
| virtual void | collectionAddEvent (MCollectionAddEvent *) |
| virtual void | collectionUpdateEvent (MCollectionUpdateEvent *) |
| virtual void | collectionsRemoveEvent (MCollectionsRemoveEvent *) |
| virtual void | experimentAddEvent (MExperimentAddEvent *) |
| virtual void | experimentUpdateEvent (MExperimentUpdateEvent *) |
| virtual void | experimentsRemoveEvent (MExperimentsRemoveEvent *) |
| virtual void | gestureAddEvent (MGestureAddEvent *) |
| virtual void | gestureUpdateEvent (MGestureUpdateEvent *) |
| virtual void | gesturesChangeClassesEvent (MGesturesChangeClassesEvent *) |
| virtual void | gesturesChangeCollectionsEvent (MGesturesChangeCollectionsEvent *) |
| virtual void | gesturesRemoveEvent (MGesturesRemoveEvent *) |
| virtual void | trainedRecogAddEvent (MTrainedRecogAddEvent *) |
| virtual void | trainedRecogUpdateEvent (MTrainedRecogUpdateEvent *) |
| virtual void | trainedRecogsRemoveEvent (MTrainedRecogsRemoveEvent *) |
| virtual bool | gesturesChangeCategories (const QString &table, const QString &categoryColumn, const IdSet &idSet, const IdSet &addSet, const IdSet &removeSet) |
| virtual bool | removeFromTable (const QString &table, const QString &idColumn, const IdSet &idSet) |
| void | handleDbError () |
The methods of this class have been separated from the QSqlDatabase class, as to provide the performance benifits (e.g. preparing QSqlQuery objects with value binding), while at the same time allowing for thread-safe access to the database (but not to a single DbAccessor instance).
Hence, each instance of DbAccessor has its own prepared QSqlQuery objects, allowing the different instances to be accessed simultaneously by different threads (in comparison to having the QSqlQuery objects static within QSqlDatabase) in a safe manner.
As for caching of gestures (to improve read performance), it should actually be better to have different caches for different callers. Different callers will most likely need to access different gestures and do so in a different way (e.g. read one every so often or read a large list of them, one after the other). For example, the cache used by the gesture browser should clearly not be interfered with by an implementation of an AbstractRecogniserTrainer.
Finally, other than in the constructor, it's not worth having a "setter" for the specific QSqlDatabase to use, as all of the members variables would need to be re-initialised (QSqlQuery objects and caches). Hence, if you need to change the database, simply re-create the DbAccessor object.
| DigestDbModel::DigestDbModel | ( | const QSqlDatabase & | database, | |
| QObject * | parent = 0 | |||
| ) |
| DigestDbController * DigestDbModel::digestDbController | ( | ) | const |
Convenience method.
Returns a cached guarded pointer that has been dynamically cast to DigestDbController* from AbstractController*.
See also AbstractModel::controller().
| static const QByteArray& DigestDbModel::classKey | ( | ) | [inline, static] |
| virtual const QByteArray& DigestDbModel::key | ( | ) | const [inline, virtual] |
| static MvcModuleId_t DigestDbModel::classModuleId | ( | ) | [inline, static] |
Returns MvcDigestDb::id().
Reimplemented from MvcBase.
| virtual MvcModuleId_t DigestDbModel::moduleId | ( | ) | const [inline, virtual] |
Returns classModuleId().
Reimplemented from MvcBase.
| const QSqlDatabase& DigestDbModel::database | ( | ) | const [inline] |
| bool DigestDbModel::createTables | ( | const QSqlDatabase & | db | ) | [static] |
| QHash< int, QString > DigestDbModel::fetchClasses | ( | ) | const |
| QString DigestDbModel::fetchClassLabel | ( | int | id | ) | const |
| bool DigestDbModel::classLabelExists | ( | const QString & | label | ) | const |
| const IdSet& DigestDbModel::lastInsertedClassIdSet | ( | ) | const [inline] |
| QHash< int, QString > DigestDbModel::fetchCollections | ( | ) | const |
| QString DigestDbModel::fetchCollectionLabel | ( | int | id | ) | const |
| bool DigestDbModel::collectionLabelExists | ( | const QString & | label | ) | const |
| const IdSet& DigestDbModel::lastInsertedCollectionIdSet | ( | ) | const [inline] |
| QHash< int, QString > DigestDbModel::fetchExperimentsBasic | ( | ) | const |
| QString DigestDbModel::fetchExperimentLabel | ( | int | id | ) | const |
| DExperimentRecord DigestDbModel::fetchExperiment | ( | int | id, | |
| bool * | ok = 0 | |||
| ) | const |
| const IdSet& DigestDbModel::lastInsertedExperimentIdSet | ( | ) | const [inline] |
| int DigestDbModel::gestureCount | ( | ) | const |
Returns the number of gestures in the database.
Returns -1 if there was an error.
| DGestureRecord DigestDbModel::fetchGesture | ( | int | id, | |
| bool * | ok = 0 | |||
| ) | const |
Fetches the first gesture from the "Gesture" table that has the given ID.
Only returning the first match sould not be a problem, given that the ID should be unique anyway.
If a gesture with the given ID could not be found or if there was some other error, then "ok" will be set to false, otherwise it will be set to true. If a null pointer is passed for "ok", then it will not attempt to set it.
| const IdSet& DigestDbModel::lastInsertedGestureIdSet | ( | ) | const [inline] |
| QHash< int, QString > DigestDbModel::fetchTrainedRecogsBasic | ( | ) | const |
| QString DigestDbModel::fetchTrainedRecogLabel | ( | int | id | ) | const |
| DTrainedRecogRecord DigestDbModel::fetchTrainedRecog | ( | int | id, | |
| bool * | ok = 0 | |||
| ) | const |
| const IdSet& DigestDbModel::lastInsertedTrainedRecogIdSet | ( | ) | const [inline] |
| QString DigestDbModel::classesToString | ( | const QSet< int > & | classes, | |
| const QString & | joinSep = QString(", ") | |||
| ) | const |
Unlike idSetToString(), this method fetches the actual labels of the classes and also sorts them.
This method was designed to be used for presentation purposes.
| QString DigestDbModel::collectionsToString | ( | const QSet< int > & | collections, | |
| const QString & | joinSep = QString(", ") | |||
| ) | const |
Unlike idSetToString(), this method fetches the actual labels of the collections and also sorts them.
This method was designed to be used for presentation purposes.
| QString DigestDbModel::idSetToString | ( | const IdSet & | idSet | ) | [static] |
Unlike classesToString() and collectionsToString(), this method does not fetch the labels of the IDs, it simply takes a set like [4,5,7,8] and returns a string like "4,5,7,8" (with the commas).
This method was designed to be used when building SQL queries.
| void DigestDbModel::prepareQueries | ( | const QSqlDatabase & | db | ) | [protected, virtual] |
| virtual void DigestDbModel::customEvent | ( | QEvent * | e | ) | [inline, protected, virtual] |
| void DigestDbModel::dispatchEvent | ( | MEvent * | event | ) | [protected, virtual] |
The model's event dispatcher.
Asserts that the event is non-null.
Warning! It is assumed that the events have their correct type set (as it uses static casts).
Reimplemented from AbstractModel.
| void DigestDbModel::changeControllerEvent | ( | MChangeControllerEvent * | event | ) | [protected, virtual] |
Re-implemented, as to also have the pointer returned by digestDbController() updated.
Asserts that the event is non-null.
Reimplemented from AbstractModel.
| void DigestDbModel::classAddEvent | ( | MClassAddEvent * | ) | [protected, virtual] |
| void DigestDbModel::classUpdateEvent | ( | MClassUpdateEvent * | ) | [protected, virtual] |
| void DigestDbModel::classesRemoveEvent | ( | MClassesRemoveEvent * | ) | [protected, virtual] |
| void DigestDbModel::collectionAddEvent | ( | MCollectionAddEvent * | ) | [protected, virtual] |
| void DigestDbModel::collectionUpdateEvent | ( | MCollectionUpdateEvent * | ) | [protected, virtual] |
| void DigestDbModel::collectionsRemoveEvent | ( | MCollectionsRemoveEvent * | ) | [protected, virtual] |
| void DigestDbModel::experimentAddEvent | ( | MExperimentAddEvent * | ) | [protected, virtual] |
| void DigestDbModel::experimentUpdateEvent | ( | MExperimentUpdateEvent * | ) | [protected, virtual] |
| void DigestDbModel::experimentsRemoveEvent | ( | MExperimentsRemoveEvent * | ) | [protected, virtual] |
| void DigestDbModel::gestureAddEvent | ( | MGestureAddEvent * | event | ) | [protected, virtual] |
Inserts the gesture into the SQL database.
The ID in the given DGestureRecord is ignored, as it's generated by the DB backend.
Asserts that the event is non-null.
| void DigestDbModel::gestureUpdateEvent | ( | MGestureUpdateEvent * | ) | [protected, virtual] |
| void DigestDbModel::gesturesChangeClassesEvent | ( | MGesturesChangeClassesEvent * | ev | ) | [protected, virtual] |
Note: If an ID appears in both CGesturesChangeClassesEvent::addSet() and CGesturesChangeClassesEvent::removeSet(), then the the ID will be in the final classes set, as it will first be removed and then immediately added back.
Asserts that the event is non-null.
| void DigestDbModel::gesturesChangeCollectionsEvent | ( | MGesturesChangeCollectionsEvent * | ev | ) | [protected, virtual] |
Note: If an ID appears in both CGesturesChangeCollectionsEvent::addSet() and CGesturesChangeCollectionsEvent::removeSet(), then the the ID will be in the final collections set, as it will first be removed and then immediately added back.
Asserts that the event is non-null.
| void DigestDbModel::gesturesRemoveEvent | ( | MGesturesRemoveEvent * | ) | [protected, virtual] |
| void DigestDbModel::trainedRecogAddEvent | ( | MTrainedRecogAddEvent * | ) | [protected, virtual] |
| void DigestDbModel::trainedRecogUpdateEvent | ( | MTrainedRecogUpdateEvent * | ) | [protected, virtual] |
| void DigestDbModel::trainedRecogsRemoveEvent | ( | MTrainedRecogsRemoveEvent * | ) | [protected, virtual] |
| bool DigestDbModel::gesturesChangeCategories | ( | const QString & | table, | |
| const QString & | categoryColumn, | |||
| const IdSet & | idSet, | |||
| const IdSet & | addSet, | |||
| const IdSet & | removeSet | |||
| ) | [protected, virtual] |
Note: If an ID appears in both addSet and removeSet, then the the ID will will be in the final category set, as it will first be removed and then immediately added back.
| bool DigestDbModel::removeFromTable | ( | const QString & | table, | |
| const QString & | idColumn, | |||
| const IdSet & | idSet | |||
| ) | [protected, virtual] |
| void DigestDbModel::handleDbError | ( | ) | [protected] |
1.5.2