diff options
author | Eike Ziller <eike.ziller@qt.io> | 2018-06-26 14:58:51 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2018-07-02 08:24:25 +0000 |
commit | 25fb87f9e773269e5e555e19025b1c863e861b32 (patch) | |
tree | 315fab6c6b471814c8798c9b5b32b1abda28e03e /src/plugins/coreplugin/editormanager | |
parent | b2d844b22aa7f37d2592ee6e98842c2264deb98f (diff) | |
download | qt-creator-25fb87f9e773269e5e555e19025b1c863e861b32.tar.gz |
Move editor factory search function to recently created private header
Change-Id: I74a9a58c679c265c6d723209705323e83901e040
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/coreplugin/editormanager')
4 files changed, 48 insertions, 48 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager_p.h b/src/plugins/coreplugin/editormanager/editormanager_p.h index 8c6619ffc2..2a88a5daaa 100644 --- a/src/plugins/coreplugin/editormanager/editormanager_p.h +++ b/src/plugins/coreplugin/editormanager/editormanager_p.h @@ -33,7 +33,6 @@ #include "ieditorfactory.h" #include <coreplugin/idocument.h> -#include <utils/mimetypes/mimedatabase.h> #include <QList> #include <QObject> @@ -278,50 +277,5 @@ private: QList<std::function<bool(IEditor *)>> m_closeEditorListeners; }; -/* For something that has a 'QStringList mimeTypes' (IEditorFactory - * or IExternalEditor), find the one best matching the mimetype passed in. - * Recurse over the parent classes of the mimetype to find them. */ -template <class EditorFactoryLike> -static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType, - const QList<EditorFactoryLike*> &allFactories, - QList<EditorFactoryLike*> *list) -{ - QSet<EditorFactoryLike *> matches; - // search breadth-first through parent hierarchy, e.g. for hierarchy - // * application/x-ruby - // * application/x-executable - // * application/octet-stream - // * text/plain - QList<Utils::MimeType> queue; - QSet<QString> seen; - queue.append(mimeType); - seen.insert(mimeType.name()); - while (!queue.isEmpty()) { - Utils::MimeType mt = queue.takeFirst(); - // check for matching factories - foreach (EditorFactoryLike *factory, allFactories) { - if (!matches.contains(factory)) { - foreach (const QString &mimeName, factory->mimeTypes()) { - if (mt.matchesName(mimeName)) { - list->append(factory); - matches.insert(factory); - } - } - } - } - // add parent mime types - QStringList parentNames = mt.parentMimeTypes(); - foreach (const QString &parentName, parentNames) { - const Utils::MimeType parent = Utils::mimeTypeForName(parentName); - if (parent.isValid()) { - int seenSize = seen.size(); - seen.insert(parent.name()); - if (seen.size() != seenSize) // not seen before, so add - queue.append(parent); - } - } - } -} - } // Internal } // Core diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp index fe21fb7a10..c889e39404 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory.cpp +++ b/src/plugins/coreplugin/editormanager/ieditorfactory.cpp @@ -26,7 +26,6 @@ #include "ieditorfactory.h" #include "ieditorfactory_p.h" #include "editormanager.h" -#include "editormanager_p.h" #include <utils/mimetypes/mimedatabase.h> #include <utils/qtcassert.h> diff --git a/src/plugins/coreplugin/editormanager/ieditorfactory_p.h b/src/plugins/coreplugin/editormanager/ieditorfactory_p.h index 74cd0ca029..3da7cf2fa9 100644 --- a/src/plugins/coreplugin/editormanager/ieditorfactory_p.h +++ b/src/plugins/coreplugin/editormanager/ieditorfactory_p.h @@ -26,8 +26,10 @@ #pragma once #include <utils/mimetypes/mimetype.h> +#include <utils/mimetypes/mimedatabase.h> #include <QHash> +#include <QSet> namespace Core { @@ -38,5 +40,50 @@ namespace Internal { QHash<Utils::MimeType, IEditorFactory *> userPreferredEditorFactories(); void setUserPreferredEditorFactories(const QHash<Utils::MimeType, IEditorFactory *> &factories); +/* For something that has a 'QStringList mimeTypes' (IEditorFactory + * or IExternalEditor), find the one best matching the mimetype passed in. + * Recurse over the parent classes of the mimetype to find them. */ +template <class EditorFactoryLike> +static void mimeTypeFactoryLookup(const Utils::MimeType &mimeType, + const QList<EditorFactoryLike*> &allFactories, + QList<EditorFactoryLike*> *list) +{ + QSet<EditorFactoryLike *> matches; + // search breadth-first through parent hierarchy, e.g. for hierarchy + // * application/x-ruby + // * application/x-executable + // * application/octet-stream + // * text/plain + QList<Utils::MimeType> queue; + QSet<QString> seen; + queue.append(mimeType); + seen.insert(mimeType.name()); + while (!queue.isEmpty()) { + Utils::MimeType mt = queue.takeFirst(); + // check for matching factories + foreach (EditorFactoryLike *factory, allFactories) { + if (!matches.contains(factory)) { + foreach (const QString &mimeName, factory->mimeTypes()) { + if (mt.matchesName(mimeName)) { + list->append(factory); + matches.insert(factory); + } + } + } + } + // add parent mime types + QStringList parentNames = mt.parentMimeTypes(); + foreach (const QString &parentName, parentNames) { + const Utils::MimeType parent = Utils::mimeTypeForName(parentName); + if (parent.isValid()) { + int seenSize = seen.size(); + seen.insert(parent.name()); + if (seen.size() != seenSize) // not seen before, so add + queue.append(parent); + } + } + } +} + } // Internal } // Core diff --git a/src/plugins/coreplugin/editormanager/iexternaleditor.cpp b/src/plugins/coreplugin/editormanager/iexternaleditor.cpp index 13d21e22ce..9fdb561587 100644 --- a/src/plugins/coreplugin/editormanager/iexternaleditor.cpp +++ b/src/plugins/coreplugin/editormanager/iexternaleditor.cpp @@ -25,7 +25,7 @@ #include "iexternaleditor.h" -#include "editormanager_p.h" +#include "ieditorfactory_p.h" namespace Core { |