Move Id from Core to Utils

And add a compatibility wrapper for Core::Id, so we don't have to rename
all occurrences from Core::Id to Utils::Id.

This allows us to use Id also in Utils, which makes it possible to e.g.
move Core::InfoBar to Utils without work arounds.

Change-Id: I5555d05b4e52f09d501dbfe5d91252a982a97c61
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Eike Ziller
2020-06-17 09:14:47 +02:00
parent 5ebe34a332
commit 1b431fe271
50 changed files with 169 additions and 135 deletions

View File

@@ -26,8 +26,8 @@ add_qtc_library(Utils
consoleprocess.cpp consoleprocess.h
cpplanguage_details.h
crumblepath.cpp crumblepath.h
delegates.cpp delegates.h
declarationmacros.h
delegates.cpp delegates.h
detailsbutton.cpp detailsbutton.h
detailswidget.cpp detailswidget.h
differ.cpp differ.h
@@ -36,14 +36,9 @@ add_qtc_library(Utils
elfreader.cpp elfreader.h
elidinglabel.cpp elidinglabel.h
environment.cpp environment.h
environmentfwd.h
environmentdialog.cpp environmentdialog.h
environmentfwd.h
environmentmodel.cpp environmentmodel.h
namevaluedictionary.cpp namevaluedictionary.h
namevalueitem.cpp namevalueitem.h
namevaluemodel.cpp namevaluemodel.h
namevaluesdialog.cpp namevaluesdialog.h
namevaluevalidator.cpp namevaluevalidator.h
execmenu.cpp execmenu.h
executeondestruction.h
fadingindicator.cpp fadingindicator.h
@@ -70,6 +65,7 @@ add_qtc_library(Utils
hostosinfo.cpp hostosinfo.h
htmldocextractor.cpp htmldocextractor.h
icon.cpp icon.h
id.cpp id.h
infolabel.cpp infolabel.h
itemviews.cpp itemviews.h
json.cpp json.h
@@ -88,9 +84,14 @@ add_qtc_library(Utils
mimetypes/mimetype.cpp mimetypes/mimetype.h mimetypes/mimetype_p.h
mimetypes/mimetypeparser.cpp mimetypes/mimetypeparser_p.h
namevaluedictionary.cpp namevaluedictionary.h
namevaluedictionary.cpp namevaluedictionary.h
namevalueitem.cpp namevalueitem.h
namevalueitem.cpp namevalueitem.h
namevaluemodel.cpp namevaluemodel.h
namevaluemodel.cpp namevaluemodel.h
namevaluesdialog.cpp namevaluesdialog.h
namevaluesdialog.cpp namevaluesdialog.h
namevaluevalidator.cpp namevaluevalidator.h
namevaluevalidator.cpp namevaluevalidator.h
navigationtreeview.cpp navigationtreeview.h
networkaccessmanager.cpp networkaccessmanager.h

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
@@ -25,8 +25,8 @@
#include "id.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include "algorithm.h"
#include "qtcassert.h"
#include <QByteArray>
#include <QDataStream>
@@ -36,17 +36,17 @@
#include <string.h>
namespace Core {
namespace Utils {
/*!
\class Core::Id
\inheaderfile coreplugin/id.h
\class Utils::Id
\inheaderfile utils/id.h
\inmodule QtCreator
\brief The Id class encapsulates an identifier that is unique
within a specific running \QC process.
\c{Core::Id} is used as facility to identify objects of interest
\c{Utils::Id} is used as facility to identify objects of interest
in a more typesafe and faster manner than a plain QString or
QByteArray would provide.
@@ -125,7 +125,7 @@ static quintptr theId(const QByteArray &ba)
}
/*!
\fn Core::Id::Id(quintptr uid)
\fn Utils::Id::Id(quintptr uid)
\internal
Constructs an id given \a UID.
@@ -312,7 +312,7 @@ bool Id::operator==(const char *name) const
}
// For debugging purposes
CORE_EXPORT const char *nameForId(quintptr id)
QTCREATOR_UTILS_EXPORT const char *nameForId(quintptr id)
{
return stringFromId.value(id).str;
}
@@ -338,24 +338,24 @@ QString Id::suffixAfter(Id baseId) const
return n.startsWith(b) ? QString::fromUtf8(n.mid(b.size())) : QString();
}
} // namespace Core
} // namespace Utils
QT_BEGIN_NAMESPACE
QDataStream &operator<<(QDataStream &ds, Core::Id id)
QDataStream &operator<<(QDataStream &ds, Utils::Id id)
{
return ds << id.name();
}
QDataStream &operator>>(QDataStream &ds, Core::Id &id)
QDataStream &operator>>(QDataStream &ds, Utils::Id &id)
{
QByteArray ba;
ds >> ba;
id = Core::Id::fromName(ba);
id = Utils::Id::fromName(ba);
return ds;
}
QDebug operator<<(QDebug dbg, const Core::Id &id)
QDebug operator<<(QDebug dbg, const Utils::Id &id)
{
return dbg << id.name();
}

92
src/libs/utils/id.h Normal file
View File

@@ -0,0 +1,92 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://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 https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "utils_global.h"
#include <QMetaType>
#include <QString>
QT_BEGIN_NAMESPACE
class QDataStream;
class QVariant;
QT_END_NAMESPACE
namespace Utils {
class QTCREATOR_UTILS_EXPORT Id
{
public:
Id() = default;
Id(const char *name); // Good to use.
Id(const QLatin1String &) = delete;
Id withSuffix(int suffix) const;
Id withSuffix(const char *suffix) const;
Id withSuffix(const QString &suffix) const;
Id withPrefix(const char *prefix) const;
QByteArray name() const;
QString toString() const; // Avoid.
QVariant toSetting() const; // Good to use.
QString suffixAfter(Id baseId) const;
bool isValid() const { return m_id; }
bool operator==(Id id) const { return m_id == id.m_id; }
bool operator==(const char *name) const;
bool operator!=(Id id) const { return m_id != id.m_id; }
bool operator!=(const char *name) const { return !operator==(name); }
bool operator<(Id id) const { return m_id < id.m_id; }
bool operator>(Id id) const { return m_id > id.m_id; }
bool alphabeticallyBefore(Id other) const;
quintptr uniqueIdentifier() const { return m_id; } // Avoid.
static Id fromString(const QString &str); // FIXME: avoid.
static Id fromName(const QByteArray &ba); // FIXME: avoid.
static Id fromSetting(const QVariant &variant); // Good to use.
static Id versionedId(const QByteArray &prefix, int major, int minor = -1);
static QSet<Id> fromStringList(const QStringList &list);
static QStringList toStringList(const QSet<Id> &ids);
private:
explicit Id(quintptr uid) : m_id(uid) {}
quintptr m_id = 0;
};
inline uint qHash(Id id) { return static_cast<uint>(id.uniqueIdentifier()); }
} // namespace Utils
Q_DECLARE_METATYPE(Utils::Id)
Q_DECLARE_METATYPE(QList<Utils::Id>)
QT_BEGIN_NAMESPACE
QTCREATOR_UTILS_EXPORT QDataStream &operator<<(QDataStream &ds, Utils::Id id);
QTCREATOR_UTILS_EXPORT QDataStream &operator>>(QDataStream &ds, Utils::Id &id);
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const Utils::Id &id);
QT_END_NAMESPACE

View File

@@ -134,7 +134,8 @@ SOURCES += \
$$PWD/camelcasecursor.cpp \
$$PWD/infolabel.cpp \
$$PWD/overlaywidget.cpp \
$$PWD/archive.cpp
$$PWD/archive.cpp \
$$PWD/id.cpp
HEADERS += \
$$PWD/environmentfwd.h \
@@ -285,7 +286,8 @@ HEADERS += \
$$PWD/camelcasecursor.h \
$$PWD/infolabel.h \
$$PWD/overlaywidget.h \
$$PWD/archive.h
$$PWD/archive.h \
$$PWD/id.h
FORMS += $$PWD/filewizardpage.ui \
$$PWD/projectintropage.ui \

View File

@@ -143,6 +143,8 @@ Project {
"htmldocextractor.h",
"icon.cpp",
"icon.h",
"id.cpp",
"id.h",
"infolabel.cpp",
"infolabel.h",
"itemviews.cpp",

View File

@@ -27,7 +27,6 @@
#include <QHash>
namespace Core { class Id; }
namespace Utils { class Environment; }
namespace Autotest {

View File

@@ -27,8 +27,6 @@
#include <QHash>
namespace Core { class Id; }
namespace Autotest {
class ITestFramework;

View File

@@ -34,10 +34,6 @@
#include <QFutureWatcher>
#include <QTimer>
namespace Core {
class Id;
}
QT_BEGIN_NAMESPACE
class QThreadPool;
QT_END_NAMESPACE

View File

@@ -31,8 +31,6 @@ QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace Core { class Id; }
namespace Autotest {
namespace Internal {
struct TestSettings;

View File

@@ -27,7 +27,9 @@
#include <QHash>
namespace Core { class Id; }
namespace Utils {
class Id;
}
QT_BEGIN_NAMESPACE
class QSettings;
@@ -60,8 +62,8 @@ struct TestSettings
bool popupOnFinish = true;
bool popupOnFail = false;
RunAfterBuildMode runAfterBuild = RunAfterBuildMode::None;
QHash<Core::Id, bool> frameworks;
QHash<Core::Id, bool> frameworksGrouping;
QHash<Utils::Id, bool> frameworks;
QHash<Utils::Id, bool> frameworksGrouping;
};
} // namespace Internal

View File

@@ -32,8 +32,6 @@ class QComboBox;
class QPushButton;
QT_END_NAMESPACE
namespace Core { class Id; }
namespace BareMetal {
namespace Internal {

View File

@@ -42,7 +42,6 @@ QT_END_NAMESPACE
namespace Core {
class IDocument;
class Id;
} // namespace Core
namespace TextEditor { class TextEditorWidget; }
namespace CppTools {

View File

@@ -29,8 +29,6 @@
#include <coreplugin/id.h>
namespace Core { class Id; }
namespace CMakeProjectManager {
class CMakeTool;

View File

@@ -85,7 +85,7 @@ add_qtc_plugin(Core
helpmanager.cpp helpmanager.h helpmanager_implementation.h
icontext.cpp icontext.h
icore.cpp icore.h
id.cpp id.h
id.h
idocument.cpp idocument.h
idocumentfactory.cpp idocumentfactory.h
ifilewizardextension.h

View File

@@ -26,6 +26,7 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QPointer>
#include <QString>
@@ -34,7 +35,6 @@
namespace Core {
class Command;
class Id;
class CORE_EXPORT CommandButton : public QToolButton
{

View File

@@ -20,7 +20,6 @@ SOURCES += corejsextensions.cpp \
fancytabwidget.cpp \
generalsettings.cpp \
themechooser.cpp \
id.cpp \
icontext.cpp \
jsexpander.cpp \
messagemanager.cpp \

View File

@@ -92,7 +92,6 @@ Project {
"icontext.h",
"icore.cpp",
"icore.h",
"id.cpp",
"id.h",
"idocument.cpp",
"idocument.h",

View File

@@ -25,6 +25,7 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <utils/icon.h>

View File

@@ -25,6 +25,7 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QObject>

View File

@@ -26,6 +26,7 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <utils/mimetypes/mimetype.h>
@@ -33,7 +34,6 @@
namespace Core {
class Id;
class IExternalEditor;
using ExternalEditorList = QList<IExternalEditor *>;

View File

@@ -25,6 +25,7 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QMap>

View File

@@ -25,6 +25,7 @@
#pragma once
#include "core_global.h"
#include "id.h"
#include <QSharedDataPointer>

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
@@ -25,68 +25,10 @@
#pragma once
#include "core_global.h"
#include <QMetaType>
#include <QString>
QT_BEGIN_NAMESPACE
class QDataStream;
class QVariant;
QT_END_NAMESPACE
#include <utils/id.h>
namespace Core {
class CORE_EXPORT Id
{
public:
Id() = default;
Id(const char *name); // Good to use.
Id(const QLatin1String &) = delete;
Id withSuffix(int suffix) const;
Id withSuffix(const char *suffix) const;
Id withSuffix(const QString &suffix) const;
Id withPrefix(const char *prefix) const;
QByteArray name() const;
QString toString() const; // Avoid.
QVariant toSetting() const; // Good to use.
QString suffixAfter(Id baseId) const;
bool isValid() const { return m_id; }
bool operator==(Id id) const { return m_id == id.m_id; }
bool operator==(const char *name) const;
bool operator!=(Id id) const { return m_id != id.m_id; }
bool operator!=(const char *name) const { return !operator==(name); }
bool operator<(Id id) const { return m_id < id.m_id; }
bool operator>(Id id) const { return m_id > id.m_id; }
bool alphabeticallyBefore(Id other) const;
quintptr uniqueIdentifier() const { return m_id; } // Avoid.
static Id fromString(const QString &str); // FIXME: avoid.
static Id fromName(const QByteArray &ba); // FIXME: avoid.
static Id fromSetting(const QVariant &variant); // Good to use.
static Id versionedId(const QByteArray &prefix, int major, int minor = -1);
static QSet<Id> fromStringList(const QStringList &list);
static QStringList toStringList(const QSet<Id> &ids);
private:
explicit Id(quintptr uid) : m_id(uid) {}
quintptr m_id = 0;
};
inline uint qHash(Id id) { return static_cast<uint>(id.uniqueIdentifier()); }
using Id = Utils::Id;
} // namespace Core
Q_DECLARE_METATYPE(Core::Id)
Q_DECLARE_METATYPE(QList<Core::Id>)
QT_BEGIN_NAMESPACE
QDataStream &operator<<(QDataStream &ds, Core::Id id);
QDataStream &operator>>(QDataStream &ds, Core::Id &id);
CORE_EXPORT QDebug operator<<(QDebug dbg, const Core::Id &id);
QT_END_NAMESPACE

View File

@@ -26,13 +26,13 @@
#pragma once
#include "core_global.h"
#include "id.h"
#include <QObject>
namespace Utils { class FilePath; }
namespace Core {
class Id;
class InfoBar;
namespace Internal {

View File

@@ -25,6 +25,7 @@
#pragma once
#include "core_global.h"
#include "id.h"
#include <QObject>

View File

@@ -25,6 +25,7 @@
#pragma once
#include "core_global.h"
#include "id.h"
#include <QObject>

View File

@@ -25,6 +25,7 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <utils/optional.h>

View File

@@ -25,6 +25,7 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QObject>

View File

@@ -25,6 +25,7 @@
#pragma once
#include "core_global.h"
#include "id.h"
#include <QWidget>

View File

@@ -26,13 +26,13 @@
#pragma once
#include <coreplugin/core_global.h>
#include <coreplugin/id.h>
#include <QString>
#include <QFuture>
#include <QWidget>
namespace Core {
class Id;
class FutureProgressPrivate;
class CORE_EXPORT FutureProgress : public QWidget

View File

@@ -25,6 +25,7 @@
#pragma once
#include "core_global.h"
#include "id.h"
#include <QWidget>

View File

@@ -26,13 +26,13 @@
#pragma once
#include "core_global.h"
#include "id.h"
#include <QString>
#include <QObject>
namespace Core {
class Id;
class IVersionControl;
namespace Internal { class MainWindow; }

View File

@@ -25,6 +25,8 @@
#pragma once
#include <coreplugin/id.h>
#include <QAction>
#include <QHash>
#include <QObject>
@@ -32,7 +34,6 @@
#include <functional>
namespace Core {
class Id;
class InfoBar;
}

View File

@@ -25,9 +25,10 @@
#pragma once
#include <coreplugin/id.h>
#include <QDialog>
namespace Core { class Id; }
namespace ProjectExplorer { class Kit; }
namespace Utils { class FilePath; }

View File

@@ -26,6 +26,8 @@
#include <extensionsystem/iplugin.h>
#include <coreplugin/id.h>
#include <QTextCursor>
// forward declarations
@@ -33,7 +35,6 @@ QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QPlainTextEdit)
namespace Core {
class Id;
class IEditor;
}
namespace TextEditor {

View File

@@ -25,16 +25,14 @@
#pragma once
#include <coreplugin/id.h>
#include <QObject>
#include <QVector>
#include <QVersionNumber>
QT_FORWARD_DECLARE_CLASS(QWidget)
namespace Core {
class Id;
}
namespace Utils {
class FilePath;
class PathChooser;

View File

@@ -25,9 +25,9 @@
#pragma once
#include <QDialog>
#include <coreplugin/id.h>
namespace Core { class Id; }
#include <QDialog>
namespace ProjectExplorer {
class IDeviceFactory;

View File

@@ -27,6 +27,8 @@
#include "projectexplorer_export.h"
#include <coreplugin/id.h>
#include <QObject>
#include <QVariantMap>
@@ -34,7 +36,6 @@
namespace Core {
class IEditor;
class Id;
}
namespace TextEditor {

View File

@@ -38,8 +38,6 @@ class QComboBox;
class QPushButton;
QT_END_NAMESPACE
namespace Core { class Id; }
namespace ProjectExplorer {
// Let the user pick a kit.

View File

@@ -40,7 +40,6 @@ QT_END_NAMESPACE
namespace Core {
class IMode;
class Id;
} // namespace Core
namespace Utils {

View File

@@ -27,12 +27,12 @@
#include "projectexplorer_export.h"
#include <coreplugin/id.h>
#include <utils/fancymainwindow.h>
#include <memory>
namespace Core { class Id; }
namespace ProjectExplorer {
namespace Internal {

View File

@@ -40,7 +40,6 @@
QT_FORWARD_DECLARE_CLASS(QSpacerItem)
namespace Core { class Id; }
namespace Utils { class FilePath; }
namespace ProjectExplorer {

View File

@@ -25,9 +25,10 @@
#pragma once
#include <coreplugin/id.h>
#include <QDialog>
namespace Core { class Id; }
namespace ProjectExplorer { class Kit; }
namespace QmlProfiler {

View File

@@ -29,7 +29,6 @@
#include <QObject>
namespace Core { class Id; }
namespace TextEditor {
class IAssistProcessor;

View File

@@ -29,9 +29,10 @@
#include "indenter.h"
#include <coreplugin/id.h>
#include <QWidget>
namespace Core { class Id; }
namespace TextEditor {
class ICodeStylePreferences;

View File

@@ -27,12 +27,12 @@
#include <texteditor/texteditor_global.h>
#include <coreplugin/id.h>
#include <QChar>
#include <QList>
#include <QString>
namespace Core { class Id; }
namespace TextEditor {
class TEXTEDITOR_EXPORT NameMangler

View File

@@ -27,12 +27,13 @@
#include "texteditor_global.h"
#include <coreplugin/id.h>
#include <QObject>
#include <functional>
namespace Core {
class Id;
class IEditor;
}

View File

@@ -27,6 +27,8 @@
#include "vcsbase_global.h"
#include <coreplugin/id.h>
#include <utils/fileutils.h>
#include <utils/synchronousprocess.h>
@@ -42,8 +44,6 @@ class QProcessEnvironment;
class QToolBar;
QT_END_NAMESPACE
namespace Core { class Id; }
namespace VcsBase {
class VcsCommand;

View File

@@ -49,7 +49,6 @@ class SynchronousProcessResponse;
namespace Core {
class Context;
class IVersionControl;
class Id;
class IDocument;
} // namespace Core

View File

@@ -349,7 +349,7 @@ extend_qtc_test(unittest
DEFINES CORE_STATIC_LIBRARY
SOURCES
coreicons.cpp coreicons.h
id.cpp id.h
id.h
find/ifindfilter.cpp find/ifindfilter.h
locator/ilocatorfilter.cpp locator/ilocatorfilter.h
)