Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
a2cb7ceb
Commit
a2cb7ceb
authored
Mar 24, 2010
by
Erik Verbruggen
Browse files
More fixes to the autotests.
parent
221f6320
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmldesigner/core/model/propertyparser.cpp
View file @
a2cb7ceb
...
...
@@ -62,16 +62,20 @@ QVariant read(const QString &typeStr, const QString &str, const MetaInfo &metaIn
QVariant
read
(
const
QString
&
typeStr
,
const
QString
&
str
)
{
QMetaType
::
Type
type
=
static_cast
<
QMetaType
::
Type
>
(
QMetaType
::
type
(
typeStr
.
toAscii
().
constData
())
)
;
int
type
=
QMetaType
::
type
(
typeStr
.
toAscii
().
constData
());
if
(
type
==
0
)
qWarning
()
<<
"Type "
<<
typeStr
<<
" is unknown to QMetaType system. Cannot create properly typed QVariant for value "
<<
str
;
return
read
(
type
,
str
);
}
QVariant
read
(
int
variantType
,
const
QString
&
str
)
{
QVariant
value
;
bool
conversionOk
=
true
;
switch
(
t
ype
)
{
switch
(
variantT
ype
)
{
case
QMetaType
::
QPoint
:
value
=
QDeclarativeStringConverters
::
pointFFromString
(
str
,
&
conversionOk
).
toPoint
();
break
;
...
...
@@ -98,15 +102,15 @@ QVariant read(const QString &typeStr, const QString &str)
break
;
default:
{
value
=
QVariant
(
str
);
QVariant
::
Type
varType
=
static_cast
<
QVariant
::
Type
>
(
type
);
value
.
convert
(
varType
);
value
.
convert
(
static_cast
<
QVariant
::
Type
>
(
variantType
));
break
;
}
}
if
(
!
conversionOk
)
{
value
=
QVariant
();
qWarning
()
<<
"Could not convert"
<<
str
<<
"to"
<<
QMetaType
::
typeName
(
type
);
qWarning
()
<<
"Could not convert"
<<
str
<<
"to"
<<
QMetaType
::
typeName
(
variantType
);
}
return
value
;
...
...
src/plugins/qmldesigner/core/model/propertyparser.h
View file @
a2cb7ceb
...
...
@@ -40,6 +40,7 @@ namespace PropertyParser {
QVariant
read
(
const
QString
&
typeStr
,
const
QString
&
str
,
const
MetaInfo
&
metaInfo
);
QVariant
read
(
const
QString
&
typeStr
,
const
QString
&
str
);
QVariant
read
(
int
variantType
,
const
QString
&
str
);
QString
write
(
const
QVariant
&
variant
,
const
MetaInfo
&
metaInfo
);
}
// namespace PropertyParser
...
...
src/plugins/qmldesigner/core/model/texttomodelmerger.cpp
View file @
a2cb7ceb
...
...
@@ -281,7 +281,7 @@ bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differen
try
{
Snapshot
snapshot
=
m_rewriterView
->
textModifier
()
->
getSnapshot
();
const
QString
fileName
=
url
.
toLocalFile
();
Document
::
Ptr
doc
=
Document
::
create
(
fileName
);
Document
::
Ptr
doc
=
Document
::
create
(
fileName
.
isEmpty
()
?
QLatin1String
(
"<internal>"
)
:
fileName
);
doc
->
setSource
(
QString
::
fromUtf8
(
data
.
constData
()));
doc
->
parseQml
();
snapshot
.
insert
(
doc
);
...
...
@@ -332,7 +332,7 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
if
(
!
astObjectType
||
!
astInitializer
)
return
;
m_rewriterView
->
positionStorage
()
->
setNodeOffset
(
modelNode
,
ast
Node
->
firstSourceLocation
()
.
offset
);
m_rewriterView
->
positionStorage
()
->
setNodeOffset
(
modelNode
,
ast
ObjectType
->
identifierToken
.
offset
);
QString
typeName
;
int
majorVersion
;
...
...
@@ -446,7 +446,8 @@ void TextToModelMerger::syncNode(ModelNode &modelNode,
if
(
!
defaultPropertyItems
.
isEmpty
())
{
QString
defaultPropertyName
=
modelNode
.
metaInfo
().
defaultProperty
();
if
(
defaultPropertyName
.
isEmpty
())
{
qWarning
()
<<
"No default property for node type"
<<
modelNode
.
type
()
<<
", ignoring child items."
;
if
(
modelNode
.
type
()
!=
QLatin1String
(
"Qt/Component"
))
qWarning
()
<<
"No default property for node type"
<<
modelNode
.
type
()
<<
", ignoring child items."
;
}
else
{
AbstractProperty
modelProperty
=
modelNode
.
property
(
defaultPropertyName
);
if
(
modelProperty
.
isNodeListProperty
())
{
...
...
@@ -598,7 +599,6 @@ void TextToModelMerger::syncNodeListProperty(NodeListProperty &modelListProperty
QString
name
;
if
(
UiObjectDefinition
*
definition
=
cast
<
UiObjectDefinition
*>
(
arrayMember
))
name
=
flatten
(
definition
->
qualifiedTypeNameId
);
// TODO: resolve name here!
if
(
name
==
QLatin1String
(
"Qt/Component"
))
setupComponent
(
newNode
);
}
...
...
@@ -646,7 +646,7 @@ QVariant TextToModelMerger::convertToVariant(const ModelNode &node,
const
PropertyMetaInfo
propertyMetaInfo
=
nodeMetaInfo
.
property
(
astName
,
true
);
if
(
propertyMetaInfo
.
isValid
())
{
return
Internal
::
PropertyParser
::
read
(
propertyMetaInfo
.
t
ype
(),
cleanedValue
,
nodeMetaInfo
.
metaInfo
()
);
return
Internal
::
PropertyParser
::
read
(
propertyMetaInfo
.
variantT
ype
Id
(),
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
);
...
...
tests/auto/qml/qmldesigner/coretests/testcore.cpp
View file @
a2cb7ceb
...
...
@@ -2126,7 +2126,7 @@ void TestCore::testRewriterPropertyDeclarations()
VariantProperty
urlProperty
=
rootModelNode
.
property
(
QLatin1String
(
"urlProperty"
)).
toVariantProperty
();
QVERIFY
(
urlProperty
.
isValid
());
QVERIFY
(
urlProperty
.
isVariantProperty
());
QCOMPARE
(
urlProperty
.
value
(),
QVariant
());
QCOMPARE
(
urlProperty
.
value
(),
QVariant
(
QUrl
()
));
}
void
TestCore
::
testRewriterPropertyAliases
()
...
...
@@ -2225,53 +2225,47 @@ void TestCore::testRewriterPositionAndOffset()
QVERIFY
(
rootNode
.
isValid
());
QCOMPARE
(
rootNode
.
type
(),
QLatin1String
(
"Qt/Rectangle"
));
QString
string
;
string
=
""
;
for
(
int
i
=
testRewriterView
->
nodeOffset
(
rootNode
);
i
<
testRewriterView
->
nodeOffset
(
rootNode
)
+
testRewriterView
->
nodeLength
(
rootNode
);
i
++
)
string
+=
QString
(
qmlString
)[
i
];
const
QString
qmlExpected0
(
"Rectangle {
\n
"
" id: root
\n
"
" x: 10;
\n
"
" y: 10;
\n
"
" Rectangle {
\n
"
" id: rectangle1
\n
"
" x: 10;
\n
"
" y: 10;
\n
"
" }
\n
"
" Rectangle {
\n
"
" id: rectangle2
\n
"
" x: 100;
\n
"
" y: 100;
\n
"
" anchors.fill: root
\n
"
" }
\n
"
" Rectangle {
\n
"
" id: rectangle3
\n
"
" x: 140;
\n
"
" y: 180;
\n
"
" gradient: Gradient {
\n
"
" GradientStop {
\n
"
" position: 0
\n
"
" color:
\"
white
\"\n
"
" }
\n
"
" GradientStop {
\n
"
" position: 1
\n
"
" color:
\"
black
\"\n
"
" }
\n
"
" }
\n
"
" }
\n
"
"}"
);
QString
string
=
QString
(
qmlString
).
mid
(
testRewriterView
->
nodeOffset
(
rootNode
),
testRewriterView
->
nodeLength
(
rootNode
));
const
QString
qmlExpected0
(
"Rectangle {
\n
"
" id: root
\n
"
" x: 10;
\n
"
" y: 10;
\n
"
" Rectangle {
\n
"
" id: rectangle1
\n
"
" x: 10;
\n
"
" y: 10;
\n
"
" }
\n
"
" Rectangle {
\n
"
" id: rectangle2
\n
"
" x: 100;
\n
"
" y: 100;
\n
"
" anchors.fill: root
\n
"
" }
\n
"
" Rectangle {
\n
"
" id: rectangle3
\n
"
" x: 140;
\n
"
" y: 180;
\n
"
" gradient: Gradient {
\n
"
" GradientStop {
\n
"
" position: 0
\n
"
" color:
\"
white
\"\n
"
" }
\n
"
" GradientStop {
\n
"
" position: 1
\n
"
" color:
\"
black
\"\n
"
" }
\n
"
" }
\n
"
" }
\n
"
"}"
);
QCOMPARE
(
string
,
qmlExpected0
);
ModelNode
lastRectNode
=
rootNode
.
allDirectSubModelNodes
().
last
();
ModelNode
gradientNode
=
lastRectNode
.
allDirectSubModelNodes
().
first
();
ModelNode
gradientStop
=
gradientNode
.
allDirectSubModelNodes
().
first
();
string
=
""
;
for
(
int
i
=
testRewriterView
->
nodeOffset
(
gradientNode
);
i
<
testRewriterView
->
nodeOffset
(
gradientNode
)
+
testRewriterView
->
nodeLength
(
gradientNode
);
i
++
)
string
+=
QString
(
qmlString
)[
i
];
int
offset
=
testRewriterView
->
nodeOffset
(
gradientNode
);
int
length
=
testRewriterView
->
nodeLength
(
gradientNode
);
string
=
QString
(
qmlString
).
mid
(
offset
,
length
);
const
QString
qmlExpected1
(
"Gradient {
\n
"
" GradientStop {
\n
"
" position: 0
\n
"
...
...
@@ -2282,13 +2276,9 @@ void TestCore::testRewriterPositionAndOffset()
" color:
\"
black
\"\n
"
" }
\n
"
" }"
);
QCOMPARE
(
string
,
qmlExpected1
);
string
=
""
;
for
(
int
i
=
testRewriterView
->
nodeOffset
(
gradientStop
);
i
<
testRewriterView
->
nodeOffset
(
gradientStop
)
+
testRewriterView
->
nodeLength
(
gradientStop
);
i
++
)
string
+=
QString
(
qmlString
)[
i
];
string
=
QString
(
qmlString
).
mid
(
testRewriterView
->
nodeOffset
(
gradientStop
),
testRewriterView
->
nodeLength
(
gradientStop
));
const
QString
qmlExpected2
(
"GradientStop {
\n
"
" position: 0
\n
"
" color:
\"
white
\"\n
"
...
...
@@ -2425,51 +2415,56 @@ void TestCore::testRewriterPreserveType()
void
TestCore
::
testRewriterForArrayMagic
()
{
const
QLatin1String
qmlString
(
"import Qt 4.6
\n
"
"
\n
"
"Rectangle {
\n
"
" states: State {
\n
"
" name:
\"
s1
\"\n
"
" }
\n
"
"}
\n
"
);
QPlainTextEdit
textEdit
;
textEdit
.
setPlainText
(
qmlString
);
NotIndentingTextEditModifier
textModifier
(
&
textEdit
);
QScopedPointer
<
Model
>
model
(
Model
::
create
(
"Qt/Item"
,
4
,
6
));
QVERIFY
(
model
.
data
());
QScopedPointer
<
TestView
>
view
(
new
TestView
);
model
->
attachView
(
view
.
data
());
try
{
const
QLatin1String
qmlString
(
"import Qt 4.6
\n
"
"
\n
"
"Rectangle {
\n
"
" states: State {
\n
"
" name:
\"
s1
\"\n
"
" }
\n
"
"}
\n
"
);
QPlainTextEdit
textEdit
;
textEdit
.
setPlainText
(
qmlString
);
NotIndentingTextEditModifier
textModifier
(
&
textEdit
);
// read in
QScopedPointer
<
TestRewriterView
>
testRewriterView
(
new
TestRewriterView
());
testRewriterView
->
setTextModifier
(
&
textModifier
);
model
->
attachView
(
testRewriterView
.
data
());
QScopedPointer
<
Model
>
model
(
Model
::
create
(
"Qt/Item"
,
4
,
6
));
QVERIFY
(
model
.
data
());
ModelNode
rootNode
=
view
->
rootModelNode
();
QVERIFY
(
rootNode
.
isValid
());
QCOMPARE
(
rootNode
.
type
(),
QString
(
"Qt/Rectangle"
));
QScopedPointer
<
TestView
>
view
(
new
TestView
);
model
->
attachView
(
view
.
data
());
QmlItemNode
rootItem
(
rootNode
);
QVERIFY
(
rootItem
.
isValid
());
// read in
QScopedPointer
<
TestRewriterView
>
testRewriterView
(
new
TestRewriterView
());
testRewriterView
->
setTextModifier
(
&
textModifier
);
model
->
attachView
(
testRewriterView
.
data
());
QmlModelState
state1
(
rootItem
.
states
().
addState
(
"s2"
));
QCOMPARE
(
state1
.
modelNode
().
type
(),
QString
(
"Qt/State"
));
ModelNode
rootNode
=
view
->
rootModelNode
();
QVERIFY
(
rootNode
.
isValid
());
QCOMPARE
(
rootNode
.
type
(),
QString
(
"Qt/Rectangle"
));
const
QLatin1String
expected
(
"import Qt 4.6
\n
"
"
\n
"
"Rectangle {
\n
"
" states: [
\n
"
" State {
\n
"
" name:
\"
s1
\"\n
"
" },
\n
"
" State {
\n
"
" name:
\"
s2
\"\n
"
" }
\n
"
" ]
\n
"
"}
\n
"
);
QCOMPARE
(
textEdit
.
toPlainText
(),
expected
);
QmlItemNode
rootItem
(
rootNode
);
QVERIFY
(
rootItem
.
isValid
());
QmlModelState
state1
(
rootItem
.
states
().
addState
(
"s2"
));
QCOMPARE
(
state1
.
modelNode
().
type
(),
QString
(
"Qt/State"
));
const
QLatin1String
expected
(
"import Qt 4.6
\n
"
"
\n
"
"Rectangle {
\n
"
" states: [
\n
"
" State {
\n
"
" name:
\"
s1
\"\n
"
" },
\n
"
" State {
\n
"
" name:
\"
s2
\"\n
"
" }
\n
"
" ]
\n
"
"}
\n
"
);
QCOMPARE
(
textEdit
.
toPlainText
(),
expected
);
}
catch
(
Exception
&
e
)
{
qDebug
()
<<
"Exception:"
<<
e
.
description
()
<<
"at line"
<<
e
.
line
()
<<
"in function"
<<
e
.
function
()
<<
"in file"
<<
e
.
file
();
QFAIL
(
qPrintable
(
e
.
description
()));
}
}
void
TestCore
::
testRewriterWithSignals
()
...
...
@@ -4930,9 +4925,7 @@ void TestCore::testRewriterChangeId()
QCOMPARE
(
rootModelNode
.
id
(),
QString
(
"rectId"
));
QString
expected
=
"import Qt 4.6
\n
"
"Rectangle {
\n
"
"id: rectId
\n
"
" }"
;
"Rectangle { id: rectId }"
;
QCOMPARE
(
textEdit
.
toPlainText
(),
expected
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment