Commit d19628dd authored by Eike Ziller's avatar Eike Ziller
Browse files

File drag&drop: Move mime data creation to central place

Especially when this gets more complicated with additional fancy windows
mime types and custom mime type for opening a file at a specific
location (dropping from Outline, Type Hierarchy et al), we should not
create that complex mime data everywhere by hand.

Change-Id: I37f6ceb287b0cd055501fdd033ac29816434a020
Reviewed-by: default avatarDaniel Teske <>
parent e815fdac
......@@ -30,6 +30,7 @@
#include "fileutils.h"
#include "savefile.h"
#include "algorithm.h"
#include "hostosinfo.h"
#include "qtcassert.h"
......@@ -718,6 +719,26 @@ FileDropSupport::FileDropSupport(QWidget *parentWidget)
QStringList FileDropSupport::mimeTypesForFilePaths()
return QStringList() << QStringLiteral("text/uri-list");
QMimeData *FileDropSupport::mimeDataForFilePaths(const QStringList &filePaths)
QList<QUrl> localUrls = Utils::transform(filePaths, [filePaths](const QString &path) {
return QUrl::fromLocalFile(path);
auto data = new QMimeData;
return data;
QMimeData *FileDropSupport::mimeDataForFilePath(const QString &filePath)
return mimeDataForFilePaths(QStringList() << filePath);
bool FileDropSupport::eventFilter(QObject *obj, QEvent *event)
......@@ -41,6 +41,7 @@ namespace Utils {class FileName; }
class QFile;
class QMimeData;
class QTemporaryFile;
class QWidget;
class QTextStream;
......@@ -199,6 +200,10 @@ class QTCREATOR_UTILS_EXPORT FileDropSupport : public QObject
FileDropSupport(QWidget *parentWidget);
static QStringList mimeTypesForFilePaths();
static QMimeData *mimeDataForFilePaths(const QStringList &filePaths);
static QMimeData *mimeDataForFilePath(const QString &filePath);
void filesDropped(const QStringList &files);
......@@ -40,7 +40,6 @@
#include <QFileInfo>
#include <QFont>
#include <QMimeData>
#include <QUrl>
namespace ProjectExplorer {
......@@ -491,20 +490,18 @@ void FlatModel::reset()
QStringList FlatModel::mimeTypes() const
return QStringList() << QStringLiteral("text/uri-list");
return Utils::FileDropSupport::mimeTypesForFilePaths();
QMimeData *FlatModel::mimeData(const QModelIndexList &indexes) const
QList<QUrl> urls;
QStringList filePaths;
foreach (const QModelIndex &index, indexes) {
Node *node = nodeForIndex(index);
if (qobject_cast<FileNode *>(node))
auto data = new QMimeData;
return data;
return Utils::FileDropSupport::mimeDataForFilePaths(filePaths);
QModelIndex FlatModel::indexForNode(const Node *node_)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment