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

List:       kde-commits
Subject:    branches/extragear/graphics/digikam/digikam
From:       Marcel Wiesweg <marcel.wiesweg () gmx ! de>
Date:       2010-09-20 19:36:05
Message-ID: 20100920193605.5CFFFAC876 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1177636 by mwiesweg:

Decouple setting the models from constructor


 M  +116 -42   albumtreeview.cpp  
 M  +22 -3     albumtreeview.h  


--- branches/extragear/graphics/digikam/digikam/albumtreeview.cpp #1177635:1177636
@@ -166,7 +166,7 @@
 
 AbstractAlbumTreeView::AbstractAlbumTreeView(AbstractSpecificAlbumModel *model, \
AlbumFilterModel *filterModel, QWidget *parent)  : QTreeView(parent), \
                StateSavingObject(this),
-      m_albumModel(0), m_albumFilterModel(0),
+      m_albumModel(0), m_albumFilterModel(0), m_dragDropHandler(0),
       d(new AbstractAlbumTreeViewPriv)
 {
     m_checkOnMiddleClick  = false;
@@ -181,29 +181,49 @@
     connect(d->resizeColumnsTimer, SIGNAL(timeout()),
             this, SLOT(adaptColumnsToContent()));
 
-    m_albumModel       = model;
+    connect(AlbumSettings::instance(), SIGNAL(setupChanged()),
+             this, SLOT(albumSettingsChanged()));
+    connect(this, SIGNAL(currentAlbumChanged(Album*)),
+            this, SLOT(currentAlbumChangedForBackupSelection(Album*)));
 
+    if (model)
+        setAlbumModel(model);
+
     if (filterModel)
         setAlbumFilterModel(filterModel);
 
-    if (!m_albumModel->rootAlbum())
+}
+
+AbstractAlbumTreeView::~AbstractAlbumTreeView()
     {
-        connect(m_albumModel, SIGNAL(rootAlbumAvailable()),
-                 this, SLOT(slotRootAlbumAvailable()));
+    delete d;
     }
 
-    connect(AlbumSettings::instance(), SIGNAL(setupChanged()),
-             this, SLOT(albumSettingsChanged()));
-    connect(this, SIGNAL(currentAlbumChanged(Album*)),
-            this, SLOT(currentAlbumChangedForBackupSelection(Album*)));
+void AbstractAlbumTreeView::setAlbumModel(AbstractSpecificAlbumModel *model)
+{
+    if (m_albumModel == model)
+        return;
 
+    if (m_albumModel)
+    {
+        disconnect(m_albumModel, 0, this, 0);
 }
 
-AbstractAlbumTreeView::~AbstractAlbumTreeView()
+    m_albumModel = model;
+    if (m_albumFilterModel)
+        m_albumFilterModel->setSourceAlbumModel(m_albumModel);
+
+    if (m_albumModel)
 {
-    delete d;
+        if (!m_albumModel->rootAlbum())
+        {
+            connect(m_albumModel, SIGNAL(rootAlbumAvailable()),
+                    this, SLOT(slotRootAlbumAvailable()));
 }
 
+    }
+}
+
 void AbstractAlbumTreeView::setAlbumFilterModel(AlbumFilterModel *filterModel)
 {
     if (filterModel == m_albumFilterModel)
@@ -886,22 +906,17 @@
                                                              AlbumFilterModel \
*filterModel, QWidget *parent)  : AbstractAlbumTreeView(model, filterModel, parent)
 {
-    // install our own connections
-    if (filterModel)
-        setAlbumFilterModel(filterModel);
-    setupConnections();
+    init();
 }
 
 AbstractCountingAlbumTreeView::AbstractCountingAlbumTreeView(AbstractCountingAlbumModel \
*model, QWidget *parent)  : AbstractAlbumTreeView(model, 0, parent)
 {
-    AlbumFilterModel *filterModel = new AlbumFilterModel(this);
-    setAlbumFilterModel(filterModel);
-    setupConnections();
+    setAlbumFilterModel(new AlbumFilterModel(this));
+    init();
 }
 
-
-void AbstractCountingAlbumTreeView::setupConnections()
+void AbstractCountingAlbumTreeView::init()
 {
     connect(this, SIGNAL(expanded(const QModelIndex &)),
              this, SLOT(slotExpanded(const QModelIndex &)));
@@ -912,6 +927,15 @@
     connect(AlbumSettings::instance(), SIGNAL(setupChanged()),
              this, SLOT(slotSetShowCount()));
 
+    if (m_albumModel)
+        setAlbumModel(static_cast<AbstractCountingAlbumModel*>(m_albumModel));
+    if (m_albumFilterModel)
+        setAlbumFilterModel(m_albumFilterModel);
+}
+
+void AbstractCountingAlbumTreeView::setAlbumModel(AbstractCountingAlbumModel *model)
+{
+    AbstractAlbumTreeView::setAlbumModel(model);
     slotSetShowCount();
 }
 
@@ -1127,31 +1151,59 @@
 
 // --------------------------------------- //
 
+AlbumTreeView::AlbumTreeView(AlbumModel *model, CheckableAlbumFilterModel \
*filterModel, QWidget *parent) +    : AbstractCheckableAlbumTreeView(model, \
filterModel, parent) +{
+    init();
+}
+
 AlbumTreeView::AlbumTreeView(AlbumModel *model, QWidget *parent)
     : AbstractCheckableAlbumTreeView(model, parent)
 {
-    AlbumDragDropHandler *handler = new AlbumDragDropHandler(albumModel());
-    albumModel()->setDragDropHandler(handler);
-    connect(handler, SIGNAL(dioResult(KJob*)),
-            this, SLOT(slotDIOResult(KJob*)));
+    init();
+}
 
-    connect(AlbumManager::instance(), SIGNAL(signalPAlbumsDirty(const QMap<int, \
                int>&)),
-            m_albumModel, SLOT(setCountMap(const QMap<int, int>&)));
-    albumModel()->setCountMap(AlbumManager::instance()->getPAlbumsCount());
-
-    expand(m_albumFilterModel->rootAlbumIndex());
+void AlbumTreeView::init()
+{
     setRootIsDecorated(false);
-
     setDragEnabled(true);
     setAcceptDrops(true);
     setDropIndicatorShown(false);
     setAutoExpandDelay(300);
+
+    if (m_albumModel)
+        setAlbumModel(albumModel());
+    if (m_albumFilterModel)
+        setAlbumFilterModel(static_cast<CheckableAlbumFilterModel*>(m_albumFilterModel));
  }
 
 AlbumTreeView::~AlbumTreeView()
 {
+    delete m_dragDropHandler;
 }
 
+void AlbumTreeView::setAlbumModel(AlbumModel *model)
+{
+    AbstractCheckableAlbumTreeView::setAlbumModel(model);
+
+    m_dragDropHandler = new AlbumDragDropHandler(albumModel());
+    connect(m_dragDropHandler, SIGNAL(dioResult(KJob*)),
+            this, SLOT(slotDIOResult(KJob*)));
+    albumModel()->setDragDropHandler(m_dragDropHandler);
+
+    connect(AlbumManager::instance(), SIGNAL(signalPAlbumsDirty(const QMap<int, \
int>&)), +            m_albumModel, SLOT(setCountMap(const QMap<int, int>&)));
+
+    albumModel()->setCountMap(AlbumManager::instance()->getPAlbumsCount());
+}
+
+void AlbumTreeView::setAlbumFilterModel(CheckableAlbumFilterModel* filterModel)
+{
+    AbstractCheckableAlbumTreeView::setAlbumFilterModel(filterModel);
+
+    expand(m_albumFilterModel->rootAlbumIndex());
+}
+
 AlbumModel *AlbumTreeView::albumModel() const
 {
     return dynamic_cast<AlbumModel*>(m_albumModel);
@@ -1193,25 +1245,53 @@
 TagTreeView::TagTreeView(TagModel *model, QWidget *parent)
     : AbstractCheckableAlbumTreeView(model, parent)
 {
-    init(model);
+    init();
 }
 
 TagTreeView::TagTreeView(TagModel *model, CheckableAlbumFilterModel* filterModel, \
QWidget *parent)  : AbstractCheckableAlbumTreeView(model, filterModel, parent)
 {
-    init(model);
+    init();
 }
 
-void TagTreeView::init(TagModel *model)
+TagTreeView::~TagTreeView()
 {
+    delete m_dragDropHandler;
+}
+
+void TagTreeView::init()
+{
     m_filteredModel = new TagPropertiesFilterModel(this);
-    m_filteredModel->setSourceTagModel(model);
+    m_modificationHelper = new TagModificationHelper(this, this);
+    setRootIsDecorated(true);
+    setDragEnabled(true);
+    setAcceptDrops(true);
+    setDropIndicatorShown(false);
+    setAutoExpandDelay(300);
+
+    if (m_albumModel)
+        setAlbumModel(albumModel());
+    if (m_albumFilterModel)
+        setAlbumFilterModel(static_cast<CheckableAlbumFilterModel*>(m_albumFilterModel));
 +}
+
+void TagTreeView::setAlbumFilterModel(CheckableAlbumFilterModel* filterModel)
+{
+    AbstractCheckableAlbumTreeView::setAlbumFilterModel(filterModel);
+
     albumFilterModel()->setSourceAlbumModel(m_filteredModel);
+    expand(m_albumFilterModel->rootAlbumIndex());
+}
 
-    m_modificationHelper = new TagModificationHelper(this, this);
+void TagTreeView::setAlbumModel(TagModel* model)
+{
+    AbstractCheckableAlbumTreeView::setAlbumModel(model);
 
-    albumModel()->setDragDropHandler(new TagDragDropHandler(albumModel()));
+    m_filteredModel->setSourceTagModel(model);
 
+    m_dragDropHandler = new TagDragDropHandler(albumModel());
+    albumModel()->setDragDropHandler(m_dragDropHandler);
+
     connect(albumModel()->dragDropHandler(), SIGNAL(assignTags(const QList<int>&, \
                const QList<int>&)),
             MetadataManager::instance(), SLOT(assignTags(const QList<int>&, const \
QList<int>&)));  
@@ -1219,14 +1299,8 @@
              m_albumModel, SLOT(setCountMap(const QMap<int, int>&)));
     albumModel()->setCountMap(AlbumManager::instance()->getTAlbumsCount());
 
-    expand(m_albumFilterModel->rootAlbumIndex());
     if (m_albumModel->rootAlbumBehavior() == AbstractAlbumModel::IncludeRootAlbum)
         setRootIsDecorated(false);
-
-    setDragEnabled(true);
-    setAcceptDrops(true);
-    setDropIndicatorShown(false);
-    setAutoExpandDelay(300);
 }
 
 TagModel *TagTreeView::albumModel() const
--- branches/extragear/graphics/digikam/digikam/albumtreeview.h #1177635:1177636
@@ -64,7 +64,11 @@
 
 public:
 
-    /// Constructs an album model. If you supply 0 for filterModel, call \
setAlbumFilterModel afterwards. +    /**
+     * Constructs an album tree view.
+     * If you give 0 for model, call setAlbumModel afterwards.
+     * If you supply 0 for filterModel, call setAlbumFilterModel afterwards.
+     */
     explicit AbstractAlbumTreeView(AbstractSpecificAlbumModel* model,
                                    AlbumFilterModel* filterModel,
                                    QWidget* parent = 0);
@@ -265,9 +269,11 @@
     virtual QPixmap pixmapForDrag(const QStyleOptionViewItem& option, \
QList<QModelIndex> indexes);  
     void setAlbumFilterModel(AlbumFilterModel* filterModel);
+    void setAlbumModel(AbstractSpecificAlbumModel* model);
 
     AbstractSpecificAlbumModel* m_albumModel;
     AlbumFilterModel*           m_albumFilterModel;
+    AlbumModelDragDropHandler*  m_dragDropHandler;
 
     bool                        m_checkOnMiddleClick;
     bool                        m_restoreCheckState;
@@ -349,6 +355,7 @@
 
 protected:
 
+    void setAlbumModel(AbstractCountingAlbumModel *model);
     void setAlbumFilterModel(AlbumFilterModel* filterModel);
     virtual void rowsInserted(const QModelIndex& parent, int start, int end);
 
@@ -361,7 +368,7 @@
 
 private:
 
-    void setupConnections();
+    void init();
 };
 
 // -------------------------------------------------------------------------------------
 @@ -433,11 +440,15 @@
 public:
 
     explicit AlbumTreeView(AlbumModel* model, QWidget* parent = 0);
+    explicit AlbumTreeView(AlbumModel* model, CheckableAlbumFilterModel* \
filteredModel, QWidget* parent = 0);  virtual ~AlbumTreeView();
     AlbumModel* albumModel() const;
     PAlbum* currentAlbum() const;
     PAlbum* albumForIndex(const QModelIndex &index) const;
 
+    void setAlbumFilterModel(CheckableAlbumFilterModel* filterModel);
+    void setAlbumModel(AlbumModel* model);
+
 public Q_SLOTS:
 
     void setCurrentAlbum(PAlbum *album, bool selectInAlbumManager = true);
@@ -446,6 +457,10 @@
 private Q_SLOTS:
 
     void slotDIOResult(KJob* job);
+
+private:
+
+    void init();
 };
 
 // -------------------------------------------------------------------------------------
 @@ -458,6 +473,7 @@
 
     explicit TagTreeView(TagModel* model, QWidget* parent = 0);
     explicit TagTreeView(TagModel* model, CheckableAlbumFilterModel* filteredModel, \
QWidget* parent = 0); +    ~TagTreeView();
     TagModel* albumModel() const;
     /// Contains only the tags filtered by properties - prefer to albumModel()
     TagPropertiesFilterModel* filteredModel() const;
@@ -465,6 +481,9 @@
     TAlbum* albumForIndex(const QModelIndex &index) const;
     TagModificationHelper* tagModificationHelper() const;
 
+    void setAlbumFilterModel(CheckableAlbumFilterModel* filterModel);
+    void setAlbumModel(TagModel* model);
+
 public Q_SLOTS:
 
     void setCurrentAlbum(TAlbum *tag, bool selectInAlbumManager = true);
@@ -481,7 +500,7 @@
 
 private:
 
-    void init(TagModel*);
+    void init();
 };
 
 // -------------------------------------------------------------------------------------



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

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