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

List:       kde-commits
Subject:    branches/extragear/graphics/digikam/modelviewport/digikam
From:       Johannes Wienke <languitar () semipol ! de>
Date:       2009-11-30 21:43:28
Message-ID: 1259617408.612216.28751.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1056797 by jwienke:

Enabled checked filtering for album tree views

 M  +33 -9     digikam/albumtreeview.cpp  
 M  +3 -0      digikam/albumtreeview.h  
 M  +3 -136    libs/imageproperties/imagedescedittab.cpp  
 M  +73 -3     libs/models/albumfiltermodel.cpp  
 M  +42 -4     libs/models/albumfiltermodel.h  


--- branches/extragear/graphics/digikam/modelviewport/digikam/digikam/albumtreeview.cpp \
#1056796:1056797 @@ -100,23 +100,22 @@
 };
 
 AbstractAlbumTreeView::AbstractAlbumTreeView(AbstractSpecificAlbumModel *model, \
                QWidget *parent)
-    : QTreeView(parent), d(new AbstractAlbumTreeViewPriv)
+    : QTreeView(parent), m_albumModel(0), m_albumFilterModel(0),
+      d(new AbstractAlbumTreeViewPriv)
 {
     m_checkOnMiddleClick  = false;
 
     m_albumModel       = model;
-    m_albumFilterModel = new AlbumFilterModel(this);
+    AlbumFilterModel *filterModel = new AlbumFilterModel(this);
+    filterModel->setSourceAlbumModel(model);
+    setAlbumFilterModel(filterModel);
 
-    connect(m_albumFilterModel, SIGNAL(filterChanged()),
-             this, SLOT(slotFilterChanged()));
-
     if (!m_albumModel->rootAlbum())
+    {
         connect(m_albumModel, SIGNAL(rootAlbumAvailable()),
                  this, SLOT(slotRootAlbumAvailable()));
+    }
 
-    m_albumFilterModel->setSourceAlbumModel(m_albumModel);
-    setModel(m_albumFilterModel);
-
     connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const \
QModelIndex &)),  this, SLOT(slotCurrentChanged()));
 
@@ -129,6 +128,23 @@
     delete d;
 }
 
+void AbstractAlbumTreeView::setAlbumFilterModel(AlbumFilterModel *filterModel)
+{
+
+    if (m_albumFilterModel)
+    {
+        disconnect(m_albumFilterModel);
+    }
+
+    m_albumFilterModel = filterModel;
+
+    connect(m_albumFilterModel, SIGNAL(filterChanged()),
+             this, SLOT(slotFilterChanged()));
+
+    setModel(m_albumFilterModel);
+
+}
+
 AbstractSpecificAlbumModel *AbstractAlbumTreeView::albumModel() const
 {
     return m_albumModel;
@@ -560,13 +576,21 @@
     : AbstractCountingAlbumTreeView(model, parent)
 {
     m_checkOnMiddleClick  = true;
+    CheckableAlbumFilterModel *filterModel = new CheckableAlbumFilterModel(this);
+    filterModel->setSourceCheckableAlbumModel(model);
+    setAlbumFilterModel(filterModel);
 }
 
 AbstractCheckableAlbumModel *AbstractCheckableAlbumTreeView::checkableModel() const
 {
-    return static_cast<AbstractCheckableAlbumModel*>(m_albumModel);
+    return dynamic_cast<AbstractCheckableAlbumModel*>(m_albumModel);
 }
 
+CheckableAlbumFilterModel \
*AbstractCheckableAlbumTreeView::checkableAlbumFilterModel() const +{
+    return dynamic_cast<CheckableAlbumFilterModel*> (m_albumFilterModel);
+}
+
 void AbstractCheckableAlbumTreeView::setCheckOnMiddleClick(bool doThat)
 {
     m_checkOnMiddleClick = doThat;
--- branches/extragear/graphics/digikam/modelviewport/digikam/digikam/albumtreeview.h \
#1056796:1056797 @@ -117,6 +117,8 @@
     virtual void middleButtonPressed(Album *a);
     virtual QPixmap pixmapForDrag(const QStyleOptionViewItem& option, \
QList<QModelIndex> indexes);  
+    void setAlbumFilterModel(AlbumFilterModel *filterModel);
+
     AbstractSpecificAlbumModel *m_albumModel;
     AlbumFilterModel           *m_albumFilterModel;
 
@@ -165,6 +167,7 @@
 
     /// Manage check state through the model directly
     AbstractCheckableAlbumModel *checkableModel() const;
+    CheckableAlbumFilterModel *checkableAlbumFilterModel() const;
 
     /// Enable checking on middle mouse button click (default: on)
     void setCheckOnMiddleClick(bool doThat);
--- branches/extragear/graphics/digikam/modelviewport/digikam/libs/imageproperties/imagedescedittab.cpp \
#1056796:1056797 @@ -29,63 +29,38 @@
 
 // Qt includes
 
-#include <QLabel>
 #include <QToolButton>
 #include <QPushButton>
-#include <QIcon>
-#include <QKeyEvent>
 #include <QGridLayout>
-#include <QPixmap>
-#include <QEvent>
+#include <qscrollarea.h>
 #include <QSignalMapper>
 
 // KDE includes
 
 #include <kmenu.h>
-#include <klocale.h>
-#include <kurl.h>
-#include <kcursor.h>
 #include <kapplication.h>
 #include <kiconloader.h>
 #include <kmessagebox.h>
-#include <kconfig.h>
-#include <klineedit.h>
 #include <kdialog.h>
-#include <kglobal.h>
-#include <kselectaction.h>
-#include <kvbox.h>
 #include <ktabwidget.h>
 #include <kdebug.h>
 
 // Local includes
 
 #include "captionedit.h"
-#include "dmetadata.h"
 #include "kdatetimeedit.h"
-#include "albumiconitem.h"
-#include "albumdb.h"
-#include "album.h"
 #include "albumsettings.h"
 #include "albumlister.h"
 #include "albumthumbnailloader.h"
 #include "collectionscanner.h"
 #include "databasetransaction.h"
-#include "tageditdlg.h"
-#include "tagcheckview.h"
 #include "ratingwidget.h"
 #include "scancontroller.h"
-#include "talbumlistview.h"
 #include "tagcheckview.h"
 #include "templateselector.h"
 #include "templateviewer.h"
-#include "imageinfo.h"
 #include "imageattributeswatch.h"
-#include "metadatahub.h"
 #include "statusprogressbar.h"
-#include "config-digikam.h"
-#ifdef HAVE_KDEPIMLIBS
-#include <kabc/stdaddressbook.h>
-#endif // HAVE_KDEPIMLIBS
 
 namespace Digikam
 {
@@ -112,7 +87,6 @@
         dateTimeEdit               = 0;
         tagCheckView               = 0;
         ratingWidget               = 0;
-        ABCMenu                    = 0;
         assignedTagsBtn            = 0;
         applyBtn                   = 0;
         revertBtn                  = 0;
@@ -135,7 +109,6 @@
     QToolButton                   *assignedTagsBtn;
     QToolButton                   *revertBtn;
 
-    KMenu                         *ABCMenu;
     KMenu                         *moreMenu;
 
     QSignalMapper                 *recentTagsMapper;
@@ -1086,114 +1059,8 @@
 
 void ImageDescEditTab::slotAssignedTagsToggled(bool t)
 {
-    // TODO update, implement this in the tree view directly
-//
-//    Q3ListViewItemIterator it(d->tagsView);
-//    while (it.current())
-//    {
-//        it.current()->setOpen(t);
-//        it.current()->setVisible(true);
-//        ++it;
-//    }
-//
-//    //TODO: this will destroy name filtering. Unify in one method.
-//    it = d->tagsView;
-//    while (it.current())
-//    {
-//        TAlbumCheckListItem* item = \
                dynamic_cast<TAlbumCheckListItem*>(it.current());
-//        TAlbum *tag               = item->album();
-//        if (tag)
-//        {
-//            if (!tag->isRoot())
-//            {
-//                if (t)
-//                {
-//                    MetadataHub::TagStatus status = \
                d->hub.tagStatus(item->album());
-//                    bool tagAssigned = (status == MetadataHub::MetadataAvailable \
                && status.hasTag)
-//                                        || status == \
                MetadataHub::MetadataDisjoint;
-//                    item->setVisible(tagAssigned);
-//
-//                    if (tagAssigned)
-//                    {
-//                        Album* parent = tag->parent();
-//                        while (parent && !parent->isRoot())
-//                        {
-//                            TAlbumCheckListItem *pitem = \
                (TAlbumCheckListItem*)parent->extraData(d->tagsView);
-//                            pitem->setVisible(true);
-//                            parent = parent->parent();
-//                        }
-//                    }
-//                }
-//                else
-//                {
-//                    item->setVisible(true);
-//                }
-//            }
-//        }
-//        ++it;
-//    }
-//
-//    // correct visibilities afterwards:
-//    // As QListViewItem::setVisible works recursively on all it's children
-//    // we have to correct this
-//    if (t)
-//    {
-//        it = d->tagsView;
-//        while (it.current())
-//        {
-//            TAlbumCheckListItem* item = \
                dynamic_cast<TAlbumCheckListItem*>(it.current());
-//            TAlbum *tag               = item->album();
-//            if (tag)
-//            {
-//                if (!tag->isRoot())
-//                {
-//                    // only if the current item is not marked as tagged, check all \
                children
-//                    MetadataHub::TagStatus status = \
                d->hub.tagStatus(item->album());
-//                    bool tagAssigned = (status == MetadataHub::MetadataAvailable \
                && status.hasTag)
-//                                        || status == \
                MetadataHub::MetadataDisjoint;
-//                    if (!tagAssigned)
-//                    {
-//                        bool somethingIsSet         = false;
-//                        Q3ListViewItem* nextSibling  = (*it)->nextSibling();
-//                        Q3ListViewItemIterator tmpIt = it;
-//                        ++tmpIt;
-//                        while (*tmpIt != nextSibling )
-//                        {
-//                            TAlbumCheckListItem* tmpItem = \
                dynamic_cast<TAlbumCheckListItem*>(tmpIt.current());
-//                            MetadataHub::TagStatus tmpStatus = \
                d->hub.tagStatus(tmpItem->album());
-//                            bool tmpTagAssigned = (tmpStatus == \
                MetadataHub::MetadataAvailable && tmpStatus.hasTag)
-//                                                || tmpStatus == \
                MetadataHub::MetadataDisjoint;
-//                            if(tmpTagAssigned)
-//                            {
-//                                somethingIsSet = true;
-//                            }
-//                            ++tmpIt;
-//                        }
-//                        if (!somethingIsSet)
-//                        {
-//                            item->setVisible(false);
-//                        }
-//                    }
-//                }
-//            }
-//            ++it;
-//        }
-//    }
-//
-//    TAlbum *root                  = AlbumManager::instance()->findTAlbum(0);
-//    TAlbumCheckListItem *rootItem = \
                (TAlbumCheckListItem*)(root->extraData(d->tagsView));
-//    if (rootItem)
-//    {
-//        if (t)
-//        {
-//            rootItem->setText(0, i18n("Assigned Tags"));
-//        }
-//        else
-//        {
-//            rootItem->setText(0, root->title());
-//        }
-//        rootItem->setOpen(true);
-//    }
+    d->tagCheckView->checkableAlbumFilterModel()->setFilterChecked(t);
+    d->tagCheckView->checkableAlbumFilterModel()->setFilterPartiallyChecked(t);
 }
 
 void ImageDescEditTab::focusLastSelectedWidget()
--- branches/extragear/graphics/digikam/modelviewport/digikam/libs/models/albumfiltermodel.cpp \
#1056796:1056797 @@ -7,6 +7,7 @@
  * Description : Qt Model for Albums - filter model
  *
  * Copyright (C) 2008-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ * Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -113,6 +114,11 @@
     return matches(sourceAlbumModel()->albumForIndex(mapToSource(index)));
 }
 
+bool AlbumFilterModel::rawMatches(Album *album) const
+{
+    return album->title().contains(m_settings.text, m_settings.caseSensitive);
+}
+
 AlbumFilterModel::MatchResult AlbumFilterModel::matches(Album *album) const
 {
     if (!album)
@@ -123,7 +129,7 @@
     if (album->isRoot() || (palbum && palbum->isAlbumRoot()))
         return SpecialMatch;
 
-    if (album->title().contains(m_settings.text, m_settings.caseSensitive))
+    if (rawMatches(album))
         return TitleMatch;
 
     // check if any of the parents match the search
@@ -132,7 +138,7 @@
 
     while (parent && !(parent->isRoot() || (pparent && pparent->isAlbumRoot()) ) )
     {
-        if (parent->title().contains(m_settings.text, m_settings.caseSensitive))
+        if (rawMatches(parent))
             return ParentMatch;
 
         parent = parent->parent();
@@ -142,7 +148,7 @@
     AlbumIterator it(album);
     while (it.current())
     {
-        if ((*it)->title().contains(m_settings.text, m_settings.caseSensitive))
+        if (rawMatches(*it))
             return ChildMatch;
         ++it;
     }
@@ -171,4 +177,68 @@
         return QSortFilterProxyModel::lessThan(left, right);
 }
 
+// -----------------------------------------------------------------------------
+
+CheckableAlbumFilterModel::CheckableAlbumFilterModel(QObject *parent) :
+                AlbumFilterModel(parent), m_filterChecked(false),
+                m_filterPartiallyChecked(false)
+{
+}
+
+void CheckableAlbumFilterModel::setSourceCheckableAlbumModel(AbstractCheckableAlbumModel \
*source) +{
+    setSourceModel(source);
+}
+
+AbstractCheckableAlbumModel *CheckableAlbumFilterModel::sourceAlbumModel() const
+{
+    return dynamic_cast<AbstractCheckableAlbumModel*> (sourceModel());
+}
+
+void CheckableAlbumFilterModel::setFilterChecked(bool filter)
+{
+    m_filterChecked = filter;
+    invalidateFilter();
+    emit filterChanged();
+}
+
+void CheckableAlbumFilterModel::setFilterPartiallyChecked(bool filter)
+{
+    m_filterPartiallyChecked = filter;
+    invalidateFilter();
+    emit filterChanged();
+}
+
+bool CheckableAlbumFilterModel::isFiltering() const
+{
+    return AlbumFilterModel::isFiltering() || m_filterChecked
+                    || m_filterPartiallyChecked;
+}
+
+bool CheckableAlbumFilterModel::rawMatches(Album *album) const
+{
+
+    bool accepted = AlbumFilterModel::rawMatches(album);
+
+    if (!m_filterChecked && !m_filterPartiallyChecked)
+    {
+        return accepted;
+    }
+
+    Qt::CheckState state = sourceAlbumModel()->checkState(album);
+
+    bool stateAccepted = false;
+    if (m_filterPartiallyChecked)
+    {
+        stateAccepted |= state == Qt::PartiallyChecked;
+    }
+    if (m_filterChecked)
+    {
+        stateAccepted |= state == Qt::Checked;
+    }
+
+    return accepted && stateAccepted;
+
+}
+
 } // namespace Digikam
--- branches/extragear/graphics/digikam/modelviewport/digikam/libs/models/albumfiltermodel.h \
#1056796:1056797 @@ -7,6 +7,7 @@
  * Description : Qt Model for Albums - filter model
  *
  * Copyright (C) 2008-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ * Copyright (C) 2009 by Johannes Wienke <languitar at semipol dot de>
  *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
@@ -52,8 +53,8 @@
     QModelIndex indexForAlbum(Album *album) const;
     QModelIndex rootAlbumIndex() const;
 
-    /// Returns if the set search text settings will result in any filtering
-    bool isFiltering() const;
+    /// Returns if the the filters will result in any filtering
+    virtual bool isFiltering() const;
     SearchTextSettings searchTextSettings() const;
 
     /** Returns if the filter matches this album (same logic as filterAcceptsRow).
@@ -83,17 +84,54 @@
 
 protected:
 
+    /**
+     * This method provides the basic match checking algorithm. It can be
+     * overridden to provide custom filtering.
+     *
+     * @param album album to tell if it matches the filter criteria or not.
+     */
+    virtual bool rawMatches(Album *album) const;
+
     // use setSourceAlbumModel please
     virtual void setSourceModel(QAbstractItemModel* model);
 
-    bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
-    bool lessThan(const QModelIndex& left, const QModelIndex& right) const;
+    virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) \
const; +    virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) \
const;  
 protected:
 
     SearchTextSettings m_settings;
 };
 
+/**
+ * Filter model for checkable album models that allows more filtering options
+ * based on check state.
+ */
+class CheckableAlbumFilterModel : public AlbumFilterModel
+{
+    Q_OBJECT
+public:
+    CheckableAlbumFilterModel(QObject *parent = 0);
+
+    void setSourceCheckableAlbumModel(AbstractCheckableAlbumModel *source);
+    AbstractCheckableAlbumModel *sourceAlbumModel() const;
+
+    void setFilterChecked(bool filter);
+    void setFilterPartiallyChecked(bool filter);
+
+    virtual bool isFiltering() const;
+
+protected:
+
+    virtual bool rawMatches(Album *album) const;
+
+    void setSourceAlbumModel(AbstractAlbumModel *source);
+
+    bool m_filterChecked;
+    bool m_filterPartiallyChecked;
+
+};
+
 } // namespace Digikam
 
 #endif // ALBUMFILTERMODEL_H


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

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