Build-in Keyboard
Built-in Keyboard Types
- Standard Keyboard
void registerStandardKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- String Keyboard
void registerStringKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- Expression Keyboard
void registerExpressionKeyboard(
QWidget *wd, std::function<ExpressionPtr(void)> init_cb = nullptr,
std::function<void(ExpressionPtr result_value)> result_cb = nullptr);
- Password Keyboard
void registerPasswordKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- IP Address Keyboard
void registerIPAddressKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- Floating-point Number Keyboard
void registerDoubleKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- Positive Floating-point Number Keyboard
void registerPositiveDoubleKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- Integer Keyboard
void registerIntegerKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- Positive Integer Keyboard
void registerPositiveIntegerKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- Code Editing Keyboard
void registerCodeEditerKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
- Numeric Keyboard
void registerNumberKeyboard(
QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
const std::shared_ptr<InputValidator> &validator = nullptr,
std::function<void(std::string)> result_cb = nullptr);
Plugin Built-in Keyboard Integration
When plugin installation nodes and program nodes need to call the built-in keyboard of AUBO Scope software, they must invoke the view
class of the node. The view
class provides the ViewApiProviderPtr view_api_{ nullptr };
interface. When using functions for different types of keyboards, attention must be paid to parameter types. Please refer to the code definition for specific parameter types.
Interface Location
The interface locations where keyboards can be called in program nodes and installation nodes are shown in the following figure within the view
class of program and installation nodes.
Interface Calls
Declare the keyboard management class pointer variable in the
contribution
class header file within the installation node or program node:std::shared_ptr<arcs::aubo_scope::KeyboardManager> keyboard_manager_;
Obtain the
KeyboardManager
interface in thebuildUi
function of the program node or installation node'scontribution
class:keyboard_manager_ = view_api_->getUserInterfaceApi()->getUserInteraction()->getKeyboardManager();
Call the keyboard registration function in the interface:
keyboard_manager_->registerDoubleKeyboard( ui->le_test, [=]() -> std::string { return ui->le_test->text().toStdString(); }, std::make_shared<DoubleRangeValidator>([=]() -> std::pair<double, double> { return { -100.0, 100.0 }; }), [=](const std::string &text) { ui->le_test->setText(text.c_str()); });
Check the results.
Common Issues
Issue 1: Keyboard Not Working Properly in Dialog Windows
Problem Description: Unable to use keyboard normally in dialog input fields; keyboard disappears after two keystrokes.
Root Cause: QDialog::exec();
blocks and captures keyboard focus events. Need to use QDialog::open();
in conjunction with QEventLoop::exec()
instead.
Solution: Override the CustomInputDialog::exec
method.
# Original code:
CustomInputDialog dialog(s1, s2);
if(dialog.exec() == QDialog::Accepted){
....
}
# Override CustomInputDialog::exec method as follows:
int CustomInputDialog::exec() {
QEventLoop loop;
connect(this, &QDialog::finished, this, [&]{
loop.exit();
});
open(); ///< exec 会抢占键盘焦点,改用 open.
loop.exec(QEventLoop::DialogExec);
return result();
}