diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2016-12-08 22:26:50 +0100 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2016-12-09 23:45:42 +0100 |
commit | 7d2e0fce392413c7a4f4292ccc0dd5e5f45f496f (patch) | |
tree | 353080c6a7e3ab2b8bba9ff2d8c2b48a18a41c27 /src/library/browse | |
parent | e49571835af3278537630b1d09af94cb54c38e26 (diff) |
Improve and simplify the design/interface of TreeItem
Diffstat (limited to 'src/library/browse')
-rw-r--r-- | src/library/browse/browsefeature.cpp | 79 | ||||
-rw-r--r-- | src/library/browse/foldertreemodel.cpp | 10 |
2 files changed, 42 insertions, 47 deletions
diff --git a/src/library/browse/browsefeature.cpp b/src/library/browse/browsefeature.cpp index 9f6231b78c..617ecc4312 100644 --- a/src/library/browse/browsefeature.cpp +++ b/src/library/browse/browsefeature.cpp @@ -54,16 +54,15 @@ BrowseFeature::BrowseFeature(QObject* parent, m_proxyModel.setDynamicSortFilter(true); // The invisible root item of the child model - TreeItem* rootItem = new TreeItem(); + TreeItem* rootItem = new TreeItem(this); - m_pQuickLinkItem = new TreeItem(tr("Quick Links"), QUICK_LINK_NODE, this, rootItem); - rootItem->appendChild(m_pQuickLinkItem); + m_pQuickLinkItem = rootItem->appendChild( + new TreeItem(this, tr("Quick Links"), QUICK_LINK_NODE)); // Create the 'devices' shortcut #if defined(__WINDOWS__) - TreeItem* devices_link = new TreeItem( - tr("Devices"), DEVICE_NODE, this, rootItem); - rootItem->appendChild(devices_link); + TreeItem* devices_link = rootItem->appendChild( + new TreeItem(this, tr("Devices"), DEVICE_NODE)); // show drive letters QFileInfoList drives = QDir::drives(); // show drive letters @@ -81,28 +80,25 @@ BrowseFeature::BrowseFeature(QObject* parent, if (display_path.endsWith("/")) { display_path.chop(1); } - TreeItem* driveLetter = new TreeItem( - display_path, // Displays C: - drive.filePath(), // Displays C:/ - this , - devices_link); - devices_link->appendChild(driveLetter); + TreeItem* driveLetter = + devices_link->appendChild( + new TreeItem( + this , + display_path, // Displays C: + drive.filePath())); // Displays C:/ } #elif defined(__APPLE__) // Apple hides the base Linux file structure But all devices are mounted at // /Volumes - TreeItem* devices_link = new TreeItem( - tr("Devices"), "/Volumes/", this, rootItem); - rootItem->appendChild(devices_link); + TreeItem* devices_link = rootItem->appendChild( + new TreeItem(this, tr("Devices"), "/Volumes/")); #else // LINUX - TreeItem* devices_link = new TreeItem( - tr("Removable Devices"), "/media/", this, rootItem); - rootItem->appendChild(devices_link); + TreeItem* devices_link = rootItem->appendChild( + new TreeItem(this, tr("Removable Devices"), "/media/")); // show root directory on UNIX-based operating systems - TreeItem* root_folder_item = new TreeItem( - QDir::rootPath(), QDir::rootPath(), this, rootItem); - rootItem->appendChild(root_folder_item); + TreeItem* root_folder_item = rootItem->appendChild( + new TreeItem(this, QDir::rootPath(), QDir::rootPath())); #endif // Just a word about how the TreeItem objects are used for the BrowseFeature: @@ -122,8 +118,8 @@ BrowseFeature::BrowseFeature(QObject* parent, foreach (QString quickLinkPath, m_quickLinkList) { QString name = extractNameFromPath(quickLinkPath); qDebug() << "Appending Quick Link: " << name << "---" << quickLinkPath; - TreeItem *item = new TreeItem(name, quickLinkPath, this, m_pQuickLinkItem); - m_pQuickLinkItem->appendChild(item); + m_pQuickLinkItem->appendChild( + new TreeItem(this, name, quickLinkPath)); } // initialize the model @@ -142,10 +138,10 @@ void BrowseFeature::slotAddQuickLink() { return; } - QString spath = m_pLastRightClickedItem->dataPath().toString(); + QVariant vpath = m_pLastRightClickedItem->getData(); + QString spath = vpath.toString(); QString name = extractNameFromPath(spath); - TreeItem *item = new TreeItem(name, spath, this, m_pQuickLinkItem); - m_pQuickLinkItem->appendChild(item); + m_pQuickLinkItem->appendChild(new TreeItem(this, name, vpath)); m_quickLinkList.append(spath); saveQuickLinks(); } @@ -154,7 +150,7 @@ void BrowseFeature::slotAddToLibrary() { if (!m_pLastRightClickedItem) { return; } - QString spath = m_pLastRightClickedItem->dataPath().toString(); + QString spath = m_pLastRightClickedItem->getData().toString(); emit(requestAddDir(spath)); QMessageBox msgBox; @@ -188,7 +184,7 @@ void BrowseFeature::slotRemoveQuickLink() { return; } - QString spath = m_pLastRightClickedItem->dataPath().toString(); + QString spath = m_pLastRightClickedItem->getData().toString(); int index = m_quickLinkList.indexOf(spath); if (index == -1) { @@ -225,10 +221,10 @@ void BrowseFeature::activate() { // Single clicks will not populate sub folders void BrowseFeature::activateChild(const QModelIndex& index) { TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); - qDebug() << "BrowseFeature::activateChild " << item->data() << " " - << item->dataPath(); + qDebug() << "BrowseFeature::activateChild " << item->getLabel() << " " + << item->getData(); - QString path = item->dataPath().toString(); + QString path = item->getData().toString(); if (path == QUICK_LINK_NODE || path == DEVICE_NODE) { m_browseModel.setPath(MDir()); } else { @@ -258,14 +254,14 @@ void BrowseFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index return; } - QString path = item->dataPath().toString(); + QString path = item->getData().toString(); if (path == QUICK_LINK_NODE || path == DEVICE_NODE) { return; } QMenu menu(NULL); - if (item->parent()->dataPath().toString() == QUICK_LINK_NODE) { + if (item->parent()->getData().toString() == QUICK_LINK_NODE) { menu.addAction(m_pRemoveQuickLinkAction); menu.exec(globalPos); onLazyChildExpandation(index); @@ -292,10 +288,10 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) { return; } - qDebug() << "BrowseFeature::onLazyChildExpandation " << item->data() - << " " << item->dataPath(); + qDebug() << "BrowseFeature::onLazyChildExpandation " << item->getLabel() + << " " << item->getData(); - QString path = item->dataPath().toString(); + QString path = item->getData().toString(); // If the item is a build-in node, e.g., 'QuickLink' return if (path == QUICK_LINK_NODE) { @@ -303,7 +299,7 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) { } // Before we populate the subtree, we need to delete old subtrees - m_childModel.removeRows(0, item->childCount(), index); + m_childModel.removeRows(0, item->childRows(), index); // List of subfolders or drive letters QList<TreeItem*> folders; @@ -327,10 +323,9 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) { display_path.chop(1); } TreeItem* driveLetter = new TreeItem( - display_path, // Displays C: - drive.filePath(), // Displays C:/ this, - item); + display_path, // Displays C: + drive.filePath()); // Displays C:/ folders << driveLetter; } } else { @@ -352,9 +347,9 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) { // Once the items are added to the TreeItemModel, // the models takes ownership of them and ensures their deletion TreeItem* folder = new TreeItem( + this, one.fileName(), - one.absoluteFilePath() + "/", - this, item); + one.absoluteFilePath() + "/"); folders << folder; } } diff --git a/src/library/browse/foldertreemodel.cpp b/src/library/browse/foldertreemodel.cpp index 62b28afc41..3c51828f15 100644 --- a/src/library/browse/foldertreemodel.cpp +++ b/src/library/browse/foldertreemodel.cpp @@ -38,14 +38,14 @@ bool FolderTreeModel::hasChildren(const QModelIndex& parent) const { * However, for, buid-in items such as 'Quick Links' there exist * child items at init time */ - if(item->dataPath().toString() == QUICK_LINK_NODE) + if(item->getData().toString() == QUICK_LINK_NODE) return true; //Can only happen on Windows - if(item->dataPath().toString() == DEVICE_NODE) + if(item->getData().toString() == DEVICE_NODE) return true; - // In all other cases the dataPath() points to a folder - QString folder = item->dataPath().toString(); + // In all other cases the getData() points to a folder + QString folder = item->getData().toString(); return directoryHasChildren(folder); } @@ -63,7 +63,7 @@ bool FolderTreeModel::directoryHasChildren(const QString& path) const { * QDIR::EntryInfoList returns a full QFileInfolist * * - * QDir dir(item->dataPath().toString()); + * QDir dir(item->getData().toString()); * QFileInfoList all = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); * return (all.count() > 0); * |