[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [digikam/frameworks] /: Adapt to TagsCompleter changes
From:       Marcel Wiesweg <marcel.wiesweg () gmx ! de>
Date:       2015-09-20 15:55:04
Message-ID: E1ZdgxE-0004Wq-Aq () scm ! kde ! org
[Download RAW message or body]

Git commit 78bf9fbbcdb19740bc9c5c9cba596875576d9874 by Marcel Wiesweg.
Committed on 20/09/2015 at 15:47.
Pushed by mwiesweg into branch 'frameworks'.

Adapt to TagsCompleter changes

M  +0    -1    app/items/overlays/assignnameoverlay.cpp
M  +1    -1    libs/imageproperties/imagedescedittab.cpp
M  +2    -1    libs/tags/CMakeLists.txt
M  +0    -1    libs/tags/addtagscombobox.cpp
M  +70   -192  libs/tags/addtagslineedit.cpp
M  +20   -20   libs/tags/addtagslineedit.h
M  +1    -1    libs/tags/tagslineeditoverlay.cpp
M  +1    -5    utilities/facemanagement/assignnamewidget.cpp

http://commits.kde.org/digikam/78bf9fbbcdb19740bc9c5c9cba596875576d9874

diff --git a/app/items/overlays/assignnameoverlay.cpp \
b/app/items/overlays/assignnameoverlay.cpp index 99b3bc0..63bffa9 100644
--- a/app/items/overlays/assignnameoverlay.cpp
+++ b/app/items/overlays/assignnameoverlay.cpp
@@ -42,7 +42,6 @@
 // Local includes
 
 #include "digikam_debug.h"
-#include "addtagscompletionbox.h"
 #include "addtagslineedit.h"
 #include "albummodel.h"
 #include "albumfiltermodel.h"
diff --git a/libs/imageproperties/imagedescedittab.cpp \
b/libs/imageproperties/imagedescedittab.cpp index fb2a570..c342e95 100644
--- a/libs/imageproperties/imagedescedittab.cpp
+++ b/libs/imageproperties/imagedescedittab.cpp
@@ -284,7 +284,7 @@ ImageDescEditTab::ImageDescEditTab(QWidget* const parent)
     d->openTagMngr = new QPushButton( i18n("Open Tag Manager"));
 
     d->newTagEdit   = new AddTagsLineEdit(tagsArea);
-    d->newTagEdit->setModel(d->tagModel);
+    d->newTagEdit->setSupportingTagModel(d->tagModel);
     d->newTagEdit->setTagTreeView(d->tagCheckView);
     //, "ImageDescEditTabNewTagEdit",
     //d->newTagEdit->setCaseSensitive(false);
diff --git a/libs/tags/CMakeLists.txt b/libs/tags/CMakeLists.txt
index 3eb1435..12da61d 100644
--- a/libs/tags/CMakeLists.txt
+++ b/libs/tags/CMakeLists.txt
@@ -7,7 +7,7 @@
 
 set(libtags_SRCS
     addtagscombobox.cpp
-    addtagscompletionbox.cpp
+    tagscompleter.cpp
     addtagslineedit.cpp
     tagcheckview.cpp
     tagfolderview.cpp
@@ -17,6 +17,7 @@ set(libtags_SRCS
     tageditdlg.cpp
     tagmodificationhelper.cpp
     tagsactionmngr.cpp
+    taggingactionfactory.cpp
 
     tagsmanager/tagsmanager.cpp
     tagsmanager/tagpropwidget.cpp
diff --git a/libs/tags/addtagscombobox.cpp b/libs/tags/addtagscombobox.cpp
index f0fad79..c34026c 100644
--- a/libs/tags/addtagscombobox.cpp
+++ b/libs/tags/addtagscombobox.cpp
@@ -152,7 +152,6 @@ TaggingAction AddTagsComboBox::currentTaggingAction()
         return d->viewTaggingAction;
     }
 
-#pragma message "KCompleter port, check what this do"
     return d->lineEdit->currentTaggingAction();
 }
 
diff --git a/libs/tags/addtagslineedit.cpp b/libs/tags/addtagslineedit.cpp
index 7c18276..27baf55 100644
--- a/libs/tags/addtagslineedit.cpp
+++ b/libs/tags/addtagslineedit.cpp
@@ -39,12 +39,14 @@
 // Local includes
 
 #include "digikam_debug.h"
-#include "addtagscompletionbox.h"
+#include "tagscompleter.h"
 #include "tageditdlg.h"
 #include "album.h"
 #include "albummodel.h"
+#include "albumfiltermodel.h"
 #include "albumtreeview.h"
 #include "tagscache.h"
+#include "taggingactionfactory.h"
 #include "databaseaccess.h"
 #include "albumdb.h"
 
@@ -56,208 +58,100 @@ class AddTagsLineEdit::Private
 public:
 
     Private()
+        : completer(0),
+          tagView(0),
+          tagFilterModel(0),
+          parentTagId(0)
     {
-        completion         = 0;
-        tagView            = 0;
-        resetFromCompleter = false;
-        parentTag          = 0;
-        currentTag         = 0;
-        tagModel           = 0;
     }
 
-    TagModelCompletion* completion;
+    TagCompleter*       completer;
     TagTreeView*        tagView;
+    AlbumFilterModel*   tagFilterModel;
     TaggingAction       currentTaggingAction;
-    bool                resetFromCompleter;
-    TAlbum*             parentTag;
-    TAlbum*             currentTag;
-    TagModel*           tagModel;
-
-public:
-
-    TaggingAction makeDefaultTaggingAction(const QString& test, int parentTagId);
+    int                 parentTagId;
 };
 
-TaggingAction AddTagsLineEdit::Private::makeDefaultTaggingAction(const QString& \
                text, int parentTagId)
-{
-    // We now take the presumedly best action, without autocompletion popup.
-    // 1. Tag exists?
-    //    a) Single tag? Assign.
-    //    b) Multiple tags? 1. Existing tag under parent. 2. Toplevel tag 3. \
                Alphabetically lowest tag
-    // 2. Create tag under parent. No parent selected? Toplevel
-
-    QList<int> tagIds = TagsCache::instance()->tagsForName(text);
-
-    if (!tagIds.isEmpty())
-    {
-        if (tagIds.count() == 1)
-        {
-            return TaggingAction(tagIds.first());
-        }
-        else
-        {
-            int tagId = 0;
-
-            if (parentTagId)
-            {
-                tagId = TagsCache::instance()->tagForName(text, parentTagId);
-            }
-
-            if (!tagId)
-            {
-                tagId = TagsCache::instance()->tagForName(text);    // toplevel tag
-            }
-
-            if (!tagId)
-            {
-                // sort lexically
-                QMap<QString, int> map;
-
-                foreach(int id, tagIds)
-                {
-                    map[TagsCache::instance()->tagPath(id, \
                TagsCache::NoLeadingSlash)] = id;
-                }
-
-                tagId = map.begin().value();
-            }
-
-            return TaggingAction(tagId);
-        }
-    }
-    else
-    {
-        return TaggingAction(text, parentTagId);
-    }
-}
-// ---------------------------------------------------------------------------------------
                
-
 AddTagsLineEdit::AddTagsLineEdit(QWidget* const parent)
     : QLineEdit(parent),
       d(new Private)
 {
-    d->completion = new TagModelCompletion;
-    setCompleter(d->completion);
+    d->completer = new TagCompleter(this);
+    d->completer->setMaxVisibleItems(15);
+    d->completer->setWidget(this);
+    setCompleter(d->completer);
+
+    connect(this, &QLineEdit::returnPressed, this, \
&AddTagsLineEdit::slotReturnPressed); +    connect(this, &QLineEdit::editingFinished, \
this, &AddTagsLineEdit::slotEditingFinished); +    connect(this, \
&QLineEdit::textChanged, this, &AddTagsLineEdit::slotTextChanged); +
+    connect(d->completer, SIGNAL(activated(TaggingAction)), this, \
SLOT(completerActivated(TaggingAction))); +    connect(d->completer, \
SIGNAL(highlighted(TaggingAction)), this, \
SIGNAL(taggingActionSelected(TaggingAction)));  }
 
 AddTagsLineEdit::~AddTagsLineEdit()
 {
-    delete d->completion;
     delete d;
 }
 
-void AddTagsLineEdit::setModel(TagModel* model)
+void AddTagsLineEdit::setSupportingTagModel(TagModel* model)
 {
-    d->completion->setModel(model);
-    d->tagModel = model;
+    d->completer->setSupportingTagModel(model);
 }
 
-void AddTagsLineEdit::setModel(AlbumFilterModel* model)
+void AddTagsLineEdit::setFilterModel(AlbumFilterModel* model)
 {
-    d->completion->setModel(model);
+    d->tagFilterModel = model;
+    d->completer->setTagFilterModel(d->tagFilterModel);
 }
 
 void AddTagsLineEdit::setModel(TagModel* model, TagPropertiesFilterModel* \
filteredModel, AlbumFilterModel* filterModel)  {
     if (filterModel)
     {
-        setModel(filterModel);
+        setFilterModel(filterModel);
     }
     else if (filteredModel)
     {
-        setModel(filteredModel);
-    }
-    else
-    {
-        setModel(model);
+        setFilterModel(filteredModel);
     }
+    setSupportingTagModel(model);
 }
 
 void AddTagsLineEdit::setTagTreeView(TagTreeView* view)
 {
     if (d->tagView)
     {
-        disconnect(d->tagView->selectionModel(), \
                SIGNAL(currentChanged(QModelIndex,QModelIndex)),
-                   this, SLOT(setParentTag(QModelIndex)));
+        disconnect(d->tagView, &TagTreeView::currentAlbumChanged, this, \
&AddTagsLineEdit::setParentTag);  }
 
     d->tagView = view;
-    setParentTag(d->tagView->currentAlbum());
 
     if (d->tagView)
     {
-        //d->completionBox->setParentTag(d->tagView->currentIndex());
-        connect(d->tagView->selectionModel(), \
                SIGNAL(currentChanged(QModelIndex,QModelIndex)),
-                this, SLOT(slotSetParentTag(QModelIndex)));
+        connect(d->tagView, &TagTreeView::currentAlbumChanged, this, \
&AddTagsLineEdit::setParentTag); +        setParentTag(d->tagView->currentAlbum());
     }
 }
 
 void AddTagsLineEdit::setCurrentTag(TAlbum* album)
 {
-    d->parentTag = album;
-}
-
-void AddTagsLineEdit::slotSetParentTag(QModelIndex index)
-{
-    if(index.isValid())
-        d->parentTag = dynamic_cast<TAlbum*>(d->tagModel->albumForIndex(index));
-}
-
-void AddTagsLineEdit::setParentTag(TAlbum* album)
-{
-    if (album)
-        d->parentTag = album;
+    setCurrentTaggingAction(album ? TaggingAction(album->id()) : TaggingAction());
+    setText(album ? album->title() : QString());
 }
 
-void AddTagsLineEdit::completerActivated(QModelIndex index)
+void AddTagsLineEdit::setParentTag(Album* album)
 {
-    int id = index.data(Qt::UserRole+5).toInt();
-
-    qCDebug(DIGIKAM_GENERAL_LOG) << "Completer activated" << index.data() << id;
-
-    if (id == -5)
-    {
-        d->currentTaggingAction = \
                TaggingAction(index.data(Qt::UserRole+4).toString(),
-                                                d->tagView->currentAlbum()->id());
-        QMap<QString, QString> errMap;
-        AlbumList al = TagEditDlg::createTAlbum(d->tagView->currentAlbum(),
-                                                \
                index.data(Qt::UserRole+4).toString(),
-                                                QLatin1String("tag"),
-                                                QKeySequence(),errMap);
-        if(!al.isEmpty())
-        {
-            d->tagModel->setCheckState((TAlbum*)(al.first()),Qt::Checked);
-        }
-    }
-    else
-    {
-        d->currentTaggingAction = TaggingAction(id);
-        TAlbum* const tAlbum = AlbumManager::instance()->findTAlbum(id);
-        d->tagModel->setCheckState(tAlbum,Qt::Checked);
-    }
-
-    QLineEdit::clear();
+    d->parentTagId = album ? album->id() : 0;
+    d->completer->setContextParentTag(d->parentTagId);
 }
 
 void AddTagsLineEdit::setAllowExceedBound(bool value)
 {
     Q_UNUSED(value);
-    // set maximum size of pop-up widget
-}
-
-void AddTagsLineEdit::setCompleter(TagModelCompletion* c)
-{
-    if (d->completion)
-        QObject::disconnect(d->completion, 0, this, 0);
-
-    d->completion = c;
-
-    if (!d->completion)
-        return;
-
-    d->completion->setWidget(this);
-
-    connect(d->completion, SIGNAL(activated(QModelIndex)),
-            this, SLOT(completerActivated(QModelIndex)));
+    // -> the pop-up is allowed to be bigger than the line edit widget
+    // Currently unimplemented, QCompleter calculates the size automatically.
+    // Idea: intercept show event via event filter on completer->popup(); from \
there, change width.  }
 
 void AddTagsLineEdit::focusInEvent(QFocusEvent* f)
@@ -266,71 +160,55 @@ void AddTagsLineEdit::focusInEvent(QFocusEvent* f)
 
     // NOTE: Need to disconnect completer from QLineEdit, otherwise
     // we won't be able to clear completion after tag was added
+    // See QLineEdit::focusInEvent(QFocusEvent *e) where this connection is made
 
-    disconnect(d->completion, SIGNAL(activated(QString)),
+    disconnect(d->completer, SIGNAL(activated(QString)),
                this, SLOT(setText(QString)));
 }
 
-void AddTagsLineEdit::keyPressEvent(QKeyEvent* e)
-{
-    if (d->completion && d->completion->popup()->isVisible())
-    {
-        // The following keys are forwarded by the completer to the widget
-        switch (e->key())
-        {
-            case Qt::Key_Return:
-                slotReturnPressed(text());
-                e->ignore();
-                return;
-            case Qt::Key_Enter:
-            case Qt::Key_Escape:
-            case Qt::Key_Tab:
-            case Qt::Key_Backtab:
-                e->ignore();
-                return; // Let the completer do default behavior
-        }
-    }
-
-    bool isShortcut = (e->modifiers() & Qt::ControlModifier) && e->key() == \
Qt::Key_E; +// Tagging action is used by facemanagement and assignwidget
 
-    if (!isShortcut)
-        QLineEdit::keyPressEvent(e); // Don't send the shortcut (CTRL-E) to the text \
edit. +void AddTagsLineEdit::slotReturnPressed()
+{
+    //qCDebug(DIGIKAM_GENERAL_LOG) << "slot return pressed";
 
-    if (!d->completion)
+    if (text().isEmpty())
+    {
+        //focus back to mainview
+        emit taggingActionFinished();
         return;
+    }
 
-    bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
-
-    if (!isShortcut && !ctrlOrShift && e->modifiers() != Qt::NoModifier)
+    if (d->currentTaggingAction.shallAssignTag() && \
d->completer->popup()->isVisible())  {
-        d->completion->popup()->hide();
-        return;
+        setText(d->currentTaggingAction.newTagName());
     }
 
-    d->completion->update(text());
-    d->completion->popup()->setCurrentIndex(d->completion->completionModel()->index(0, \
0)); +    emit taggingActionActivated(currentTaggingAction());
 }
 
-// Tagging action is used by facemanagement and assignwidget
-
-void AddTagsLineEdit::slotReturnPressed(const QString& text)
+void AddTagsLineEdit::slotEditingFinished()
 {
-    qCDebug(DIGIKAM_GENERAL_LOG) << "slot return pressed";
+    d->currentTaggingAction = TaggingAction();
+}
 
+void AddTagsLineEdit::slotTextChanged(const QString &text)
+{
     if (text.isEmpty())
     {
-      //focus back to mainview
-      emit taggingActionFinished();
-      return;
+        d->currentTaggingAction = TaggingAction();
     }
+}
 
-    if (d->currentTaggingAction.shallAssignTag() && \
                d->completion->popup()->isVisible())
-    {
-        setText(d->completion->currentCompletion());
-    }
+void AddTagsLineEdit::completerActivated(const TaggingAction &action)
+{
+    setCurrentTaggingAction(action);
+    emit taggingActionActivated(action);
+}
 
-    //Q_UNUSED(text);
-    emit taggingActionActivated(currentTaggingAction());
+void AddTagsLineEdit::completerHighlighted(const TaggingAction &action)
+{
+    setCurrentTaggingAction(action);
 }
 
 void AddTagsLineEdit::setCurrentTaggingAction(const TaggingAction& action)
@@ -352,7 +230,7 @@ TaggingAction AddTagsLineEdit::currentTaggingAction() const
     }
     else if(!text().isEmpty())
     {
-        return d->makeDefaultTaggingAction(text(),d->currentTag->id());
+        return TaggingActionFactory::defaultTaggingAction(text(), d->parentTagId);
     }
     else
     {
diff --git a/libs/tags/addtagslineedit.h b/libs/tags/addtagslineedit.h
index 177907b..72be4f5 100644
--- a/libs/tags/addtagslineedit.h
+++ b/libs/tags/addtagslineedit.h
@@ -34,11 +34,12 @@ namespace Digikam
 {
 
 class AlbumFilterModel;
+class Album;
 class TAlbum;
 class TagModel;
 class TagPropertiesFilterModel;
 class TagTreeView;
-class TagModelCompletion;
+class TagCompleter;
 
 class AddTagsLineEdit : public QLineEdit
 {
@@ -49,13 +50,17 @@ public:
     explicit AddTagsLineEdit(QWidget* const parent = 0);
     ~AddTagsLineEdit();
 
-    /** Set the tag model to use for completion.
-     *  The line edit only needs one model and used the model last set.
-     *  From the method giving three models, it will use a non-null model,
-     *  filter models having precedence.
+    /**
+     * Optional: set a model for additional information, like tag icons
+     */
+    void setSupportingTagModel(TagModel* model);
+    /**
+     * Set a tag filter model. Completion suggestions will be limited to tags \
contained in the filter model. +     */
+    void setFilterModel(AlbumFilterModel* model);
+    /**
+     * Convenience: Will call setSupportingTagModel() and setFilterModel()
      */
-    void setModel(TagModel* model);
-    void setModel(AlbumFilterModel* model);
     void setModel(TagModel* model, TagPropertiesFilterModel* filteredModel, \
AlbumFilterModel* filterModel);  
     /** Reads a tag treeview and takes the currently selected tag into account
@@ -64,11 +69,9 @@ public:
     void setTagTreeView(TagTreeView* treeView);
 
     /**
-     * Sets the currently selected tagging action to the given tag
+     * Adjusts the current default tagging action to assign the given tag
      */
-    void setCurrentTag(TAlbum* album);
-
-    void setCompleter(TagModelCompletion* c);
+    void setCurrentTag(TAlbum* tag);
 
     void setAllowExceedBound(bool value);
 
@@ -81,11 +84,7 @@ public Q_SLOTS:
     /** Set a parent tag for suggesting a parent tag for a new tag, and a default \
                action.
      *  If you set a tag tree view, this is taken care for automatically.
      */
-    void slotSetParentTag(QModelIndex index);
-
-    void setParentTag(TAlbum* album);
-
-    void slotReturnPressed(const QString& text);
+    void setParentTag(Album* album);
 
 Q_SIGNALS:
 
@@ -97,14 +96,15 @@ Q_SIGNALS:
 
 protected Q_SLOTS:
 
-    void completerActivated(QModelIndex index);
+    void completerHighlighted(const TaggingAction& action);
+    void completerActivated(const TaggingAction& action);
+    void slotReturnPressed();
+    void slotEditingFinished();
+    void slotTextChanged(const QString& text);
 
 protected:
 
     void focusInEvent(QFocusEvent* f);
-    void keyPressEvent(QKeyEvent* e);
-
-//    void setCompletionObject(KCompletion* comp, bool dontuse=false);
 
 private:
 
diff --git a/libs/tags/tagslineeditoverlay.cpp b/libs/tags/tagslineeditoverlay.cpp
index f356dba..16441ee 100644
--- a/libs/tags/tagslineeditoverlay.cpp
+++ b/libs/tags/tagslineeditoverlay.cpp
@@ -63,7 +63,7 @@ QWidget* TagsLineEditOverlay::createWidget()
     TagModel* const model           = new \
TagModel(AbstractAlbumModel::IncludeRootAlbum, this);  model->setCheckable(true);
     model->setRootCheckable(false);
-    lineEdit->setModel(model);
+    lineEdit->setSupportingTagModel(model);
 
     return lineEdit;
 }
diff --git a/utilities/facemanagement/assignnamewidget.cpp \
b/utilities/facemanagement/assignnamewidget.cpp index 2a2ff90..074e538 100644
--- a/utilities/facemanagement/assignnamewidget.cpp
+++ b/utilities/facemanagement/assignnamewidget.cpp
@@ -40,7 +40,7 @@
 
 #include "digikam_debug.h"
 #include "addtagscombobox.h"
-#include "addtagscompletionbox.h"
+#include "tagscompleter.h"
 #include "addtagslineedit.h"
 #include "album.h"
 #include "albummanager.h"
@@ -501,9 +501,7 @@ void AssignNameWidget::Private::setAddTagsWidgetContents(T* const \
widget)  {
         widget->setCurrentTag(currentTag);
         widget->setPlaceholderText((mode == UnconfirmedEditMode) ? i18n("Who is \
                this?") : QString());
-        qCDebug(DIGIKAM_GENERAL_LOG) << "************setAddTagsWidgetContents \
called: confirm button";  
-#pragma message "QCompleter port"
         if (confirmButton)
         {
             confirmButton->setEnabled(widget->currentTaggingAction().isValid());
@@ -711,8 +709,6 @@ void AssignNameWidget::setCurrentTag(TAlbum* album)
 
 void AssignNameWidget::slotConfirm()
 {
-#pragma message "QCompleter port, check what this do"
-    qCDebug(DIGIKAM_GENERAL_LOG) << "*******************AssignName widget slot \
confirm";  if (d->comboBox)
     {
         emit assigned(d->comboBox->currentTaggingAction(), d->info, \
d->faceIdentifier);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic