From 2b2be635be7c58dfe55c2e23629d94c450f87ce5 Mon Sep 17 00:00:00 2001 From: Violet Giraffe Date: Fri, 13 Sep 2024 17:23:38 +0300 Subject: [PATCH] Unnecessary code removed (performance and memory use optimization) --- .../src/iconprovider/ciconproviderimpl.cpp | 2 +- qt-app/src/panel/cpanelwidget.cpp | 25 ++++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/file-commander-core/src/iconprovider/ciconproviderimpl.cpp b/file-commander-core/src/iconprovider/ciconproviderimpl.cpp index a1fdfa02..d5cbb8af 100644 --- a/file-commander-core/src/iconprovider/ciconproviderimpl.cpp +++ b/file-commander-core/src/iconprovider/ciconproviderimpl.cpp @@ -49,7 +49,7 @@ QIcon CIconProviderImpl::iconFor(const CFileSystemObject& object, const bool gue if (!guessIconByFileExtension) { WCHAR pathStringBuffer[32768]; - // TODO: create a helper function for this in cpputils + // This function does not accept UNC paths! const auto length = object.fullAbsolutePath().toWCharArray(pathStringBuffer); pathStringBuffer[length] = 0; diff --git a/qt-app/src/panel/cpanelwidget.cpp b/qt-app/src/panel/cpanelwidget.cpp index 692d6360..cff84bab 100644 --- a/qt-app/src/panel/cpanelwidget.cpp +++ b/qt-app/src/panel/cpanelwidget.cpp @@ -186,15 +186,6 @@ void CPanelWidget::fillFromList(const FileListHashMap& items, FileListRefreshCau int itemRow = 0; - struct TreeViewItem { - const int row; - const FileListViewColumn column; - QStandardItem* const item; - }; - - std::vector qTreeViewItems; - qTreeViewItems.reserve(items.size() * NumberOfColumns); - const bool useLessPreciseIcons = items.size() > 500; for (const auto& item: items) { @@ -202,6 +193,7 @@ void CPanelWidget::fillFromList(const FileListHashMap& items, FileListRefreshCau const auto& props = object.properties(); auto* fileNameItem = new QStandardItem(); + fileNameItem->setEditable(false); if (props.type == Directory) fileNameItem->setData(QString("[" % (object.isCdUp() ? QLatin1String("..") : props.fullName) % "]"), Qt::DisplayRole); @@ -209,16 +201,18 @@ void CPanelWidget::fillFromList(const FileListHashMap& items, FileListRefreshCau fileNameItem->setData(QString('.') + props.extension, Qt::DisplayRole); else fileNameItem->setData(props.completeBaseName, Qt::DisplayRole); - fileNameItem->setIcon(CIconProvider::iconForFilesystemObject(object, useLessPreciseIcons)); + + const bool isExeFile = false;//props.type == File && props.extension.compare("exe", Qt::CaseInsensitive) == 0; + fileNameItem->setIcon(CIconProvider::iconForFilesystemObject(object, useLessPreciseIcons && !isExeFile)); fileNameItem->setData(static_cast(props.hash), Qt::UserRole); // Unique identifier for this object - qTreeViewItems.emplace_back(TreeViewItem{ itemRow, NameColumn, fileNameItem }); + _model->setItem(itemRow, NameColumn, fileNameItem); auto* fileExtItem = new QStandardItem(); fileExtItem->setEditable(false); if (!object.isCdUp() && !props.completeBaseName.isEmpty() && !props.extension.isEmpty()) fileExtItem->setData(props.extension, Qt::DisplayRole); fileExtItem->setData(static_cast(props.hash), Qt::UserRole); // Unique identifier for this object - qTreeViewItems.emplace_back(TreeViewItem{ itemRow, ExtColumn, fileExtItem }); + _model->setItem(itemRow, ExtColumn, fileExtItem); auto* sizeItem = new QStandardItem(); sizeItem->setEditable(false); @@ -226,7 +220,7 @@ void CPanelWidget::fillFromList(const FileListHashMap& items, FileListRefreshCau sizeItem->setData(fileSizeToString(props.size), Qt::DisplayRole); sizeItem->setData(static_cast(props.hash), Qt::UserRole); // Unique identifier for this object - qTreeViewItems.emplace_back(TreeViewItem{ itemRow, SizeColumn, sizeItem }); + _model->setItem(itemRow, SizeColumn, sizeItem); auto* dateItem = new QStandardItem(); dateItem->setEditable(false); @@ -236,14 +230,11 @@ void CPanelWidget::fillFromList(const FileListHashMap& items, FileListRefreshCau dateItem->setData(modificationDate.toString(QSL("dd.MM.yyyy hh:mm:ss")), Qt::DisplayRole); } dateItem->setData(static_cast(props.hash), Qt::UserRole); // Unique identifier for this object - qTreeViewItems.emplace_back(TreeViewItem{ itemRow, DateColumn, dateItem }); + _model->setItem(itemRow, DateColumn, dateItem); ++itemRow; } - for (const auto& qTreeViewItem: qTreeViewItems) - _model->setItem(qTreeViewItem.row, qTreeViewItem.column, qTreeViewItem.item); - _sortModel->setSourceModel(_model); ui->_list->restoreHeaderState();