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