forked from qt-creator/qt-creator
Lua: Fix Layout.Span & Tab constructor
* Allows to use Span {...} or Span(...) syntax.
* Same for Tab {...} or Tab(...).
* Fixes some documentation issues.
* Adds "withFormAlignment()" and "spacing()"
Change-Id: I05ec0823617e99384e309f34a4861e29045eff94
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -137,12 +137,52 @@ std::unique_ptr<T> constructWidgetType(const sol::table &children, QObject *guar
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Tab> constructTabFromTable(const sol::table &children)
|
||||||
|
{
|
||||||
|
if (children.size() != 2)
|
||||||
|
throw sol::error("Tab must have exactly two children");
|
||||||
|
|
||||||
|
auto tabName = children[1];
|
||||||
|
if (tabName.get_type() != sol::type::string)
|
||||||
|
throw sol::error("Tab name (first argument) must be a string");
|
||||||
|
|
||||||
|
const auto &layout = children[2];
|
||||||
|
if (!layout.is<Layout *>())
|
||||||
|
throw sol::error("Tab child (second argument) must be a Layout");
|
||||||
|
|
||||||
|
std::unique_ptr<Tab> item = std::make_unique<Tab>(tabName, *layout.get<Layout *>());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<Tab> constructTab(const QString &tabName, const Layout &layout)
|
std::unique_ptr<Tab> constructTab(const QString &tabName, const Layout &layout)
|
||||||
{
|
{
|
||||||
std::unique_ptr<Tab> item = std::make_unique<Tab>(tabName, layout);
|
std::unique_ptr<Tab> item = std::make_unique<Tab>(tabName, layout);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Span> constructSpanFromTable(const sol::table &children)
|
||||||
|
{
|
||||||
|
if (children.size() != 2)
|
||||||
|
throw sol::error("Span must have exactly two children");
|
||||||
|
|
||||||
|
auto spanSize = children[1];
|
||||||
|
if (spanSize.get_type() != sol::type::number)
|
||||||
|
throw sol::error("Span size (first argument) must be a number");
|
||||||
|
|
||||||
|
const auto &layout = children[2];
|
||||||
|
if (!layout.is<Layout *>())
|
||||||
|
throw sol::error("Span child (second argument) must be a Layout");
|
||||||
|
|
||||||
|
std::unique_ptr<Span> item = std::make_unique<Span>(spanSize, *layout.get<Layout *>());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Span> constructSpan(int n, const Layout &layout)
|
||||||
|
{
|
||||||
|
std::unique_ptr<Span> item = std::make_unique<Span>(n, layout);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<TabWidget> constructTabWidget(const sol::table &children, QObject *guard)
|
std::unique_ptr<TabWidget> constructTabWidget(const sol::table &children, QObject *guard)
|
||||||
{
|
{
|
||||||
std::unique_ptr<TabWidget> item(new TabWidget({}));
|
std::unique_ptr<TabWidget> item(new TabWidget({}));
|
||||||
@@ -183,7 +223,7 @@ void addLayoutModule()
|
|||||||
sol::table layout = l.create_table();
|
sol::table layout = l.create_table();
|
||||||
|
|
||||||
layout.new_usertype<Span>(
|
layout.new_usertype<Span>(
|
||||||
"Span", sol::call_constructor, sol::constructors<Span(int n, const Layout::I &item)>());
|
"Span", sol::call_constructor, sol::factories(&constructSpan, &constructSpanFromTable));
|
||||||
|
|
||||||
layout.new_usertype<Space>("Space", sol::call_constructor, sol::constructors<Space(int)>());
|
layout.new_usertype<Space>("Space", sol::call_constructor, sol::constructors<Space(int)>());
|
||||||
|
|
||||||
@@ -268,7 +308,7 @@ void addLayoutModule()
|
|||||||
layout.new_usertype<Tab>(
|
layout.new_usertype<Tab>(
|
||||||
"Tab",
|
"Tab",
|
||||||
sol::call_constructor,
|
sol::call_constructor,
|
||||||
sol::factories(&constructTab),
|
sol::factories(&constructTab, &constructTabFromTable),
|
||||||
sol::base_classes,
|
sol::base_classes,
|
||||||
sol::bases<Widget, Object, Thing>());
|
sol::bases<Widget, Object, Thing>());
|
||||||
|
|
||||||
@@ -327,6 +367,8 @@ void addLayoutModule()
|
|||||||
layout["hr"] = &hr;
|
layout["hr"] = &hr;
|
||||||
layout["noMargin"] = &noMargin;
|
layout["noMargin"] = &noMargin;
|
||||||
layout["normalMargin"] = &normalMargin;
|
layout["normalMargin"] = &normalMargin;
|
||||||
|
layout["withFormAlignment"] = &withFormAlignment;
|
||||||
|
layout["spacing"] = &spacing;
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,98 +2,99 @@
|
|||||||
|
|
||||||
local layout = {}
|
local layout = {}
|
||||||
|
|
||||||
---The base class of all layout items
|
---The base class of all layout classes
|
||||||
---@class LayoutItem
|
---@class Object
|
||||||
layout.LayoutItem = {
|
layout.Layout = {}
|
||||||
---Attaches the layout to the specified widget
|
|
||||||
---@param widget QWidget
|
---The base class of all layout classes
|
||||||
attachTo = function(widget) end
|
---@class Layout : Object
|
||||||
}
|
layout.Layout = {}
|
||||||
|
|
||||||
|
---The base class of all widget classes, an empty widget itself.
|
||||||
|
---@class Widget : Object
|
||||||
|
Widget = {}
|
||||||
|
|
||||||
|
---@param children Layout
|
||||||
|
---@return Widget
|
||||||
|
function layout.Widget(children) end
|
||||||
|
|
||||||
---Column layout
|
---Column layout
|
||||||
---@class Column : LayoutItem
|
---@class Column : Layout
|
||||||
local column = {}
|
local column = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Column
|
---@return Column
|
||||||
function layout.Column(children) end
|
function layout.Column(children) end
|
||||||
|
|
||||||
---A group box with a title
|
---A group box with a title
|
||||||
---@class Group : LayoutItem
|
---@class Group : Widget
|
||||||
local group = {}
|
local group = {}
|
||||||
|
|
||||||
---@return Group
|
---@return Group
|
||||||
function layout.Group(children) end
|
function layout.Group(children) end
|
||||||
|
|
||||||
---Row layout
|
---Row layout
|
||||||
---@class Row : LayoutItem
|
---@class Row : Layout
|
||||||
local row = {}
|
local row = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Row
|
---@return Row
|
||||||
function layout.Row(children) end
|
function layout.Row(children) end
|
||||||
|
|
||||||
---Flow layout
|
---Flow layout
|
||||||
---@class Flow : LayoutItem
|
---@class Flow : Layout
|
||||||
local flow = {}
|
local flow = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Flow
|
---@return Flow
|
||||||
function layout.Flow(children) end
|
function layout.Flow(children) end
|
||||||
|
|
||||||
---Grid layout
|
---Grid layout
|
||||||
---@class Grid : LayoutItem
|
---@class Grid : Layout
|
||||||
local grid = {}
|
local grid = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Grid
|
---@return Grid
|
||||||
function layout.Grid(children) end
|
function layout.Grid(children) end
|
||||||
|
|
||||||
---Form layout
|
---Form layout
|
||||||
---@class Form : LayoutItem
|
---@class Form : Layout
|
||||||
local form = {}
|
local form = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Form
|
---@return Form
|
||||||
function layout.Form(children) end
|
function layout.Form(children) end
|
||||||
|
|
||||||
---An empty widget
|
|
||||||
---@class Widget : LayoutItem
|
|
||||||
local widget = {}
|
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
|
||||||
---@return Widget
|
|
||||||
function layout.Widget(children) end
|
|
||||||
|
|
||||||
---A stack of multiple widgets
|
---A stack of multiple widgets
|
||||||
---@class Stack : LayoutItem
|
---@class Stack : Widget
|
||||||
local stack = {}
|
local stack = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Stack
|
---@return Stack
|
||||||
function layout.Stack(children) end
|
function layout.Stack(children) end
|
||||||
|
|
||||||
---A Tab widget
|
---A Tab widget
|
||||||
---@class Tab : LayoutItem
|
---@class Tab : Widget
|
||||||
local tab = {}
|
local tab = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Tab
|
---@return Tab
|
||||||
function layout.Tab(children) end
|
function layout.Tab(children) end
|
||||||
|
|
||||||
---A Multiline text edit
|
---A Multiline text edit
|
||||||
---@class TextEdit : LayoutItem
|
---@class TextEdit : Widget
|
||||||
local textEdit = {}
|
local textEdit = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return TextEdit
|
---@return TextEdit
|
||||||
function layout.TextEdit(children) end
|
function layout.TextEdit(children) end
|
||||||
|
|
||||||
---A PushButton
|
---A PushButton
|
||||||
---@class PushButton : LayoutItem
|
---@class PushButton : Widget
|
||||||
local pushButton = {}
|
local pushButton = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return PushButton
|
---@return PushButton
|
||||||
function layout.PushButton(children) end
|
function layout.PushButton(children) end
|
||||||
|
|
||||||
@@ -106,37 +107,41 @@ local label = {}
|
|||||||
function layout.Label(children) end
|
function layout.Label(children) end
|
||||||
|
|
||||||
---A SpinBox
|
---A SpinBox
|
||||||
---@class SpinBox : LayoutItem
|
---@class SpinBox : Widget
|
||||||
local spinBox = {}
|
local spinBox = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return SpinBox
|
---@return SpinBox
|
||||||
function layout.SpinBox(children) end
|
function layout.SpinBox(children) end
|
||||||
|
|
||||||
---A Splitter
|
---A Splitter
|
||||||
---@class Splitter : LayoutItem
|
---@class Splitter : Widget
|
||||||
local splitter = {}
|
local splitter = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return Splitter
|
---@return Splitter
|
||||||
function layout.Splitter(children) end
|
function layout.Splitter(children) end
|
||||||
|
|
||||||
---A Toolbar
|
---A Toolbar
|
||||||
---@class ToolBar : LayoutItem
|
---@class ToolBar : Widget
|
||||||
local toolBar = {}
|
local toolBar = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return ToolBar
|
---@return ToolBar
|
||||||
function layout.ToolBar(children) end
|
function layout.ToolBar(children) end
|
||||||
|
|
||||||
---A TabWidget
|
---A TabWidget
|
||||||
---@class TabWidget : LayoutItem
|
---@class TabWidget : Widget
|
||||||
local tabWidget = {}
|
local tabWidget = {}
|
||||||
|
|
||||||
---@param children LayoutItem|string|BaseAspect|function
|
---@param children Layout|string|BaseAspect|function
|
||||||
---@return TabWidget
|
---@return TabWidget
|
||||||
function layout.TabWidget(children) end
|
function layout.TabWidget(children) end
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param child Layout|string|BaseAspect|function
|
||||||
|
---@return TabWidget
|
||||||
|
function layout.TabWidget(name, child) end
|
||||||
---A "Line break" in the layout
|
---A "Line break" in the layout
|
||||||
function layout.br() end
|
function layout.br() end
|
||||||
|
|
||||||
@@ -155,33 +160,15 @@ function layout.noMargin() end
|
|||||||
---Sets the margin of the layout to the default value
|
---Sets the margin of the layout to the default value
|
||||||
function layout.normalMargin() end
|
function layout.normalMargin() end
|
||||||
|
|
||||||
---Sets the margin of the layout to a custom value
|
|
||||||
function layout.customMargin(left, top, right, bottom) end
|
|
||||||
|
|
||||||
---Sets the alignment of the layout to "Form"
|
---Sets the alignment of the layout to "Form"
|
||||||
function layout.withFormAlignment() end
|
function layout.withFormAlignment() end
|
||||||
|
|
||||||
---Sets the title of the parent object if possible
|
|
||||||
function layout.title(text) end
|
|
||||||
|
|
||||||
---Sets the text of the parent object if possible
|
|
||||||
function layout.text(text) end
|
|
||||||
|
|
||||||
---Sets the tooltip of the parent object if possible
|
|
||||||
function layout.tooltip(text) end
|
|
||||||
|
|
||||||
---Sets the size of the parent object if possible
|
---Sets the size of the parent object if possible
|
||||||
function layout.resize(width, height) end
|
function layout.resize(width, height) end
|
||||||
|
|
||||||
---Sets the stretch of the column at `index`
|
|
||||||
function layout.columnStretch(index, stretch) end
|
|
||||||
|
|
||||||
---Sets the spacing of the layout
|
---Sets the spacing of the layout
|
||||||
function layout.spacing(spacing) end
|
function layout.spacing(spacing) end
|
||||||
|
|
||||||
---Sets the window title of the parent object if possible
|
|
||||||
function layout.windowTitle(text) end
|
|
||||||
|
|
||||||
---Sets the field growth policy of the layout
|
---Sets the field growth policy of the layout
|
||||||
function layout.fieldGrowthPolicy(policy) end
|
function layout.fieldGrowthPolicy(policy) end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user