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

QHeaderView::reset() should reset logical indices

    XMLWordPrintable

Details

    Description

      Platform
      Linux
      Platform details
      Compilers
      GCC

      Steps to reproduce / test case

      1. initialize a QTableView with a custom but basic model (inheriting from QTableModel) with, say, 9 columns.
      2. set the table view headers movable.
      3. have a model reset that in fact is triggered by just one column added at the last position

      • at this point everything's well, see below.
        4. in the view, move the new column somewhere in the middle, let's say at visual index 7
        5. remove the last (most recent) column from the model and let the model emit reset() instead of column removed signals.
        6. now, logicalIndex(7) on the header returns 9 but there are just 9 columns left...
        More information
        When QHeaderView::reset() is called the logical indices (QHeaderViewPrivate::logicalIndices) are not correctly reset nor their mapping with QHeaderViewPrivate::visualIndices. See both QHeaderView::initializeSections() functions, particularly lines 1939 ff of qheaderview.cpp. Indices inferior to new column count are left untouched). At step 3, above, the view was correctly updated b the new count is superior to the old count.

      The only way I found to reset the indices and their mapping is through connections established in QHeaderView::setModel() since QHeaderView::sectionsInserted and QHeaderViewPrivate::_q_sectionsRemoved seem to behave in a nicer way, but this is somewhat inconvenient since this forces the model to emit signals to mimick erasing of all columns then insertion of all new columns.

      At the very least, the default should be documented.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            peppe Giuseppe D'Angelo
            dakovaci Daniel Kovacic
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes