From 64763c9d7ed77d60bb7f183ca34f5fce530cda12 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Mon, 7 Oct 2024 13:38:18 +0200 Subject: [PATCH] Lua: Refactor Clipboard access Clipboard is now accessed via "qt.clipboard()" to stay in line with other code that returns a global singleton. Also fixed documentation. Change-Id: I4298f036ef6558e48f36d156d6482fc0bde5d898 Reviewed-by: Artur Twardy Reviewed-by: hjk --- src/plugins/lua/bindings/qt.cpp | 30 ++++++++++++++---------------- src/plugins/lua/meta/qt.lua | 25 +++++++++++++------------ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/plugins/lua/bindings/qt.cpp b/src/plugins/lua/bindings/qt.cpp index 6f4daeb5862..355c6c6958a 100644 --- a/src/plugins/lua/bindings/qt.cpp +++ b/src/plugins/lua/bindings/qt.cpp @@ -29,29 +29,27 @@ void setupQtModule() "currentCompletion", &QCompleter::currentCompletion, "completionMode", - sol::property(&QCompleter::completionMode, - [](QCompleter *c, QCompleter::CompletionMode mode) { - c->setCompletionMode(mode); - }), + sol::property( + &QCompleter::completionMode, + [](QCompleter *c, QCompleter::CompletionMode mode) { c->setCompletionMode(mode); }), "onActivated", sol::property([guard = pluginSpec](QCompleter &obj, sol::function callback) { - QObject::connect(&obj, - QOverload::of(&QCompleter::activated), - guard->connectionGuard.get(), - [callback](const QString &arg) { - void_safe_call(callback, arg); - });}) - ); + QObject::connect( + &obj, + QOverload::of(&QCompleter::activated), + guard->connectionGuard.get(), + [callback](const QString &arg) { void_safe_call(callback, arg); }); + })); qt.new_usertype( "QClipboard", - sol::call_constructor, - &QApplication::clipboard, + sol::no_constructor, "text", - sol::property([](QClipboard &self) { return self.text(); }, - [](QClipboard &self, const QString &value) { self.setText(value); }) - ); + sol::property( + [](QClipboard &self) { return self.text(); }, + [](QClipboard &self, const QString &value) { self.setText(value); })); + qt["clipboard"] = &QApplication::clipboard; mirrorEnum(qt, QMetaEnum::fromType(), "QCompleterCompletionMode"); diff --git a/src/plugins/lua/meta/qt.lua b/src/plugins/lua/meta/qt.lua index 168c8092171..7543302c600 100644 --- a/src/plugins/lua/meta/qt.lua +++ b/src/plugins/lua/meta/qt.lua @@ -11,27 +11,28 @@ qt.CompleterCompletionMode = { UnfilteredPopupCompletion = 2, }; ----Creates QCompleter. ---@class QCompleter ---@field completionMode CompleterCompletionMode The completion mode. local QCompleter = {} +---Creates a new Completer. +---@param params string[] The list of suggestions. +---@return QCompleter completer The new Completer. +function qt.QCompleter.create(params) end + ---Returns current completion. ---@return string function qt.QCompleter:currentCompletion() end +---@param callback function The function to be called when user choice is selected from popup. +function qt.QCompleter.onActivated(callback) end ----@param params string list A list of suggestions. ----@return QCompleter Created Completer. -function qt.QCompleter.create(params) end +---@class QClipboard A Lua wrapper for the Qt `QClipboard` class. +---@field text string The text content of the clipboard. Gets or sets the text content of the clipboard. +qt.QClipboard = {} ----@param function The function to be called when user choice is selected from popup. -function qt.QCompleter.onActivated(function) end - ----@class QClipboard ---- A Lua wrapper for the Qt `QClipboard` class. - -qt.QClipboard() Creates QClipboard object, which is a singleton instance of the system clipboard. ----@field text The text content of the clipboard. Gets or sets the text content of the clipboard. +---Returns the global clipboard object. +---@return QClipboard globalClipboard The global clipboard object. +function qt.clipboard() end ---@enum TextElideMode qt.TextElideMode = {