VirtualBox

Changeset 67147 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 30, 2017 3:54:09 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115823
Message:

FE/Qt: Selector UI: Tools pane: Snapshot pane: Extend snapshot details dialog with corresponding alterable structure; Cleanup snapshot pane as well.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

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

    r67146 r67147  
    266266}
    267267
    268 void VBoxSnapshotDetailsDlg::setData(const CSnapshot &comSnapshot)
    269 {
     268void VBoxSnapshotDetailsDlg::setData(const UIDataSnapshot &data, const CSnapshot &comSnapshot)
     269{
     270    /* Cache old/new data: */
     271    m_oldData = data;
     272    m_newData = m_oldData;
     273
    270274    /* Cache snapshot: */
    271275    m_comSnapshot = comSnapshot;
    272276
     277    /* Load general snapshot properties: */
     278    mLeName->setText(m_newData.m_strName);
     279    mTeDescription->setText(m_newData.m_strDescription);
     280
    273281    /* If there is really a snapshot: */
    274282    if (m_comSnapshot.isNotNull())
    275283    {
    276         /* Read general snapshot properties: */
    277         mLeName->setText(m_comSnapshot.GetName());
    278         mTeDescription->setText(m_comSnapshot.GetDescription());
    279 
    280284        /* Calculate snapshot timestamp info: */
    281285        QDateTime timestamp;
     
    364368
    365369    /* Save snapshot name: */
    366     m_comSnapshot.SetName(mLeName->text());
     370    m_comSnapshot.SetName(m_newData.m_strName);
    367371    /* Save snapshot description: */
    368     m_comSnapshot.SetDescription(mTeDescription->toPlainText());
     372    m_comSnapshot.SetDescription(m_newData.m_strDescription);
    369373
    370374    /* Close the session again. */
     
    451455void VBoxSnapshotDetailsDlg::sltHandleNameChange(const QString &strName)
    452456{
     457    /* Recache snapshot name: */
     458    m_newData.m_strName = strName;
    453459    /* Perform snapshot name sanity check: */
    454460    mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!strName.trimmed().isEmpty());
     461}
     462
     463void VBoxSnapshotDetailsDlg::sltHandleDescriptionChange()
     464{
     465    /* Recache snapshot description: */
     466    m_newData.m_strDescription = mTeDescription->toPlainText();
    455467}
    456468
     
    470482        }
    471483
     484        /* Description editor created in the .ui file: */
     485        AssertPtrReturnVoid(mTeDescription);
     486        {
     487            /* Configure editor: */
     488            connect(mTeDescription, &QTextEdit::textChanged,
     489                    this, &VBoxSnapshotDetailsDlg::sltHandleDescriptionChange);
     490        }
     491
    472492        /* Thumbnail label created in the .ui file: */
    473493        AssertPtrReturnVoid(mLbThumbnail);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.h

    r67146 r67147  
    2727
    2828
     29/** Snapshot pane: Snapshot data structure. */
     30struct UIDataSnapshot
     31{
     32    /** Constructs data. */
     33    UIDataSnapshot()
     34        : m_strName(QString())
     35        , m_strDescription(QString())
     36    {}
     37
     38    /** Returns whether the @a other passed data is equal to this one. */
     39    bool equal(const UIDataSnapshot &other) const
     40    {
     41        return true
     42               && (m_strName == other.m_strName)
     43               && (m_strDescription == other.m_strDescription)
     44               ;
     45    }
     46
     47    /** Returns whether the @a other passed data is equal to this one. */
     48    bool operator==(const UIDataSnapshot &other) const { return equal(other); }
     49    /** Returns whether the @a other passed data is different from this one. */
     50    bool operator!=(const UIDataSnapshot &other) const { return !equal(other); }
     51
     52    /** Holds the snapshot name. */
     53    QString m_strName;
     54    /** Holds the snapshot description. */
     55    QString m_strDescription;
     56};
     57
     58
    2959/** QDialog extension providing GUI with snapshot details dialog. */
    3060class VBoxSnapshotDetailsDlg : public QIWithRetranslateUI<QDialog>, public Ui::VBoxSnapshotDetailsDlg
     
    3868
    3969    /** Defines the snapshot @a data. */
    40     void setData(const CSnapshot &comSnapshot);
     70    void setData(const UIDataSnapshot &data, const CSnapshot &comSnapshot);
    4171    /** Saves the snapshot data. */
    4272    void saveData();
     
    5989    /** Handles snapshot @a strName change. */
    6090    void sltHandleNameChange(const QString &strName);
     91    /** Handles snapshot description change. */
     92    void sltHandleDescriptionChange();
    6193
    6294private:
     
    71103    CSnapshot m_comSnapshot;
    72104
     105    /** Holds the old data copy. */
     106    UIDataSnapshot  m_oldData;
     107    /** Holds the new data copy. */
     108    UIDataSnapshot  m_newData;
     109
    73110    /** Holds the cached thumbnail. */
    74111    QPixmap m_pixmapThumbnail;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r67146 r67147  
    5959
    6060/** QITreeWidgetItem subclass for snapshots items. */
    61 class UISnapshotItem : public QITreeWidgetItem
     61class UISnapshotItem : public QITreeWidgetItem, public UIDataSnapshot
    6262{
    6363    Q_OBJECT;
     
    147147    bool                     m_fOnline;
    148148
    149     /** Holds the item description. */
    150     QString                  m_strDesc;
    151149    /** Holds the item timestamp. */
    152150    QDateTime                m_timestamp;
     
    330328        AssertReturnVoid(!m_comMachine.isNull());
    331329        m_fCurrentStateModified = m_comMachine.GetCurrentStateModified();
    332         setText(0, m_fCurrentStateModified ?
    333                    UISnapshotPane::tr("Current State (changed)", "Current State (Modified)") :
    334                    UISnapshotPane::tr("Current State", "Current State (Unmodified)"));
    335         m_strDesc = m_fCurrentStateModified ?
    336                     UISnapshotPane::tr("The current state differs from the state stored in the current snapshot") :
    337                     QTreeWidgetItem::parent() != 0 ?
    338                     UISnapshotPane::tr("The current state is identical to the state stored in the current snapshot") :
    339                     QString();
     330        m_strName = m_fCurrentStateModified ?
     331                    UISnapshotPane::tr("Current State (changed)", "Current State (Modified)") :
     332                    UISnapshotPane::tr("Current State", "Current State (Unmodified)");
     333        setText(0, m_strName);
     334        m_strDescription = m_fCurrentStateModified ?
     335                           UISnapshotPane::tr("The current state differs from the state stored in the current snapshot") :
     336                           QTreeWidgetItem::parent() != 0 ?
     337                           UISnapshotPane::tr("The current state is identical to the state stored in the current snapshot") :
     338                           QString();
    340339    }
    341340    /* For others: */
     
    345344        AssertReturnVoid(!m_comSnapshot.isNull());
    346345        m_strSnapshotID = m_comSnapshot.GetId();
    347         setText(0, m_comSnapshot.GetName());
     346        m_strName = m_comSnapshot.GetName();
     347        setText(0, m_strName);
    348348        m_fOnline = m_comSnapshot.GetOnline();
    349349        setIcon(0, *m_pSnapshotWidget->snapshotItemIcon(m_fOnline));
    350         m_strDesc = m_comSnapshot.GetDescription();
     350        m_strDescription = m_comSnapshot.GetDescription();
    351351        m_timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000);
    352352        m_fCurrentStateModified = false;
     
    490490
    491491    /* Append description if any: */
    492     if (!m_strDesc.isEmpty())
    493         strToolTip += "<hr>" + m_strDesc;
     492    if (!m_strDescription.isEmpty())
     493        strToolTip += "<hr>" + m_strDescription;
    494494
    495495    /* Assign tool-tip finally: */
     
    585585    m_pActionCloneSnapshot->setText(tr("&Clone..."));
    586586    /* Translate actions tool-tips: */
    587     m_pActionTakeSnapshot->setToolTip(tr("Take Snapshot (%1)").arg(m_pActionTakeSnapshot->shortcut().toString()));
    588     m_pActionDeleteSnapshot->setToolTip(tr("Delete Snapshot (%1)").arg(m_pActionDeleteSnapshot->shortcut().toString()));
    589     m_pActionRestoreSnapshot->setToolTip(tr("Restore Snapshot (%1)").arg(m_pActionRestoreSnapshot->shortcut().toString()));
    590     m_pActionShowSnapshotDetails->setToolTip(tr("Show Snapshot Details (%1)").arg(m_pActionShowSnapshotDetails->shortcut().toString()));
    591     m_pActionCloneSnapshot->setToolTip(tr("Clone Virtual Machine (%1)").arg(m_pActionCloneSnapshot->shortcut().toString()));
     587    m_pActionTakeSnapshot->setToolTip(tr("Take Snapshot (%1)")
     588                                      .arg(m_pActionTakeSnapshot->shortcut().toString()));
     589    m_pActionDeleteSnapshot->setToolTip(tr("Delete Snapshot (%1)")
     590                                        .arg(m_pActionDeleteSnapshot->shortcut().toString()));
     591    m_pActionRestoreSnapshot->setToolTip(tr("Restore Snapshot (%1)")
     592                                         .arg(m_pActionRestoreSnapshot->shortcut().toString()));
     593    m_pActionShowSnapshotDetails->setToolTip(tr("Show Snapshot Details (%1)")
     594                                             .arg(m_pActionShowSnapshotDetails->shortcut().toString()));
     595    m_pActionCloneSnapshot->setToolTip(tr("Clone Virtual Machine (%1)")
     596                                       .arg(m_pActionCloneSnapshot->shortcut().toString()));
    592597    /* Translate actions status-tips: */
    593598    m_pActionTakeSnapshot->setStatusTip(tr("Take a snapshot of the current virtual machine state"));
     
    618623    QWriteLocker locker(m_pLockReadWrite);
    619624
    620     /* Recache state current item: */
     625    /* Recache current item data: */
    621626    currentStateItem()->recache();
    622627}
     
    631636    QWriteLocker locker(m_pLockReadWrite);
    632637
    633     /* Recache new machine state: */
     638    /* Recache current item data and machine-state: */
    634639    currentStateItem()->recache();
    635640    currentStateItem()->updateCurrentState(enmState);
     
    645650    QWriteLocker locker(m_pLockReadWrite);
    646651
    647     /* Recache new session state: */
     652    /* Recache current session-state: */
    648653    m_enmSessionState = enmState;
    649     sltCurrentItemChanged(m_pSnapshotTree->currentItem());
     654    sltHandleCurrentItemChange();
    650655}
    651656
     
    657662
    658663    /* Search for smallest snapshot age to optimize timer timeout: */
    659     const SnapshotAgeFormat age = traverseSnapshotAge(m_pSnapshotTree->invisibleRootItem());
    660     switch (age)
     664    const SnapshotAgeFormat enmAge = traverseSnapshotAge(m_pSnapshotTree->invisibleRootItem());
     665    switch (enmAge)
    661666    {
    662667        case SnapshotAgeFormat_InSeconds: m_pTimerUpdateAge->setInterval(5 * 1000); break;
     
    672677}
    673678
    674 void UISnapshotPane::sltCurrentItemChanged(QTreeWidgetItem *pItem)
     679void UISnapshotPane::sltHandleCurrentItemChange()
    675680{
    676681    /* Acquire corresponding snapshot item: */
    677     const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(pItem);
     682    const UISnapshotItem *pSnapshotItem = UISnapshotItem::toSnapshotItem(m_pSnapshotTree->currentItem());
    678683
    679684    /* Make the selected item visible: */
     
    736741}
    737742
    738 void UISnapshotPane::sltContextMenuRequested(const QPoint &point)
     743void UISnapshotPane::sltHandleContextMenuRequest(const QPoint &position)
    739744{
    740745    /* Search for corresponding item: */
    741     const QTreeWidgetItem *pItem = m_pSnapshotTree->itemAt(point);
     746    const QTreeWidgetItem *pItem = m_pSnapshotTree->itemAt(position);
    742747    if (!pItem)
    743748        return;
     
    768773
    769774    /* Show menu: */
    770     menu.exec(m_pSnapshotTree->viewport()->mapToGlobal(point));
    771 }
    772 
    773 void UISnapshotPane::sltItemChanged(QTreeWidgetItem *pItem)
     775    menu.exec(m_pSnapshotTree->viewport()->mapToGlobal(position));
     776}
     777
     778void UISnapshotPane::sltHandleItemChange(QTreeWidgetItem *pItem)
    774779{
    775780    /* Make sure nothing being edited in the meantime: */
     
    782787
    783788    /* Rename corresponding snapshot: */
    784     CSnapshot comSnapshot = pSnapshotItem->snapshotID().isNull() ? CSnapshot() : m_comMachine.FindSnapshot(pSnapshotItem->snapshotID());
     789    CSnapshot comSnapshot = pSnapshotItem->snapshotID().isNull()
     790                          ? CSnapshot()
     791                          : m_comMachine.FindSnapshot(pSnapshotItem->snapshotID());
    785792    if (!comSnapshot.isNull() && comSnapshot.isOk() && comSnapshot.GetName() != pSnapshotItem->text(0))
    786793        comSnapshot.SetName(pSnapshotItem->text(0));
     
    790797}
    791798
    792 void UISnapshotPane::sltItemDoubleClicked(QTreeWidgetItem *pItem)
     799void UISnapshotPane::sltHandleItemDoubleClick(QTreeWidgetItem *pItem)
    793800{
    794801    /* Acquire corresponding snapshot item: */
     
    862869    /* Create snapshot toolbar: */
    863870    m_pToolBar = new UIToolBar(this);
     871    AssertPtrReturnVoid(m_pToolBar);
    864872    {
    865873        /* Configure toolbar: */
     
    873881                                                                              ":/snapshot_take_disabled_22px.png",
    874882                                                                              ":/snapshot_take_disabled_16px.png"),
    875                                                     QString(), this, &UISnapshotPane::sltTakeSnapshot);
     883                                                      QString(), this, &UISnapshotPane::sltTakeSnapshot);
    876884        {
    877885            m_pActionTakeSnapshot->setShortcut(QString("Ctrl+Shift+S"));
     
    883891                                                                                ":/snapshot_delete_disabled_22px.png",
    884892                                                                                ":/snapshot_delete_disabled_16px.png"),
    885                                                       QString(), this, &UISnapshotPane::sltDeleteSnapshot);
     893                                                        QString(), this, &UISnapshotPane::sltDeleteSnapshot);
    886894        {
    887895            m_pActionDeleteSnapshot->setShortcut(QString("Ctrl+Shift+D"));
     
    895903                                                                                 ":/snapshot_restore_disabled_22px.png",
    896904                                                                                 ":/snapshot_restore_disabled_16px.png"),
    897                                                        QString(), this, &UISnapshotPane::sltRestoreSnapshot);
     905                                                         QString(), this, &UISnapshotPane::sltRestoreSnapshot);
    898906        {
    899907            m_pActionRestoreSnapshot->setShortcut(QString("Ctrl+Shift+R"));
     
    905913                                                                                     ":/snapshot_show_details_disabled_22px.png",
    906914                                                                                     ":/snapshot_details_show_disabled_16px.png"),
    907                                                            QString(), this, &UISnapshotPane::sltShowSnapshotDetails);
     915                                                             QString(), this, &UISnapshotPane::sltShowSnapshotDetails);
    908916        {
    909917            m_pActionShowSnapshotDetails->setShortcut(QString("Ctrl+Space"));
     
    917925                                                                               ":/vm_clone_disabled_22px.png",
    918926                                                                               ":/vm_clone_disabled_16px.png"),
    919                                                      QString(), this, &UISnapshotPane::sltCloneSnapshot);
     927                                                       QString(), this, &UISnapshotPane::sltCloneSnapshot);
    920928        {
    921929            m_pActionCloneSnapshot->setShortcut(QString("Ctrl+Shift+C"));
     
    931939    /* Create snapshot tree: */
    932940    m_pSnapshotTree = new UISnapshotTree(this);
     941    AssertPtrReturnVoid(m_pSnapshotTree);
    933942    {
    934943        /* Configure tree: */
    935944        connect(m_pSnapshotTree, &UISnapshotTree::currentItemChanged,
    936                 this, &UISnapshotPane::sltCurrentItemChanged);
     945                this, &UISnapshotPane::sltHandleCurrentItemChange);
    937946        connect(m_pSnapshotTree, &UISnapshotTree::customContextMenuRequested,
    938                 this, &UISnapshotPane::sltContextMenuRequested);
     947                this, &UISnapshotPane::sltHandleContextMenuRequest);
    939948        connect(m_pSnapshotTree, &UISnapshotTree::itemChanged,
    940                 this, &UISnapshotPane::sltItemChanged);
     949                this, &UISnapshotPane::sltHandleItemChange);
    941950        connect(m_pSnapshotTree, &UISnapshotTree::itemDoubleClicked,
    942                 this, &UISnapshotPane::sltItemDoubleClicked);
     951                this, &UISnapshotPane::sltHandleItemDoubleClick);
    943952
    944953        /* Add into layout: */
     
    955964    if (m_comMachine.isNull())
    956965    {
    957         sltCurrentItemChanged();
     966        sltHandleCurrentItemChange();
    958967        return;
    959968    }
     
    9981007        m_pSnapshotTree->scrollToItem(pCurrentItem);
    9991008        m_pSnapshotTree->setCurrentItem(pCurrentItem);
    1000         sltCurrentItemChanged(pCurrentItem);
     1009        sltHandleCurrentItemChange();
    10011010    }
    10021011    /* If machine has no snapshots: */
     
    10131022        /* Choose current item: */
    10141023        m_pSnapshotTree->setCurrentItem(pCsi);
    1015         sltCurrentItemChanged(pCsi);
     1024        sltHandleCurrentItemChange();
    10161025    }
    10171026
     
    13251334    /* Show Snapshot Details dialog: */
    13261335    QPointer<VBoxSnapshotDetailsDlg> pDlg = new VBoxSnapshotDetailsDlg(this);
    1327     pDlg->setData(comSnapshot);
     1336    pDlg->setData(*pSnapshotItem, comSnapshot);
    13281337    if (pDlg->exec() == QDialog::Accepted)
    13291338        pDlg->saveData();
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h

    r67121 r67147  
    105105    /** @name Tree-widget handlers.
    106106      * @{ */
    107         /** Handles cursor change to @a pItem. */
    108         void sltCurrentItemChanged(QTreeWidgetItem *pItem = 0);
    109         /** Handles context menu request for @a point. */
    110         void sltContextMenuRequested(const QPoint &point);
    111         /** Handles modification for @a pItem. */
    112         void sltItemChanged(QTreeWidgetItem *pItem);
    113         /** Handles double-click for @a pItem. */
    114         void sltItemDoubleClicked(QTreeWidgetItem *pItem);
     107        /** Handles tree-widget current item change. */
     108        void sltHandleCurrentItemChange();
     109        /** Handles context menu request for tree-widget @a position. */
     110        void sltHandleContextMenuRequest(const QPoint &position);
     111        /** Handles tree-widget @a pItem change. */
     112        void sltHandleItemChange(QTreeWidgetItem *pItem);
     113        /** Handles tree-widget @a pItem double-click. */
     114        void sltHandleItemDoubleClick(QTreeWidgetItem *pItem);
    115115    /** @} */
    116116
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