VirtualBox

Ignore:
Timestamp:
Mar 13, 2014 2:45:41 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Medium Manager rework/cleanup: More abstract usage of tree-widgets which in theory can be reordered.

File:
1 edited

Legend:

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

    r50768 r50769  
    862862void UIMediumManager::sltHandleDoubleClick()
    863863{
    864     /* Call for modify-action if hard-drive medium-item double-clicked: */
    865     if (currentMediumType() == UIMediumType_HardDisk)
    866         sltModifyMedium();
     864    /* Skip for non-hard-drives: */
     865    if (currentMediumType() != UIMediumType_HardDisk)
     866        return;
     867
     868    /* Call for modify-action: */
     869    sltModifyMedium();
    867870}
    868871
     
    886889{
    887890    /* Get all the tree-widgets: */
    888     QList<QITreeWidget*> trees;
    889     trees << mTwHD;
    890     trees << mTwCD;
    891     trees << mTwFD;
     891    QList<QTreeWidget*> trees;
     892    trees << treeWidget(UIMediumType_HardDisk);
     893    trees << treeWidget(UIMediumType_DVD);
     894    trees << treeWidget(UIMediumType_Floppy);
    892895
    893896    /* Calculate deduction for every header: */
     
    11471150    {
    11481151        /* Configure HD tree-widget: */
    1149         mTwHD->setColumnCount(3);
    1150         mTwHD->sortItems(0, Qt::AscendingOrder);
    1151         mTwHD->header()->setResizeMode(0, QHeaderView::Fixed);
    1152         mTwHD->header()->setResizeMode(1, QHeaderView::ResizeToContents);
    1153         mTwHD->header()->setResizeMode(2, QHeaderView::ResizeToContents);
    1154         mTwHD->header()->setStretchLastSection(false);
    1155         mTwHD->setSortingEnabled(true);
    1156         connect(mTwHD, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
     1152        QTreeWidget *pTreeWidget = treeWidget(UIMediumType_HardDisk);
     1153        pTreeWidget->setColumnCount(3);
     1154        pTreeWidget->sortItems(0, Qt::AscendingOrder);
     1155        pTreeWidget->header()->setResizeMode(0, QHeaderView::Fixed);
     1156        pTreeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents);
     1157        pTreeWidget->header()->setResizeMode(2, QHeaderView::ResizeToContents);
     1158        pTreeWidget->header()->setStretchLastSection(false);
     1159        pTreeWidget->setSortingEnabled(true);
     1160        connect(pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    11571161                this, SLOT(sltHandleCurrentItemChanged()));
    1158         connect(mTwHD, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
     1162        connect(pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    11591163                this, SLOT(sltHandleDoubleClick()));
    1160         connect(mTwHD, SIGNAL(customContextMenuRequested(const QPoint&)),
     1164        connect(pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint&)),
    11611165                this, SLOT(sltHandleContextMenuCall(const QPoint&)));
    1162         connect(mTwHD, SIGNAL(resized(const QSize&, const QSize&)),
     1166        connect(pTreeWidget, SIGNAL(resized(const QSize&, const QSize&)),
    11631167                this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    1164         connect(mTwHD->header(), SIGNAL(sectionResized(int, int, int)),
     1168        connect(pTreeWidget->header(), SIGNAL(sectionResized(int, int, int)),
    11651169                this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    11661170    }
     
    11721176    {
    11731177        /* Configure CD tree-widget: */
    1174         mTwCD->setColumnCount(2);
    1175         mTwCD->sortItems(0, Qt::AscendingOrder);
    1176         mTwCD->header()->setResizeMode(0, QHeaderView::Fixed);
    1177         mTwCD->header()->setResizeMode(1, QHeaderView::ResizeToContents);
    1178         mTwCD->header()->setStretchLastSection(false);
    1179         mTwCD->setSortingEnabled(true);
    1180         connect(mTwCD, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
     1178        QTreeWidget *pTreeWidget = treeWidget(UIMediumType_DVD);
     1179        pTreeWidget->setColumnCount(2);
     1180        pTreeWidget->sortItems(0, Qt::AscendingOrder);
     1181        pTreeWidget->header()->setResizeMode(0, QHeaderView::Fixed);
     1182        pTreeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents);
     1183        pTreeWidget->header()->setStretchLastSection(false);
     1184        pTreeWidget->setSortingEnabled(true);
     1185        connect(pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    11811186                this, SLOT(sltHandleCurrentItemChanged()));
    1182         connect(mTwCD, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
     1187        connect(pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    11831188                this, SLOT(sltHandleDoubleClick()));
    1184         connect(mTwCD, SIGNAL(customContextMenuRequested(const QPoint&)),
     1189        connect(pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint&)),
    11851190                this, SLOT(sltHandleContextMenuCall(const QPoint&)));
    1186         connect(mTwCD, SIGNAL(resized(const QSize&, const QSize&)),
     1191        connect(pTreeWidget, SIGNAL(resized(const QSize&, const QSize&)),
    11871192                this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    1188         connect(mTwCD->header(), SIGNAL(sectionResized(int, int, int)),
     1193        connect(pTreeWidget->header(), SIGNAL(sectionResized(int, int, int)),
    11891194                this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    11901195    }
     
    11961201    {
    11971202        /* Configure FD tree-widget: */
    1198         mTwFD->setColumnCount(2);
    1199         mTwFD->sortItems(0, Qt::AscendingOrder);
    1200         mTwFD->header()->setResizeMode(0, QHeaderView::Fixed);
    1201         mTwFD->header()->setResizeMode(1, QHeaderView::ResizeToContents);
    1202         mTwFD->header()->setStretchLastSection(false);
    1203         mTwFD->setSortingEnabled(true);
    1204         connect(mTwFD, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
     1203        QTreeWidget *pTreeWidget = treeWidget(UIMediumType_Floppy);
     1204        pTreeWidget->setColumnCount(2);
     1205        pTreeWidget->sortItems(0, Qt::AscendingOrder);
     1206        pTreeWidget->header()->setResizeMode(0, QHeaderView::Fixed);
     1207        pTreeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents);
     1208        pTreeWidget->header()->setStretchLastSection(false);
     1209        pTreeWidget->setSortingEnabled(true);
     1210        connect(pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    12051211                this, SLOT(sltHandleCurrentItemChanged()));
    1206         connect(mTwFD, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
     1212        connect(pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    12071213                this, SLOT(sltHandleDoubleClick()));
    1208         connect(mTwFD, SIGNAL(customContextMenuRequested(const QPoint&)),
     1214        connect(pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint&)),
    12091215                this, SLOT(sltHandleContextMenuCall(const QPoint&)));
    1210         connect(mTwFD, SIGNAL(resized(const QSize&, const QSize&)),
     1216        connect(pTreeWidget, SIGNAL(resized(const QSize&, const QSize&)),
    12111217                this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    1212         connect(mTwFD->header(), SIGNAL(sectionResized(int, int, int)),
     1218        connect(pTreeWidget->header(), SIGNAL(sectionResized(int, int, int)),
    12131219                this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    12141220    }
     
    16021608    setWindowTitle(QApplication::translate("VBoxMediaManagerDlg", "Virtual Media Manager"));
    16031609    mTabWidget->setTabText(0, tr("&Hard drives"));
    1604     mTwHD->headerItem()->setText(0, QApplication::translate("VBoxMediaManagerDlg", "Name"));
    1605     mTwHD->headerItem()->setText(1, QApplication::translate("VBoxMediaManagerDlg", "Virtual Size"));
    1606     mTwHD->headerItem()->setText(2, QApplication::translate("VBoxMediaManagerDlg", "Actual Size"));
     1610    QTreeWidget *pTreeWidgetHD = treeWidget(UIMediumType_HardDisk);
     1611    pTreeWidgetHD->headerItem()->setText(0, QApplication::translate("VBoxMediaManagerDlg", "Name"));
     1612    pTreeWidgetHD->headerItem()->setText(1, QApplication::translate("VBoxMediaManagerDlg", "Virtual Size"));
     1613    pTreeWidgetHD->headerItem()->setText(2, QApplication::translate("VBoxMediaManagerDlg", "Actual Size"));
    16071614    m_pTypeLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Type:"));
    16081615    m_pLocationLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
     
    16111618    m_pUsageLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
    16121619    mTabWidget->setTabText(1, tr("&Optical disks"));
    1613     mTwCD->headerItem()->setText(0, QApplication::translate("VBoxMediaManagerDlg", "Name"));
    1614     mTwCD->headerItem()->setText(1, QApplication::translate("VBoxMediaManagerDlg", "Size"));
     1620    QTreeWidget *pTreeWidgetCD = treeWidget(UIMediumType_DVD);
     1621    pTreeWidgetCD->headerItem()->setText(0, QApplication::translate("VBoxMediaManagerDlg", "Name"));
     1622    pTreeWidgetCD->headerItem()->setText(1, QApplication::translate("VBoxMediaManagerDlg", "Size"));
    16151623    mLbCD1->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
    16161624    mLbCD2->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
    16171625    mTabWidget->setTabText(2, tr("&Floppy disks"));
    1618     mTwFD->headerItem()->setText(0, QApplication::translate("VBoxMediaManagerDlg", "Name"));
    1619     mTwFD->headerItem()->setText(1, QApplication::translate("VBoxMediaManagerDlg", "Size"));
     1626    QTreeWidget *pTreeWidgetFD = treeWidget(UIMediumType_Floppy);
     1627    pTreeWidgetFD->headerItem()->setText(0, QApplication::translate("VBoxMediaManagerDlg", "Name"));
     1628    pTreeWidgetFD->headerItem()->setText(1, QApplication::translate("VBoxMediaManagerDlg", "Size"));
    16201629    mLbFD1->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
    16211630    mLbFD2->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
     
    16351644
    16361645    /* Full refresh if there is at least one item present: */
    1637     if (mTwHD->topLevelItemCount() || mTwCD->topLevelItemCount() || mTwFD->topLevelItemCount())
     1646    if (pTreeWidgetHD->topLevelItemCount() || pTreeWidgetCD->topLevelItemCount() || pTreeWidgetFD->topLevelItemCount())
    16381647        sltRefreshAll();
    16391648}
     
    16551664            if (pMediumItem->id() == m_strCurrentIdHD)
    16561665            {
    1657                 setCurrentItem(mTwHD, pMediumItem);
     1666                setCurrentItem(treeWidget(UIMediumType_HardDisk), pMediumItem);
    16581667                m_strCurrentIdHD = QString();
    16591668            }
     
    16631672        case UIMediumType_DVD:
    16641673        {
    1665             pMediumItem = new UIMediumItemCD(medium, mTwCD);
     1674            pMediumItem = new UIMediumItemCD(medium, treeWidget(UIMediumType_DVD));
    16661675            LogRel2(("UIMediumManager: Optical medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
    16671676            AssertPtrReturn(pMediumItem, 0);
    16681677            if (pMediumItem->id() == m_strCurrentIdCD)
    16691678            {
    1670                 setCurrentItem(mTwCD, pMediumItem);
     1679                setCurrentItem(treeWidget(UIMediumType_DVD), pMediumItem);
    16711680                m_strCurrentIdCD = QString();
    16721681            }
     
    16761685        case UIMediumType_Floppy:
    16771686        {
    1678             pMediumItem = new UIMediumItemFD(medium, mTwFD);
     1687            pMediumItem = new UIMediumItemFD(medium, treeWidget(UIMediumType_Floppy));
    16791688            LogRel2(("UIMediumManager: Floppy medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
    16801689            AssertPtrReturn(pMediumItem, 0);
    16811690            if (pMediumItem->id() == m_strCurrentIdFD)
    16821691            {
    1683                 setCurrentItem(mTwFD, pMediumItem);
     1692                setCurrentItem(treeWidget(UIMediumType_Floppy), pMediumItem);
    16841693                m_strCurrentIdFD = QString();
    16851694            }
     
    17061715    AssertReturn(!medium.medium().isNull(), 0);
    17071716
     1717    /* Get corresponding tree-widget: */
     1718    QTreeWidget *pTreeWidget = treeWidget(UIMediumType_HardDisk);
     1719
    17081720    /* Search for existing medium-item: */
    1709     UIMediumItem *pMediumItem = searchItem(mTwHD, CheckIfSuitableByID(medium.id()));
     1721    UIMediumItem *pMediumItem = searchItem(pTreeWidget, CheckIfSuitableByID(medium.id()));
    17101722
    17111723    /* If medium-item do not exists: */
     
    17161728        {
    17171729            /* Try to find parent medium-item: */
    1718             UIMediumItem *pParentMediumItem = searchItem(mTwHD, CheckIfSuitableByID(medium.parentID()));
     1730            UIMediumItem *pParentMediumItem = searchItem(pTreeWidget, CheckIfSuitableByID(medium.parentID()));
    17191731            /* If parent medium-item was not found: */
    17201732            if (!pParentMediumItem)
     
    17381750        if (!pMediumItem)
    17391751        {
    1740             pMediumItem = new UIMediumItemHD(medium, mTwHD);
     1752            pMediumItem = new UIMediumItemHD(medium, pTreeWidget);
    17411753            LogRel2(("UIMediumManager: Root hard-drive medium-item with ID={%s} created.\n", medium.id().toAscii().constData()));
    17421754        }
     
    18061818{
    18071819    /* Hard-drive tree-widget: */
    1808     if (pTreeWidget == mTwHD) return UIMediumType_HardDisk;
     1820    if (pTreeWidget == treeWidget(UIMediumType_HardDisk)) return UIMediumType_HardDisk;
    18091821    /* Optical-image tree-widget: */
    1810     if (pTreeWidget == mTwCD) return UIMediumType_DVD;
     1822    if (pTreeWidget == treeWidget(UIMediumType_DVD)) return UIMediumType_DVD;
    18111823    /* Floppy-image tree-widget: */
    1812     if (pTreeWidget == mTwFD) return UIMediumType_Floppy;
     1824    if (pTreeWidget == treeWidget(UIMediumType_Floppy)) return UIMediumType_Floppy;
    18131825    /* Invalid by default: */
    18141826    AssertFailedReturn(UIMediumType_Invalid);
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