diff options
author | Eike Ziller <eike.ziller@digia.com> | 2014-09-12 12:52:34 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2014-09-23 13:05:47 +0200 |
commit | fd9b2af9217ea295614b3061863c6b29080c42fe (patch) | |
tree | f0ad7282ce560fb03be4f12a89358db5d1856215 /src/plugins/bookmarks | |
parent | 72c33cbadd004fb9c04fa22909dcb52f855a26c2 (diff) | |
download | qt-creator-fd9b2af9217ea295614b3061863c6b29080c42fe.tar.gz |
Editors: Support drag & drop from bookmarks pane
Change-Id: I9b68d35b04968779f111885ba7a24f18fecfada5
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src/plugins/bookmarks')
-rw-r--r-- | src/plugins/bookmarks/bookmarkmanager.cpp | 31 | ||||
-rw-r--r-- | src/plugins/bookmarks/bookmarkmanager.h | 5 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp index ff8c49d276..57f6d68d42 100644 --- a/src/plugins/bookmarks/bookmarkmanager.cpp +++ b/src/plugins/bookmarks/bookmarkmanager.cpp @@ -229,6 +229,8 @@ BookmarkView::BookmarkView(BookmarkManager *manager) : setSelectionModel(manager->selectionModel()); setSelectionMode(QAbstractItemView::SingleSelection); setSelectionBehavior(QAbstractItemView::SelectRows); + setDragEnabled(true); + setDragDropMode(QAbstractItemView::DragOnly); connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(gotoBookmark(QModelIndex))); @@ -408,6 +410,35 @@ QVariant BookmarkManager::data(const QModelIndex &index, int role) const return QVariant(); } +Qt::ItemFlags BookmarkManager::flags(const QModelIndex &index) const +{ + if (!index.isValid() || index.column() !=0 || index.row() < 0 || index.row() >= m_bookmarksList.count()) + return Qt::NoItemFlags; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; +} + +Qt::DropActions BookmarkManager::supportedDragActions() const +{ + return Qt::MoveAction; +} + +QStringList BookmarkManager::mimeTypes() const +{ + return FileDropSupport::mimeTypesForFilePaths(); +} + +QMimeData *BookmarkManager::mimeData(const QModelIndexList &indexes) const +{ + auto data = new Utils::FileDropMimeData; + foreach (const QModelIndex &index, indexes) { + if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= m_bookmarksList.count()) + continue; + Bookmark *bookMark = m_bookmarksList.at(index.row()); + data->addFile(bookMark->fileName(), bookMark->lineNumber()); + } + return data; +} + void BookmarkManager::toggleBookmark() { BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); diff --git a/src/plugins/bookmarks/bookmarkmanager.h b/src/plugins/bookmarks/bookmarkmanager.h index 0fbd7876da..c390bdfe31 100644 --- a/src/plugins/bookmarks/bookmarkmanager.h +++ b/src/plugins/bookmarks/bookmarkmanager.h @@ -74,6 +74,11 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + + Qt::DropActions supportedDragActions() const; + QStringList mimeTypes() const; + QMimeData *mimeData(const QModelIndexList &indexes) const; // this QItemSelectionModel is shared by all views QItemSelectionModel *selectionModel() const; |