Commit 6be9d180 authored by Kai Koehne's avatar Kai Koehne
Browse files

QuickDesigner: Fix Drag&Drop with items from different directories

Replace all non-valid characters in the item library entry name with
underscores. E.g. "subdir/X" will become "subdir_X", which is a valid name.

Reviewed-by: Thomas Hartmann
parent 095f2060
......@@ -33,9 +33,11 @@
#include "itemlibraryinfo.h"
#include "modelutilities.h"
#include "mathutils.h"
#include "invalididexception.h"
#include <QDir>
#include <QFileInfo>
#include <QDebug>
#include <QMessageBox>
namespace QmlDesigner {
......@@ -159,13 +161,20 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryEntry &itemLibraryE
QString id;
int i = 1;
QString name(;
name.remove(QLatin1Char(' '));
//remove forbidden characters
name.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_"));
do {
id = name + QString::number(i);
} while (hasId(id)); //If the name already exists count upwards
try {
} catch (InvalidIdException &e) {
// should never happen
QMessageBox::warning(0, tr("Invalid Id"), e.description());
if (!currentState().isBaseState()) {
newNode.modelNode().variantProperty("visible") = false;
newNode.setVariantProperty("visible", true);
Supports Markdown
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