Commit b3ad65d8 authored by Erik Verbruggen's avatar Erik Verbruggen

Fixed property conversion. Again.

parent 2295aa28
......@@ -538,7 +538,7 @@ void RewriterView::qmlTextChanged()
default: {
emitCustomNotification(StartRewriterAmend);
ModelAmender differenceHandler(m_textToModelMerger.data());
if (m_textToModelMerger->load(newQmlText.toUtf8(), differenceHandler)) {
if (m_textToModelMerger->load(newQmlText, differenceHandler)) {
lastCorrectQmlSource = newQmlText;
}
emitCustomNotification(EndRewriterAmend);
......
......@@ -255,8 +255,10 @@ void TextToModelMerger::setupImports(const Document::Ptr &doc,
differenceHandler.importAbsentInQMl(import);
}
bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differenceHandler)
bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceHandler)
{
// qDebug() << "TextToModelMerger::load with data:" << data;
const QUrl url = m_rewriterView->model()->fileUrl();
const QStringList importPaths = m_rewriterView->textModifier()->importPaths();
setActive(true);
......@@ -266,7 +268,7 @@ bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differen
foreach (const QString &importPath, importPaths)
engine.addImportPath(importPath);
QDeclarativeComponent comp(&engine);
comp.setData(data, url);
comp.setData(data.toUtf8(), url);
if (comp.status() == QDeclarativeComponent::Error) {
QList<RewriterView::Error> errors;
foreach (const QDeclarativeError &error, comp.errors())
......@@ -288,7 +290,7 @@ bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differen
Snapshot snapshot = m_rewriterView->textModifier()->getSnapshot();
const QString fileName = url.toLocalFile();
Document::Ptr doc = Document::create(fileName.isEmpty() ? QLatin1String("<internal>") : fileName);
doc->setSource(QString::fromUtf8(data.constData()));
doc->setSource(data);
doc->parseQml();
snapshot.insert(doc);
ReadingContext ctxt(snapshot, doc, importPaths);
......@@ -671,7 +673,14 @@ QVariant TextToModelMerger::convertToVariant(const ModelNode &node,
const PropertyMetaInfo propertyMetaInfo = nodeMetaInfo.property(astName, true);
if (propertyMetaInfo.isValid()) {
return Internal::PropertyParser::read(propertyMetaInfo.variantTypeId(), cleanedValue);
QVariant::Type type = propertyMetaInfo.variantTypeId();
if (type == QVariant::Invalid) {
const QString propType = propertyMetaInfo.type();
// qDebug() << "converting" << cleanedValue << "to" << propType;
return Internal::PropertyParser::read(propType, cleanedValue, node.metaInfo().metaInfo());
} else {
return Internal::PropertyParser::read(type, cleanedValue);
}
} else if (node.type() == QLatin1String("Qt/PropertyChanges")) {
// In the future, we should do the type resolving in a second pass, or delay setting properties until the full file has been parsed.
return QVariant(cleanedValue);
......@@ -827,6 +836,10 @@ void ModelAmender::shouldBeNodeListProperty(AbstractProperty &modelProperty,
void ModelAmender::variantValuesDiffer(VariantProperty &modelProperty, const QVariant &qmlVariantValue, const QString &dynamicType)
{
// qDebug()<< "ModelAmender::variantValuesDiffer for property"<<modelProperty.name()
// << "in node" << modelProperty.parentModelNode().id()
// << ", old value:" << modelProperty.value()
// << "new value:" << qmlVariantValue;
if (dynamicType.isEmpty())
modelProperty.setValue(qmlVariantValue);
else
......
......@@ -55,7 +55,7 @@ public:
bool isActive() const;
void setupImports(const QmlJS::Document::Ptr &doc, DifferenceHandler &differenceHandler);
bool load(const QByteArray &data, DifferenceHandler &differenceHandler);
bool load(const QString &data, DifferenceHandler &differenceHandler);
RewriterView *view() const
{ return m_rewriterView; }
......
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