Changeset 72086 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- May 3, 2018 12:17:54 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileModel.cpp
r71832 r72086 32 32 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 33 33 34 const char* UIGuestControlFileModel::strUpDirectoryString = ".."; 35 36 UIGuestControlFileProxyModel::UIGuestControlFileProxyModel(QObject *parent /* = 0 */) 37 :QSortFilterProxyModel(parent) 38 { 39 } 40 41 bool UIGuestControlFileProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const 42 { 43 QVariant leftData = sourceModel()->data(left); 44 QVariant rightData = sourceModel()->data(right); 45 46 if (leftData.canConvert(QMetaType::QString) && rightData.canConvert(QMetaType::QString)) 47 { 48 49 if (leftData == UIGuestControlFileModel::strUpDirectoryString) 50 return true && (sortOrder() == Qt::AscendingOrder); 51 else if (rightData == UIGuestControlFileModel::strUpDirectoryString) 52 return false && (sortOrder() == Qt::AscendingOrder); 53 } 54 55 return QSortFilterProxyModel::lessThan(left, right); 56 } 34 57 35 58 UIGuestControlFileModel::UIGuestControlFileModel(QObject *parent) -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileModel.h
r71639 r72086 21 21 /* Qt includes: */ 22 22 #include <QAbstractItemModel> 23 #include <QSortFilterProxyModel> 23 24 24 25 /* GUI includes: */ … … 29 30 class UIGuestControlFileTable; 30 31 32 /** A QSortFilterProxyModel extension used in file tables. Modifies some 33 * of the base class behavior like lessThan(..) */ 34 class UIGuestControlFileProxyModel : public QSortFilterProxyModel 35 { 36 37 Q_OBJECT; 38 39 public: 40 41 UIGuestControlFileProxyModel(QObject *parent = 0); 42 43 protected: 44 45 bool lessThan(const QModelIndex &left, const QModelIndex &right) const /* override */; 46 }; 47 31 48 /** UIGuestControlFileModel serves as the model for a file structure. 32 33 34 35 49 * it supports a tree level hierarchy which can be displayed with 50 * QTableView and/or QTreeView. Note the file structure data is not 51 * kept by the model but rather by the containing widget which also servers 52 * as the interface to functionality this model provides.*/ 36 53 class UIGuestControlFileModel : public QAbstractItemModel 37 54 { … … 61 78 void endReset(); 62 79 bool insertRows(int position, int rows, const QModelIndex &parent); 80 static const char* strUpDirectoryString; 63 81 64 82 private: … … 72 90 73 91 #endif /* !___UIGuestControlFileModel_h___ */ 74 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.cpp
r71861 r72086 29 29 # include <QGridLayout> 30 30 # include <QMenu> 31 # include <QSortFilterProxyModel> 31 32 # include <QTextEdit> 32 33 # include <QPushButton> … … 691 692 if (!isDirectory()) 692 693 return false; 693 if (data(0) == QString(".."))694 if (data(0) == UIGuestControlFileModel::strUpDirectoryString) 694 695 return true; 695 696 return false; … … 739 740 :QIWithRetranslateUI<QWidget>(pParent) 740 741 , m_pRootItem(0) 741 , m_pView(0)742 , m_pModel(0)743 742 , m_pLocationLabel(0) 744 743 , m_pCopy(0) … … 746 745 , m_pPaste(0) 747 746 , m_pPropertiesDialog(0) 747 , m_pModel(0) 748 , m_pView(0) 749 , m_pProxyModel(0) 748 750 , m_pMainLayout(0) 749 751 , m_pLocationComboBox(0) … … 827 829 return; 828 830 831 m_pProxyModel = new UIGuestControlFileProxyModel(this); 832 if (!m_pProxyModel) 833 return; 834 m_pProxyModel->setSourceModel(m_pModel); 829 835 830 836 m_pView = new UIGuestControlFileView; … … 832 838 { 833 839 m_pMainLayout->addWidget(m_pView, 2, 0, 5, 5); 834 m_pView->setModel(m_pModel); 840 m_pView->setModel(m_pProxyModel); 841 //m_pView->setModel(m_pModel); 835 842 m_pView->setItemDelegate(new UIFileDelegate); 843 m_pView->setSortingEnabled(true); 844 m_pView->sortByColumn(0, Qt::AscendingOrder); 836 845 837 846 connect(m_pView, &UIGuestControlFileView::doubleClicked, 838 847 this, &UIGuestControlFileTable::sltItemDoubleClicked); 839 840 848 connect(m_pView, &UIGuestControlFileView::sigGoUp, 841 849 this, &UIGuestControlFileTable::sltGoUp); … … 993 1001 if (!index.isValid() || !m_pView) 994 1002 return; 995 m_pView->setRootIndex( index);1003 m_pView->setRootIndex(m_pProxyModel->mapFromSource(index)); 996 1004 m_pView->clearSelection(); 997 1005 … … 1001 1009 updateCurrentLocationEdit(item->path()); 1002 1010 } 1003 m_pModel->signalUpdate(); 1011 /** @todo check if we really need this and if not remove it */ 1012 //m_pModel->signalUpdate(); 1004 1013 } 1005 1014 … … 1022 1031 startItem->setIsOpened(false); 1023 1032 populateStartDirectory(startItem); 1024 m_pView->setRootIndex(m_pModel->rootIndex()); 1033 1025 1034 m_pModel->signalUpdate(); 1026 1035 updateCurrentLocationEdit(startPath); 1036 m_pView->setRootIndex(m_pProxyModel->mapFromSource(m_pModel->rootIndex())); 1027 1037 } 1028 1038 … … 1050 1060 } 1051 1061 } 1052 1053 1062 } 1054 1063 … … 1058 1067 if (parent) 1059 1068 1060 /* Make sure we have a ".." item within directories, and make sure it is not there for the start dir: */1069 /* Make sure we have an item representing up directory, and make sure it is not there for the start dir: */ 1061 1070 if (isDirectoryMap) 1062 1071 { 1063 if (!map.contains( "..") && !isStartDir)1072 if (!map.contains(UIGuestControlFileModel::strUpDirectoryString) && !isStartDir) 1064 1073 { 1065 1074 QList<QVariant> data; 1066 data << ".."<< 4096 << "";1075 data << UIGuestControlFileModel::strUpDirectoryString << 4096 << ""; 1067 1076 UIFileTableItem *item = new UIFileTableItem(data, parent, FileObjectType_Directory); 1068 1077 item->setIsOpened(false); 1069 map.insert( "..", item);1078 map.insert(UIGuestControlFileModel::strUpDirectoryString, item); 1070 1079 } 1071 else if (map.contains( "..") && isStartDir)1080 else if (map.contains(UIGuestControlFileModel::strUpDirectoryString) && isStartDir) 1072 1081 { 1073 map.remove( "..");1082 map.remove(UIGuestControlFileModel::strUpDirectoryString); 1074 1083 } 1075 1084 } … … 1087 1096 if (!index.isValid() || !m_pModel || !m_pView) 1088 1097 return; 1089 goIntoDirectory(index); 1098 QModelIndex nIndex = m_pProxyModel ? m_pProxyModel->mapToSource(index) : index; 1099 goIntoDirectory(nIndex); 1090 1100 } 1091 1101 … … 1094 1104 if (!m_pView || !m_pModel) 1095 1105 return; 1096 QModelIndex currentRoot = m_pView->rootIndex(); 1106 QModelIndex currentRoot = currentRootIndex(); 1107 1097 1108 if (!currentRoot.isValid()) 1098 1109 return; … … 1190 1201 if (!m_pView || !m_pModel) 1191 1202 return; 1192 QModelIndex currentIndex = m_pView->rootIndex();1203 QModelIndex currentIndex = currentRootIndex(); 1193 1204 1194 1205 UIFileTableItem *treeItem = indexData(currentIndex); … … 1204 1215 readDirectory(treeItem->path(), treeItem, isRootDir); 1205 1216 m_pModel->endReset(); 1206 m_pView->setRootIndex( currentIndex);1217 m_pView->setRootIndex(m_pProxyModel->mapFromSource(currentIndex)); 1207 1218 } 1208 1219 … … 1218 1229 for(int i = 0; i < selectedItemIndices.size(); ++i) 1219 1230 { 1220 deleteByIndex(selectedItemIndices.at(i)); 1231 QModelIndex index = 1232 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i); 1233 deleteByIndex(index); 1221 1234 } 1222 1235 /** @todo dont refresh here, just delete the rows and update the table view: */ … … 1235 1248 if (selectedItemIndices.size() == 0) 1236 1249 return; 1237 UIFileTableItem *item = indexData(selectedItemIndices.at(0)); 1250 QModelIndex modelIndex = 1251 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(0)) : selectedItemIndices.at(0); 1252 UIFileTableItem *item = indexData(modelIndex); 1238 1253 if (!item || item->isUpDirectory()) 1239 1254 return; … … 1245 1260 if (!m_pModel || !m_pView) 1246 1261 return; 1247 QModelIndex currentIndex = m_pView->rootIndex();1262 QModelIndex currentIndex = currentRootIndex(); 1248 1263 if (!currentIndex.isValid()) 1249 1264 return; … … 1334 1349 if (!pSelectionModel) 1335 1350 return; 1336 QModelIndex currentRoot = m_pView->rootIndex();1351 QModelIndex currentRoot = currentRootIndex(); 1337 1352 if (!currentRoot.isValid()) 1338 1353 return; … … 1348 1363 if (item && item->isUpDirectory()) 1349 1364 { 1350 pSelectionModel->select(index, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); 1365 QModelIndex indexToDeselect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index; 1366 pSelectionModel->select(indexToDeselect, QItemSelectionModel::Deselect | QItemSelectionModel::Rows); 1351 1367 } 1352 1368 } … … 1360 1376 if (!pSelectionModel) 1361 1377 return; 1362 QModelIndex currentRoot = m_pView->rootIndex();1378 QModelIndex currentRoot = currentRootIndex(); 1363 1379 if (!currentRoot.isValid()) 1364 1380 return; … … 1369 1385 if (!index.isValid()) 1370 1386 continue; 1371 pSelectionModel->select(index, flags); 1387 QModelIndex indexToSelect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index; 1388 pSelectionModel->select(indexToSelect, flags); 1372 1389 } 1373 1390 } … … 1548 1565 for(int i = 0; i < selectedItemIndices.size(); ++i) 1549 1566 { 1550 UIFileTableItem *item = static_cast<UIFileTableItem*>(selectedItemIndices.at(i).internalPointer()); 1567 QModelIndex index = 1568 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i); 1569 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer()); 1551 1570 if (!item) 1552 1571 continue; … … 1585 1604 } 1586 1605 1587 /* static */QString UIGuestControlFileTable::fileTypeString(FileObjectType type)1606 QString UIGuestControlFileTable::fileTypeString(FileObjectType type) 1588 1607 { 1589 1608 QString strType("Unknown"); … … 1635 1654 } 1636 1655 1656 QModelIndex UIGuestControlFileTable::currentRootIndex() const 1657 { 1658 if (!m_pView) 1659 return QModelIndex(); 1660 if (!m_pProxyModel) 1661 return m_pView->rootIndex(); 1662 return m_pProxyModel->mapToSource(m_pView->rootIndex()); 1663 } 1664 1637 1665 #include "UIGuestControlFileTable.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestControlFileTable.h
r71852 r72086 42 42 class QILineEdit; 43 43 class QGridLayout; 44 class QSortFilterProxyModel; 44 45 class QTextEdit; 45 46 class QVBoxLayout; 46 47 class UIFileTableItem; 47 48 class UIGuestControlFileModel; 49 class UIGuestControlFileProxyModel; 48 50 class UIGuestControlFileView; 49 51 class UIToolBar; … … 265 267 void retranslateUi(); 266 268 void updateCurrentLocationEdit(const QString& strLocation); 269 /* @p index is for model not for 'proxy' model */ 267 270 void changeLocation(const QModelIndex &index); 268 271 void initializeFileTree(); … … 279 282 * drive letters */ 280 283 virtual void determineDriveLetters() = 0; 281 static QString fileTypeString(FileObjectType type); 284 QString fileTypeString(FileObjectType type); 285 /* @p item index is item location in model not in 'proxy' model */ 282 286 void goIntoDirectory(const QModelIndex &itemIndex); 283 287 /** Follows the path trail, opens directories as it descends */ … … 290 294 291 295 UIFileTableItem *m_pRootItem; 292 UIGuestControlFileView *m_pView;293 UIGuestControlFileModel *m_pModel;294 296 QILabel *m_pLocationLabel; 295 297 QAction *m_pCopy; … … 306 308 307 309 private slots: 308 310 /* index is passed by the item view and represents the double clicked object's 'proxy' model index */ 309 311 void sltItemDoubleClicked(const QModelIndex &index); 310 312 void sltGoUp(); … … 327 329 void prepareObjects(); 328 330 void prepareActions(); 331 /* @itemIndex is assumed to be 'model' index not 'proxy model' index */ 329 332 void deleteByIndex(const QModelIndex &itemIndex); 330 333 /** Returns the UIFileTableItem for path / which is a direct (and single) child of m_pRootItem */ … … 339 342 * drive letter are direct children of the start directory. On other systems start directory is '/' */ 340 343 void populateStartDirectory(UIFileTableItem *startItem); 344 QModelIndex currentRootIndex() const; 345 UIGuestControlFileModel *m_pModel; 346 UIGuestControlFileView *m_pView; 347 UIGuestControlFileProxyModel *m_pProxyModel; 348 341 349 QGridLayout *m_pMainLayout; 342 350 QComboBox *m_pLocationComboBox; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.cpp
r71861 r72086 402 402 } 403 403 404 /* static */FileObjectType UIGuestFileTable::fileType(const CFsObjInfo &fsInfo)404 FileObjectType UIGuestFileTable::fileType(const CFsObjInfo &fsInfo) 405 405 { 406 406 if (fsInfo.isNull() || !fsInfo.isOk()) … … 416 416 } 417 417 418 /* static */FileObjectType UIGuestFileTable::fileType(const CGuestFsObjInfo &fsInfo)418 FileObjectType UIGuestFileTable::fileType(const CGuestFsObjInfo &fsInfo) 419 419 { 420 420 if (fsInfo.isNull() || !fsInfo.isOk()) -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIGuestFileTable.h
r71861 r72086 41 41 protected: 42 42 43 void retranslateUi() /* override */;44 virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;45 virtual void deleteByItem(UIFileTableItem *item) /* override */;46 virtual void goToHomeDirectory() /* override */;47 virtual bool renameItem(UIFileTableItem *item, QString newBaseName);48 virtual bool createDirectory(const QString &path, const QString &directoryName);43 void retranslateUi() /* override */; 44 virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */; 45 virtual void deleteByItem(UIFileTableItem *item) /* override */; 46 virtual void goToHomeDirectory() /* override */; 47 virtual bool renameItem(UIFileTableItem *item, QString newBaseName); 48 virtual bool createDirectory(const QString &path, const QString &directoryName); 49 49 virtual QString fsObjectPropertyString() /* override */; 50 virtual void showProperties() /* override */;51 virtual void determineDriveLetters() /* override */;50 virtual void showProperties() /* override */; 51 virtual void determineDriveLetters() /* override */; 52 52 53 53 private: 54 54 55 static FileObjectTypefileType(const CFsObjInfo &fsInfo);56 static FileObjectTypefileType(const CGuestFsObjInfo &fsInfo);55 FileObjectType fileType(const CFsObjInfo &fsInfo); 56 FileObjectType fileType(const CGuestFsObjInfo &fsInfo); 57 57 58 58 bool copyGuestToHost(const QString &guestSourcePath, const QString& hostDestinationPath); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.cpp
r71861 r72086 27 27 /* GUI includes: */ 28 28 # include "QILabel.h" 29 # include "UIGuestControlFileModel.h" 29 30 # include "UIHostFileTable.h" 30 31 # include "UIVMInformationDialog.h" … … 100 101 { 101 102 const QFileInfo &entryInfo = entryList.at(i); 102 if (entryInfo.baseName().isEmpty() || entryInfo.baseName() == "." || entryInfo.baseName() == "..") 103 if (entryInfo.baseName().isEmpty() || entryInfo.baseName() == "." || 104 entryInfo.baseName() == UIGuestControlFileModel::strUpDirectoryString) 103 105 continue; 104 106 statistics.m_totalSize += entryInfo.size(); … … 164 166 for (int i = 0; i < entries.size(); ++i) 165 167 { 168 166 169 const QFileInfo &fileInfo = entries.at(i); 167 170 QList<QVariant> data; … … 256 259 } 257 260 258 /* static */FileObjectType UIHostFileTable::fileType(const QFileInfo &fsInfo)261 FileObjectType UIHostFileTable::fileType(const QFileInfo &fsInfo) 259 262 { 260 263 if (!fsInfo.exists()) -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/guestctrl/UIHostFileTable.h
r71861 r72086 34 34 protected: 35 35 36 static FileObjectTypefileType(const QFileInfo &fsInfo);37 void retranslateUi() /* override */;38 virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */;39 virtual void deleteByItem(UIFileTableItem *item) /* override */;40 virtual void goToHomeDirectory() /* override */;41 virtual bool renameItem(UIFileTableItem *item, QString newBaseName);42 virtual bool createDirectory(const QString &path, const QString &directoryName);36 FileObjectType fileType(const QFileInfo &fsInfo); 37 void retranslateUi() /* override */; 38 virtual void readDirectory(const QString& strPath, UIFileTableItem *parent, bool isStartDir = false) /* override */; 39 virtual void deleteByItem(UIFileTableItem *item) /* override */; 40 virtual void goToHomeDirectory() /* override */; 41 virtual bool renameItem(UIFileTableItem *item, QString newBaseName); 42 virtual bool createDirectory(const QString &path, const QString &directoryName); 43 43 virtual QString fsObjectPropertyString() /* override */; 44 virtual void showProperties() /* override */;45 virtual void determineDriveLetters() /* override */;44 virtual void showProperties() /* override */; 45 virtual void determineDriveLetters() /* override */; 46 46 47 47 private:
Note:
See TracChangeset
for help on using the changeset viewer.