Commit 125eb66b authored by Marco Bubke's avatar Marco Bubke Committed by Thomas Hartmann

QmlDesigner: Move generateNewId to AbstractView

Change-Id: I8753eae6c4f79967822003709e7cd35dbea4eeba
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent a63732e3
......@@ -159,6 +159,7 @@ public:
ModelNode modelNodeForId(const QString &id);
bool hasId(const QString &id) const;
QString generateNewId(const QString prefixName) const;
ModelNode modelNodeForInternalId(qint32 internalId);
bool hasModelNodeForInternalId(qint32 internalId) const;
......
......@@ -185,7 +185,7 @@ public:
private: // functions
Internal::InternalNodePointer internalNode() const;
QString generateNewId() const;
private: // variables
Internal::InternalNodePointer m_internalNode;
......
......@@ -375,6 +375,20 @@ bool AbstractView::hasId(const QString &id) const
return model()->d->hasId(id);
}
QString AbstractView::generateNewId(const QString prefixName) const
{
int counter = 1;
QString newId = QString("%1%2").arg(prefixName.toLower()).arg(counter);
while (hasId(newId)) {
counter += 1;
newId = QString("%1%2").arg(prefixName.toLower()).arg(counter);
}
return newId;
}
ModelNode AbstractView::modelNodeForInternalId(qint32 internalId)
{
return ModelNode(model()->d->nodeForInternalId(internalId), model(), this);
......
......@@ -125,19 +125,6 @@ ModelNode::~ModelNode()
{
}
QString ModelNode::generateNewId() const
{
int counter = 1;
QString newId = QString("%1%2").arg(QString::fromUtf8(simplifiedTypeName()).toLower()).arg(counter);
while (view()->hasId(newId)) {
counter += 1;
newId = QString("%1%2").arg(QString::fromUtf8(simplifiedTypeName()).toLower()).arg(counter);
}
return newId;
}
/*! \brief returns the name of node which is a short cut to a property like objectName
\return name of the node
*/
......@@ -152,7 +139,7 @@ QString ModelNode::id() const
QString ModelNode::validId()
{
if (id().isEmpty())
setId(generateNewId());
setId(view()->generateNewId(QString::fromUtf8(simplifiedTypeName())));
return id();
}
......
......@@ -147,17 +147,7 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary
if (!newQmlItemNode.isValid())
return newQmlItemNode;
QString id;
int i = 1;
QString name(itemLibraryEntry.name().toLower());
//remove forbidden characters
name.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
do {
id = name + QString::number(i);
i++;
} while (view->hasId(id)); //If the name already exists count upwards
newQmlItemNode.setId(id);
newQmlItemNode.setId(view->generateNewId("image"));
if (!QmlModelState(view->actualStateNode()).isBaseState()) {
newQmlItemNode.modelNode().variantProperty("opacity").setValue(0);
......@@ -224,16 +214,8 @@ QmlItemNode QmlItemNode::createQmlItemNodeFromImage(AbstractView *view, const QS
Q_ASSERT(newQmlItemNode.isValid());
QString id;
int i = 1;
QString name("image");
name.remove(QLatin1Char(' '));
do {
id = name + QString::number(i);
i++;
} while (view->hasId(id)); //If the name already exists count upwards
newQmlItemNode.setId(view->generateNewId("image"));
newQmlItemNode.setId(id);
if (!QmlModelState(view->actualStateNode()).isBaseState()) {
newQmlItemNode.modelNode().variantProperty("opacity").setValue(0);
newQmlItemNode.setVariantProperty("opacity", 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment