Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-30304

Indentation is incorrect when pasting copied code

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • Qt Creator 12.0.1
    • None

    Description

      To reproduce, checkout https://codereview.qt-project.org/c/qt/qtdeclarative/+/535523/18 and then copy and paste dynamicSubmenus somewhere in the file. The original code looks like this:

      void tst_NativeMenus::dynamicSubmenus()
      {
          QQuickControlsApplicationHelper helper(this, QLatin1String("dynamicSubmenus.qml"));
          QVERIFY2(helper.ready, helper.failureMessage());
          QQuickApplicationWindow *window = helper.appWindow;
          window->show();
          QVERIFY(QTest::qWaitForWindowExposed(window));
      
          QQuickMenu *contextMenu = window->property("contextMenu").value<QQuickMenu*>();
          QVERIFY(contextMenu);
          auto *contextMenuPrivate = QQuickMenuPrivate::get(contextMenu);
      
          // We construct the sub-menu first in QML. At least on Windows, menu items
          // added to an empty sub-menu won't show up (tested with Widgets): QTBUG-120494.
          // So, this adds an already-populated menu as a sub-menu.
          QVERIFY(QMetaObject::invokeMethod(window, "addSubMenu", Q_ARG(QString, "subMenu1")));
          auto subMenu1 = contextMenu->menuAt(0);
          QVERIFY(subMenu1);
          QCOMPARE(subMenu1->title(), "subMenu1");
          auto *subMenu1Private = QQuickMenuPrivate::get(subMenu1);
      #ifdef HAVE_NATIVE_MENU_SUPPORT
          QVERIFY(subMenu1Private->handle);
          QCOMPARE(subMenu1Private->nativeItems.size(), 1);
      #endif
          auto *subMenu1MenuItem = qobject_cast<QQuickMenuItem *>(contextMenu->itemAt(0));
          QVERIFY(subMenu1MenuItem);
          COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(contextMenuPrivate->contentData.at(0)),
              subMenu1MenuItem);
          QCOMPARE(contextMenuPrivate->contentData.size(), 1);
          {
              auto subMenuAction1 = subMenu1->actionAt(0);
              QVERIFY(subMenuAction1);
              QCOMPARE(subMenuAction1->text(), "subMenu1Action1");
              auto *subMenuAction1MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(0));
              QVERIFY(subMenuAction1MenuItem);
              QCOMPARE(subMenuAction1MenuItem->action(), subMenuAction1);
              COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(subMenu1Private->contentData.at(0)),
                  subMenuAction1MenuItem);
      #ifdef HAVE_NATIVE_MENU_SUPPORT
              QCOMPARE(subMenu1Private->nativeItems.size(), 1);
      #endif
          }
      
          // Check that actions can be appended after existing items in the sub-menu.
          QCOMPARE(subMenu1->actionAt(1), nullptr);
          QVERIFY(QMetaObject::invokeMethod(window, "addAction",
              Q_ARG(QQuickMenu *, subMenu1), Q_ARG(QString, "subMenu1Action2")));
          {
              auto subMenu1Action2 = subMenu1->actionAt(1);
              QVERIFY(subMenu1Action2);
              QCOMPARE(subMenu1Action2->text(), "subMenu1Action2");
              auto *subMenu1Action2MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(1));
              QVERIFY(subMenu1Action2MenuItem);
              QCOMPARE(subMenu1Action2MenuItem->action(), subMenu1Action2);
              COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(subMenu1Private->contentData.at(1)),
                  subMenu1Action2MenuItem);
              QCOMPARE(subMenu1Private->contentData.size(), 2);
          }
      
          // Check that actions can be inserted before existing items in the sub-menu.
          QVERIFY(QMetaObject::invokeMethod(window, "insertAction",
              Q_ARG(QQuickMenu *, subMenu1), Q_ARG(int, 0), Q_ARG(QString, "subMenu1Action0")));
          {
              auto subMenu1Action0 = subMenu1->actionAt(0);
              QVERIFY(subMenu1Action0);
              QCOMPARE(subMenu1Action0->text(), "subMenu1Action0");
              auto *subMenu1Action0MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(0));
              QVERIFY(subMenu1Action0MenuItem);
              QCOMPARE(subMenu1Action0MenuItem->action(), subMenu1Action0);
              // New items are always appended to contentData, regardless of the actual insertion index
              // in contentModel.
              COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(subMenu1Private->contentData.at(2)),
                  subMenu1Action0MenuItem);
              QCOMPARE(subMenu1Private->contentData.size(), 3);
          }
      
          {
              // Check that takeMenu works.
              auto *takenSubMenu = contextMenu->takeMenu(0);
              QCOMPARE(takenSubMenu, subMenu1);
              QCOMPARE(contextMenuPrivate->contentData.size(), 0);
      #ifdef HAVE_NATIVE_MENU_SUPPORT
              QVERIFY(!subMenu1Private->handle);
              QCOMPARE(subMenu1Private->nativeItems.size(), 0);
      #endif
      
              // Check that the sub-menu can be added back in to the menu.
              contextMenu->addMenu(takenSubMenu);
              QCOMPARE(contextMenuPrivate->contentData.size(), 1);
              auto *subMenu1MenuItem = qobject_cast<QQuickMenuItem *>(contextMenu->itemAt(0));
              QVERIFY(subMenu1MenuItem);
              QCOMPARE(subMenu1MenuItem->text(), "subMenu1");
      #ifdef HAVE_NATIVE_MENU_SUPPORT
              QVERIFY(subMenu1Private->handle);
              QCOMPARE(subMenu1Private->nativeItems.size(), 3);
      #endif
              QCOMPARE(subMenu1Private->contentData.size(), 3);
      
              auto *subMenu1Action0MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(0));
              QVERIFY(subMenu1Action0MenuItem);
          }
      
          // Check that removeMenu works.
          QVERIFY(contextMenu->menuAt(0));
          contextMenu->removeMenu(contextMenu->menuAt(0));
          QCOMPARE(contextMenuPrivate->contentData.size(), 0);
      }
      

      The pasted code has incorrect indentation for the comments:

      void tst_NativeMenus::dynamicSubmenus()
      {
          QQuickControlsApplicationHelper helper(this, QLatin1String("dynamicSubmenus.qml"));
          QVERIFY2(helper.ready, helper.failureMessage());
          QQuickApplicationWindow *window = helper.appWindow;
          window->show();
          QVERIFY(QTest::qWaitForWindowExposed(window));
          
          QQuickMenu *contextMenu = window->property("contextMenu").value<QQuickMenu*>();
          QVERIFY(contextMenu);
          auto *contextMenuPrivate = QQuickMenuPrivate::get(contextMenu);
          
                 // We construct the sub-menu first in QML. At least on Windows, menu items
                 // added to an empty sub-menu won't show up (tested with Widgets): QTBUG-120494.
                 // So, this adds an already-populated menu as a sub-menu.
          QVERIFY(QMetaObject::invokeMethod(window, "addSubMenu", Q_ARG(QString, "subMenu1")));
          auto subMenu1 = contextMenu->menuAt(0);
          QVERIFY(subMenu1);
          QCOMPARE(subMenu1->title(), "subMenu1");
          auto *subMenu1Private = QQuickMenuPrivate::get(subMenu1);
      #ifdef HAVE_NATIVE_MENU_SUPPORT
          QVERIFY(subMenu1Private->handle);
          QCOMPARE(subMenu1Private->nativeItems.size(), 1);
      #endif
          auto *subMenu1MenuItem = qobject_cast<QQuickMenuItem *>(contextMenu->itemAt(0));
          QVERIFY(subMenu1MenuItem);
          COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(contextMenuPrivate->contentData.at(0)),
                            subMenu1MenuItem);
          QCOMPARE(contextMenuPrivate->contentData.size(), 1);
          {
              auto subMenuAction1 = subMenu1->actionAt(0);
              QVERIFY(subMenuAction1);
              QCOMPARE(subMenuAction1->text(), "subMenu1Action1");
              auto *subMenuAction1MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(0));
              QVERIFY(subMenuAction1MenuItem);
              QCOMPARE(subMenuAction1MenuItem->action(), subMenuAction1);
              COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(subMenu1Private->contentData.at(0)),
                                subMenuAction1MenuItem);
      #ifdef HAVE_NATIVE_MENU_SUPPORT
              QCOMPARE(subMenu1Private->nativeItems.size(), 1);
      #endif
          }
          
                 // Check that actions can be appended after existing items in the sub-menu.
          QCOMPARE(subMenu1->actionAt(1), nullptr);
          QVERIFY(QMetaObject::invokeMethod(window, "addAction",
                                            Q_ARG(QQuickMenu *, subMenu1), Q_ARG(QString, "subMenu1Action2")));
          {
              auto subMenu1Action2 = subMenu1->actionAt(1);
              QVERIFY(subMenu1Action2);
              QCOMPARE(subMenu1Action2->text(), "subMenu1Action2");
              auto *subMenu1Action2MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(1));
              QVERIFY(subMenu1Action2MenuItem);
              QCOMPARE(subMenu1Action2MenuItem->action(), subMenu1Action2);
              COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(subMenu1Private->contentData.at(1)),
                                subMenu1Action2MenuItem);
              QCOMPARE(subMenu1Private->contentData.size(), 2);
          }
          
                 // Check that actions can be inserted before existing items in the sub-menu.
          QVERIFY(QMetaObject::invokeMethod(window, "insertAction",
                                            Q_ARG(QQuickMenu *, subMenu1), Q_ARG(int, 0), Q_ARG(QString, "subMenu1Action0")));
          {
              auto subMenu1Action0 = subMenu1->actionAt(0);
              QVERIFY(subMenu1Action0);
              QCOMPARE(subMenu1Action0->text(), "subMenu1Action0");
              auto *subMenu1Action0MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(0));
              QVERIFY(subMenu1Action0MenuItem);
              QCOMPARE(subMenu1Action0MenuItem->action(), subMenu1Action0);
              // New items are always appended to contentData, regardless of the actual insertion index
              // in contentModel.
              COMPARE_MENUITEMS(qobject_cast<QQuickMenuItem *>(subMenu1Private->contentData.at(2)),
                                subMenu1Action0MenuItem);
              QCOMPARE(subMenu1Private->contentData.size(), 3);
          }
          
          {
              // Check that takeMenu works.
              auto *takenSubMenu = contextMenu->takeMenu(0);
              QCOMPARE(takenSubMenu, subMenu1);
              QCOMPARE(contextMenuPrivate->contentData.size(), 0);
      #ifdef HAVE_NATIVE_MENU_SUPPORT
              QVERIFY(!subMenu1Private->handle);
              QCOMPARE(subMenu1Private->nativeItems.size(), 0);
      #endif
              
                     // Check that the sub-menu can be added back in to the menu.
              contextMenu->addMenu(takenSubMenu);
              QCOMPARE(contextMenuPrivate->contentData.size(), 1);
              auto *subMenu1MenuItem = qobject_cast<QQuickMenuItem *>(contextMenu->itemAt(0));
              QVERIFY(subMenu1MenuItem);
              QCOMPARE(subMenu1MenuItem->text(), "subMenu1");
      #ifdef HAVE_NATIVE_MENU_SUPPORT
              QVERIFY(subMenu1Private->handle);
              QCOMPARE(subMenu1Private->nativeItems.size(), 3);
      #endif
              QCOMPARE(subMenu1Private->contentData.size(), 3);
              
              auto *subMenu1Action0MenuItem = qobject_cast<QQuickMenuItem *>(subMenu1->itemAt(0));
              QVERIFY(subMenu1Action0MenuItem);
          }
          
                 // Check that removeMenu works.
          QVERIFY(contextMenu->menuAt(0));
          contextMenu->removeMenu(contextMenu->menuAt(0));
          QCOMPARE(contextMenuPrivate->contentData.size(), 0);
      }
      

      Text editor indentation settings:

      C++ code style settings:

      Qt Creator 12.0.1
      Based on Qt 6.6.0 (MSVC 2019, x86_64)
      
      Built on Dec 11 2023 00:22:59
      
      From revision ee75c7276b
      

      Attachments

        1. screenshot-1.png
          screenshot-1.png
          86 kB
        2. screenshot-2.png
          screenshot-2.png
          88 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            artem.sokolovskii Artem Sokolovskii
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes