summaryrefslogtreecommitdiff
path: root/src/libs
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2014-09-29 14:41:42 +0200
committerEike Ziller <eike.ziller@digia.com>2014-09-30 13:08:49 +0200
commit81cb471997a83b2caf3dbb107accb0cece084e10 (patch)
treebed10b5156769fa3e81b5ba8d33c864b4a4e4d99 /src/libs
parent92c4f26e99397adb44728270011384a453e900c2 (diff)
downloadqt-creator-81cb471997a83b2caf3dbb107accb0cece084e10.tar.gz
Editors: Support dragging from outline views
Fill the line and column information in the location returned by QmlOutlineModel::sourceLocation for that. The drag & drop code also needed a way to override the executed drop action for file drops, because the QML outline supports move-drags, which would lead to the items being removed from the outline when dragged onto a split... Change-Id: I2478abc7d5aa2f3aa676cdd609ecb69a50adce8c Reviewed-by: Daniel Teske <daniel.teske@digia.com> Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/cplusplus/OverviewModel.cpp33
-rw-r--r--src/libs/cplusplus/OverviewModel.h5
-rw-r--r--src/libs/utils/fileutils.cpp44
-rw-r--r--src/libs/utils/fileutils.h8
4 files changed, 87 insertions, 3 deletions
diff --git a/src/libs/cplusplus/OverviewModel.cpp b/src/libs/cplusplus/OverviewModel.cpp
index 372d80fe5a..e016109017 100644
--- a/src/libs/cplusplus/OverviewModel.cpp
+++ b/src/libs/cplusplus/OverviewModel.cpp
@@ -34,6 +34,7 @@
#include <cplusplus/Scope.h>
#include <cplusplus/Literals.h>
#include <cplusplus/Symbols.h>
+#include <utils/fileutils.h>
using namespace CPlusPlus;
@@ -242,3 +243,35 @@ void OverviewModel::rebuild(Document::Ptr doc)
_cppDocument = doc;
endResetModel();
}
+
+Qt::ItemFlags OverviewModel::flags(const QModelIndex &index) const
+{
+ Q_UNUSED(index)
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
+}
+
+Qt::DropActions OverviewModel::supportedDragActions() const
+{
+ return Qt::MoveAction;
+}
+
+QStringList OverviewModel::mimeTypes() const
+{
+ return Utils::FileDropSupport::mimeTypesForFilePaths();
+}
+
+QMimeData *OverviewModel::mimeData(const QModelIndexList &indexes) const
+{
+ auto mimeData = new Utils::FileDropMimeData;
+ foreach (const QModelIndex &index, indexes) {
+ const QVariant fileName = data(index, FileNameRole);
+ if (!fileName.canConvert<QString>())
+ continue;
+ const QVariant lineNumber = data(index, LineNumberRole);
+ if (!fileName.canConvert<unsigned>())
+ continue;
+ mimeData->addFile(fileName.toString(), lineNumber.value<unsigned>());
+ }
+ return mimeData;
+}
+
diff --git a/src/libs/cplusplus/OverviewModel.h b/src/libs/cplusplus/OverviewModel.h
index 3f739c2a66..683da81c62 100644
--- a/src/libs/cplusplus/OverviewModel.h
+++ b/src/libs/cplusplus/OverviewModel.h
@@ -61,6 +61,11 @@ public:
Document::Ptr document() const;
Symbol *symbolFromIndex(const QModelIndex &index) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ Qt::DropActions supportedDragActions() const;
+ QStringList mimeTypes() const;
+ QMimeData *mimeData(const QModelIndexList &indexes) const;
+
public Q_SLOTS:
void rebuild(CPlusPlus::Document::Ptr doc);
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp
index a314c69ff5..1a07192066 100644
--- a/src/libs/utils/fileutils.cpp
+++ b/src/libs/utils/fileutils.cpp
@@ -778,12 +778,22 @@ bool FileDropSupport::eventFilter(QObject *obj, QEvent *event)
QList<FileSpec> tempFiles;
if (isFileDrop(de->mimeData(), &tempFiles)
&& (!m_filterFunction || m_filterFunction(de))) {
+ const FileDropMimeData *fileDropMimeData = qobject_cast<const FileDropMimeData *>(de->mimeData());
event->accept();
- de->acceptProposedAction();
+ if (fileDropMimeData && fileDropMimeData->isOverridingFileDropAction())
+ de->setDropAction(fileDropMimeData->overrideFileDropAction());
+ else
+ de->acceptProposedAction();
bool needToScheduleEmit = m_files.isEmpty();
m_files.append(tempFiles);
- if (needToScheduleEmit) // otherwise we already have a timer pending
- QTimer::singleShot(0, this, SLOT(emitFilesDropped()));
+ if (needToScheduleEmit) { // otherwise we already have a timer pending
+ // Delay the actual drop, to avoid conflict between
+ // actions that happen when opening files, and actions that the item views do
+ // after the drag operation.
+ // If we do not do this, e.g. dragging from Outline view crashes if the editor and
+ // the selected item changes
+ QTimer::singleShot(100, this, SLOT(emitFilesDropped()));
+ }
} else {
event->ignore();
}
@@ -799,6 +809,34 @@ void FileDropSupport::emitFilesDropped()
m_files.clear();
}
+/*!
+ Sets the drop action to effectively use, instead of the "proposed" drop action from the
+ drop event. This can be useful when supporting move drags within an item view, but not
+ "moving" an item from the item view into a split.
+ */
+FileDropMimeData::FileDropMimeData()
+ : m_overrideDropAction(Qt::IgnoreAction),
+ m_isOverridingDropAction(false)
+{
+
+}
+
+void FileDropMimeData::setOverrideFileDropAction(Qt::DropAction action)
+{
+ m_isOverridingDropAction = true;
+ m_overrideDropAction = action;
+}
+
+Qt::DropAction FileDropMimeData::overrideFileDropAction() const
+{
+ return m_overrideDropAction;
+}
+
+bool FileDropMimeData::isOverridingFileDropAction() const
+{
+ return m_isOverridingDropAction;
+}
+
void FileDropMimeData::addFile(const QString &filePath, int line, int column)
{
// standard mime data
diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h
index 1f20d645ff..df874c0d92 100644
--- a/src/libs/utils/fileutils.h
+++ b/src/libs/utils/fileutils.h
@@ -236,11 +236,19 @@ class QTCREATOR_UTILS_EXPORT FileDropMimeData : public QMimeData
{
Q_OBJECT
public:
+ FileDropMimeData();
+
+ void setOverrideFileDropAction(Qt::DropAction action);
+ Qt::DropAction overrideFileDropAction() const;
+ bool isOverridingFileDropAction() const;
+
void addFile(const QString &filePath, int line = -1, int column = -1);
QList<FileDropSupport::FileSpec> files() const;
private:
QList<FileDropSupport::FileSpec> m_files;
+ Qt::DropAction m_overrideDropAction;
+ bool m_isOverridingDropAction;
};
} // namespace Utils