forked from qt-creator/qt-creator
Designer: Add predicate to check id collisions
Task-number: QDS-8944 Change-Id: Icaff4768fbc4bd37223bccce72e40234752c5db0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -145,7 +145,9 @@ public:
|
|||||||
bool hasId(const QString &id) const;
|
bool hasId(const QString &id) const;
|
||||||
bool hasImport(const QString &importUrl) const;
|
bool hasImport(const QString &importUrl) const;
|
||||||
|
|
||||||
QString generateNewId(const QString &prefixName, const QString &fallbackPrefix = "element") const;
|
QString generateNewId(const QString &prefixName,
|
||||||
|
const QString &fallbackPrefix = "element",
|
||||||
|
std::optional<std::function<bool(const QString &)>> isDuplicate = {}) const;
|
||||||
QString generateIdFromName(const QString &name, const QString &fallbackId = "element") const;
|
QString generateIdFromName(const QString &name, const QString &fallbackId = "element") const;
|
||||||
|
|
||||||
void setActive3DSceneId(qint32 sceneId);
|
void setActive3DSceneId(qint32 sceneId);
|
||||||
|
|||||||
@@ -1516,7 +1516,9 @@ static QString firstCharToLower(const QString &string)
|
|||||||
return resultString;
|
return resultString;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Model::generateNewId(const QString &prefixName, const QString &fallbackPrefix) const
|
QString Model::generateNewId(const QString &prefixName,
|
||||||
|
const QString &fallbackPrefix,
|
||||||
|
std::optional<std::function<bool(const QString &)>> isDuplicate) const
|
||||||
{
|
{
|
||||||
// First try just the prefixName without number as postfix, then continue with 2 and further
|
// First try just the prefixName without number as postfix, then continue with 2 and further
|
||||||
// as postfix until id does not already exist.
|
// as postfix until id does not already exist.
|
||||||
@@ -1538,7 +1540,10 @@ QString Model::generateNewId(const QString &prefixName, const QString &fallbackP
|
|||||||
|
|
||||||
QString newId = newBaseId;
|
QString newId = newBaseId;
|
||||||
|
|
||||||
while (!ModelNode::isValidId(newId) || hasId(newId)
|
if (!isDuplicate.has_value())
|
||||||
|
isDuplicate = std::bind(&Model::hasId, this, std::placeholders::_1);
|
||||||
|
|
||||||
|
while (!ModelNode::isValidId(newId) || isDuplicate.value()(newId)
|
||||||
|| d->rootNode()->hasProperty(newId.toUtf8())) {
|
|| d->rootNode()->hasProperty(newId.toUtf8())) {
|
||||||
++counter;
|
++counter;
|
||||||
newId = QString(QStringLiteral("%1%2")).arg(firstCharToLower(newBaseId)).arg(counter);
|
newId = QString(QStringLiteral("%1%2")).arg(firstCharToLower(newBaseId)).arg(counter);
|
||||||
|
|||||||
Reference in New Issue
Block a user