[calligra/calligra/2.9] libs/widgets: Fix restoring the presets in the editor preset strip

Boudewijn Rempt boud at valdyas.org
Sat May 30 09:07:46 UTC 2015


Git commit 55b1e5c3247410b0f74bd25a70007d979df585f6 by Boudewijn Rempt.
Committed on 30/05/2015 at 09:07.
Pushed by rempt into branch 'calligra/2.9'.

Fix restoring the presets in the editor preset strip

This also makes restoring the preset a lot more robust. It needs
testing, though!

CCMAIL:kimageshop at kde.org
BUG:348337

M  +3    -6    libs/widgets/KoResourceItemChooser.cpp
M  +6    -3    libs/widgets/KoResourceModel.cpp
M  +2    -1    libs/widgets/KoResourceServer.h
M  +62   -58   libs/widgets/KoResourceTaggingManager.cpp
M  +1    -1    libs/widgets/KoTagChooserWidget.cpp

http://commits.kde.org/calligra/55b1e5c3247410b0f74bd25a70007d979df585f6

diff --git a/libs/widgets/KoResourceItemChooser.cpp b/libs/widgets/KoResourceItemChooser.cpp
index 6db138d..6eb984c 100644
--- a/libs/widgets/KoResourceItemChooser.cpp
+++ b/libs/widgets/KoResourceItemChooser.cpp
@@ -116,14 +116,11 @@ KoResourceItemChooser::KoResourceItemChooser(QSharedPointer<KoAbstractResourceSe
     d->view->setSelectionMode( QAbstractItemView::SingleSelection );
     d->view->viewport()->installEventFilter(this);
 
-    connect(d->view, SIGNAL(currentResourceChanged(QModelIndex)),
-            this, SLOT(activated(QModelIndex)));
+    connect(d->view, SIGNAL(currentResourceChanged(QModelIndex)), this, SLOT(activated(QModelIndex)));
     connect(d->view, SIGNAL(clicked(QModelIndex)), this, SLOT(activated(QModelIndex)));
-    connect (d->view, SIGNAL(contextMenuRequested(QPoint)),
-            this, SLOT(contextMenuRequested(QPoint)));
+    connect (d->view, SIGNAL(contextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
 
-    connect (d->view, SIGNAL(sigSizeChanged()),
-            this, SLOT(updateView()));
+    connect (d->view, SIGNAL(sigSizeChanged()), this, SLOT(updateView()));
 
     d->splitter->addWidget(d->view);
     d->splitter->setStretchFactor(0, 2);
diff --git a/libs/widgets/KoResourceModel.cpp b/libs/widgets/KoResourceModel.cpp
index 589033e..aa24cfa 100644
--- a/libs/widgets/KoResourceModel.cpp
+++ b/libs/widgets/KoResourceModel.cpp
@@ -203,9 +203,12 @@ void KoResourceModel::tagBoxEntryWasRemoved(const QString& tag)
 QModelIndex KoResourceModel::indexFromResource(KoResource* resource) const
 {
     int resourceIndex = m_resourceAdapter->resources().indexOf(resource);
-    int row = resourceIndex / columnCount();
-    int column = resourceIndex % columnCount();
-    return index(row, column);
+    if (columnCount() > 0) {
+        int row = resourceIndex / columnCount();
+        int column = resourceIndex % columnCount();
+        return index(row, column);
+    }
+    return QModelIndex();
 }
 
 QString KoResourceModel::extensions() const
diff --git a/libs/widgets/KoResourceServer.h b/libs/widgets/KoResourceServer.h
index 0b2f957..e7e2516 100644
--- a/libs/widgets/KoResourceServer.h
+++ b/libs/widgets/KoResourceServer.h
@@ -140,6 +140,7 @@ public:
         m_blackListFile = KStandardDirs::locateLocal("data", "krita/" + type + ".blacklist");
         m_blackListFileNames = readBlackListFile();
         m_tagStore = new KoResourceTagStore(this);
+        m_tagStore->loadTags();
     }
 
     virtual ~KoResourceServer()
@@ -171,6 +172,7 @@ public:
      * @param filenames list of filenames to be loaded
      */
     void loadResources(QStringList filenames) {
+
         QStringList uniqueFiles;
 
         while (!filenames.empty()) {
@@ -214,7 +216,6 @@ public:
         }
 
         m_resources = sortedResources();
-        m_tagStore->loadTags();
 
         foreach(ObserverType* observer, m_observers) {
             observer->syncTaggedResourceView();
diff --git a/libs/widgets/KoResourceTaggingManager.cpp b/libs/widgets/KoResourceTaggingManager.cpp
index 541b7a0..7000cf5 100644
--- a/libs/widgets/KoResourceTaggingManager.cpp
+++ b/libs/widgets/KoResourceTaggingManager.cpp
@@ -73,10 +73,70 @@ public:
     QPointer<KoResourceModel> model;
 };
 
+
+KoResourceTaggingManager::KoResourceTaggingManager(KoResourceModel *model, QWidget* parent)
+    : QObject(parent)
+    , d(new Private())
+{
+    d->model = model;
+
+    d->tagChooser = new KoTagChooserWidget(parent);
+    d->tagChooser->addReadOnlyItem(i18n("All"));
+    d->tagChooser->addItems(d->model->tagNamesList());
+
+    d->tagFilter = new KoTagFilterWidget(parent);
+
+    connect(d->tagChooser, SIGNAL(tagChosen(QString)),
+            this, SLOT(tagChooserIndexChanged(QString)));
+    connect(d->tagChooser, SIGNAL(newTagRequested(QString)),
+            this, SLOT(contextCreateNewTag(QString)));
+    connect(d->tagChooser, SIGNAL(tagDeletionRequested(QString)),
+            this, SLOT(removeTagFromComboBox(QString)));
+    connect(d->tagChooser, SIGNAL(tagRenamingRequested(QString, QString)),
+            this, SLOT(renameTag(QString, QString)));
+    connect(d->tagChooser, SIGNAL(tagUndeletionRequested(QString)),
+            this, SLOT(undeleteTag(QString)));
+    connect(d->tagChooser, SIGNAL(tagUndeletionListPurgeRequested()),
+            this, SLOT(purgeTagUndeleteList()));
+
+    connect(d->tagFilter, SIGNAL(saveButtonClicked()),
+            this, SLOT(tagSaveButtonPressed()));
+    connect(d->tagFilter, SIGNAL(filterTextChanged(QString)),
+            this, SLOT(tagSearchLineEditTextChanged(QString)));
+
+    connect(d->model, SIGNAL(tagBoxEntryAdded(QString)),
+            this, SLOT(syncTagBoxEntryAddition(QString)));
+    connect(d->model, SIGNAL(tagBoxEntryRemoved(QString)),
+            this, SLOT(syncTagBoxEntryRemoval(QString)));
+    connect(d->model, SIGNAL(tagBoxEntryModified()),
+            this, SLOT(syncTagBoxEntries()));
+
+    // FIXME: fix tag completer
+    // d->tagCompleter = new QCompleter(this);
+    //  d->tagSearchLineEdit->setCompleter(d->tagCompleter);
+
+    syncTagBoxEntries();
+}
+
+KoResourceTaggingManager::~KoResourceTaggingManager()
+{
+    delete d;
+}
+
 void KoResourceTaggingManager::showTaggingBar(bool show)
 {
     show ? d->tagFilter->show() : d->tagFilter->hide();
     show ? d->tagChooser->show() : d->tagChooser->hide();
+
+    blockSignals(!show);
+
+    QString tag("All");
+    if (show) {
+        KConfigGroup group = KGlobal::config()->group("SelectedTags");
+        tag = group.readEntry<QString>(d->model->serverType(), "All");
+    }
+
+    d->tagChooser->setCurrentIndex(d->tagChooser->findIndexOf(tag));
 }
 
 void KoResourceTaggingManager::purgeTagUndeleteList()
@@ -171,9 +231,9 @@ void KoResourceTaggingManager::syncTagBoxEntryRemoval(const QString& tag)
 
 void KoResourceTaggingManager::syncTagBoxEntries()
 {
-    QList<QString> tags = d->model->tagNamesList();
+    QStringList tags = d->model->tagNamesList();
 
-    foreach (QString tag, tags) {
+    foreach (const QString &tag, tags) {
         d->tagChooser->insertItem(tag);
     }
 }
@@ -330,59 +390,3 @@ KoTagFilterWidget* KoResourceTaggingManager::tagFilterWidget()
     return d->tagFilter;
 }
 
-KoResourceTaggingManager::KoResourceTaggingManager(KoResourceModel *model, QWidget* parent)
-    : QObject(parent)
-    , d(new Private())
-{
-    d->model = model;
-
-    d->tagChooser = new KoTagChooserWidget(parent);
-    d->tagChooser->addReadOnlyItem(i18n("All"));
-    d->tagChooser->addItems(d->model->tagNamesList());
-
-    d->tagFilter = new KoTagFilterWidget(parent);
-
-    connect(d->tagChooser, SIGNAL(tagChosen(QString)),
-            this, SLOT(tagChooserIndexChanged(QString)));
-    connect(d->tagChooser, SIGNAL(newTagRequested(QString)),
-            this, SLOT(contextCreateNewTag(QString)));
-    connect(d->tagChooser, SIGNAL(tagDeletionRequested(QString)),
-            this, SLOT(removeTagFromComboBox(QString)));
-    connect(d->tagChooser, SIGNAL(tagRenamingRequested(QString, QString)),
-            this, SLOT(renameTag(QString, QString)));
-    connect(d->tagChooser, SIGNAL(tagUndeletionRequested(QString)),
-            this, SLOT(undeleteTag(QString)));
-    connect(d->tagChooser, SIGNAL(tagUndeletionListPurgeRequested()),
-            this, SLOT(purgeTagUndeleteList()));
-
-    connect(d->tagFilter, SIGNAL(saveButtonClicked()),
-            this, SLOT(tagSaveButtonPressed()));
-    connect(d->tagFilter, SIGNAL(filterTextChanged(QString)),
-            this, SLOT(tagSearchLineEditTextChanged(QString)));
-
-    connect(d->model, SIGNAL(tagBoxEntryAdded(QString)),
-            this, SLOT(syncTagBoxEntryAddition(QString)));
-    connect(d->model, SIGNAL(tagBoxEntryRemoved(QString)),
-            this, SLOT(syncTagBoxEntryRemoval(QString)));
-    connect(d->model, SIGNAL(tagBoxEntryModified()),
-            this, SLOT(syncTagBoxEntries()));
-
-    // FIXME: fix tag completer
-    // d->tagCompleter = new QCompleter(this);
-    //  d->tagSearchLineEdit->setCompleter(d->tagCompleter);
-
-    KConfigGroup group = KGlobal::config()->group("SelectedTags");
-    QString tag = group.readEntry<QString>(d->model->serverType(), "");
-    if (!tag.isEmpty()) {
-        d->tagChooser->setCurrentIndex(d->tagChooser->findIndexOf(tag));
-    }
-    else {
-        d->tagChooser->setCurrentIndex(0);
-    }
-
-}
-
-KoResourceTaggingManager::~KoResourceTaggingManager()
-{
-    delete d;
-}
diff --git a/libs/widgets/KoTagChooserWidget.cpp b/libs/widgets/KoTagChooserWidget.cpp
index 08bc52e..8b95e06 100644
--- a/libs/widgets/KoTagChooserWidget.cpp
+++ b/libs/widgets/KoTagChooserWidget.cpp
@@ -138,7 +138,7 @@ void KoTagChooserWidget::insertItem(QString tagName)
     }
 
     int index = tags.indexOf(tagName);
-    if (findIndexOf(tagName) == -1) {
+    if (d->comboBox->findText(tagName) == -1) {
         insertItemAt(index, tagName);
         d->tags.append(tagName);
     }


More information about the kimageshop mailing list