aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--src/ui/widgets/FileTreeView.cpp21
-rw-r--r--src/ui/widgets/FileTreeView.h8
2 files changed, 24 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
diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h
index cd3b1cb8..b1cc8897 100644
--- a/src/ui/widgets/FileTreeView.h
+++ b/src/ui/widgets/FileTreeView.h
@@ -219,6 +219,12 @@ class FileTreeView : public QTreeView {
*/
void slot_create_popup_menu();
+ /**
+ * @brief
+ *
+ */
+ void slot_adjust_column_widths();
+
private:
QFileSystemModel* dir_model_; ///<
QString current_path_; ///<
@@ -233,5 +239,7 @@ class FileTreeView : public QTreeView {
QAction* action_create_empty_file_;
QAction* action_make_directory_;
QAction* action_compress_files_;
+
+ bool initial_resize_done_ = false;
};
} // namespace GpgFrontend::UI \ No newline at end of file