VirtualBox

Changeset 105056 in vbox


Ignore:
Timestamp:
Jun 27, 2024 11:06:49 AM (9 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
163675
Message:

FE/Qt: bugref:10681: UIShortcutConfigurationEditor: A bit of rework related to model view assigning.

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

    r105034 r105056  
    55
    66/*
    7  * Copyright (C) 2006-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
     
    315315
    316316    /** Constructs table passing @a pParent to the base-class.
    317       * @param  pModel         Brings the model this table is bound to.
    318317      * @param  strObjectName  Brings the object name this table has, required for fast referencing. */
    319     UIShortcutConfigurationView(QWidget *pParent, UIShortcutConfigurationModel *pModel, const QString &strObjectName);
     318    UIShortcutConfigurationView(QWidget *pParent, const QString &strObjectName);
    320319    /** Destructs table. */
    321320    virtual ~UIShortcutConfigurationView() RT_OVERRIDE;
     321
     322    /** Sets the @a pModel for the view to present. */
     323    virtual void setModel(QAbstractItemModel *pModel) RT_OVERRIDE;
    322324
    323325private slots:
     
    332334    /** Cleanups all. */
    333335    void cleanup();
     336
     337    /** Holds whether the view is polished. */
     338    bool  m_fPolished;
    334339
    335340    /** Holds the item editor factory instance. */
     
    703708
    704709UIShortcutConfigurationView::UIShortcutConfigurationView(QWidget *pParent,
    705                                                          UIShortcutConfigurationModel *pModel,
    706710                                                         const QString &strObjectName)
    707711    : QITableView(pParent)
     712    , m_fPolished(false)
    708713    , m_pItemEditorFactory(0)
    709714{
    710715    /* Set object name: */
    711716    setObjectName(strObjectName);
    712     /* Set model: */
    713     setModel(pModel);
    714717
    715718    /* Prepare all: */
     
    721724    /* Cleanup all: */
    722725    cleanup();
     726}
     727
     728void UIShortcutConfigurationView::setModel(QAbstractItemModel *pModel)
     729{
     730    /* Call to base-class: */
     731    QITableView::setModel(pModel);
     732
     733    /* Some stuff to be polished after a model is assigned: */
     734    if (model() && !m_fPolished)
     735    {
     736        m_fPolished = true;
     737
     738        // WORKAROUND:
     739        // Due to internal Qt bug QHeaderView::::setSectionResizeMode is only possible
     740        // to be used after model is already assigned. Getting Qt crash otherwise.
     741        horizontalHeader()->setSectionResizeMode(TableColumnIndex_Description, QHeaderView::Interactive);
     742        horizontalHeader()->setSectionResizeMode(TableColumnIndex_Sequence, QHeaderView::Stretch);
     743
     744        /* Connect model: */
     745        UIShortcutConfigurationModel *pHotKeyTableModel = qobject_cast<UIShortcutConfigurationModel*>(model());
     746        if (pHotKeyTableModel)
     747            connect(pHotKeyTableModel, &UIShortcutConfigurationModel::sigShortcutsLoaded,
     748                    this, &UIShortcutConfigurationView::sltHandleShortcutsLoaded);
     749    }
    723750}
    724751
     
    746773    verticalHeader()->setDefaultSectionSize((int)(verticalHeader()->minimumSectionSize() * 1.33));
    747774    horizontalHeader()->setStretchLastSection(false);
    748     horizontalHeader()->setSectionResizeMode(TableColumnIndex_Description, QHeaderView::Interactive);
    749     horizontalHeader()->setSectionResizeMode(TableColumnIndex_Sequence, QHeaderView::Stretch);
    750 
    751     /* Connect model: */
    752     UIShortcutConfigurationModel *pHotKeyTableModel = qobject_cast<UIShortcutConfigurationModel*>(model());
    753     if (pHotKeyTableModel)
    754         connect(pHotKeyTableModel, &UIShortcutConfigurationModel::sigShortcutsLoaded,
    755                 this, &UIShortcutConfigurationView::sltHandleShortcutsLoaded);
     775    // WORKAROUND:
     776    // Rest of horizontalHeader stuff is in setModel() above..
    756777
    757778    /* Check if we do have proper item delegate: */
     
    915936
    916937            /* Prepare Manager UI table: */
    917             m_pTableManager = new UIShortcutConfigurationView(pTabManager, m_pModelManager, "m_pTableManager");
     938            m_pTableManager = new UIShortcutConfigurationView(pTabManager, "m_pTableManager");
    918939            if (m_pTableManager)
     940            {
     941                m_pTableManager->setModel(m_pModelManager);
    919942                pLayoutManager->addWidget(m_pTableManager);
     943            }
    920944        }
    921945
     
    949973
    950974            /* Create Runtime UI table: */
    951             m_pTableRuntime = new UIShortcutConfigurationView(pTabMachine, m_pModelRuntime, "m_pTableRuntime");
     975            m_pTableRuntime = new UIShortcutConfigurationView(pTabMachine, "m_pTableRuntime");
    952976            if (m_pTableRuntime)
     977            {
     978                m_pTableRuntime->setModel(m_pModelRuntime);
    953979                pLayoutMachine->addWidget(m_pTableRuntime);
     980            }
    954981        }
    955982
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIShortcutConfigurationEditor.h

    r105033 r105056  
    55
    66/*
    7  * Copyright (C) 2006-2023 Oracle and/or its affiliates.
     7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
    88 *
    99 * This file is part of VirtualBox base platform packages, as
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