VirtualBox

Changeset 63834 in vbox


Ignore:
Timestamp:
Sep 14, 2016 1:15:45 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6899: Accessibility support (step 29): Selector UI: UISnapshotPane: Replacing self-made guard-block with QReadWriteLock.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r63833 r63834  
    2727# include <QPointer>
    2828# include <QApplication>
     29# include <QWriteLocker>
    2930
    3031/* GUI includes: */
     
    407408
    408409
    409 /** Simple guard block to prevent cyclic call caused by:
    410   * changing tree-widget item content (rename) leads to snapshot
    411   * update & snapshot update leads to changing tree-widget item content. */
    412 class SnapshotEditBlocker
    413 {
    414 public:
    415 
    416     /** Constructs edit blocker. */
    417     SnapshotEditBlocker(bool &fProtector) : m_fProtector(fProtector) { m_fProtector = true; }
    418     /** Destructs edit blocker. */
    419     virtual ~SnapshotEditBlocker() { m_fProtector = false; }
    420 
    421 private:
    422 
    423     /** Holds the protector flag reference. */
    424     bool &m_fProtector;
    425 };
    426 
    427 
    428410UISnapshotPane::UISnapshotPane(QWidget *pParent)
    429411    : QIWithRetranslateUI<QWidget>(pParent)
    430412    , m_pCurrentSnapshotItem(0)
    431     , m_fEditProtector(false)
    432413    , m_pSnapshotItemActionGroup(new QActionGroup(this))
    433414    , m_pCurrentStateItemActionGroup(new QActionGroup(this))
     
    680661void UISnapshotPane::sltItemChanged(QTreeWidgetItem *pItem)
    681662{
    682     /* Make sure nothing is being edited currently: */
    683     if (m_fEditProtector)
     663    /* Make sure nothing being edited in the meantime: */
     664    if (!m_lockReadWrite.tryLockForWrite())
    684665        return;
    685666
     
    692673    if (!comSnapshot.isNull() && comSnapshot.isOk() && comSnapshot.GetName() != pSnapshotItem->text(0))
    693674        comSnapshot.SetName(pSnapshotItem->text(0));
     675
     676    /* Allows editing again: */
     677    m_lockReadWrite.unlock();
    694678}
    695679
    696680void UISnapshotPane::sltItemDoubleClicked(QTreeWidgetItem *pItem)
    697681{
    698     /* Make sure nothing is being edited currently: */
    699     if (m_fEditProtector)
    700         return;
    701 
    702682    /* Acquire corresponding snapshot item: */
    703683    const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(pItem);
     
    858838void UISnapshotPane::sltMachineDataChange(QString strMachineID)
    859839{
    860     /* Prevent snapshot editing in the meantime: */
    861     SnapshotEditBlocker guardBlock(m_fEditProtector);
    862 
    863840    /* Make sure it's our VM: */
    864841    if (strMachineID != m_strMachineID)
    865842        return;
    866843
     844    /* Prevent snapshot editing in the meantime: */
     845    QWriteLocker locker(&m_lockReadWrite);
     846
    867847    /* Recache state current item: */
    868848    currentStateItem()->recache();
     
    871851void UISnapshotPane::sltMachineStateChange(QString strMachineID, KMachineState enmState)
    872852{
    873     /* Prevent snapshot editing in the meantime: */
    874     SnapshotEditBlocker guardBlock(m_fEditProtector);
    875 
    876853    /* Make sure it's our VM: */
    877854    if (strMachineID != m_strMachineID)
    878855        return;
    879856
     857    /* Prevent snapshot editing in the meantime: */
     858    QWriteLocker locker(&m_lockReadWrite);
     859
    880860    /* Recache new machine state: */
    881861    currentStateItem()->recache();
     
    885865void UISnapshotPane::sltSessionStateChange(QString strMachineID, KSessionState enmState)
    886866{
    887     /* Prevent snapshot editing in the meantime: */
    888     SnapshotEditBlocker guardBlock(m_fEditProtector);
    889 
    890867    /* Make sure it's our VM: */
    891868    if (strMachineID != m_strMachineID)
    892869        return;
     870
     871    /* Prevent snapshot editing in the meantime: */
     872    QWriteLocker locker(&m_lockReadWrite);
    893873
    894874    /* Recache new session state: */
     
    1003983{
    1004984    /* Prevent snapshot editing in the meantime: */
    1005     SnapshotEditBlocker guardBlock(m_fEditProtector);
     985    QWriteLocker locker(&m_lockReadWrite);
    1006986
    1007987    /* If VM is null, just updated the current itm: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h

    r63833 r63834  
    2222#include <QTimer>
    2323#include <QIcon>
     24#include <QReadWriteLock>
    2425
    2526/* GUI includes: */
     
    155156    SnapshotWgtItem *m_pCurrentSnapshotItem;
    156157    /** Holds the snapshot item editing protector. */
    157     bool             m_fEditProtector;
     158    QReadWriteLock   m_lockReadWrite;
    158159
    159160    /** Holds the snapshot item action group instance. */
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