aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/widgets/FileTreeView.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-04-15 14:21:26 +0000
committersaturneric <[email protected]>2024-04-15 14:21:26 +0000
commitc59deb6f6c05497f668f384bfe7c1d07c6ace5fc (patch)
tree7af2fcf2571e627d2363eda9e5f320c9f3236e38 /src/ui/widgets/FileTreeView.cpp
parentfeat: prefer to show module name instead of module id (diff)
downloadGpgFrontend-c59deb6f6c05497f668f384bfe7c1d07c6ace5fc.tar.gz
GpgFrontend-c59deb6f6c05497f668f384bfe7c1d07c6ace5fc.zip
fix: high cpu usage when using file tab
Diffstat (limited to 'src/ui/widgets/FileTreeView.cpp')
-rw-r--r--src/ui/widgets/FileTreeView.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp
index 7a725e10..de22ec83 100644
--- a/src/ui/widgets/FileTreeView.cpp
+++ b/src/ui/widgets/FileTreeView.cpp
@@ -54,6 +54,10 @@ FileTreeView::FileTreeView(QWidget* parent, const QString& target_path)
&FileTreeView::slot_show_custom_context_menu);
connect(this, &QTreeView::doubleClicked, this,
&FileTreeView::slot_file_tree_view_item_double_clicked);
+ connect(dir_model_, &QFileSystemModel::layoutChanged, this,
+ &FileTreeView::slot_adjust_column_widths);
+ connect(dir_model_, &QFileSystemModel::dataChanged, this,
+ &FileTreeView::slot_adjust_column_widths);
}
void FileTreeView::selectionChanged(const QItemSelection& selected,
@@ -82,9 +86,7 @@ void FileTreeView::SlotGoPath(const QString& target_path) {
GF_UI_LOG_DEBUG("file tree view set target path: {}", current_path_);
this->setRootIndex(dir_model_->index(file_info.filePath()));
dir_model_->setRootPath(file_info.filePath());
- for (int i = 1; i < dir_model_->columnCount(); ++i) {
- this->resizeColumnToContents(i);
- }
+ slot_adjust_column_widths();
} else {
QMessageBox::critical(
this, tr("Error"),
@@ -413,12 +415,21 @@ void FileTreeView::slot_compress_files() {}
void FileTreeView::paintEvent(QPaintEvent* event) {
QTreeView::paintEvent(event);
- for (int i = 1; i < dir_model_->columnCount(); ++i) {
- this->resizeColumnToContents(i);
+
+ if (!initial_resize_done_) {
+ slot_adjust_column_widths();
+ initial_resize_done_ = true;
}
}
void FileTreeView::mousePressEvent(QMouseEvent* event) {
QTreeView::mousePressEvent(event);
}
+
+void FileTreeView::slot_adjust_column_widths() {
+ for (int i = 1; i < dir_model_->columnCount(); ++i) {
+ this->resizeColumnToContents(i);
+ }
+}
+
} // namespace GpgFrontend::UI