示教器内置键盘使用说明

一、内置键盘类型说明:

  1. 提供标准键盘

    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

  2. 提供 string 类型键盘

    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

  3. 提供表达式键盘

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

    keyboard-3

  4. 提供密码键盘

    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

  5. 提供输入ip地址专用键盘

    void registerIPAddressKeyboard(
         QWidget *wd, std::function<std::string(void)> init_cb = nullptr,
         std::function<void(std::string)> result_cb = nullptr);
    

    keyboard-5

  6. 提供浮点数字键盘

    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

  7. 提供正浮点数字键盘

    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

  8. 提供整数键盘

    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

  9. 提供正整数键盘

    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

  10. 提供代码编辑键盘

    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

  11. 提供数字键盘

    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

二、插件中使用示教器内置键盘的方法:

在安装节点和程序节点的view类中均提供了ViewApiProviderPtr view_api_{ nullptr };接口,该接口可调用到上述内置键盘说明中提到的各类型键盘接口。具体调用方式如下所示:(注意不同类型键盘在使用他们的函数的时候需要注意参数类型,具体需要什么参数,代码中可转到定义处进行查看)

程序节点和安装节点中可调用键盘的接口位置如下:(在程序和安装节点view类中)

keyboard-12

调用方法:

  • 首先,在程序节点或者安装节点的 contribution 类头文件中声明键盘管理类指针变量:

    std::shared_ptr<arcs::aubo_scope::KeyboardManager> keyboard_manager_;

  • 其次,在程序节点或者安装节点的 contributionbuildUi 函数中为需要获取 KeyboardManager 接口,具体实现如下:

    keyboard_manager_ = view_api_->getUserInterfaceApi()->getUserInteraction()->getKeyboardManager();

  • 最后,我们需要调用接口中的注册键盘函数:

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()); });

效果如下:

keyboard-15

三、常见问题

常见问题 1:弹窗中的输入框无法使用键盘,点两下键盘就会消失。

问题原因:QDialog::exec(); 的阻塞运行方式抢占了键盘的焦点事件,需要用 QDialog::open(); 配合 QEventLoop::exec() 实现。

解决方案:

原代码:
CustomInputDialog dialog(s1, s2);
if(dialog.exec() == QDialog::Accepted){
    ....
}

修复方案:重写 CustomInputDialog::exec 方法。
int CustomInputDialog::exec() {
    QEventLoop loop;
    connect(this, &QDialog::finished, this, [&]{
        loop.exit();
    });
    open(); ///< exec 会抢占键盘焦点,改用 open.
    loop.exec(QEventLoop::DialogExec);
    return result();
}

results matching ""

    No results matching ""