Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89356

Refactor QQuickTextInput test to use QKeyCombination

    XMLWordPrintable

Details

    • 8257cf75c68bd3d2a2af0cd8260e3cc96f5d0df4 (qt/qtdeclarative/dev) 01f3bb703e22ef6722cb2d9a04a57fc9d7f2a2bc (qt/qtdeclarative/6.0)

    Description

      The test cases uses a

      struct Key {
      // ...
          int key; // a Qt::Key
          QChar character; // the character corresponding to the key (if any)
      };
      

      to manage a list of key clicks that should be simulated. Note that "a Qt::Key" comment.

      It then populates the list with e.g. the following insertion operator:

      QList<Key> &operator <<(QList<Key> &keys, const QKeySequence &sequence)
      {
          for (int i = 0; i < sequence.count(); ++i)
              keys << Key(sequence[i], QChar());
          return keys;
      }
      

      QKeySequence::operator[] however returns an integer that is a combination of a Qt::Key with an optional set of Qt::KeyboardModifier values. In Qt 6, we have QKeyCombination to express this kind of data in a type-safe way.

      The simulation then is done via

      void tst_qquicktextinput::simulateKeys(QWindow *window, const QList<Key> &keys)
      {
          for (int i = 0; i < keys.count(); ++i) {
              const int key = keys.at(i).key & ~Qt::KeyboardModifierMask;
              const int modifiers = keys.at(i).key & Qt::KeyboardModifierMask;
              const QString text = keys.at(i).toString();
      
              QKeyEvent press(QEvent::KeyPress, Qt::Key(key), Qt::KeyboardModifiers(modifiers), text);
              QKeyEvent release(QEvent::KeyRelease, Qt::Key(key), Qt::KeyboardModifiers(modifiers), text);
      
              QGuiApplication::sendEvent(window, &press);
              QGuiApplication::sendEvent(window, &release);
      }
      

      This should be refactored to use QKeyCombination

      Attachments

        For Gerrit Dashboard: QTBUG-89356
        # Subject Branch Project Status CR V

        Activity

          People

            vhilshei Volker Hilsheimer
            vhilshei Volker Hilsheimer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes