Skip to content

Build-in Keyboard

Built-in Keyboard Types

  1. 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);

keyboard-1

  1. 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);

keyboard-2

  1. Expression Keyboard
void registerExpressionKeyboard(
        QWidget *wd, std::function<ExpressionPtr(void)> init_cb = nullptr,
        std::function<void(ExpressionPtr result_value)> result_cb = nullptr);

keyboard-3

  1. 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);

keyboard-4

  1. IP Address Keyboard
void registerIPAddressKeyboard(
        QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
        std::function<void(std::string)> result_cb = nullptr);

keyboard-5

  1. 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);

keyboard-6

  1. 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);

keyboard-7

  1. 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);

keyboard-8

  1. 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);

keyboard-9

  1. 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);

keyboard-10

  1. 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);

keyboard-11

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

  1. 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_;
  2. Obtain the KeyboardManager interface in the buildUi function of the program node or installation node's contribution class:

    keyboard_manager_ = view_api_->getUserInterfaceApi()->getUserInteraction()->getKeyboardManager();
  3. 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()); });
  4. 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();
}