forked from qt-creator/qt-creator
Utils: Add convenience function for generating a unique Id
Change-Id: I74516ef5077009ebcf1d47c724ca63e502729ede Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <QDebug>
|
||||
#include <QHash>
|
||||
#include <QReadWriteLock>
|
||||
#include <QUuid>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Utils {
|
||||
@@ -132,6 +133,11 @@ Id::Id(const char *name)
|
||||
: m_id(theId(name, 0))
|
||||
{}
|
||||
|
||||
Id Id::generate()
|
||||
{
|
||||
return {QUuid::createUuid().toByteArray()};
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns an internal representation of the id.
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,8 @@ public:
|
||||
Id(const char *name); // Good to use.
|
||||
Id(const QLatin1String &) = delete;
|
||||
|
||||
static Id generate();
|
||||
|
||||
Id withSuffix(int suffix) const;
|
||||
Id withSuffix(const char *suffix) const;
|
||||
Id withSuffix(const QString &suffix) const;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QUuid>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Core;
|
||||
@@ -261,7 +260,7 @@ AxivionServer DashboardSettingsWidget::dashboardServer() const
|
||||
if (m_id.isValid())
|
||||
result.id = m_id;
|
||||
else
|
||||
result.id = Id::fromName(QUuid::createUuid().toByteArray());
|
||||
result.id = Id::generate();
|
||||
result.dashboard = fixUrl(m_dashboardUrl());
|
||||
result.username = m_username();
|
||||
return result;
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include <QTreeView>
|
||||
#include <QTreeWidget>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QUuid>
|
||||
|
||||
using namespace CppEditor;
|
||||
using namespace Utils;
|
||||
@@ -1295,7 +1294,7 @@ void disableChecks(const QList<Diagnostic> &diagnostics)
|
||||
QTC_ASSERT(configs.isEmpty(), return);
|
||||
config = builtinConfig();
|
||||
config.setIsReadOnly(false);
|
||||
config.setId(Utils::Id::fromString(QUuid::createUuid().toString()));
|
||||
config.setId(Id::generate());
|
||||
config.setDisplayName(Tr::tr("Custom Configuration"));
|
||||
configs << config;
|
||||
RunSettings runSettings = settings->runSettings();
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTreeView>
|
||||
#include <QUuid>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
@@ -95,7 +94,7 @@ public:
|
||||
const FilePath &qchFile,
|
||||
bool autoRun,
|
||||
bool autodetected)
|
||||
: m_id(Id::fromString(QUuid::createUuid().toString()))
|
||||
: m_id(Id::generate())
|
||||
, m_name(name)
|
||||
, m_executable(executable)
|
||||
, m_qchFile(qchFile)
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QUuid>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -104,7 +103,7 @@ CMakeTool::CMakeTool(Detection d, const Id &id)
|
||||
, m_isAutoDetected(d == AutoDetection)
|
||||
, m_introspection(std::make_unique<Internal::IntrospectionData>())
|
||||
{
|
||||
QTC_ASSERT(m_id.isValid(), m_id = Id::fromString(QUuid::createUuid().toString()));
|
||||
QTC_ASSERT(m_id.isValid(), m_id = Id::generate());
|
||||
}
|
||||
|
||||
CMakeTool::CMakeTool(const Store &map, bool fromSdk) :
|
||||
@@ -133,7 +132,7 @@ CMakeTool::~CMakeTool() = default;
|
||||
|
||||
Id CMakeTool::createId()
|
||||
{
|
||||
return Id::fromString(QUuid::createUuid().toString());
|
||||
return Id::generate();
|
||||
}
|
||||
|
||||
void CMakeTool::setFilePath(const FilePath &executable)
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QUuid>
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
@@ -70,7 +69,7 @@ ClangDiagnosticConfig ClangDiagnosticConfigsModel::createCustomConfig(
|
||||
const ClangDiagnosticConfig &baseConfig, const QString &displayName)
|
||||
{
|
||||
ClangDiagnosticConfig copied = baseConfig;
|
||||
copied.setId(Utils::Id::fromString(QUuid::createUuid().toString()));
|
||||
copied.setId(Utils::Id::generate());
|
||||
copied.setDisplayName(displayName);
|
||||
copied.setIsReadOnly(false);
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <QDir>
|
||||
#include <QMenu>
|
||||
#include <QTextCodec>
|
||||
#include <QUuid>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Utils;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QUuid>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
@@ -110,7 +109,7 @@ GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
|
||||
GitLabServer GitLabServerWidget::gitLabServer() const
|
||||
{
|
||||
GitLabServer result;
|
||||
result.id = m_mode == Edit ? Id::fromName(QUuid::createUuid().toByteArray()) : m_id;
|
||||
result.id = m_mode == Edit ? Id::generate() : m_id;
|
||||
result.host = m_host();
|
||||
result.description = m_description();
|
||||
result.token = m_token();
|
||||
|
||||
@@ -128,7 +128,7 @@ class ClientPrivate : public QObject
|
||||
public:
|
||||
ClientPrivate(Client *client, BaseClientInterface *clientInterface, const Utils::Id &id)
|
||||
: q(client)
|
||||
, m_id(id.isValid() ? id : Utils::Id::fromString(QUuid::createUuid().toString()))
|
||||
, m_id(id.isValid() ? id : Id::generate())
|
||||
, m_clientCapabilities(q->defaultClientCapabilities())
|
||||
, m_clientInterface(new InterfaceController(clientInterface))
|
||||
, m_documentSymbolCache(q)
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QUuid>
|
||||
|
||||
namespace {
|
||||
template<typename First>
|
||||
void impl_option_cat(QStringList &list, const First &first)
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QUuid>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
@@ -16,7 +15,7 @@ namespace Internal {
|
||||
ToolTreeItem::ToolTreeItem(const QString &name)
|
||||
: m_name{name}
|
||||
, m_autoDetected{false}
|
||||
, m_id(Utils::Id::fromString(QUuid::createUuid().toString()))
|
||||
, m_id(Utils::Id::generate())
|
||||
, m_unsavedChanges{true}
|
||||
{
|
||||
self_check();
|
||||
@@ -37,7 +36,7 @@ ToolTreeItem::ToolTreeItem(const ToolTreeItem &other)
|
||||
: m_name{Tr::tr("Clone of %1").arg(other.m_name)}
|
||||
, m_executable{other.m_executable}
|
||||
, m_autoDetected{false}
|
||||
, m_id{Utils::Id::fromString(QUuid::createUuid().toString())}
|
||||
, m_id{Utils::Id::generate()}
|
||||
, m_unsavedChanges{true}
|
||||
{
|
||||
self_check();
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QUuid>
|
||||
|
||||
namespace MesonProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
@@ -14,7 +12,7 @@ ToolWrapper::ToolWrapper(const QString &name, const Utils::FilePath &path, bool
|
||||
: m_version(read_version(path))
|
||||
, m_isValid{path.exists() && m_version.isValid}
|
||||
, m_autoDetected{autoDetected}
|
||||
, m_id{Utils::Id::fromString(QUuid::createUuid().toString())}
|
||||
, m_id{Utils::Id::generate()}
|
||||
, m_exe{path}
|
||||
, m_name{name}
|
||||
{}
|
||||
@@ -30,7 +28,7 @@ ToolWrapper::ToolWrapper(const QString &name,
|
||||
, m_exe{path}
|
||||
, m_name{name}
|
||||
{
|
||||
QTC_ASSERT(m_id.isValid(), m_id = Utils::Id::fromString(QUuid::createUuid().toString()));
|
||||
QTC_ASSERT(m_id.isValid(), m_id = Utils::Id::generate());
|
||||
}
|
||||
|
||||
void ToolWrapper::setExe(const Utils::FilePath &newExe)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <QList>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QUuid>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
@@ -55,7 +54,7 @@ public:
|
||||
if (dlg.exec() != QDialog::Accepted)
|
||||
return;
|
||||
CustomParserSettings newParser = dlg.settings();
|
||||
newParser.id = Utils::Id::fromString(QUuid::createUuid().toString());
|
||||
newParser.id = Utils::Id::generate();
|
||||
newParser.displayName = Tr::tr("New Parser");
|
||||
m_customParsers << newParser;
|
||||
resetListView();
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QUuid>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
|
||||
@@ -530,7 +530,6 @@ IDevice::ConstPtr DeviceManager::defaultDevice(Id deviceType) const
|
||||
#include <projectexplorer/projectexplorer_test.h>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
#include <QUuid>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
@@ -539,7 +538,7 @@ class TestDevice : public IDevice
|
||||
public:
|
||||
TestDevice()
|
||||
{
|
||||
setupId(AutoDetected, Id::fromString(QUuid::createUuid().toString()));
|
||||
setupId(AutoDetected, Id::generate());
|
||||
setType(testTypeId());
|
||||
setMachineType(Hardware);
|
||||
setOsType(HostOsInfo::hostOs());
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QDateTime>
|
||||
#include <QReadWriteLock>
|
||||
#include <QString>
|
||||
#include <QUuid>
|
||||
|
||||
/*!
|
||||
* \class ProjectExplorer::IDevice::DeviceAction
|
||||
@@ -89,7 +88,7 @@ namespace ProjectExplorer {
|
||||
|
||||
static Id newId()
|
||||
{
|
||||
return Id::fromString(QUuid::createUuid().toString());
|
||||
return Id::generate();
|
||||
}
|
||||
|
||||
const char DisplayNameKey[] = "Name";
|
||||
|
||||
@@ -131,8 +131,6 @@ bool GnuMakeParser::hasFatalErrors() const
|
||||
#ifdef WITH_TESTS
|
||||
# include <QTest>
|
||||
|
||||
# include <QUuid>
|
||||
|
||||
# include "outputparser_test.h"
|
||||
# include "projectexplorer_test.h"
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include <QIcon>
|
||||
#include <QTextStream>
|
||||
#include <QUuid>
|
||||
|
||||
#include <numeric>
|
||||
#include <optional>
|
||||
@@ -60,7 +59,7 @@ public:
|
||||
m_id(id)
|
||||
{
|
||||
if (!id.isValid())
|
||||
m_id = Id::fromString(QUuid::createUuid().toString());
|
||||
m_id = Id::generate();
|
||||
|
||||
m_unexpandedDisplayName.setDefaultValue(Tr::tr("Unnamed"));
|
||||
|
||||
|
||||
@@ -1068,7 +1068,7 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
|
||||
, m_codeAssistant(parent)
|
||||
, m_hoverHandlerRunner(parent, m_hoverHandlers)
|
||||
, m_autoCompleter(new AutoCompleter)
|
||||
, m_editorContext(Id::fromString(QUuid::createUuid().toString()))
|
||||
, m_editorContext(Id::generate())
|
||||
{
|
||||
m_selectionHighlightOverlay->show();
|
||||
auto aggregate = new Aggregation::Aggregate;
|
||||
|
||||
Reference in New Issue
Block a user