forked from qt-creator/qt-creator
Lua: Improve SelectionAspect binding
Change-Id: I4fa4bd2ae64078ca702637625975cf8fbfa7c116 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -305,10 +305,58 @@ void addSettingsModule()
|
|||||||
|
|
||||||
addTypedAspect<BoolAspect>(settings, "BoolAspect");
|
addTypedAspect<BoolAspect>(settings, "BoolAspect");
|
||||||
addTypedAspect<ColorAspect>(settings, "ColorAspect");
|
addTypedAspect<ColorAspect>(settings, "ColorAspect");
|
||||||
addTypedAspect<SelectionAspect>(settings, "SelectionAspect");
|
|
||||||
addTypedAspect<MultiSelectionAspect>(settings, "MultiSelectionAspect");
|
addTypedAspect<MultiSelectionAspect>(settings, "MultiSelectionAspect");
|
||||||
addTypedAspect<StringAspect>(settings, "StringAspect");
|
addTypedAspect<StringAspect>(settings, "StringAspect");
|
||||||
|
|
||||||
|
settings.new_usertype<SelectionAspect>(
|
||||||
|
"SelectionAspect",
|
||||||
|
"create",
|
||||||
|
[](const sol::table &options) {
|
||||||
|
return createAspectFromTable<SelectionAspect>(
|
||||||
|
options,
|
||||||
|
[](SelectionAspect *aspect, const std::string &key, const sol::object &value) {
|
||||||
|
if (key == "options") {
|
||||||
|
sol::table options = value.as<sol::table>();
|
||||||
|
for (size_t i = 1; i <= options.size(); ++i) {
|
||||||
|
sol::optional<sol::table> optiontable
|
||||||
|
= options[i].get<sol::optional<sol::table>>();
|
||||||
|
if (optiontable) {
|
||||||
|
sol::table option = *optiontable;
|
||||||
|
sol::optional<QString> data = option["data"];
|
||||||
|
if (data) {
|
||||||
|
aspect->addOption(
|
||||||
|
{option["name"],
|
||||||
|
option["tooltip"].get_or(QString()),
|
||||||
|
*data});
|
||||||
|
} else {
|
||||||
|
aspect->addOption(
|
||||||
|
option["name"], option["tooltip"].get_or(QString()));
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
sol::optional<QString> name
|
||||||
|
= options[i].get<sol::optional<QString>>()) {
|
||||||
|
aspect->addOption(*name);
|
||||||
|
} else {
|
||||||
|
throw sol::error("Invalid option type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (key == "displayStyle") {
|
||||||
|
aspect->setDisplayStyle((SelectionAspect::DisplayStyle) value.as<int>());
|
||||||
|
} else
|
||||||
|
typedAspectCreate(aspect, key, value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
"stringValue",
|
||||||
|
sol::property(&SelectionAspect::stringValue, &SelectionAspect::setStringValue),
|
||||||
|
"addOption",
|
||||||
|
sol::overload(
|
||||||
|
[](SelectionAspect &self, const QString &name) { self.addOption(name); },
|
||||||
|
[](SelectionAspect &self, const QString &name, const QString &tooltip) {
|
||||||
|
self.addOption(name, tooltip);
|
||||||
|
}),
|
||||||
|
sol::base_classes,
|
||||||
|
sol::bases<TypedAspect<int>, BaseAspect>());
|
||||||
|
|
||||||
auto filePathAspectType = addTypedAspect<FilePathAspect>(settings, "FilePathAspect");
|
auto filePathAspectType = addTypedAspect<FilePathAspect>(settings, "FilePathAspect");
|
||||||
filePathAspectType.set(
|
filePathAspectType.set(
|
||||||
"setValue",
|
"setValue",
|
||||||
@@ -524,6 +572,11 @@ void addSettingsModule()
|
|||||||
"PasswordLineEdit", StringAspect::DisplayStyle::PasswordLineEditDisplay
|
"PasswordLineEdit", StringAspect::DisplayStyle::PasswordLineEditDisplay
|
||||||
);
|
);
|
||||||
|
|
||||||
|
settings["SelectionDisplayStyle"] = l.create_table_with(
|
||||||
|
"RadioButtons", SelectionAspect::DisplayStyle::RadioButtons,
|
||||||
|
"ComboBox", SelectionAspect::DisplayStyle::ComboBox
|
||||||
|
);
|
||||||
|
|
||||||
settings["CheckBoxPlacement"] = l.create_table_with(
|
settings["CheckBoxPlacement"] = l.create_table_with(
|
||||||
"Top", CheckBoxPlacement::Top,
|
"Top", CheckBoxPlacement::Top,
|
||||||
"Right", CheckBoxPlacement::Right
|
"Right", CheckBoxPlacement::Right
|
||||||
|
@@ -73,9 +73,34 @@ function settings.BoolAspect.create(options) end
|
|||||||
settings.ColorAspect = {}
|
settings.ColorAspect = {}
|
||||||
function settings.ColorAspect.create(options) end
|
function settings.ColorAspect.create(options) end
|
||||||
|
|
||||||
|
---@class SelectionAspect : TypedAspect<int>
|
||||||
|
---@field stringValue string The string value of the aspect.
|
||||||
settings.SelectionAspect = {}
|
settings.SelectionAspect = {}
|
||||||
|
---@enum SelectionDisplayStyle
|
||||||
|
settings.SelectionDisplayStyle = {
|
||||||
|
RadioButtons = 0,
|
||||||
|
ComboBox = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
---@class SelectionOption
|
||||||
|
---@field name string The name of the option.
|
||||||
|
---@field tooltip? string The tooltip of the option.
|
||||||
|
---@field data? any The data of the option.
|
||||||
|
SelectionOption = {}
|
||||||
|
|
||||||
|
---@class SelectionAspectCreate : TypedAspectCreate<int>
|
||||||
|
---@field displayStyle? SelectionDisplayStyle The display type of the aspect.
|
||||||
|
---@field options? string[]|SelectionOption[] The available options.
|
||||||
|
SelectionAspectCreate = {}
|
||||||
|
|
||||||
|
---Creates a new SelectionAspect
|
||||||
|
---@param options SelectionAspectCreate
|
||||||
|
---@return SelectionAspect aspect The Aspect
|
||||||
function settings.SelectionAspect.create(options) end
|
function settings.SelectionAspect.create(options) end
|
||||||
|
|
||||||
|
function settings.SelectionAspect:addOption(option) end
|
||||||
|
|
||||||
|
function settings.SelectionAspect:addOption(option, tooltip) end
|
||||||
settings.MultiSelectionAspect = {}
|
settings.MultiSelectionAspect = {}
|
||||||
function settings.MultiSelectionAspect.create(options) end
|
function settings.MultiSelectionAspect.create(options) end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user