diff --git a/src/libs/cplusplus/OverviewModel.cpp b/src/libs/cplusplus/OverviewModel.cpp index 0792448a119..3942dcadb82 100644 --- a/src/libs/cplusplus/OverviewModel.cpp +++ b/src/libs/cplusplus/OverviewModel.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include using namespace CPlusPlus; @@ -258,12 +258,12 @@ Qt::DropActions OverviewModel::supportedDragActions() const QStringList OverviewModel::mimeTypes() const { - return Utils::FileDropSupport::mimeTypesForFilePaths(); + return Utils::DropSupport::mimeTypesForFilePaths(); } QMimeData *OverviewModel::mimeData(const QModelIndexList &indexes) const { - auto mimeData = new Utils::FileDropMimeData; + auto mimeData = new Utils::DropMimeData; foreach (const QModelIndex &index, indexes) { const QVariant fileName = data(index, FileNameRole); if (!fileName.canConvert()) diff --git a/src/libs/utils/dropsupport.cpp b/src/libs/utils/dropsupport.cpp new file mode 100644 index 00000000000..6f325a175b9 --- /dev/null +++ b/src/libs/utils/dropsupport.cpp @@ -0,0 +1,240 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "dropsupport.h" + +#include "qtcassert.h" + +#include +#include +#include +#include + +#ifdef Q_OS_OSX +// for file drops from Finder, working around QTBUG-40449 +namespace Utils { +namespace Internal { +extern QUrl filePathUrl(const QUrl &url); +} // Internal +} // Utils +#endif + +namespace Utils { + +static bool isFileDrop(const QMimeData *d, QList *files = 0) +{ + // internal drop + if (const DropMimeData *internalData = qobject_cast(d)) { + if (files) + *files = internalData->files(); + return !internalData->files().isEmpty(); + } + + // external drop + if (files) + files->clear(); + // Extract dropped files from Mime data. + if (!d->hasUrls()) + return false; + const QList urls = d->urls(); + if (urls.empty()) + return false; + // Try to find local files + bool hasFiles = false; + const QList::const_iterator cend = urls.constEnd(); + for (QList::const_iterator it = urls.constBegin(); it != cend; ++it) { + QUrl url = *it; +#ifdef Q_OS_OSX + // for file drops from Finder, working around QTBUG-40449 + url = Internal::filePathUrl(url); +#endif + const QString fileName = url.toLocalFile(); + if (!fileName.isEmpty()) { + hasFiles = true; + if (files) + files->append(DropSupport::FileSpec(fileName)); + else + break; // No result list, sufficient for checking + } + } + return hasFiles; +} + +DropSupport::DropSupport(QWidget *parentWidget, const DropFilterFunction &filterFunction) + : QObject(parentWidget), + m_filterFunction(filterFunction) +{ + QTC_ASSERT(parentWidget, return); + parentWidget->setAcceptDrops(true); + parentWidget->installEventFilter(this); +} + +QStringList DropSupport::mimeTypesForFilePaths() +{ + return QStringList() << QStringLiteral("text/uri-list"); +} + +bool DropSupport::isFileDrop(QDropEvent *event) const +{ + return Utils::isFileDrop(event->mimeData()); +} + +bool DropSupport::isValueDrop(QDropEvent *event) const +{ + if (const DropMimeData *internalData = qobject_cast(event->mimeData())) { + return !internalData->values().isEmpty(); + } + return false; +} + +bool DropSupport::eventFilter(QObject *obj, QEvent *event) +{ + Q_UNUSED(obj) + if (event->type() == QEvent::DragEnter) { + auto dee = static_cast(event); + if ((isFileDrop(dee) || isValueDrop(dee)) && (!m_filterFunction || m_filterFunction(dee, this))) { + event->accept(); + } else { + event->ignore(); + } + return true; + } else if (event->type() == QEvent::DragMove) { + event->accept(); + return true; + } else if (event->type() == QEvent::Drop) { + bool accepted = false; + auto de = static_cast(event); + if (!m_filterFunction || m_filterFunction(de, this)) { + const DropMimeData *fileDropMimeData = qobject_cast(de->mimeData()); + QList tempFiles; + if (Utils::isFileDrop(de->mimeData(), &tempFiles)) { + event->accept(); + accepted = true; + 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 + // 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())); + } + } + if (fileDropMimeData && !fileDropMimeData->values().isEmpty()) { + event->accept(); + accepted = true; + bool needToScheduleEmit = m_values.isEmpty(); + m_values.append(fileDropMimeData->values()); + m_dropPos = de->pos(); + if (needToScheduleEmit) + QTimer::singleShot(100, this, SLOT(emitValuesDropped())); + } + } + if (!accepted) { + event->ignore(); + } + return true; + } + return false; +} + +void DropSupport::emitFilesDropped() +{ + QTC_ASSERT(!m_files.isEmpty(), return); + emit filesDropped(m_files); + m_files.clear(); +} + +void DropSupport::emitValuesDropped() +{ + QTC_ASSERT(!m_values.isEmpty(), return); + emit valuesDropped(m_values, m_dropPos); + m_values.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. + */ +DropMimeData::DropMimeData() + : m_overrideDropAction(Qt::IgnoreAction), + m_isOverridingDropAction(false) +{ + +} + +void DropMimeData::setOverrideFileDropAction(Qt::DropAction action) +{ + m_isOverridingDropAction = true; + m_overrideDropAction = action; +} + +Qt::DropAction DropMimeData::overrideFileDropAction() const +{ + return m_overrideDropAction; +} + +bool DropMimeData::isOverridingFileDropAction() const +{ + return m_isOverridingDropAction; +} + +void DropMimeData::addFile(const QString &filePath, int line, int column) +{ + // standard mime data + QList currentUrls = urls(); + currentUrls.append(QUrl::fromLocalFile(filePath)); + setUrls(currentUrls); + // special mime data + m_files.append(DropSupport::FileSpec(filePath, line, column)); +} + +QList DropMimeData::files() const +{ + return m_files; +} + +void DropMimeData::addValue(const QVariant &value) +{ + m_values.append(value); +} + +QList DropMimeData::values() const +{ + return m_values; +} + +} // namespace Utils diff --git a/src/libs/utils/dropsupport.h b/src/libs/utils/dropsupport.h new file mode 100644 index 00000000000..ff3213d8435 --- /dev/null +++ b/src/libs/utils/dropsupport.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef UTILS_DROPSUPPORT_H +#define UTILS_DROPSUPPORT_H + +#include "utils_global.h" + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE +class QDropEvent; +class QWidget; +QT_END_NAMESPACE + +namespace Utils { + +class QTCREATOR_UTILS_EXPORT DropSupport : public QObject +{ + Q_OBJECT +public: + struct FileSpec { + FileSpec(const QString &path, int r = -1, int c = -1) : filePath(path), line(r), column(c) {} + QString filePath; + int line; + int column; + }; + // returns true if the event should be accepted + typedef std::function DropFilterFunction; + + DropSupport(QWidget *parentWidget, const DropFilterFunction &filterFunction = DropFilterFunction()); + + static QStringList mimeTypesForFilePaths(); + +signals: + void filesDropped(const QList &files); + void valuesDropped(const QList &values, const QPoint &dropPos); + +public: + bool isFileDrop(QDropEvent *event) const; + bool isValueDrop(QDropEvent *event) const; + +protected: + bool eventFilter(QObject *obj, QEvent *event); + +private slots: + void emitFilesDropped(); + void emitValuesDropped(); + +private: + DropFilterFunction m_filterFunction; + QList m_files; + QList m_values; + QPoint m_dropPos; + +}; + +class QTCREATOR_UTILS_EXPORT DropMimeData : public QMimeData +{ + Q_OBJECT +public: + DropMimeData(); + + void setOverrideFileDropAction(Qt::DropAction action); + Qt::DropAction overrideFileDropAction() const; + bool isOverridingFileDropAction() const; + + void addFile(const QString &filePath, int line = -1, int column = -1); + QList files() const; + + void addValue(const QVariant &value); + QList values() const; + +private: + QList m_files; + QList m_values; + Qt::DropAction m_overrideDropAction; + bool m_isOverridingDropAction; +}; + +} // namespace Utils + +#endif // UTILS_DROPSUPPORT_H diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 9979f2d6a6d..748c9ed8467 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -57,15 +57,6 @@ QDebug operator<<(QDebug dbg, const Utils::FileName &c) QT_END_NAMESPACE -#ifdef Q_OS_OSX -// for file drops from Finder, working around QTBUG-40449 -namespace Utils { -namespace Internal { -extern QUrl filePathUrl(const QUrl &url); -} // Internal -} // Utils -#endif - namespace Utils { /*! \class Utils::FileUtils @@ -785,152 +776,6 @@ int FileNameList::removeDuplicates() return removed; } -static bool isFileDrop(const QMimeData *d, QList *files = 0) -{ - // internal drop - if (const FileDropMimeData *internalData = qobject_cast(d)) { - if (files) - *files = internalData->files(); - return true; - } - - // external drop - if (files) - files->clear(); - // Extract dropped files from Mime data. - if (!d->hasUrls()) - return false; - const QList urls = d->urls(); - if (urls.empty()) - return false; - // Try to find local files - bool hasFiles = false; - const QList::const_iterator cend = urls.constEnd(); - for (QList::const_iterator it = urls.constBegin(); it != cend; ++it) { - QUrl url = *it; -#ifdef Q_OS_OSX - // for file drops from Finder, working around QTBUG-40449 - url = Internal::filePathUrl(url); -#endif - const QString fileName = url.toLocalFile(); - if (!fileName.isEmpty()) { - hasFiles = true; - if (files) - files->append(FileDropSupport::FileSpec(fileName)); - else - break; // No result list, sufficient for checking - } - } - return hasFiles; -} - -FileDropSupport::FileDropSupport(QWidget *parentWidget, const DropFilterFunction &filterFunction) - : QObject(parentWidget), - m_filterFunction(filterFunction) -{ - QTC_ASSERT(parentWidget, return); - parentWidget->setAcceptDrops(true); - parentWidget->installEventFilter(this); -} - -QStringList FileDropSupport::mimeTypesForFilePaths() -{ - return QStringList() << QStringLiteral("text/uri-list"); -} - -bool FileDropSupport::eventFilter(QObject *obj, QEvent *event) -{ - Q_UNUSED(obj) - if (event->type() == QEvent::DragEnter) { - auto dee = static_cast(event); - if (isFileDrop(dee->mimeData()) - && (!m_filterFunction || m_filterFunction(dee))) - event->accept(); - else - event->ignore(); - return true; - } else if (event->type() == QEvent::DragMove) { - event->accept(); - return true; - } else if (event->type() == QEvent::Drop) { - auto de = static_cast(event); - QList tempFiles; - if (isFileDrop(de->mimeData(), &tempFiles) - && (!m_filterFunction || m_filterFunction(de))) { - const FileDropMimeData *fileDropMimeData = qobject_cast(de->mimeData()); - event->accept(); - 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 - // 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(); - } - return true; - } - return false; -} - -void FileDropSupport::emitFilesDropped() -{ - QTC_ASSERT(!m_files.isEmpty(), return); - emit filesDropped(m_files); - 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 - QList currentUrls = urls(); - currentUrls.append(QUrl::fromLocalFile(filePath)); - setUrls(currentUrls); - // special mime data - m_files.append(FileDropSupport::FileSpec(filePath, line, column)); -} - -QList FileDropMimeData::files() const -{ - return m_files; -} - } // namespace Utils QT_BEGIN_NAMESPACE diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h index 920bbc70afe..bcb2fd5f937 100644 --- a/src/libs/utils/fileutils.h +++ b/src/libs/utils/fileutils.h @@ -36,7 +36,6 @@ #include #include // Mac. #include -#include #include #include @@ -215,58 +214,6 @@ private: bool m_autoRemove; }; -class QTCREATOR_UTILS_EXPORT FileDropSupport : public QObject -{ - Q_OBJECT -public: - struct FileSpec { - FileSpec(const QString &path, int r = -1, int c = -1) : filePath(path), line(r), column(c) {} - QString filePath; - int line; - int column; - }; - // returns true if the event should be accepted - typedef std::function DropFilterFunction; - - FileDropSupport(QWidget *parentWidget, const DropFilterFunction &filterFunction - = DropFilterFunction()); - - static QStringList mimeTypesForFilePaths(); - -signals: - void filesDropped(const QList &files); - -protected: - bool eventFilter(QObject *obj, QEvent *event); - -private slots: - void emitFilesDropped(); - -private: - DropFilterFunction m_filterFunction; - QList m_files; - -}; - -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 files() const; - -private: - QList m_files; - Qt::DropAction m_overrideDropAction; - bool m_isOverridingDropAction; -}; - } // namespace Utils QT_BEGIN_NAMESPACE diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 1b456b873ba..ed9045abf2b 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -91,7 +91,8 @@ SOURCES += $$PWD/environment.cpp \ $$PWD/progressindicator.cpp \ $$PWD/fadingindicator.cpp \ $$PWD/overridecursor.cpp \ - $$PWD/categorysortfiltermodel.cpp + $$PWD/categorysortfiltermodel.cpp \ + $$PWD/dropsupport.cpp win32:SOURCES += $$PWD/consoleprocess_win.cpp else:SOURCES += $$PWD/consoleprocess_unix.cpp @@ -194,7 +195,8 @@ HEADERS += \ $$PWD/fadingindicator.h \ $$PWD/executeondestruction.h \ $$PWD/overridecursor.h \ - $$PWD/categorysortfiltermodel.h + $$PWD/categorysortfiltermodel.h \ + $$PWD/dropsupport.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index c92516ba6cf..419c508dc8e 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -64,6 +64,8 @@ QtcLibrary { "detailsbutton.h", "detailswidget.cpp", "detailswidget.h", + "dropsupport.cpp", + "dropsupport.h", "elfreader.cpp", "elfreader.h", "elidinglabel.cpp", diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp index 1d7b08905ae..8ab54dbc4d4 100644 --- a/src/plugins/bookmarks/bookmarkmanager.cpp +++ b/src/plugins/bookmarks/bookmarkmanager.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -420,12 +421,12 @@ Qt::DropActions BookmarkManager::supportedDragActions() const QStringList BookmarkManager::mimeTypes() const { - return FileDropSupport::mimeTypesForFilePaths(); + return DropSupport::mimeTypesForFilePaths(); } QMimeData *BookmarkManager::mimeData(const QModelIndexList &indexes) const { - auto data = new FileDropMimeData; + auto data = new DropMimeData; foreach (const QModelIndex &index, indexes) { if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= m_bookmarksList.count()) continue; diff --git a/src/plugins/classview/classviewtreeitemmodel.cpp b/src/plugins/classview/classviewtreeitemmodel.cpp index 22f220f8a9b..ad14da6acaa 100644 --- a/src/plugins/classview/classviewtreeitemmodel.cpp +++ b/src/plugins/classview/classviewtreeitemmodel.cpp @@ -34,7 +34,7 @@ #include "classviewutils.h" #include -#include +#include namespace ClassView { namespace Internal { @@ -141,12 +141,12 @@ Qt::DropActions TreeItemModel::supportedDragActions() const QStringList TreeItemModel::mimeTypes() const { - return ::Utils::FileDropSupport::mimeTypesForFilePaths(); + return ::Utils::DropSupport::mimeTypesForFilePaths(); } QMimeData *TreeItemModel::mimeData(const QModelIndexList &indexes) const { - auto mimeData = new ::Utils::FileDropMimeData; + auto mimeData = new ::Utils::DropMimeData; mimeData->setOverrideFileDropAction(Qt::CopyAction); foreach (const QModelIndex &index, indexes) { const QSet locations = Utils::roleToLocations( diff --git a/src/plugins/coreplugin/editormanager/documentmodel.cpp b/src/plugins/coreplugin/editormanager/documentmodel.cpp index 997c0b21437..41b6fe05aa0 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel.cpp +++ b/src/plugins/coreplugin/editormanager/documentmodel.cpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include @@ -509,7 +509,7 @@ Qt::DropActions DocumentModelPrivate::supportedDragActions() const QStringList DocumentModelPrivate::mimeTypes() const { - return Utils::FileDropSupport::mimeTypesForFilePaths(); + return Utils::DropSupport::mimeTypesForFilePaths(); } DocumentModel::Entry *DocumentModel::entryAtRow(int row) @@ -569,7 +569,7 @@ Qt::ItemFlags DocumentModelPrivate::flags(const QModelIndex &index) const QMimeData *DocumentModelPrivate::mimeData(const QModelIndexList &indexes) const { - auto data = new Utils::FileDropMimeData; + auto data = new Utils::DropMimeData; foreach (const QModelIndex &index, indexes) { const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row()); if (!e || e->fileName().isEmpty()) diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index 2178644e240..525a684cdc1 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -135,16 +135,18 @@ EditorView::EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent) : m_container->addWidget(empty); m_widgetEditorMap.insert(empty, 0); - auto dropSupport = new FileDropSupport(this, [this](QDropEvent *event) -> bool { + auto dropSupport = new DropSupport(this, [this](QDropEvent *event, DropSupport *dropSupport) -> bool { // do not accept move events except from other editor views (i.e. their tool bars) // otherwise e.g. item views that support moving items within themselves would // also "move" the item into the editor view, i.e. the item would be removed from the // item view if (!qobject_cast(event->source())) event->setDropAction(Qt::CopyAction); + if (event->type() == QDropEvent::DragEnter && !dropSupport->isFileDrop(event)) + return false; // do not accept drops without files return event->source() != m_toolBar; // do not accept drops on ourselves }); - connect(dropSupport, &FileDropSupport::filesDropped, + connect(dropSupport, &DropSupport::filesDropped, this, &EditorView::openDroppedFiles); updateNavigatorActions(); @@ -375,11 +377,11 @@ void EditorView::closeSplit() EditorManagerPrivate::updateActions(); } -void EditorView::openDroppedFiles(const QList &files) +void EditorView::openDroppedFiles(const QList &files) { const int count = files.size(); for (int i = 0; i < count; ++i) { - const FileDropSupport::FileSpec spec = files.at(i); + const DropSupport::FileSpec spec = files.at(i); EditorManagerPrivate::openEditorAt(this, spec.filePath, spec.line, spec.column, Id(), i < count - 1 ? EditorManager::DoNotChangeCurrentEditor | EditorManager::DoNotMakeVisible diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h index b5a272e3ede..5b7d56f66a5 100644 --- a/src/plugins/coreplugin/editormanager/editorview.h +++ b/src/plugins/coreplugin/editormanager/editorview.h @@ -33,7 +33,7 @@ #include "coreplugin/id.h" -#include +#include #include #include @@ -122,7 +122,7 @@ private slots: void splitVertically(); void splitNewWindow(); void closeSplit(); - void openDroppedFiles(const QList &files); + void openDroppedFiles(const QList &files); private: friend class SplitterOrView; // for setParentSplitterOrView diff --git a/src/plugins/coreplugin/editortoolbar.cpp b/src/plugins/coreplugin/editortoolbar.cpp index f2dc220f9e5..0af71226f7f 100644 --- a/src/plugins/coreplugin/editortoolbar.cpp +++ b/src/plugins/coreplugin/editortoolbar.cpp @@ -456,7 +456,7 @@ bool EditorToolBar::eventFilter(QObject *obj, QEvent *event) if (!entry) // no document return Utils::StyledBar::eventFilter(obj, event); auto drag = new QDrag(this); - auto data = new Utils::FileDropMimeData; + auto data = new Utils::DropMimeData; data->addFile(entry->fileName().toString()); drag->setMimeData(data); Qt::DropAction action = drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction); diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 713c6372d03..a502b595a66 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -207,10 +207,10 @@ MainWindow::MainWindow() : statusBar()->setProperty("p_styled", true); - auto dropSupport = new FileDropSupport(this, [](QDropEvent *event) { + auto dropSupport = new DropSupport(this, [](QDropEvent *event, DropSupport *) { return event->source() == 0; // only accept drops from the "outside" (e.g. file manager) }); - connect(dropSupport, &FileDropSupport::filesDropped, + connect(dropSupport, &DropSupport::filesDropped, this, &MainWindow::openDroppedFiles); } @@ -371,11 +371,11 @@ void MainWindow::closeEvent(QCloseEvent *event) event->accept(); } -void MainWindow::openDroppedFiles(const QList &files) +void MainWindow::openDroppedFiles(const QList &files) { raiseWindow(); QStringList filePaths = Utils::transform(files, - [](const FileDropSupport::FileSpec &spec) -> QString { + [](const DropSupport::FileSpec &spec) -> QString { return spec.filePath; }); openFiles(filePaths, ICore::SwitchMode); diff --git a/src/plugins/coreplugin/mainwindow.h b/src/plugins/coreplugin/mainwindow.h index 516c3156f31..558c1636acf 100644 --- a/src/plugins/coreplugin/mainwindow.h +++ b/src/plugins/coreplugin/mainwindow.h @@ -35,7 +35,7 @@ #include "icore.h" #include -#include +#include #include #include @@ -135,7 +135,7 @@ private slots: void updateFocusWidget(QWidget *old, QWidget *now); void setSidebarVisible(bool visible); void destroyVersionDialog(); - void openDroppedFiles(const QList &files); + void openDroppedFiles(const QList &files); void restoreWindowState(); void newItemDialogFinished(); diff --git a/src/plugins/cppeditor/cppincludehierarchymodel.cpp b/src/plugins/cppeditor/cppincludehierarchymodel.cpp index a55c60ed228..83a63bc81c8 100644 --- a/src/plugins/cppeditor/cppincludehierarchymodel.cpp +++ b/src/plugins/cppeditor/cppincludehierarchymodel.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include @@ -260,12 +260,12 @@ Qt::DropActions CppIncludeHierarchyModel::supportedDragActions() const QStringList CppIncludeHierarchyModel::mimeTypes() const { - return Utils::FileDropSupport::mimeTypesForFilePaths(); + return Utils::DropSupport::mimeTypesForFilePaths(); } QMimeData *CppIncludeHierarchyModel::mimeData(const QModelIndexList &indexes) const { - auto data = new Utils::FileDropMimeData; + auto data = new Utils::DropMimeData; foreach (const QModelIndex &index, indexes) { const TextEditor::TextEditorWidget::Link link = index.data(LinkRole).value(); diff --git a/src/plugins/cppeditor/cpptypehierarchy.cpp b/src/plugins/cppeditor/cpptypehierarchy.cpp index 0b27e1360e1..324a304900a 100644 --- a/src/plugins/cppeditor/cpptypehierarchy.cpp +++ b/src/plugins/cppeditor/cpptypehierarchy.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -245,12 +246,12 @@ Qt::DropActions CppTypeHierarchyModel::supportedDragActions() const QStringList CppTypeHierarchyModel::mimeTypes() const { - return FileDropSupport::mimeTypesForFilePaths(); + return DropSupport::mimeTypesForFilePaths(); } QMimeData *CppTypeHierarchyModel::mimeData(const QModelIndexList &indexes) const { - auto data = new FileDropMimeData; + auto data = new DropMimeData; data->setOverrideFileDropAction(Qt::CopyAction); // do not remove the item from the model foreach (const QModelIndex &index, indexes) { auto link = index.data(LinkRole).value(); diff --git a/src/plugins/macros/macroevent.h b/src/plugins/macros/macroevent.h index f8a83e53ebd..a5904da0874 100644 --- a/src/plugins/macros/macroevent.h +++ b/src/plugins/macros/macroevent.h @@ -34,10 +34,10 @@ #include #include +#include QT_BEGIN_NAMESPACE class QByteArray; -class QVariant; class QDataStream; QT_END_NAMESPACE diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h index 736cad6e3bb..530f576d73d 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfactory.h @@ -38,6 +38,7 @@ #include #include +#include QT_BEGIN_NAMESPACE class QDir; diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp index 5986f548763..4fa29622dbe 100644 --- a/src/plugins/projectexplorer/projectmodels.cpp +++ b/src/plugins/projectexplorer/projectmodels.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -313,7 +314,7 @@ Qt::ItemFlags FlatModel::flags(const QModelIndex &index) const // We claim that everything is editable // That's slightly wrong // We control the only view, and that one does the checks - Qt::ItemFlags f = Qt::ItemIsSelectable|Qt::ItemIsEnabled; + Qt::ItemFlags f = Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled; if (Node *node = nodeForIndex(index)) { if (node == m_rootNode) return 0; // no flags for session node... @@ -321,8 +322,6 @@ Qt::ItemFlags FlatModel::flags(const QModelIndex &index) const // either folder or file node if (node->supportedActions(node).contains(Rename)) f = f | Qt::ItemIsEditable; - if (node->asFileNode()) - f = f | Qt::ItemIsDragEnabled; } } return f; @@ -490,16 +489,17 @@ Qt::DropActions FlatModel::supportedDragActions() const QStringList FlatModel::mimeTypes() const { - return Utils::FileDropSupport::mimeTypesForFilePaths(); + return Utils::DropSupport::mimeTypesForFilePaths(); } QMimeData *FlatModel::mimeData(const QModelIndexList &indexes) const { - auto data = new Utils::FileDropMimeData; + auto data = new Utils::DropMimeData; foreach (const QModelIndex &index, indexes) { Node *node = nodeForIndex(index); if (node->asFileNode()) data->addFile(node->path().toString()); + data->addValue(QVariant::fromValue(node)); } return data; } diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp index 7231abb171d..0b3f8b6797e 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.cpp +++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp @@ -39,8 +39,8 @@ #include #include -#include #include +#include #include #include @@ -318,7 +318,7 @@ QStringList QmlOutlineModel::mimeTypes() const { QStringList types; types << QLatin1String(INTERNAL_MIMETYPE); - types << Utils::FileDropSupport::mimeTypesForFilePaths(); + types << Utils::DropSupport::mimeTypesForFilePaths(); return types; } @@ -327,7 +327,7 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const { if (indexes.count() <= 0) return 0; - auto data = new Utils::FileDropMimeData; + auto data = new Utils::DropMimeData; data->setOverrideFileDropAction(Qt::CopyAction); QByteArray encoded; QDataStream stream(&encoded, QIODevice::WriteOnly); diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 71b5ec42082..3b78f9dd651 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -79,6 +79,7 @@ #include #include #include +#include #include #include #include @@ -7319,7 +7320,7 @@ void TextEditorLinkLabel::mouseMoveEvent(QMouseEvent *event) if ((event->pos() - m_dragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; - auto data = new FileDropMimeData; + auto data = new DropMimeData; data->addFile(m_link.targetFileName, m_link.targetLine, m_link.targetColumn); auto drag = new QDrag(this); drag->setMimeData(data); diff --git a/src/plugins/vcsbase/vcsbaseclient.h b/src/plugins/vcsbase/vcsbaseclient.h index f88b2440a04..50827a1384b 100644 --- a/src/plugins/vcsbase/vcsbaseclient.h +++ b/src/plugins/vcsbase/vcsbaseclient.h @@ -37,12 +37,12 @@ #include #include +#include #include QT_BEGIN_NAMESPACE class QFileInfo; -class QVariant; class QProcessEnvironment; QT_END_NAMESPACE