12#include <klocalizedstring.h>
36 : QAbstractTableModel(parent)
55 for (
int i = 0; i < model.rowCount(); i++) {
56 QModelIndex idx = model.index(i, 0);
71 if (parent.isValid()) {
77 const bool r = q.prepare(
"SELECT count(*)\n"
80 "LEFT JOIN tag_translations ON tag_translations.tag_id = tags.id AND tag_translations.language = :language\n"
81 "WHERE tags.resource_type_id = resource_types.id\n"
82 "AND resource_types.name = :resource_type\n");
84 qWarning() <<
"Could not execute tags rowcount query" << q.lastError();
90 qWarning() <<
"Could not execute tags rowcount query" << q.lastError();
102 if (parent.isValid()) {
113 if (!index.isValid())
return v;
120 case Qt::DisplayRole:
121 case Qt::ToolTipRole:
122 case Qt::StatusTipRole:
123 case Qt::WhatsThisRole:
124 case Qt::UserRole +
Name:
126 case Qt::UserRole +
Id:
128 case Qt::UserRole +
Url: {
133 case Qt::UserRole +
Active:
139 response.setValue(tag);
147 case Qt::DisplayRole:
148 case Qt::ToolTipRole:
149 case Qt::StatusTipRole:
150 case Qt::WhatsThisRole:
151 case Qt::UserRole +
Name:
152 return i18n(
"All untagged");
153 case Qt::UserRole +
Id:
155 case Qt::UserRole +
Url: {
160 case Qt::UserRole +
Active:
166 response.setValue(tag);
178 case Qt::DisplayRole:
179 case Qt::UserRole +
Name:
181 QVariant name =
d->
query.value(
"translated_name");
183 name =
d->
query.value(
"name");
187 case Qt::ToolTipRole:
188 case Qt::StatusTipRole:
189 case Qt::WhatsThisRole:
191 QVariant comment =
d->
query.value(
"translated_comment");
192 if (comment.isNull()) {
193 comment =
d->
query.value(
"comment");
197 case Qt::UserRole +
Id:
198 return d->
query.value(
"id");
199 case Qt::UserRole +
Url:
200 return d->
query.value(
"url");
202 return d->
query.value(
"resource_type");
203 case Qt::UserRole +
Active:
204 return d->
query.value(
"active");
209 response.setValue(tag);
222 int id =
data(index, Qt::UserRole +
Id).toInt();
224 if (index.isValid() &&
225 (role == Qt::UserRole +
Active)) {
228 if (!q.prepare(
"UPDATE tags\n"
229 "SET active = :active\n"
230 "WHERE id = :id\n")) {
231 qWarning() <<
"Could not prepare make existing tag active query" << q.lastError();
234 q.bindValue(
":active",
value.toBool());
235 q.bindValue(
":id",
id);
238 qWarning() <<
"Could not execute make existing tag active query" << q.boundValues(), q.lastError();
244 Q_EMIT dataChanged(index, index, {role});
250 if (!index.isValid()) {
251 return Qt::NoItemFlags;
253 return QAbstractTableModel::flags(index) | Qt::ItemIsEditable | Qt::ItemNeverHasChildren;
258 if (!tag)
return QModelIndex();
267 bool r =
d->
query.first();
269 return QModelIndex();
272 if (tag->id() >= 0) {
273 if (
d->
query.value(
"id").toInt() == tag->id()) {
281 if (
d->
query.value(
"url").toString() == tag->url()
286 }
while (
d->
query.next());
288 return QModelIndex();
294 if (!index.isValid())
return tag;
295 if (index.row() >
rowCount())
return tag;
301 tag->setName(i18n(
"All"));
304 tag->setComment(i18n(
"All resources"));
306 tag->setActive(
true);
311 tag->setName(i18n(
"All untagged"));
314 tag->setComment(i18n(
"All untagged resources"));
316 tag->setActive(
true);
333 tag->setName(tagName);
334 tag->setUrl(tagName);
336 tag->setActive(
true);
339 if (
addTag(tag, allowOverwrite, taggedResources)) {
350 if (!tag)
return false;
351 if (!tag->valid())
return false;
358 qWarning() <<
"Could not add tag" << tag;
365 else if (allowOverwrite) {
369 tag->setComment(trueTag->comment());
370 tag->setFilename(trueTag->filename());
380 if (!taggedResources.isEmpty()) {
382 Q_FOREACH(
const KoResourceSP resource, taggedResources) {
384 if (!resource)
continue;
385 if (!resource->valid())
continue;
386 if (resource->resourceId() < 0)
continue;
388 resourceIds << resource->resourceId();
398 if (!tag)
return false;
399 if (!tag->valid())
return false;
401 tag->setActive(
true);
409 if (!tag)
return false;
410 if (!tag->valid())
return false;
412 tag->setActive(
false);
419 if (!tag)
return false;
420 if (!tag->valid())
return false;
421 if (tag->id() < 0)
return false;
423 if (newName.isEmpty())
return false;
427 if (dstTag && dstTag->active() && !allowOverwrite) {
432 dstTag =
addTag(newName,
false, {});
434 if (!dstTag->active()) {
445 for (
int i = 0; i < model.rowCount(); i++) {
446 QModelIndex idx = model.index(i, 0);
459 if (!tag)
return false;
460 if (!tag->valid())
return false;
463 tag->setActive(active);
470 if (tagUrl.isEmpty()) {
485 bool r =
d->
query.prepare(
"SELECT tags.id\n"
491 ", resource_types.name as resource_type\n"
492 ", tag_translations.name as translated_name\n"
493 ", tag_translations.comment as translated_comment\n"
496 "LEFT JOIN tag_translations ON tag_translations.tag_id = tags.id AND tag_translations.language = :language\n"
497 "WHERE tags.resource_type_id = resource_types.id\n"
498 "AND resource_types.name = :resource_type\n"
499 "ORDER BY tags.id\n");
502 qWarning() <<
"Could not prepare KisAllTagsModel query" <<
d->
query.lastError();
511 qWarning() <<
"Could not select tags" <<
d->
query.lastError();
545 : QSortFilterProxyModel(parent)
577 return mapFromSource(
source->indexForTag(tag));
579 return QModelIndex();
587 return source->tagForIndex(mapToSource(index));
597 return source->addTag(tagName, allowOverwrite, taggedResources);
606 return source->tagForUrl(url);
616 return source->addTag(tag, allowOverwrite, taggedResources) ;
625 return source->setTagInactive(tag) ;
634 return source->setTagActive(tag) ;
644 return source->renameTag(tag, newName, allowOverwrite);
653 return source->changeTagActive(tag, active);
665 QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
666 if (!idx.isValid()) {
686 const bool r = q.prepare(
"SELECT count(*)\n"
687 "FROM tags_storages\n"
689 "WHERE tags_storages.tag_id = :tag_id\n"
690 "AND tags_storages.storage_id = storages.id\n"
691 "AND storages.active = 1\n");
693 qWarning() <<
"Could not execute tags in storages query" << q.lastError();
697 q.bindValue(
":tag_id", tagId);
700 qWarning() <<
"Could not execute tags in storages query" << q.lastError() << q.boundValues();
706 if (q.value(0).toInt() > 0) {
725 if (leftIsFakeRow && rightIsFakeRow) {
726 return source_left.row() < source_right.row();
727 }
else if (leftIsFakeRow) {
729 }
else if (rightIsFakeRow) {
732 QString nameLeft = sourceModel()->data(source_left, Qt::UserRole +
KisAllTagsModel::Name).toString().toLower();
733 QString nameRight = sourceModel()->data(source_right, Qt::UserRole +
KisAllTagsModel::Name).toString().toLower();
734 return (nameLeft < nameRight);
float value(const T *src, size_t ch)
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
static int s_fakeRowsCount
QSharedPointer< KisTag > KisTagSP
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static bool addTag(const QString &resourceType, const QString storageLocation, KisTagSP tag)
static bool hasTag(const QString &url, const QString &resourceType)
KisTagSP tagForUrl(const QString &tagUrl, const QString resourceType)
tagForUrl create a tag from the database
void purgeTag(const QString tagUrl, const QString resourceType)
static KisResourceLocator * instance()
static KisAllTagsModel * tagModel(const QString &resourceType)
static KisStorageModel * instance()
bool renameTag(const KisTagSP tag, const QString &newName, const bool allowOverwrite) override
KisTagSP addTag(const QString &tagName, const bool allowOverwrite, QVector< KoResourceSP > taggedResources) override
Add a new tag with a possibly empty list of resources to tag.
KisTagSP tagForUrl(const QString &url) const override
Retrieve a tag by url.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
void setTagFilter(TagFilter filter)
KisTagModel(const QString &type, QObject *parent=0)
bool setTagActive(const KisTagSP tag) override
QModelIndex indexForTag(KisTagSP tag) const override
void setStorageFilter(StorageFilter filter)
bool setTagInactive(const KisTagSP tag) override
KisTagSP tagForIndex(QModelIndex index=QModelIndex()) const override
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
bool changeTagActive(const KisTagSP tag, bool active) override
The KisTagResourceModel class makes it possible to retrieve the resources for certain tags or the tag...
bool untagResources(const KisTagSP tag, const QVector< int > &resourceIds) override
bool tagResources(const KisTagSP tag, const QVector< int > &resourceIds) override
void setTagsFilter(const QVector< int > tagIds)
The KisTag loads a tag from a .tag file. A .tag file is a .desktop file. The following fields are imp...
static QString currentLocale()
StorageFilter storageFilter