VirtualBox

Changeset 105063 in vbox


Ignore:
Timestamp:
Jun 27, 2024 2:04:43 PM (5 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10681: QITableView: Reworking accessibility interface to support proxy-models.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/extensions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITableView.cpp

    r103987 r105063  
    2828/* Qt includes: */
    2929#include <QAccessibleWidget>
     30#include <QSortFilterProxyModel>
    3031
    3132/* GUI includes: */
     
    260261}
    261262
    262 QAccessibleInterface *QIAccessibilityInterfaceForQITableViewRow::child(int iIndex) const /* override */
     263QAccessibleInterface *QIAccessibilityInterfaceForQITableViewRow::child(int iIndex) const
    263264{
    264265    /* Make sure row still alive: */
     
    271272}
    272273
    273 int QIAccessibilityInterfaceForQITableViewRow::indexOfChild(const QAccessibleInterface *pChild) const /* override */
     274int QIAccessibilityInterfaceForQITableViewRow::indexOfChild(const QAccessibleInterface *pChild) const
    274275{
    275276    /* Search for corresponding child: */
     
    345346    /* Make sure table still alive: */
    346347    AssertPtrReturn(table(), 0);
     348    /* Make sure model still alive: */
     349    AssertPtrReturn(table()->model(), 0);
    347350
    348351    /* Return the number of children: */
    349     return table()->childCount();
     352    return table()->model()->rowCount();
    350353}
    351354
     
    353356{
    354357    /* Make sure table still alive: */
    355     AssertPtrReturn(table(), 0);
     358    QITableView *pTable = table();
     359    AssertPtrReturn(pTable, 0);
     360    /* Make sure model still alive: */
     361    QAbstractItemModel *pModel = pTable->model();
     362    AssertPtrReturn(pModel, 0);
    356363    /* Make sure index is valid: */
    357364    AssertReturn(iIndex >= 0, 0);
    358     if (iIndex >= childCount())
    359     {
    360         // WORKAROUND:
    361         // Normally I would assert here, but Qt5 accessibility code has
    362         // a hard-coded architecture for a table-views which we do not like
    363         // but have to live with and this architecture enumerates cells
    364         // including header column and row, so Qt5 can try to address
    365         // our interface with index which surely out of bounds by our laws.
    366         // So let's assume that's exactly such case and try to enumerate
    367         // table cells including header column and row.
    368         // printf("Invalid index: %d\n", iIndex);
    369 
     365
     366    /* Real index might be different: */
     367    int iRealRowIndex = iIndex;
     368
     369    // WORKAROUND:
     370    // For a table-views Qt accessibility code has a hard-coded architecture which we do not like
     371    // but have to live with, this architecture enumerates cells including header column and row,
     372    // so Qt can try to address our interface with index which surely out of bounds by our laws.
     373    // Let's assume that's exactly the case and try to enumerate cells including header column and row.
     374    if (iRealRowIndex >= childCount())
     375    {
    370376        // Split delimeter is overall column count, including vertical header:
    371         const int iColumnCount = table()->model()->columnCount() + 1 /* v_header */;
     377        const int iColumnCount = pModel->columnCount() + 1 /* v_header */;
    372378        // Real index is zero-based, incoming is 1-based:
    373379        const int iRealIndex = iIndex - 1;
    374380        // Real row index, excluding horizontal header:
    375         const int iRealRowIndex = iRealIndex / iColumnCount - 1 /* h_header */;
    376         // printf("Actual row index: %d\n", iRealRowIndex);
    377 
    378         // Return what we found:
    379         return iRealRowIndex >= 0 && iRealRowIndex < childCount() ?
    380                QAccessible::queryAccessibleInterface(table()->childItem(iRealRowIndex)) : 0;
    381     }
    382 
    383     /* Return the child with the passed iIndex: */
    384     return QAccessible::queryAccessibleInterface(table()->childItem(iIndex));
     381        iRealRowIndex = iRealIndex / iColumnCount - 1 /* h_header */;
     382        // printf("Invalid index: %d, Actual index: %d\n", iIndex, iRealRowIndex);
     383    }
     384
     385    /* Make sure index fits the bounds finally: */
     386    if (iRealRowIndex >= childCount())
     387        return 0;
     388
     389    /* Acquire child-index: */
     390    const QModelIndex childIndex = pModel->index(iRealRowIndex, 0);
     391    /* Check whether we have proxy model set or source one otherwise: */
     392    const QSortFilterProxyModel *pProxyModel = qobject_cast<const QSortFilterProxyModel*>(pModel);
     393    /* Acquire source-model child-index (can be the same as original if there is no proxy model): */
     394    const QModelIndex sourceChildIndex = pProxyModel ? pProxyModel->mapToSource(childIndex) : childIndex;
     395
     396    /* Acquire row item: */
     397    QITableViewRow *pRow = static_cast<QITableViewRow*>(sourceChildIndex.internalPointer());
     398    /* Return row's accessibility interface: */
     399    return QAccessible::queryAccessibleInterface(pRow);
    385400}
    386401
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QITableView.h

    r104897 r105063  
    117117    virtual ~QITableView() RT_OVERRIDE;
    118118
    119     /** Returns the number of children. */
    120     virtual int childCount() const { return 0; }
    121     /** Returns the child item with @a iIndex. */
    122     virtual QITableViewRow *childItem(int /* iIndex */) const { return 0; }
    123 
    124119    /** Makes sure current editor data committed. */
    125120    void makeSureEditorDataCommitted();
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette