diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-08-09 17:12:14 +0200 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2020-08-09 17:12:14 +0200 |
commit | 0afe9ca6bf53da111e445d2aea7cfc94e7e3c601 (patch) | |
tree | dba69d8eb86e81a1a56a388eafa85817762cf87f /tagscene.cpp | |
parent | 872bb95acf6fabd639da57cd41a4844d7e6dd0f0 (diff) | |
download | numberator-0afe9ca6bf53da111e445d2aea7cfc94e7e3c601.tar.gz numberator-0afe9ca6bf53da111e445d2aea7cfc94e7e3c601.tar.bz2 numberator-0afe9ca6bf53da111e445d2aea7cfc94e7e3c601.zip |
db backend: mostly feature-complete
Diffstat (limited to 'tagscene.cpp')
-rw-r--r-- | tagscene.cpp | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/tagscene.cpp b/tagscene.cpp index 5b028a0..fb52574 100644 --- a/tagscene.cpp +++ b/tagscene.cpp @@ -1,6 +1,81 @@ #include "tagscene.h" -TagScene::TagScene() +#include <QGraphicsSceneMouseEvent> + +TagScene::TagScene(SQLiteSaveFile &proj) + : proj(proj) +{ + reloadPicture(); + reloadTags(); + + connect(&proj, &SQLiteSaveFile::tagChange, this, &TagScene::tagChanged); + connect(&proj, &SQLiteSaveFile::fileReload, + [=]() { reloadTags(); }); +} + +void TagScene::tagChanged(TagChange change, const Tag &tag) +{ + TagItem *it; + + switch(change) + { + case TagChange::CREATED: + addTag(tag); + break; + + case TagChange::DELETED: + it = tags.take(tag.id); + assert(it); + removeItem(it); + break; + + case TagChange::CHANGED: + it = tags[tag.id]; + assert(it); + + it->tagUpdated(tag); + break; + } +} + +void TagScene::reloadPicture() +{ + pix.loadFromData(proj.getImage()); + if (pix_it) + removeItem(pix_it); + pix_it = new QGraphicsPixmapItem(pix); + addItem(pix_it); +} + +void TagScene::addTag(const Tag tag) { + TagItem *it = new TagItem(tag); + addItem(it); + tags[tag.id] = it; +} + +void TagScene::reloadTags() { + clear(); + for (auto *it : tags.values()) { + delete it; + } + + for (const Tag &tag : proj.getAllTags()) { + addTag(tag); + } +} + +void TagScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + QGraphicsItem *it = itemAt(event->scenePos(), QTransform()); + if (!it) { + QGraphicsScene::mouseDoubleClickEvent(event); + } + + TagItem *tagitem = qgraphicsitem_cast<TagItem *>(it); + if (!tagitem) { + QGraphicsScene::mouseDoubleClickEvent(event); + } + tagDoubleClicked(tagitem->tag()); } |