diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 769c00553..37cec5339 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -97,7 +97,6 @@ bool FeedsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int Q_UNUSED(row) Q_UNUSED(column) - if (action == Qt::IgnoreAction) { return true; } @@ -134,6 +133,8 @@ bool FeedsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int feed_new->setParent(target_item); editFeed(actual_feed, feed_new); + + emit requireItemValidationAfterDragDrop(indexForItem(actual_feed)); } else if (dragged_item->kind() == FeedsModelRootItem::Category) { qDebug("Drag-drop action for category '%s' detected, editing the feed.", qPrintable(dragged_item->title())); @@ -144,6 +145,8 @@ bool FeedsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int category_new->clearChildren(); category_new->setParent(target_item); editCategory(actual_category, category_new); + + emit requireItemValidationAfterDragDrop(indexForItem(actual_category)); } } @@ -173,10 +176,6 @@ Qt::ItemFlags FeedsModel::flags(const QModelIndex &index) const { default: return base_flags | Qt::ItemIsDropEnabled; } - - - // TODO: Pokračovat tady: http://qt-project.org/doc/qt-4.8/model-view-programming.html#using-drag-and-drop-with-item-views - // neumožnit drag ani drop nad odpadkovým košem } QVariant FeedsModel::headerData(int section, Qt::Orientation orientation, int role) const { diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 19beb0eac..20bf20e3b 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -179,6 +179,9 @@ class FeedsModel : public QAbstractItemModel { void assembleCategories(CategoryAssignment categories); void assembleFeeds(FeedAssignment feeds); + signals: + void requireItemValidationAfterDragDrop(const QModelIndex &source_index); + private: FeedsModelRootItem *m_rootItem; FeedsModelRecycleBin *m_recycleBin; diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 30b430147..c35ec6dad 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -53,7 +53,8 @@ FeedsView::FeedsView(QWidget *parent) m_proxyModel = new FeedsProxyModel(this); m_sourceModel = m_proxyModel->sourceModel(); - // Timed actions. + // Connections. + connect(m_sourceModel, SIGNAL(requireItemValidationAfterDragDrop(QModelIndex)), this, SLOT(validateItemAfterDragDrop(QModelIndex))); connect(m_autoUpdateTimer, SIGNAL(timeout()), this, SLOT(executeNextAutoUpdate())); setModel(m_proxyModel); @@ -685,3 +686,12 @@ void FeedsView::contextMenuEvent(QContextMenuEvent *event) { m_contextMenuEmptySpace->exec(event->globalPos()); } } + +void FeedsView::validateItemAfterDragDrop(const QModelIndex &source_index) { + QModelIndex mapped = m_proxyModel->mapFromSource(source_index); + + if (mapped.isValid()) { + setExpanded(mapped, true); + setCurrentIndex(mapped); + } +} diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index bfc04f034..1cbc658fc 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -131,9 +131,7 @@ class FeedsView : public QTreeView { // Notifies other components about messages // counts. inline void notifyWithCounts() { - emit messageCountsChanged(m_sourceModel->countOfUnreadMessages(), - m_sourceModel->countOfAllMessages(), - m_sourceModel->hasAnyFeedNewMessages()); + emit messageCountsChanged(m_sourceModel->countOfUnreadMessages(), m_sourceModel->countOfAllMessages(), m_sourceModel->hasAnyFeedNewMessages()); } // Selects next/previous item (feed/category) in the list. @@ -162,6 +160,9 @@ class FeedsView : public QTreeView { // Show custom context menu. void contextMenuEvent(QContextMenuEvent *event); + private slots: + void validateItemAfterDragDrop(const QModelIndex &source_index); + signals: // Emitted if user/application requested updating of some feeds. void feedsUpdateRequested(const QList feeds);