Changeset 76707 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jan 8, 2019 3:24:35 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UICustomFileSystemModel.cpp
r76690 r76707 98 98 } 99 99 100 void UICustomFileSystemItem::removeChild(UICustomFileSystemItem *pItem) 101 { 102 int iIndex = m_childItems.indexOf(pItem); 103 if (iIndex == -1 || iIndex > m_childItems.size()) 104 return; 105 m_childItems.removeAt(iIndex); 106 m_childMap.remove(pItem->name()); 107 delete pItem; 108 pItem = 0; 109 } 110 100 111 int UICustomFileSystemItem::columnCount() const 101 112 { … … 574 585 } 575 586 587 void UICustomFileSystemModel::deleteItem(UICustomFileSystemItem* pItem) 588 { 589 if (!pItem) 590 return; 591 UICustomFileSystemItem *pParent = pItem->parentItem(); 592 if (pParent) 593 pParent->removeChild(pItem); 594 } 595 576 596 void UICustomFileSystemModel::initializeTree() 577 597 { -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UICustomFileSystemModel.h
r76690 r76707 59 59 int childCount() const; 60 60 QList<const UICustomFileSystemItem*> children() const; 61 /** Removes the item from the list of children and !!DELETES!! the item. */ 62 void removeChild(UICustomFileSystemItem *pItem); 61 63 int columnCount() const; 62 64 QVariant data(int column) const; … … 188 190 void setShowHumanReadableSizes(bool fShowHumanReadableSizes); 189 191 bool showHumanReadableSizes() const; 192 void deleteItem(UICustomFileSystemItem* pItem); 190 193 UICustomFileSystemItem* rootItem(); 191 194 const UICustomFileSystemItem* rootItem() const; -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.cpp
r76690 r76707 137 137 pAddedItem->setIsSymLinkToADirectory(QFileInfo(fileInfo.symLinkTarget()).isDir()); 138 138 } 139 m_entryList <<createAnIsoEntry(pAddedItem);139 createAnIsoEntry(pAddedItem); 140 140 } 141 141 if (m_pTableProxyModel) … … 148 148 } 149 149 150 QString UIVisoContentBrowser::createAnIsoEntry(UICustomFileSystemItem *pItem) 151 { 152 QString strEntry; 150 void UIVisoContentBrowser::createAnIsoEntry(UICustomFileSystemItem *pItem, bool bRemove /* = false */) 151 { 153 152 if (!pItem) 154 return strEntry; 155 if (pItem->data(UICustomFileSystemModelColumn_Path).toString().isEmpty() || 156 pItem->data(UICustomFileSystemModelColumn_LocalPath).toString().isEmpty()) 157 return strEntry; 158 strEntry = QString("%1=%2").arg(pItem->data(UICustomFileSystemModelColumn_Path).toString()). 159 arg(pItem->data(UICustomFileSystemModelColumn_LocalPath).toString()); 160 return strEntry; 153 return; 154 if (pItem->data(UICustomFileSystemModelColumn_Path).toString().isEmpty()) 155 return; 156 157 if (!bRemove && pItem->data(UICustomFileSystemModelColumn_LocalPath).toString().isEmpty()) 158 return; 159 if (!bRemove) 160 m_entryMap.insert(pItem->data(UICustomFileSystemModelColumn_Path).toString(), 161 pItem->data(UICustomFileSystemModelColumn_LocalPath).toString()); 162 else 163 m_entryMap.insert(pItem->data(UICustomFileSystemModelColumn_Path).toString(), 164 ":remove:"); 161 165 } 162 166 163 167 QStringList UIVisoContentBrowser::entryList() 164 168 { 165 return m_entryList; 169 QStringList entryList; 170 for (QMap<QString, QString>::const_iterator iterator = m_entryMap.begin(); iterator != m_entryMap.end(); ++iterator) 171 { 172 QString strEntry = QString("%1=%2").arg(iterator.key()).arg(iterator.value()); 173 entryList << strEntry; 174 } 175 return entryList; 166 176 } 167 177 … … 234 244 } 235 245 236 237 246 UICustomFileSystemItem* pAddedItem = new UICustomFileSystemItem(strNewDirectoryName, pParentItem, 238 247 KFsObjType_Directory); … … 246 255 } 247 256 257 void UIVisoContentBrowser::sltHandleRemoveItems() 258 { 259 QVector<UICustomFileSystemItem*> selectedItems = tableSelectedItems(); 260 foreach(UICustomFileSystemItem *pItem, selectedItems) 261 { 262 if (!pItem) 263 continue; 264 /* If the item is a directory the remove the item from iso entry list: */ 265 if (pItem->type() == KFsObjType_Directory) 266 { 267 for (QMap<QString, QString>::iterator iterator = m_entryMap.begin(); iterator != m_entryMap.end(); ) 268 { 269 QString strIsoPath = pItem->data(UICustomFileSystemModelColumn_Path).toString(); 270 if (strIsoPath.isEmpty()) 271 continue; 272 if (iterator.key().startsWith(strIsoPath, Qt::CaseInsensitive)) 273 iterator = m_entryMap.erase(iterator); 274 else 275 ++iterator; 276 } 277 } 278 /* Else mark it as "removed" in the viso file entry list: */ 279 else 280 { 281 createAnIsoEntry(pItem, true /* bool bRemove */); 282 } 283 } 284 foreach(UICustomFileSystemItem *pItem, selectedItems) 285 { 286 if (!pItem) 287 continue; 288 /* Remove the item from the m_pModel: */ 289 if (m_pModel) 290 m_pModel->deleteItem(pItem); 291 if (m_pTreeProxyModel) 292 m_pTreeProxyModel->invalidate(); 293 if (m_pTableProxyModel) 294 m_pTableProxyModel->invalidate(); 295 } 296 } 297 248 298 void UIVisoContentBrowser::prepareObjects() 249 299 { … … 269 319 { 270 320 m_pTreeView->setModel(m_pTreeProxyModel); 271 // m_pTreeView->setRootIndex(m_pProxyModel->mapFromSource(m_pModel->rootIndex()));272 321 m_pTreeView->setCurrentIndex(m_pTreeProxyModel->mapFromSource(m_pModel->rootIndex())); 273 322 m_pTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers); 274 323 /* Show only the 0th column that is "name': */ 275 324 m_pTreeView->hideColumn(UICustomFileSystemModelColumn_Owner); … … 317 366 connect(m_pModel, &UICustomFileSystemModel::sigItemRenamed, 318 367 this, &UIVisoContentBrowser::sltHandleItemRenameAttempt); 368 if (m_pAddRemoveButton) 369 connect(m_pAddRemoveButton, &QIToolButton::clicked, 370 this, &UIVisoContentBrowser::sltHandleRemoveItems); 371 if (m_pTableView->selectionModel()) 372 connect(m_pTableView->selectionModel(), &QItemSelectionModel::selectionChanged, 373 this, &UIVisoContentBrowser::sltHandleTableSelectionChanged); 374 319 375 } 320 376 … … 553 609 } 554 610 611 void UIVisoContentBrowser::sltHandleTableSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) 612 { 613 Q_UNUSED(deselected); 614 if (m_pAddRemoveButton) 615 m_pAddRemoveButton->setEnabled(!selected.isEmpty()); 616 } 617 555 618 void UIVisoContentBrowser::reset() 556 619 { 557 m_entryList.clear(); 558 } 620 m_entryMap.clear(); 621 } 622 623 QVector<UICustomFileSystemItem*> UIVisoContentBrowser::tableSelectedItems() 624 { 625 QVector<UICustomFileSystemItem*> selectedItems; 626 if (!m_pTableProxyModel) 627 return selectedItems; 628 QItemSelectionModel *selectionModel = m_pTableView->selectionModel(); 629 if (!selectionModel || selectionModel->selectedIndexes().isEmpty()) 630 return selectedItems; 631 QModelIndexList list = selectionModel->selectedIndexes(); 632 foreach (QModelIndex index, list) 633 { 634 UICustomFileSystemItem *pItem = 635 static_cast<UICustomFileSystemItem*>(m_pTableProxyModel->mapToSource(index).internalPointer()); 636 if (pItem) 637 selectedItems << pItem; 638 } 639 return selectedItems; 640 } 641 559 642 #include "UIVisoContentBrowser.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.h
r76690 r76707 76 76 void sltHandleCreateNewDirectory(); 77 77 void sltHandleItemRenameAttempt(UICustomFileSystemItem *pItem, QString strOldName, QString strNewName); 78 78 void sltHandleRemoveItems(); 79 void sltHandleTableSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); 79 80 80 81 private: … … 90 91 void updateStartItemName(); 91 92 void renameFileObject(UICustomFileSystemItem *pItem); 92 QString createAnIsoEntry(UICustomFileSystemItem *pItem); 93 /** Creates and entry for pItem consisting of a map item (key is iso path and value is host file system path) 94 * if @p bRemove is true then the value is the string ":remove:" which effectively removes the file object 95 * from the iso image. */ 96 void createAnIsoEntry(UICustomFileSystemItem *pItem, bool bRemove = false); 93 97 void reset(); 94 98 /** Returns a list of items which are currecntly selected 99 * in the table view. */ 100 QVector<UICustomFileSystemItem*> tableSelectedItems(); 95 101 UICustomFileSystemModel *m_pModel; 96 102 UICustomFileSystemProxyModel *m_pTableProxyModel; 97 103 UIVisoContentTreeProxyModel *m_pTreeProxyModel; 98 104 QIToolButton *m_pNewDirectoryButton; 105 QIToolButton *m_pRenameButton; 99 106 QString m_strVisoName; 100 QStringList m_entryList; 107 /** keys of m_entryMap are iso locations and values are 108 * local location of file objects. these keys and values are 109 * concatenated and passed to the client to create ad-hoc.viso entries. */ 110 QMap<QString, QString> m_entryMap; 101 111 }; 102 112 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoHostBrowser.cpp
r76671 r76707 160 160 { 161 161 Q_UNUSED(deselected); 162 Q_UNUSED(selected);163 m_pAddRemoveButton->setEnabled(!selected.isEmpty());162 if (m_pAddRemoveButton) 163 m_pAddRemoveButton->setEnabled(!selected.isEmpty()); 164 164 } 165 165
Note:
See TracChangeset
for help on using the changeset viewer.