VirtualBox

Changeset 105000 in vbox


Ignore:
Timestamp:
Jun 24, 2024 2:55:48 PM (5 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10681: UIPortForwardingTable: Rework restoring previously chosen rule procedure to use abstract Qt API instead of our own API written just for that, we will remove that code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.cpp

    r104585 r105000  
    843843                                     bool fHoldPosition /* = false */)
    844844{
    845     /* Remember last chosen item: */
     845    /* Store last chosen item: */
     846    QString strPreviousName;
    846847    const QModelIndex currentIndex = m_pTableView->currentIndex();
    847     QITableViewRow *pCurrentItem = currentIndex.isValid() ? m_pTableModel->childItem(currentIndex.row()) : 0;
    848     const QString strCurrentName = pCurrentItem ? pCurrentItem->childItem(0)->text() : QString();
     848    if (currentIndex.isValid())
     849    {
     850        const int iCurrentRow = currentIndex.row();
     851        const QModelIndex firstCurrentIndex = m_pTableModel->index(iCurrentRow, 0);
     852        if (firstCurrentIndex.isValid())
     853            strPreviousName = m_pTableModel->data(firstCurrentIndex, Qt::DisplayRole).toString();
     854    }
    849855
    850856    /* Update the list of rules: */
     
    854860
    855861    /* Restore last chosen item: */
    856     if (fHoldPosition && !strCurrentName.isEmpty())
    857     {
    858         for (int i = 0; i < m_pTableModel->childCount(); ++i)
     862    if (fHoldPosition && !strPreviousName.isEmpty())
     863    {
     864        for (int i = 0; i < m_pTableModel->rowCount(); ++i)
    859865        {
    860             QITableViewRow *pItem = m_pTableModel->childItem(i);
    861             const QString strName = pItem ? pItem->childItem(0)->text() : QString();
    862             if (strName == strCurrentName)
    863                 m_pTableView->setCurrentIndex(m_pTableModel->index(i, 0));
     866            const QModelIndex firstIteratedIndex = m_pTableModel->index(i, 0);
     867            if (firstIteratedIndex.isValid())
     868            {
     869                const QString strName = m_pTableModel->data(firstIteratedIndex, Qt::DisplayRole).toString();
     870                if (strName == strPreviousName)
     871                    m_pTableView->setCurrentIndex(m_pTableModel->index(i, 0));
     872            }
    864873        }
    865874    }
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