VirtualBox

Changeset 105033 in vbox


Ignore:
Timestamp:
Jun 26, 2024 5:05:04 PM (9 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
163651
Message:

FE/Qt: bugref:10681: UIShortcutConfigurationEditor: A bit of rework related to table rows; pointers instead of object copies.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIShortcutConfigurationEditor.cpp

    r105032 r105033  
    181181
    182182/** Shortcut configuration editor row list. */
    183 typedef QList<UIShortcutTableViewRow> UIShortcutTableViewContent;
     183typedef QList<UIShortcutTableViewRow*> UIShortcutTableViewContent;
    184184
    185185
     
    197197    {}
    198198
    199     /** Returns whether the @a item1 is more/less than the @a item2.
     199    /** Returns whether the @a pItem1 is more/less than the @a pItem2.
    200200      * @note  Order depends on the one set through constructor, stored in m_enmOrder. */
    201     bool operator()(const UIShortcutTableViewRow &item1, const UIShortcutTableViewRow &item2)
     201    bool operator()(UIShortcutTableViewRow *pItem1, UIShortcutTableViewRow *pItem2)
    202202    {
    203203        switch (m_iColumn)
     
    205205            case TableColumnIndex_Description:
    206206                return   m_enmOrder == Qt::AscendingOrder
    207                        ? item1.description() < item2.description()
    208                        : item1.description() > item2.description();
     207                       ? pItem1->description() < pItem2->description()
     208                       : pItem1->description() > pItem2->description();
    209209            case TableColumnIndex_Sequence:
    210210                return   m_enmOrder == Qt::AscendingOrder
    211                        ? item1.currentSequence() < item2.currentSequence()
    212                        : item1.currentSequence() > item2.currentSequence();
     211                       ? pItem1->currentSequence() < pItem2->currentSequence()
     212                       : pItem1->currentSequence() > pItem2->currentSequence();
    213213            default:
    214214                break;
    215215        }
    216216        return   m_enmOrder == Qt::AscendingOrder
    217                ? item1.key() < item2.key()
    218                : item1.key() > item2.key();
     217               ? pItem1->key() < pItem2->key()
     218               : pItem1->key() > pItem2->key();
    219219    }
    220220
     
    245245      * @param  enmType  Brings the action-pool type this model is related to. */
    246246    UIShortcutConfigurationModel(UIShortcutConfigurationEditor *pParent, UIType enmType);
     247    /** Destructs model. */
     248    virtual ~UIShortcutConfigurationModel() RT_OVERRIDE;
    247249
    248250    /** Loads a @a list of shortcuts to the model. */
     
    347349}
    348350
     351UIShortcutConfigurationModel::~UIShortcutConfigurationModel()
     352{
     353    /* Delete the cached data: */
     354    qDeleteAll(m_shortcuts);
     355    m_shortcuts.clear();
     356    m_filteredShortcuts.clear();
     357}
     358
    349359void UIShortcutConfigurationModel::load(const UIShortcutConfigurationList &list)
    350360{
     
    357367            continue;
    358368        /* Add suitable item to the model as a new shortcut: */
    359         m_shortcuts << UIShortcutTableViewRow(view(), item);
     369        m_shortcuts << new UIShortcutTableViewRow(view(), item);
    360370    }
    361371    /* Apply filter: */
     
    368378{
    369379    /* Save cached model shortcuts: */
    370     foreach (const UIShortcutTableViewRow &row, m_shortcuts)
    371     {
    372         const UIShortcutConfigurationItem &item = row;
    373 
     380    foreach (UIShortcutTableViewRow *pRow, m_shortcuts)
     381    {
    374382        /* Search for corresponding item position: */
    375         const int iShortcutItemPosition = UIShortcutSearchFunctor<UIShortcutConfigurationItem>()(list, item);
     383        const int iShortcutItemPosition = UIShortcutSearchFunctor<UIShortcutConfigurationItem>()(list, pRow);
    376384        /* Make sure position is valid: */
    377385        if (iShortcutItemPosition == -1)
    378386            continue;
    379387        /* Save cached model shortcut to a list: */
    380         list[iShortcutItemPosition] = item;
     388        list[iShortcutItemPosition] = *pRow;
    381389    }
    382390}
     
    386394    /* Enumerate all the sequences: */
    387395    QMultiMap<QString, QString> usedSequences;
    388     foreach (const UIShortcutTableViewRow &item, m_shortcuts)
    389     {
    390         QString strKey = item.currentSequence();
     396    foreach (UIShortcutTableViewRow *pRow, m_shortcuts)
     397    {
     398        QString strKey = pRow->currentSequence();
    391399        if (!strKey.isEmpty())
    392400        {
    393             const QString strScope = item.scope();
     401            const QString strScope = pRow->scope();
    394402            strKey = strScope.isNull() ? strKey : QString("%1: %2").arg(strScope, strKey);
    395             usedSequences.insert(strKey, item.key());
     403            usedSequences.insert(strKey, pRow->key());
    396404        }
    397405    }
     
    495503                {
    496504                    /* Return shortcut scope and description: */
    497                     const QString strScope = m_filteredShortcuts[iIndex].scope();
    498                     const QString strDescription = m_filteredShortcuts[iIndex].description();
     505                    const QString strScope = m_filteredShortcuts.at(iIndex)->scope();
     506                    const QString strDescription = m_filteredShortcuts.at(iIndex)->description();
    499507                    return strScope.isNull() ? strDescription : QString("%1: %2").arg(strScope, strDescription);
    500508                }
     
    502510                {
    503511                    /* If that is host-combo cell: */
    504                     if (m_filteredShortcuts[iIndex].key() == UIHostCombo::hostComboCacheKey())
     512                    if (m_filteredShortcuts.at(iIndex)->key() == UIHostCombo::hostComboCacheKey())
    505513                        /* We should return host-combo: */
    506                         return UIHostCombo::toReadableString(m_filteredShortcuts[iIndex].currentSequence());
     514                        return UIHostCombo::toReadableString(m_filteredShortcuts.at(iIndex)->currentSequence());
    507515                    /* In other cases we should return hot-combo: */
    508                     QString strHotCombo = m_filteredShortcuts[iIndex].currentSequence();
     516                    QString strHotCombo = m_filteredShortcuts.at(iIndex)->currentSequence();
    509517                    /* But if that is machine table and hot-combo is not empty: */
    510518                    if (m_enmType == UIType_RuntimeUI && !strHotCombo.isEmpty())
     
    525533            {
    526534                case TableColumnIndex_Sequence:
    527                     return   m_filteredShortcuts[iIndex].key() == UIHostCombo::hostComboCacheKey()
    528                            ? QVariant::fromValue(UIHostComboWrapper(m_filteredShortcuts[iIndex].currentSequence()))
     535                    return   m_filteredShortcuts.at(iIndex)->key() == UIHostCombo::hostComboCacheKey()
     536                           ? QVariant::fromValue(UIHostComboWrapper(m_filteredShortcuts.at(iIndex)->currentSequence()))
    529537                           : QVariant::fromValue(UIHotKey(  m_enmType == UIType_RuntimeUI
    530538                                                          ? UIHotKeyType_Simple
    531539                                                          : UIHotKeyType_WithModifiers,
    532                                                           m_filteredShortcuts[iIndex].currentSequence(),
    533                                                           m_filteredShortcuts[iIndex].defaultSequence()));
     540                                                          m_filteredShortcuts.at(iIndex)->currentSequence(),
     541                                                          m_filteredShortcuts.at(iIndex)->defaultSequence()));
    534542                default:
    535543                    break;
     
    547555                case TableColumnIndex_Sequence:
    548556                {
    549                     if (   m_filteredShortcuts[iIndex].key() != UIHostCombo::hostComboCacheKey()
    550                         && m_filteredShortcuts[iIndex].currentSequence() != m_filteredShortcuts[iIndex].defaultSequence())
     557                    if (   m_filteredShortcuts.at(iIndex)->key() != UIHostCombo::hostComboCacheKey()
     558                        && m_filteredShortcuts.at(iIndex)->currentSequence() != m_filteredShortcuts.at(iIndex)->defaultSequence())
    551559                        font.setBold(true);
    552560                    break;
     
    564572                case TableColumnIndex_Sequence:
    565573                {
    566                     if (m_duplicatedSequences.contains(m_filteredShortcuts[iIndex].key()))
     574                    if (m_duplicatedSequences.contains(m_filteredShortcuts.at(iIndex)->key()))
    567575                        return QBrush(Qt::red);
    568576                    break;
     
    597605                    const int iIndex = index.row();
    598606                    /* Set sequence to shortcut: */
    599                     UIShortcutTableViewRow &filteredShortcut = m_filteredShortcuts[iIndex];
    600                     const int iShortcutIndex = UIShortcutSearchFunctor<UIShortcutTableViewRow>()(m_shortcuts, filteredShortcut);
     607                    UIShortcutTableViewRow *pFilteredShortcut = m_filteredShortcuts.at(iIndex);
     608                    const int iShortcutIndex = UIShortcutSearchFunctor<UIShortcutTableViewRow>()(m_shortcuts, pFilteredShortcut);
    601609                    if (iShortcutIndex != -1)
    602610                    {
    603                         filteredShortcut.setCurrentSequence(  filteredShortcut.key() == UIHostCombo::hostComboCacheKey()
    604                                                             ? value.value<UIHostComboWrapper>().toString()
    605                                                             : value.value<UIHotKey>().sequence());
    606                         m_shortcuts[iShortcutIndex] = filteredShortcut;
     611                        pFilteredShortcut->setCurrentSequence(  pFilteredShortcut->key() == UIHostCombo::hostComboCacheKey()
     612                                                              ? value.value<UIHostComboWrapper>().toString()
     613                                                              : value.value<UIHotKey>().sequence());
    607614                        emit sigDataChanged();
    608615                        return true;
     
    632639    if (iIndexOfHostComboItem != -1)
    633640    {
    634         UIShortcutTableViewRow hostComboItem = m_shortcuts.takeAt(iIndexOfHostComboItem);
    635         m_shortcuts.prepend(hostComboItem);
     641        UIShortcutTableViewRow *pHostComboItem = m_shortcuts.takeAt(iIndexOfHostComboItem);
     642        m_shortcuts.prepend(pHostComboItem);
    636643    }
    637644    /* Apply the filter: */
     
    652659void UIShortcutConfigurationModel::applyFilter()
    653660{
    654     /* Erase items first if necessary: */
     661    /* Erase rows first if necessary: */
    655662    if (!m_filteredShortcuts.isEmpty())
    656663    {
     
    663670    if (m_strFilter.isEmpty())
    664671    {
    665         /* Just add all the items: */
     672        /* Just add all the rows: */
    666673        m_filteredShortcuts = m_shortcuts;
    667674    }
     
    669676    {
    670677        /* Check if the description matches the filter: */
    671         foreach (const UIShortcutTableViewRow &item, m_shortcuts)
    672         {
    673             /* If neither scope nor description or sequence matches the filter, skip item: */
    674             if (   !item.scope().contains(m_strFilter, Qt::CaseInsensitive)
    675                 && !item.description().contains(m_strFilter, Qt::CaseInsensitive)
    676                 && !item.currentSequence().contains(m_strFilter, Qt::CaseInsensitive))
     678        foreach (UIShortcutTableViewRow *pRow, m_shortcuts)
     679        {
     680            /* If neither scope nor description or sequence matches the filter, skip the pRow: */
     681            if (   !pRow->scope().contains(m_strFilter, Qt::CaseInsensitive)
     682                && !pRow->description().contains(m_strFilter, Qt::CaseInsensitive)
     683                && !pRow->currentSequence().contains(m_strFilter, Qt::CaseInsensitive))
    677684                continue;
    678             /* Add that item: */
    679             m_filteredShortcuts << item;
    680         }
    681     }
    682 
    683     /* Add items finally if necessary: */
     685            /* Add that pRow: */
     686            m_filteredShortcuts << pRow;
     687        }
     688    }
     689
     690    /* Add rows finally if necessary: */
    684691    if (!m_filteredShortcuts.isEmpty())
    685692    {
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIShortcutConfigurationEditor.h

    r105032 r105033  
    5858            const BaseClass &iteratedShortcut = shortcuts.at(i);
    5959            if (iteratedShortcut.key() == shortcut.key())
     60                return i;
     61        }
     62        return -1;
     63    }
     64
     65    /** Returns the position of the 1st occurrence of the
     66      * @a shortcut in the @a shortcuts list, or -1 otherwise. */
     67    int operator()(const QList<BaseClass*> &shortcuts, const BaseClass &shortcut)
     68    {
     69        for (int i = 0; i < shortcuts.size(); ++i)
     70        {
     71            const BaseClass *pIteratedShortcut = shortcuts.at(i);
     72            if (pIteratedShortcut->key() == shortcut.key())
     73                return i;
     74        }
     75        return -1;
     76    }
     77
     78    /** Returns the position of the 1st occurrence of the
     79      * @a shortcut in the @a shortcuts list, or -1 otherwise. */
     80    int operator()(const QList<BaseClass> &shortcuts, const BaseClass *pShortcut)
     81    {
     82        for (int i = 0; i < shortcuts.size(); ++i)
     83        {
     84            const BaseClass &iteratedShortcut = shortcuts.at(i);
     85            if (iteratedShortcut.key() == pShortcut->key())
     86                return i;
     87        }
     88        return -1;
     89    }
     90
     91    /** Returns the position of the 1st occurrence of the
     92      * @a shortcut in the @a shortcuts list, or -1 otherwise. */
     93    int operator()(const QList<BaseClass*> &shortcuts, const BaseClass *pShortcut)
     94    {
     95        for (int i = 0; i < shortcuts.size(); ++i)
     96        {
     97            const BaseClass *pIteratedShortcut = shortcuts.at(i);
     98            if (pIteratedShortcut->key() == pShortcut->key())
    6099                return i;
    61100        }
Note: See TracChangeset for help on using the changeset viewer.

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