Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Kig
Commits
2d60444f
Commit
2d60444f
authored
May 23, 2021
by
Antonello Palazzi
Committed by
Yuri Chornoivan
Jul 05, 2021
Browse files
Fix updating function signature for python scripts to reflect object selection
BUG: 336020
parent
532f432d
Changes
3
Hide whitespace changes
Inline
Side-by-side
scripting/script-common.cc
View file @
2d60444f
...
...
@@ -31,25 +31,9 @@ QString ScriptType::templateCode( ScriptType::Type type, std::list<ObjectHolder*
{
if
(
type
==
Python
)
{
QString
tempcode
=
QStringLiteral
(
"def calc( "
);
bool
firstarg
=
true
;
KLocalizedString
temparg
=
ki18nc
(
"Note to translators: this should be a default "
"name for an argument in a Python function. The "
"default is
\"
arg%1
\"
which would become arg1, "
"arg2, etc. Give something which seems "
"appropriate for your language."
,
"arg%1"
);
uint
id
=
1
;
for
(
std
::
list
<
ObjectHolder
*>::
const_iterator
i
=
args
.
begin
();
i
!=
args
.
end
();
++
i
)
{
if
(
!
firstarg
)
tempcode
+=
QLatin1String
(
", "
);
else
firstarg
=
false
;
QString
n
=
(
*
i
)
->
name
();
tempcode
+=
n
.
isEmpty
()
?
temparg
.
subs
(
id
).
toString
()
:
n
;
id
++
;
};
QString
tempcode
{
ScriptType
::
scriptFunctionDefinition
(
type
,
args
)
};
tempcode
+=
"
):
\n
"
"
\n
"
"
\t
# Calculate whatever you want to show here, and return it.
\n
"
;
if
(
args
.
empty
()
)
{
...
...
@@ -90,6 +74,48 @@ QString ScriptType::templateCode( ScriptType::Type type, std::list<ObjectHolder*
return
QLatin1String
(
""
);
}
QString
ScriptType
::
scriptFunctionDefinition
(
ScriptType
::
Type
type
,
std
::
list
<
ObjectHolder
*>
args
)
{
if
(
type
==
Python
)
{
QString
newHeader
{
QStringLiteral
(
"def calc( "
)};
bool
firstarg
{
true
};
KLocalizedString
temparg
{
ki18nc
(
"Note to translators: this should be a default "
"name for an argument in a Python function. The "
"default is
\"
arg%1
\"
which would become arg1, "
"arg2, etc. Give something which seems "
"appropriate for your language."
,
"arg%1"
)};
uint
id
{
1
};
for
(
auto
i
{
args
.
begin
()
};
i
!=
args
.
end
();
++
i
)
{
if
(
!
firstarg
)
newHeader
+=
QLatin1String
(
", "
);
else
firstarg
=
false
;
QString
n
=
(
*
i
)
->
name
();
newHeader
+=
n
.
isEmpty
()
?
temparg
.
subs
(
id
).
toString
()
:
n
;
id
++
;
};
newHeader
+=
" ):"
;
return
newHeader
;
}
qDebug
()
<<
"No such script type: "
<<
type
;
return
QLatin1String
(
""
);
}
void
ScriptType
::
updateCodeFunction
(
ScriptType
::
Type
type
,
std
::
list
<
ObjectHolder
*>
args
,
QString
&
script
)
{
if
(
type
==
Python
)
{
QString
newHeader
{
ScriptType
::
scriptFunctionDefinition
(
type
,
args
)
};
size_t
newlinePos
=
script
.
toStdString
().
find_first_of
(
'\n'
,
0
);
script
.
remove
(
0
,
newlinePos
);
script
.
insert
(
0
,
newHeader
);
}
}
const
char
*
ScriptType
::
icon
(
ScriptType
::
Type
type
)
{
return
scripts_properties
[
type
].
icon
;
...
...
scripting/script-common.h
View file @
2d60444f
...
...
@@ -30,6 +30,14 @@ public:
* Returns a template code for a script language.
*/
static
QString
templateCode
(
ScriptType
::
Type
type
,
std
::
list
<
ObjectHolder
*>
args
);
/**
* Update the existing script function definition with the new argument selection
*/
static
void
updateCodeFunction
(
ScriptType
::
Type
type
,
std
::
list
<
ObjectHolder
*>
args
,
QString
&
script
);
/**
* Return the function definition for the script
*/
static
QString
scriptFunctionDefinition
(
ScriptType
::
Type
type
,
std
::
list
<
ObjectHolder
*>
args
);
/**
* Returns the icon's name for a script language.
*/
...
...
scripting/script_mode.cc
View file @
2d60444f
...
...
@@ -137,12 +137,18 @@ void ScriptModeBase::enableActions()
void
ScriptModeBase
::
codePageEntered
()
{
if
(
mwizard
->
text
().
isEmpty
()
)
QString
wizardText
{
mwizard
->
text
()
};
if
(
wizardText
.
isEmpty
()
)
{
// insert template code..
QString
tempcode
=
ScriptType
::
templateCode
(
mtype
,
margs
);
mwizard
->
setText
(
tempcode
);
};
wizardText
=
ScriptType
::
templateCode
(
mtype
,
margs
);
}
else
{
ScriptType
::
updateCodeFunction
(
mtype
,
margs
,
wizardText
);
}
mwizard
->
setText
(
wizardText
);
mwawd
=
EnteringCode
;
mdoc
.
redrawScreen
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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