Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kumir
kumir2
Commits
c75cb788
Commit
c75cb788
authored
Jun 01, 2017
by
Victor Yacovlev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Choice combo box for actor settings entry
parent
0f17cf50
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
3 deletions
+62
-3
scripts/gen_actor_source.py
scripts/gen_actor_source.py
+12
-2
src/kumir2-libs/widgets/declarativesettingspage.cpp
src/kumir2-libs/widgets/declarativesettingspage.cpp
+3
-0
src/kumir2-libs/widgets/declarativesettingspage.h
src/kumir2-libs/widgets/declarativesettingspage.h
+2
-1
src/kumir2-libs/widgets/declarativesettingspage_impl.cpp
src/kumir2-libs/widgets/declarativesettingspage_impl.cpp
+44
-0
src/kumir2-libs/widgets/declarativesettingspage_impl.h
src/kumir2-libs/widgets/declarativesettingspage_impl.h
+1
-0
No files found.
scripts/gen_actor_source.py
View file @
c75cb788
...
...
@@ -194,7 +194,8 @@ SETTINGS_TYPES = {
"char"
:
"Char"
,
"bool"
:
"Bool"
,
"color"
:
"Color"
,
"font"
:
"Font"
"font"
:
"Font"
,
"choice"
:
"Choice"
,
}
...
...
@@ -1099,6 +1100,10 @@ class SettingsEntry:
self
.
_order
=
json_entry
[
"order"
]
else
:
self
.
_order
=
99999999
if
"items"
in
json_entry
:
self
.
_items
=
json_entry
[
"items"
]
else
:
self
.
_items
=
None
def
get_entry_cpp_implementation
(
self
,
map_to_add
):
"""
...
...
@@ -1128,6 +1133,10 @@ class SettingsEntry:
maximum
=
"QVariant::Invalid"
else
:
maximum
=
unicode
(
self
.
_maximum
)
items
=
"QStringList()"
;
if
self
.
_items
:
for
item
in
self
.
_items
:
items
+=
" << QString::fromUtf8(
\"
"
+
item
+
"
\"
)"
return
"""
{
Widgets::DeclarativeSettingsPage::Entry entry;
...
...
@@ -1136,10 +1145,11 @@ class SettingsEntry:
entry.defaultValue = %s;
entry.minimumValue = %s;
entry.maximumValue = %s;
entry.items = %s;
entry.displayOrder = %s;
%s["%s"] = entry;
}
"""
%
(
title
,
typee
,
default
,
minimum
,
maximum
,
self
.
_order
,
map_to_add
,
self
.
_key
)
"""
%
(
title
,
typee
,
default
,
minimum
,
maximum
,
items
,
self
.
_order
,
map_to_add
,
self
.
_key
)
class
Settings
:
...
...
src/kumir2-libs/widgets/declarativesettingspage.cpp
View file @
c75cb788
...
...
@@ -37,6 +37,9 @@ DeclarativeSettingsPage::DeclarativeSettingsPage(
else
if
(
entry
.
type
==
String
)
{
pImpl_
->
addStringField
(
key
,
entry
);
}
else
if
(
entry
.
type
==
Choice
)
{
pImpl_
->
addChoiceField
(
key
,
entry
);
}
else
{
qFatal
(
"Not implemented"
);
}
...
...
src/kumir2-libs/widgets/declarativesettingspage.h
View file @
c75cb788
...
...
@@ -24,7 +24,7 @@ class WIDGETS_EXPORT DeclarativeSettingsPage
friend
class
DeclarativeSettingsPageImpl
;
Q_OBJECT
public:
enum
Type
{
Integer
,
Double
,
String
,
Char
,
Bool
,
Color
,
Font
};
enum
Type
{
Integer
,
Double
,
String
,
Char
,
Bool
,
Color
,
Font
,
Choice
};
struct
Entry
{
Type
type
;
...
...
@@ -32,6 +32,7 @@ public:
QVariant
defaultValue
;
QVariant
minimumValue
;
QVariant
maximumValue
;
QStringList
items
;
qreal
displayOrder
;
QString
key
;
...
...
src/kumir2-libs/widgets/declarativesettingspage_impl.cpp
View file @
c75cb788
#include "declarativesettingspage_impl.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QLineEdit>
#include <QSpinBox>
namespace
Widgets
{
DeclarativeSettingsPageImpl
::
DeclarativeSettingsPageImpl
(
DeclarativeSettingsPage
*
parent
)
...
...
@@ -53,6 +59,17 @@ void DeclarativeSettingsPageImpl::init()
if
(
control
)
control
->
setChecked
(
value
);
}
else
if
(
entry
.
type
==
DeclarativeSettingsPage
::
Choice
)
{
QComboBox
*
control
=
0
;
if
(
widgets_
.
contains
(
key
)
&&
QString
(
widgets_
[
key
]
->
metaObject
()
->
className
())
==
"QComboBox"
)
{
control
=
qobject_cast
<
QComboBox
*>
(
widgets_
[
key
]);
}
if
(
control
)
{
const
QString
defaultText
=
control
->
itemText
(
entry
.
defaultValue
.
toInt
());
const
QString
value
=
settings_
->
value
(
key
,
defaultText
).
toString
();
control
->
setCurrentText
(
value
);
}
}
else
{
qFatal
(
"Not implemented"
);
}
...
...
@@ -103,6 +120,15 @@ void DeclarativeSettingsPageImpl::resetToDefaults()
if
(
control
)
control
->
setChecked
(
value
);
}
else
if
(
entry
.
type
==
DeclarativeSettingsPage
::
Choice
)
{
QComboBox
*
control
=
0
;
if
(
widgets_
.
contains
(
key
)
&&
QString
(
widgets_
[
key
]
->
metaObject
()
->
className
())
==
"QComboBox"
)
{
control
=
qobject_cast
<
QComboBox
*>
(
widgets_
[
key
]);
}
if
(
control
)
{
control
->
setCurrentIndex
(
entry
.
defaultValue
.
toInt
());
}
}
else
{
qFatal
(
"Not implemented"
);
}
...
...
@@ -149,6 +175,14 @@ void DeclarativeSettingsPageImpl::accept()
if
(
control
)
settings_
->
setValue
(
key
,
control
->
isChecked
());
}
else
if
(
entry
.
type
==
DeclarativeSettingsPage
::
Choice
)
{
QComboBox
*
control
=
0
;
if
(
widgets_
.
contains
(
key
)
&&
QString
(
widgets_
[
key
]
->
metaObject
()
->
className
())
==
"QComboBox"
)
{
control
=
qobject_cast
<
QComboBox
*>
(
widgets_
[
key
]);
}
if
(
control
)
settings_
->
setValue
(
key
,
control
->
currentText
());
}
else
{
qFatal
(
"Not implemented"
);
}
...
...
@@ -192,6 +226,16 @@ void DeclarativeSettingsPageImpl::addStringField(const QString &key, const Decla
addField
(
entry
.
title
,
control
);
}
void
DeclarativeSettingsPageImpl
::
addChoiceField
(
const
QString
&
key
,
const
DeclarativeSettingsPage
::
Entry
&
entry
)
{
QComboBox
*
control
=
new
QComboBox
(
pClass_
);
control
->
addItems
(
entry
.
items
);
if
(
entry
.
defaultValue
.
isValid
())
control
->
setCurrentIndex
(
entry
.
defaultValue
.
toInt
());
widgets_
[
key
]
=
control
;
addField
(
entry
.
title
,
control
);
}
void
DeclarativeSettingsPageImpl
::
addBoolField
(
const
QString
&
key
,
const
DeclarativeSettingsPage
::
Entry
&
entry
)
{
QCheckBox
*
control
=
new
QCheckBox
(
entry
.
title
,
pClass_
);
...
...
src/kumir2-libs/widgets/declarativesettingspage_impl.h
View file @
c75cb788
...
...
@@ -28,6 +28,7 @@ private /*methods*/:
void
addRealField
(
const
QString
&
key
,
const
DeclarativeSettingsPage
::
Entry
&
entry
);
void
addBoolField
(
const
QString
&
key
,
const
DeclarativeSettingsPage
::
Entry
&
entry
);
void
addStringField
(
const
QString
&
key
,
const
DeclarativeSettingsPage
::
Entry
&
entry
);
void
addChoiceField
(
const
QString
&
key
,
const
DeclarativeSettingsPage
::
Entry
&
entry
);
void
addField
(
const
QString
&
labelText
,
QWidget
*
controlWidget
);
private
slots
:
...
...
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