Expand correct node and set it as current after drag-drop action.

This commit is contained in:
Martin Rotter 2014-10-28 18:31:19 +01:00
parent 0bf6a2436d
commit 57e05f34d8
4 changed files with 22 additions and 9 deletions

View File

@ -97,7 +97,6 @@ bool FeedsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int
Q_UNUSED(row) Q_UNUSED(row)
Q_UNUSED(column) Q_UNUSED(column)
if (action == Qt::IgnoreAction) { if (action == Qt::IgnoreAction) {
return true; return true;
} }
@ -134,6 +133,8 @@ bool FeedsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int
feed_new->setParent(target_item); feed_new->setParent(target_item);
editFeed(actual_feed, feed_new); editFeed(actual_feed, feed_new);
emit requireItemValidationAfterDragDrop(indexForItem(actual_feed));
} }
else if (dragged_item->kind() == FeedsModelRootItem::Category) { else if (dragged_item->kind() == FeedsModelRootItem::Category) {
qDebug("Drag-drop action for category '%s' detected, editing the feed.", qPrintable(dragged_item->title())); 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->clearChildren();
category_new->setParent(target_item); category_new->setParent(target_item);
editCategory(actual_category, category_new); editCategory(actual_category, category_new);
emit requireItemValidationAfterDragDrop(indexForItem(actual_category));
} }
} }
@ -173,10 +176,6 @@ Qt::ItemFlags FeedsModel::flags(const QModelIndex &index) const {
default: default:
return base_flags | Qt::ItemIsDropEnabled; 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 { QVariant FeedsModel::headerData(int section, Qt::Orientation orientation, int role) const {

View File

@ -179,6 +179,9 @@ class FeedsModel : public QAbstractItemModel {
void assembleCategories(CategoryAssignment categories); void assembleCategories(CategoryAssignment categories);
void assembleFeeds(FeedAssignment feeds); void assembleFeeds(FeedAssignment feeds);
signals:
void requireItemValidationAfterDragDrop(const QModelIndex &source_index);
private: private:
FeedsModelRootItem *m_rootItem; FeedsModelRootItem *m_rootItem;
FeedsModelRecycleBin *m_recycleBin; FeedsModelRecycleBin *m_recycleBin;

View File

@ -53,7 +53,8 @@ FeedsView::FeedsView(QWidget *parent)
m_proxyModel = new FeedsProxyModel(this); m_proxyModel = new FeedsProxyModel(this);
m_sourceModel = m_proxyModel->sourceModel(); 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())); connect(m_autoUpdateTimer, SIGNAL(timeout()), this, SLOT(executeNextAutoUpdate()));
setModel(m_proxyModel); setModel(m_proxyModel);
@ -685,3 +686,12 @@ void FeedsView::contextMenuEvent(QContextMenuEvent *event) {
m_contextMenuEmptySpace->exec(event->globalPos()); 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);
}
}

View File

@ -131,9 +131,7 @@ class FeedsView : public QTreeView {
// Notifies other components about messages // Notifies other components about messages
// counts. // counts.
inline void notifyWithCounts() { inline void notifyWithCounts() {
emit messageCountsChanged(m_sourceModel->countOfUnreadMessages(), emit messageCountsChanged(m_sourceModel->countOfUnreadMessages(), m_sourceModel->countOfAllMessages(), m_sourceModel->hasAnyFeedNewMessages());
m_sourceModel->countOfAllMessages(),
m_sourceModel->hasAnyFeedNewMessages());
} }
// Selects next/previous item (feed/category) in the list. // Selects next/previous item (feed/category) in the list.
@ -162,6 +160,9 @@ class FeedsView : public QTreeView {
// Show custom context menu. // Show custom context menu.
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event);
private slots:
void validateItemAfterDragDrop(const QModelIndex &source_index);
signals: signals:
// Emitted if user/application requested updating of some feeds. // Emitted if user/application requested updating of some feeds.
void feedsUpdateRequested(const QList<FeedsModelFeed*> feeds); void feedsUpdateRequested(const QList<FeedsModelFeed*> feeds);