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
beb7724d
Commit
beb7724d
authored
Feb 09, 2010
by
Erik Verbruggen
Browse files
Change rewriting to use the indentation depth of the underlying text
editor.
parent
d76fa87f
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmldesigner/core/filemanager/addobjectvisitor.cpp
View file @
beb7724d
...
...
@@ -75,18 +75,18 @@ void AddObjectVisitor::insertInto(QmlJS::AST::UiObjectInitializer *ast)
UiObjectMemberList
*
insertAfter
=
searchMemberToInsertAfter
(
ast
->
members
,
QString
(),
m_propertyOrder
);
int
insertionPoint
;
int
indentD
epth
;
int
d
epth
;
QString
textToInsert
;
if
(
insertAfter
&&
insertAfter
->
member
)
{
insertionPoint
=
insertAfter
->
member
->
lastSourceLocation
().
end
();
indentD
epth
=
calculateIndentDepth
(
insertAfter
->
member
->
lastSourceLocation
());
d
epth
=
calculateIndentDepth
(
insertAfter
->
member
->
lastSourceLocation
());
textToInsert
+=
QLatin1String
(
"
\n
"
);
}
else
{
insertionPoint
=
ast
->
lbraceToken
.
end
();
indentD
epth
=
calculateIndentDepth
(
ast
->
lbraceToken
)
+
4
;
d
epth
=
calculateIndentDepth
(
ast
->
lbraceToken
)
+
indentDepth
()
;
}
textToInsert
+=
addIndentation
(
m_content
,
indentD
epth
);
textToInsert
+=
addIndentation
(
m_content
,
d
epth
);
replace
(
insertionPoint
,
0
,
QLatin1String
(
"
\n
"
)
+
textToInsert
);
setDidRewriting
(
true
);
...
...
src/plugins/qmldesigner/core/filemanager/addpropertyvisitor.cpp
View file @
beb7724d
...
...
@@ -83,7 +83,7 @@ void AddPropertyVisitor::addInMembers(QmlJS::AST::UiObjectInitializer *initializ
UiObjectMemberList
*
insertAfter
=
searchMemberToInsertAfter
(
initializer
->
members
,
m_name
,
m_propertyOrder
);
SourceLocation
endOfPreviousMember
;
SourceLocation
startOfNextMember
;
unsigned
indentD
epth
;
unsigned
d
epth
;
if
(
insertAfter
==
0
||
insertAfter
->
member
==
0
)
{
// insert as first member
...
...
@@ -94,7 +94,7 @@ void AddPropertyVisitor::addInMembers(QmlJS::AST::UiObjectInitializer *initializ
else
startOfNextMember
=
initializer
->
rbraceToken
;
indentD
epth
=
calculateIndentDepth
(
endOfPreviousMember
)
+
4
;
d
epth
=
calculateIndentDepth
(
endOfPreviousMember
)
+
indentDepth
()
;
}
else
{
endOfPreviousMember
=
insertAfter
->
member
->
lastSourceLocation
();
...
...
@@ -103,7 +103,7 @@ void AddPropertyVisitor::addInMembers(QmlJS::AST::UiObjectInitializer *initializ
else
startOfNextMember
=
initializer
->
rbraceToken
;
indentD
epth
=
calculateIndentDepth
(
endOfPreviousMember
);
d
epth
=
calculateIndentDepth
(
endOfPreviousMember
);
}
QString
newPropertyTemplate
;
...
...
@@ -129,7 +129,7 @@ void AddPropertyVisitor::addInMembers(QmlJS::AST::UiObjectInitializer *initializ
if
(
isOneLiner
)
newPropertyTemplate
+=
QLatin1Char
(
'\n'
);
const
QString
newPropertyText
=
addIndentation
(
newPropertyTemplate
.
arg
(
m_name
,
m_value
),
indentD
epth
);
const
QString
newPropertyText
=
addIndentation
(
newPropertyTemplate
.
arg
(
m_name
,
m_value
),
d
epth
);
replace
(
endOfPreviousMember
.
end
(),
0
,
QLatin1Char
(
'\n'
)
+
newPropertyText
);
setDidRewriting
(
true
);
...
...
src/plugins/qmldesigner/core/filemanager/changepropertyvisitor.cpp
View file @
beb7724d
...
...
@@ -184,8 +184,8 @@ void ChangePropertyVisitor::insertIntoArray(QmlJS::AST::UiArrayBinding *ast)
return
;
const
int
insertionPoint
=
lastMember
->
lastSourceLocation
().
end
();
const
int
indentD
epth
=
calculateIndentDepth
(
lastMember
->
firstSourceLocation
());
const
QString
indentedArrayMember
=
addIndentation
(
m_value
,
indentD
epth
);
const
int
d
epth
=
calculateIndentDepth
(
lastMember
->
firstSourceLocation
());
const
QString
indentedArrayMember
=
addIndentation
(
m_value
,
d
epth
);
replace
(
insertionPoint
,
0
,
QLatin1String
(
",
\n
"
)
+
indentedArrayMember
);
setDidRewriting
(
true
);
}
src/plugins/qmldesigner/core/filemanager/qmlrewriter.h
View file @
beb7724d
...
...
@@ -61,6 +61,8 @@ protected:
QString
textBetween
(
int
startPosition
,
int
endPosition
)
const
;
QString
textAt
(
const
QmlJS
::
AST
::
SourceLocation
&
location
)
const
;
int
indentDepth
()
const
{
return
textModifier
()
->
indentDepth
();
}
unsigned
calculateIndentDepth
(
const
QmlJS
::
AST
::
SourceLocation
&
position
)
const
;
static
QString
addIndentation
(
const
QString
&
text
,
unsigned
depth
);
static
QString
removeIndentation
(
const
QString
&
text
,
unsigned
depth
);
...
...
src/plugins/qmldesigner/core/include/basetexteditmodifier.h
View file @
beb7724d
...
...
@@ -42,6 +42,8 @@ public:
BaseTextEditModifier
(
QPlainTextEdit
*
textEdit
);
virtual
void
indent
(
int
offset
,
int
length
);
virtual
int
indentDepth
()
const
;
};
}
// namespace QmlDesigner
...
...
src/plugins/qmldesigner/core/include/componenttextmodifier.h
View file @
beb7724d
...
...
@@ -45,6 +45,8 @@ public:
virtual
void
move
(
const
MoveInfo
&
moveInfo
);
virtual
void
indent
(
int
offset
,
int
length
);
virtual
int
indentDepth
()
const
;
virtual
void
startGroup
();
virtual
void
flushGroup
();
virtual
void
commitGroup
();
...
...
src/plugins/qmldesigner/core/include/textmodifier.h
View file @
beb7724d
...
...
@@ -70,6 +70,8 @@ public:
virtual
void
move
(
const
MoveInfo
&
moveInfo
)
=
0
;
virtual
void
indent
(
int
offset
,
int
length
)
=
0
;
virtual
int
indentDepth
()
const
=
0
;
virtual
void
startGroup
()
=
0
;
virtual
void
flushGroup
()
=
0
;
virtual
void
commitGroup
()
=
0
;
...
...
src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp
View file @
beb7724d
...
...
@@ -30,6 +30,7 @@
#include
"basetexteditmodifier.h"
#include
<texteditor/basetexteditor.h>
#include
<texteditor/tabsettings.h>
using
namespace
QmlDesigner
;
...
...
@@ -58,3 +59,13 @@ void BaseTextEditModifier::indent(int offset, int length)
// qDebug() << "**** Skipping indentation";
}
}
int
BaseTextEditModifier
::
indentDepth
()
const
{
if
(
TextEditor
::
BaseTextEditor
*
bte
=
dynamic_cast
<
TextEditor
::
BaseTextEditor
*>
(
plainTextEdit
()))
{
return
bte
->
tabSettings
().
m_indentSize
;
}
else
{
Q_ASSERT
(
false
&&
"BaseTextEditModifier does not have a BaseTextEditor"
);
return
0
;
}
}
src/plugins/qmldesigner/core/model/componenttextmodifier.cpp
View file @
beb7724d
...
...
@@ -63,6 +63,11 @@ void ComponentTextModifier::indent(int offset, int length)
m_originalModifier
->
indent
(
offset
,
length
);
}
int
ComponentTextModifier
::
indentDepth
()
const
{
return
m_originalModifier
->
indentDepth
();
}
void
ComponentTextModifier
::
startGroup
()
{
m_originalModifier
->
startGroup
();
...
...
src/plugins/qmldesigner/core/model/modeltotextmerger.cpp
View file @
beb7724d
...
...
@@ -41,8 +41,6 @@
#include
<QDebug>
#define INDENT_DEPTH 4
namespace
{
enum
{
DebugRewriteActions
=
0
...
...
@@ -92,6 +90,9 @@ void ModelToTextMerger::propertiesChanged(const QList<AbstractProperty>& propert
continue
;
ModelNode
containedModelNode
;
const
int
indentDepth
=
m_rewriterView
->
textModifier
()
->
indentDepth
();
const
QString
propertyTextValue
=
QmlTextGenerator
(
getPropertyOrder
(),
indentDepth
)(
property
);
switch
(
propertyChange
)
{
case
AbstractView
::
PropertiesAdded
:
...
...
@@ -99,7 +100,7 @@ void ModelToTextMerger::propertiesChanged(const QList<AbstractProperty>& propert
containedModelNode
=
property
.
toNodeProperty
().
modelNode
();
schedule
(
new
AddPropertyRewriteAction
(
property
,
QmlTextGenerator
(
getPropertyOrder
(),
INDENT_DEPTH
)(
property
)
,
propertyTextValue
,
propertyType
(
property
),
containedModelNode
));
break
;
...
...
@@ -109,7 +110,7 @@ void ModelToTextMerger::propertiesChanged(const QList<AbstractProperty>& propert
containedModelNode
=
property
.
toNodeProperty
().
modelNode
();
schedule
(
new
ChangePropertyRewriteAction
(
property
,
QmlTextGenerator
(
getPropertyOrder
(),
INDENT_DEPTH
)(
property
)
,
propertyTextValue
,
propertyType
(
property
),
containedModelNode
));
break
;
...
...
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