Commit 2fd800bb authored by Agata Cacko's avatar Agata Cacko

Fix untagResource query in KisTagModel

Before this commit, removing a tag from a resource
would result in nothing happening. That was because of
a broken query. This commit fixes the query.
Additionally this commit ensures that the TagChooserWidget
is refreshed (the index is set once again) so it updates
automatically.
parent 41e40adf
......@@ -301,16 +301,18 @@ bool KisTagModel::untagResource(const KisTagSP tag, const KoResourceSP resource)
if (!resource->valid()) return false;
if (resource->resourceId() < 0) return false;
bool r = d->query.prepare("DELETE FROM resource_tags.id\n"
// we need to delete an entry in resource_tags
bool r = d->query.prepare("DELETE FROM resource_tags\n"
"WHERE resource_id = :resource_id\n"
"AND tag_id in (SELECT id\n"
" FROM tags where ");
"AND tag_id = :tag_id");
if (!r) {
qWarning() << "Could not prepare KisTagModel query" << d->query.lastError();
}
d->query.bindValue(":resource_type", d->resourceType);
d->query.bindValue(":resource_id", resource->resourceId());
d->query.bindValue(":tag_id", tag->id());
r = d->query.exec();
......
......@@ -299,8 +299,10 @@ void KisResourceTaggingManager::removeTagFromComboBox(const KisTagSP tag)
void KisResourceTaggingManager::removeResourceTag(KoResourceSP resource, const KisTagSP tag)
{
ENTER_FUNCTION();
int previousIndex = d->tagChooser->currentIndex();
bool success = d->tagModel->untagResource(tag, resource);
fprintf(stderr, "remove Resource tag: %d\n", success);
d->tagChooser->setCurrentIndex(previousIndex);
// QStringList tagsList = d->model->assignedTagsList(resource);
......
......@@ -157,6 +157,11 @@ void KisTagChooserWidget::setCurrentIndex(int index)
d->comboBox->setCurrentIndex(index);
}
int KisTagChooserWidget::currentIndex() const
{
return d->comboBox->currentIndex();
}
int KisTagChooserWidget::findIndexOf(KisTagSP tagName)
{
ENTER_FUNCTION();
......
......@@ -41,6 +41,7 @@ public:
explicit KisTagChooserWidget(KisTagModel* model, QWidget* parent);
~KisTagChooserWidget() override;
void setCurrentIndex(int index);
int currentIndex() const;
int findIndexOf(KisTagSP tagName);
KisTagSP currentlySelectedTag();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment