summaryrefslogtreecommitdiff
path: root/sqlitebackend.h
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-08-09 17:12:14 +0200
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-08-09 17:12:14 +0200
commit0afe9ca6bf53da111e445d2aea7cfc94e7e3c601 (patch)
treedba69d8eb86e81a1a56a388eafa85817762cf87f /sqlitebackend.h
parent872bb95acf6fabd639da57cd41a4844d7e6dd0f0 (diff)
downloadnumberator-0afe9ca6bf53da111e445d2aea7cfc94e7e3c601.tar.gz
numberator-0afe9ca6bf53da111e445d2aea7cfc94e7e3c601.tar.bz2
numberator-0afe9ca6bf53da111e445d2aea7cfc94e7e3c601.zip
db backend: mostly feature-complete
Diffstat (limited to 'sqlitebackend.h')
-rw-r--r--sqlitebackend.h65
1 files changed, 40 insertions, 25 deletions
diff --git a/sqlitebackend.h b/sqlitebackend.h
index 4dfd2f9..52faedc 100644
--- a/sqlitebackend.h
+++ b/sqlitebackend.h
@@ -16,86 +16,101 @@ enum TagChange {
class Tag
{
public:
+ Tag() : valid(false) {}
Tag(long long int id, QString name, qreal anchor_x, qreal anchor_y, QByteArray metadata);
- Tag();
Tag(long long int id, const Tag &other);
+ bool isValid() { return valid; }
+
long long int id;
QString name;
QPointF anchor;
QVariantMap metadata;
+
+private:
+ bool valid;
};
class SQLiteSaveFile : public QObject
{
Q_OBJECT
public:
- explicit SQLiteSaveFile(QObject *parent = nullptr, QString filename = ":memory:");
- bool connect();
- bool isOpen() { return m_isOpen; }
+ explicit SQLiteSaveFile(QObject *parent = nullptr);
QList<Tag> getAllTags();
- QByteArray getImage();
+ const QByteArray &getImage() const { return m_image; };
bool updateTag(Tag tag);
bool deleteTag(Tag tag);
bool createTag(Tag tag);
+ bool isMemory() { return m_memory; } /* backend db points to temporary memory db */
+ bool isDirty() { return m_dirty; } /* backend db was changed since opening */
+ bool isOpen() { return m_open; } /* backend db is open */
+
bool setMeta(const QString &key, const QVariant &value);
bool setMeta(std::initializer_list<QPair<QString, QVariant>> metas);
- QVariant getMeta(const QString &key);
+ const QVariant getMeta(const QString &key) const;
- QString errorString() { return lastErrorString; }
+ const QString &errorString() const { return m_lastErrorString; }
enum Error {
NoError = 0,
+ FileNotFoundError,
SQLiteError,
ImageOpenError,
- ImageReadError
+ ImageReadError,
+ MaxError
};
- inline const static QString errorNames[] = {
+ inline const static QString errorNames[MaxError] = {
[NoError] = "No Error",
+ [FileNotFoundError] = "File not found",
[SQLiteError] = "Database Error",
[ImageOpenError] = "Error Opening Image",
[ImageReadError] = "Error Reading Image"
};
Error error();
- void resetError() { lastError = NoError; lastErrorString = QString(); }
+ void resetError() const { m_lastError = NoError; m_lastErrorString = QString(); }
public slots:
/** Save this project file under a new name. This changes the backend database this project file object points to, and copies all data.
* Callers can continue to use the same project file object afterwards.
*/
bool saveAs(const QString &filename);
+ bool open(const QString &filename);
bool reloadImageFromDisk();
- bool loadImageFromDisk(const QString &filename);
+ bool loadImageFromDisk(const QString &m_filename);
bool clearNew();
signals:
void tagChange(TagChange change, const Tag &tag);
void fileReload();
- void fileIOError(Error e, QString errorName, QString description);
+ void fileIOError(Error e, QString errorName, QString description) const;
private:
+ bool connect();
bool initDb(bool setCreationDate=true);
bool runSql(QString query, std::initializer_list<QVariant> bindings={});
bool setMetaLocked(const QString &key, const QVariant &value);
bool setMetaLocked(std::initializer_list<QPair<QString, QVariant>> metas);
- QVariant getMetaLocked(const QString &key);
-
- void setError(Error e, QString desc) { lastError = e; lastErrorString = desc; fileIOError(e, errorNames[e], desc); }
- bool setDatabaseError(const QSqlQuery &q);
- bool setDatabaseError(const QSqlDatabase &db);
-
- Error lastError;
- QString lastErrorString;
- QSqlDatabase db;
- QMutex dbMut;
- QString filename;
- QByteArray imageData;
- bool m_isOpen;
+ const QVariant getMetaLocked(const QString &key) const;
+
+ void setError(Error e, QString desc) const { m_lastError = e; m_lastErrorString = desc; fileIOError(e, errorNames[e], desc); }
+ bool setDatabaseError(const QSqlQuery &q) const;
+ bool setDatabaseError(const QSqlDatabase &m_db) const;
+
+ mutable Error m_lastError;
+ mutable QString m_lastErrorString;
+ QSqlDatabase m_db;
+ mutable QMutex m_dbMut;
+ QString m_filename;
+ QByteArray m_image;
+
+ bool m_open;
+ bool m_dirty;
+ bool m_memory;
};