From 83371d7881fefcf06ad6bd8f474286462bb16700 Mon Sep 17 00:00:00 2001 From: joern274 Date: Mon, 20 Nov 2023 18:47:37 +0100 Subject: [PATCH] Added button to expand or collapse all tree items --- CHANGELOG.md | 1 + .../gui/module_widget/module_tree_view.h | 13 ++ .../include/gui/module_widget/module_widget.h | 50 ++++--- plugins/gui/resources/gui_resources.qrc | 2 + .../gui/resources/icons/tree-collapsed.svg | 67 +++++++++ plugins/gui/resources/icons/tree-expanded.svg | 90 ++++++++++++ plugins/gui/resources/stylesheet/dark.qss | 19 ++- plugins/gui/resources/stylesheet/light.qss | 19 ++- .../src/module_widget/module_tree_view.cpp | 20 ++- .../gui/src/module_widget/module_widget.cpp | 134 +++++++++++------- 10 files changed, 316 insertions(+), 99 deletions(-) create mode 100755 plugins/gui/resources/icons/tree-collapsed.svg create mode 100755 plugins/gui/resources/icons/tree-expanded.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index ae25ee8def1..459c0cf9721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. * refactored module widget * added option to show gate content for each module * added option to show interior nets for each module + * added button to expand or collapse all tree items * added delete module action and shortcut * added entries for context menu * refactored search bar diff --git a/plugins/gui/include/gui/module_widget/module_tree_view.h b/plugins/gui/include/gui/module_widget/module_tree_view.h index 5710163fce7..abf5443dc21 100644 --- a/plugins/gui/include/gui/module_widget/module_tree_view.h +++ b/plugins/gui/include/gui/module_widget/module_tree_view.h @@ -42,6 +42,14 @@ namespace hal class ModuleTreeView : public QTreeView { Q_OBJECT + + bool mToggleStateExpanded; + + public Q_SLOTS: + void expandAllModules(); + + void collapseAllModules(); + public: /** * Constructor. @@ -61,5 +69,10 @@ namespace hal * Sets the default width of each column. MUST be called after setting the model. */ void setDefaultColumnWidth(); + + /** + * Returns whether last toggle action was 'expand all' or 'collapse all' + */ + bool toggleStateExpanded() const; }; } // namespace hal diff --git a/plugins/gui/include/gui/module_widget/module_widget.h b/plugins/gui/include/gui/module_widget/module_widget.h index f77ceed6d76..d3df33a65b2 100644 --- a/plugins/gui/include/gui/module_widget/module_widget.h +++ b/plugins/gui/include/gui/module_widget/module_widget.h @@ -58,19 +58,18 @@ namespace hal { Q_OBJECT Q_PROPERTY(QString disabledIconStyle READ disabledIconStyle WRITE setDisabledIconStyle) + Q_PROPERTY(QString activeIconStyle READ activeIconStyle WRITE setActiveIconStyle) Q_PROPERTY(QString showNetsIconPath READ showNetsIconPath WRITE setShowNetsIconPath) - Q_PROPERTY(QString showNetsIconStyle READ showNetsIconStyle WRITE setShowNetsIconStyle) Q_PROPERTY(QString hideNetsIconPath READ hideNetsIconPath WRITE setHideNetsIconPath) - Q_PROPERTY(QString hideNetsIconStyle READ hideNetsIconStyle WRITE setHideNetsIconStyle) Q_PROPERTY(QString showGatesIconPath READ showGatesIconPath WRITE setShowGatesIconPath) - Q_PROPERTY(QString showGatesIconStyle READ showGatesIconStyle WRITE setShowGatesIconStyle) Q_PROPERTY(QString hideGatesIconPath READ hideGatesIconPath WRITE setHideGatesIconPath) - Q_PROPERTY(QString hideGatesIconStyle READ hideGatesIconStyle WRITE setHideGatesIconStyle) Q_PROPERTY(QString searchIconPath READ searchIconPath WRITE setSearchIconPath) Q_PROPERTY(QString searchIconStyle READ searchIconStyle WRITE setSearchIconStyle) Q_PROPERTY(QString searchActiveIconStyle READ searchActiveIconStyle WRITE setSearchActiveIconStyle) + Q_PROPERTY(QString renameIconPath READ renameIconPath WRITE setRenameIconPath) Q_PROPERTY(QString deleteIconPath READ deleteIconPath WRITE setDeleteIconPath) - Q_PROPERTY(QString deleteIconStyle READ deleteIconStyle WRITE setDeleteIconStyle) + Q_PROPERTY(QString expandedIconPath READ expandedIconPath WRITE setExpandedIconPath) + Q_PROPERTY(QString collapsedIconPath READ collapsedIconPath WRITE setCollapsedIconPath) public: /** @@ -114,38 +113,37 @@ namespace hal */ ///@{ QString disabledIconStyle() const; + QString activeIconStyle() const; QString showNetsIconPath() const; - QString showNetsIconStyle() const; QString hideNetsIconPath() const; - QString hideNetsIconStyle() const; QString showGatesIconPath() const; - QString showGatesIconStyle() const; QString hideGatesIconPath() const; - QString hideGatesIconStyle() const; QString searchIconPath() const; QString searchIconStyle() const; QString searchActiveIconStyle() const; QString deleteIconPath() const; - QString deleteIconStyle() const; + QString renameIconPath() const; + QString expandedIconPath() const; + QString collapsedIconPath() const; + ///@} /** @name Q_PROPERTY WRITE Functions */ ///@{ void setDisabledIconStyle(const QString& style); + void setActiveIconStyle(const QString& style); void setShowNetsIconPath(const QString &path); - void setShowNetsIconStyle(const QString &path); void setHideNetsIconPath(const QString &path); - void setHideNetsIconStyle(const QString &path); void setShowGatesIconPath(const QString &path); - void setShowGatesIconStyle(const QString &path); void setHideGatesIconPath(const QString &path); - void setHideGatesIconStyle(const QString &path); void setSearchIconPath(const QString &path); void setSearchIconStyle(const QString &style); void setSearchActiveIconStyle(const QString &style); void setDeleteIconPath(const QString& path); - void setDeleteIconStyle(const QString& style); + void setRenameIconPath(const QString& path); + void setExpandedIconPath(const QString& path); + void setCollapsedIconPath(const QString& path); ///@} public Q_SLOTS: @@ -223,6 +221,15 @@ namespace hal */ void handleToggleGatesClicked(); + /** + * Q_SLOT to toggle whether the tree is entirely expanded or collapsed + */ + void handleToggleExpandTreeClicked(); + + /** + * Q_SLOT to handle rename button + */ + void handleRenameClicked(); private Q_SLOTS: void handleDeleteShortcutOnFocusChanged(QWidget *oldWidget, QWidget *newWidget); @@ -235,24 +242,25 @@ namespace hal QAction* mToggleNetsAction; QAction* mToggleGatesAction; + QAction* mRenameAction; QAction* mDeleteAction; + QAction* mToggleExpandTreeAction; QString mDisabledIconStyle; + QString mActiveIconStyle; + QString mShowNetsIconPath; - QString mShowNetsIconStyle; QString mHideNetsIconPath; - QString mHideNetsIconStyle; - QString mShowGatesIconPath; - QString mShowGatesIconStyle; QString mHideGatesIconPath; - QString mHideGatesIconStyle; QString mDeleteIconPath; - QString mDeleteIconStyle; QString mSearchIconPath; QString mSearchIconStyle; QString mSearchActiveIconStyle; + QString mRenameIconPath; + QString mExpandedIconPath; + QString mCollapsedIconPath; QAction* mFilterAction; diff --git a/plugins/gui/resources/gui_resources.qrc b/plugins/gui/resources/gui_resources.qrc index 76358aaf07e..804397056c4 100644 --- a/plugins/gui/resources/gui_resources.qrc +++ b/plugins/gui/resources/gui_resources.qrc @@ -102,6 +102,8 @@ icons/0501-insert-plugin.svg icons/0502-cli-options.svg icons/0503-invoke-gui.svg + icons/tree-collapsed.svg + icons/tree-expanded.svg images/oval.svg diff --git a/plugins/gui/resources/icons/tree-collapsed.svg b/plugins/gui/resources/icons/tree-collapsed.svg new file mode 100755 index 00000000000..5e267030954 --- /dev/null +++ b/plugins/gui/resources/icons/tree-collapsed.svg @@ -0,0 +1,67 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/plugins/gui/resources/icons/tree-expanded.svg b/plugins/gui/resources/icons/tree-expanded.svg new file mode 100755 index 00000000000..10c21ff4e3c --- /dev/null +++ b/plugins/gui/resources/icons/tree-expanded.svg @@ -0,0 +1,90 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/plugins/gui/resources/stylesheet/dark.qss b/plugins/gui/resources/stylesheet/dark.qss index c1d97b62cd5..c435968bc0d 100755 --- a/plugins/gui/resources/stylesheet/dark.qss +++ b/plugins/gui/resources/stylesheet/dark.qss @@ -1197,25 +1197,22 @@ hal--Toolbar QPushButton:checked:hover { } hal--ModuleWidget { - qproperty-showNetsIconStyle: "all->#e8e8e8"; - qproperty-showNetsIconPath: ":/icons/ne_net"; + qproperty-disabledIconStyle: "all->#515050"; + qproperty-activeIconStyle: "all->#e8e8e8"; - qproperty-hideNetsIconStyle: "all->#e8e8e8"; + qproperty-showNetsIconPath: ":/icons/ne_net"; qproperty-hideNetsIconPath: ":/icons/ne_no_net"; - - qproperty-showGatesIconStyle: "all->#e8e8e8"; qproperty-showGatesIconPath: ":/icons/ne_gate"; - - qproperty-hideGatesIconStyle: "all->#e8e8e8"; qproperty-hideGatesIconPath: ":/icons/ne_no_gate"; - qproperty-deleteIconStyle: "all->#e8e8e8"; - qproperty-deleteIconPath: ":/icons/trashcan"; - qproperty-disabledIconStyle: "all->#515050"; - qproperty-searchActiveIconStyle: "all->#30ac4f"; qproperty-searchIconStyle: "all->#e8e8e8"; qproperty-searchIconPath: ":/icons/search"; + + qproperty-renameIconPath: ":/icons/pen"; + qproperty-deleteIconPath: ":/icons/trashcan"; + qproperty-expandedIconPath: ":/icons/tree-expanded"; + qproperty-collapsedIconPath: ":/icons/tree-collapsed"; } hal--MainWindow diff --git a/plugins/gui/resources/stylesheet/light.qss b/plugins/gui/resources/stylesheet/light.qss index b24d80992b3..2094bdb0cd3 100755 --- a/plugins/gui/resources/stylesheet/light.qss +++ b/plugins/gui/resources/stylesheet/light.qss @@ -1221,25 +1221,22 @@ hal--Toolbar QPushButton:checked:hover { } hal--ModuleWidget { - qproperty-showNetsIconStyle: "all->#FFFFFF"; - qproperty-showNetsIconPath: ":/icons/ne_net"; + qproperty-disabledIconStyle: "all->#515050"; + qproperty-activeIconStyle: "all->#FFFFFF"; - qproperty-hideNetsIconStyle: "all->#FFFFFF"; + qproperty-showNetsIconPath: ":/icons/ne_net"; qproperty-hideNetsIconPath: ":/icons/ne_no_net"; - - qproperty-showGatesIconStyle: "all->#FFFFFF"; qproperty-showGatesIconPath: ":/icons/ne_gate"; - - qproperty-hideGatesIconStyle: "all->#FFFFFF"; qproperty-hideGatesIconPath: ":/icons/ne_no_gate"; - qproperty-deleteIconStyle: "all->#FFFFFF"; - qproperty-deleteIconPath: ":/icons/trashcan"; - qproperty-disabledIconStyle: "all->#515050"; - qproperty-searchActiveIconStyle: "all->#30ac4f"; qproperty-searchIconStyle: "all->#FFFFFF"; qproperty-searchIconPath: ":/icons/search"; + + qproperty-renameIconPath: ":/icons/pen"; + qproperty-deleteIconPath: ":/icons/trashcan"; + qproperty-expandedIconPath: ":/icons/tree-expanded"; + qproperty-collapsedIconPath: ":/icons/tree-collapsed"; } hal--MainWindow diff --git a/plugins/gui/src/module_widget/module_tree_view.cpp b/plugins/gui/src/module_widget/module_tree_view.cpp index cd0a168dcbe..cde8eb00df8 100644 --- a/plugins/gui/src/module_widget/module_tree_view.cpp +++ b/plugins/gui/src/module_widget/module_tree_view.cpp @@ -4,10 +4,28 @@ namespace hal { - ModuleTreeView::ModuleTreeView(QWidget *parent) : QTreeView(parent) + ModuleTreeView::ModuleTreeView(QWidget *parent) + : QTreeView(parent), mToggleStateExpanded(true) { } + void ModuleTreeView::expandAllModules() + { + mToggleStateExpanded = true; + expandAll(); + } + + void ModuleTreeView::collapseAllModules() + { + mToggleStateExpanded = false; + collapseAll(); + } + + bool ModuleTreeView::toggleStateExpanded() const + { + return mToggleStateExpanded; + } + void ModuleTreeView::setDefaultColumnWidth() { setColumnWidth(0, 240); diff --git a/plugins/gui/src/module_widget/module_widget.cpp b/plugins/gui/src/module_widget/module_widget.cpp index 0b4c7c1ffa8..b10a12eb9be 100644 --- a/plugins/gui/src/module_widget/module_widget.cpp +++ b/plugins/gui/src/module_widget/module_widget.cpp @@ -39,7 +39,9 @@ namespace hal mSearchbar(new Searchbar(this)), mToggleNetsAction(new QAction(this)), mToggleGatesAction(new QAction(this)), + mRenameAction(new QAction(this)), mDeleteAction(new QAction(this)), + mToggleExpandTreeAction(new QAction(this)), mModuleProxyModel(new ModuleProxyModel(this)) { @@ -47,17 +49,18 @@ namespace hal connect(mTreeView, &QTreeView::customContextMenuRequested, this, &ModuleWidget::handleTreeViewContextMenuRequested); - mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mHideNetsIconStyle, mHideNetsIconPath)); - mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mHideGatesIconStyle, mHideGatesIconPath)); + mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mHideNetsIconPath)); + mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mHideGatesIconPath)); mSearchAction->setIcon(gui_utility::getStyledSvgIcon(mSearchIconStyle, mSearchIconPath)); + mRenameAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mRenameIconPath)); + mToggleExpandTreeAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mExpandedIconPath)); mToggleNetsAction->setToolTip("Toggle net visibility"); mToggleGatesAction->setToolTip("Toggle gate visibility"); mDeleteAction->setToolTip("Delete module"); mSearchAction->setToolTip("Search"); - - mDeleteAction->setText("Delete module"); - + mRenameAction->setToolTip("Rename"); + mToggleExpandTreeAction->setToolTip("Toggle expand all / collapse all"); mModuleProxyModel->setSourceModel(gNetlistRelay->getModuleModel()); @@ -72,7 +75,7 @@ namespace hal mTreeView->setExpandsOnDoubleClick(false); mTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); mTreeView->setSelectionMode(QAbstractItemView::SingleSelection); - mTreeView->expandAll(); + mTreeView->expandAllModules(); mContentLayout->addWidget(mTreeView); mSearchbar->setColumnNames(gNetlistRelay->getModuleModel()->headerLabels()); @@ -108,23 +111,25 @@ namespace hal connect(mToggleNetsAction, &QAction::triggered, this, &ModuleWidget::handleToggleNetsClicked); connect(mToggleGatesAction, &QAction::triggered, this, &ModuleWidget::handleToggleGatesClicked); + connect(mToggleExpandTreeAction, &QAction::triggered, this, &ModuleWidget::handleToggleExpandTreeClicked); + connect(mRenameAction, &QAction::triggered, this, &ModuleWidget::handleRenameClicked); } void ModuleWidget::enableDeleteAction(bool enable) { mDeleteAction->setEnabled(enable); - mDeleteAction->setIcon(gui_utility::getStyledSvgIcon(enable?mDeleteIconStyle:mDisabledIconStyle, mDeleteIconPath)); + mDeleteAction->setIcon(gui_utility::getStyledSvgIcon(enable?mActiveIconStyle:mDisabledIconStyle, mDeleteIconPath)); } void ModuleWidget::handleToggleNetsClicked() { if(mModuleProxyModel->toggleFilterNets()) { - mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mHideNetsIconStyle, mHideNetsIconPath)); + mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mHideNetsIconPath)); } else { - mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mShowNetsIconStyle, mShowNetsIconPath)); + mToggleNetsAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mShowNetsIconPath)); } } @@ -132,11 +137,38 @@ namespace hal { if(mModuleProxyModel->toggleFilterGates()) { - mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mHideGatesIconStyle, mHideGatesIconPath)); + mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mHideGatesIconPath)); } else { - mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mShowGatesIconStyle, mShowGatesIconPath)); + mToggleGatesAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mShowGatesIconPath)); + } + } + + void ModuleWidget::handleToggleExpandTreeClicked() + { + if (mTreeView->toggleStateExpanded()) + { + mTreeView->collapseAllModules(); + mToggleExpandTreeAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mCollapsedIconPath)); + } + else + { + mTreeView->expandAllModules(); + mToggleExpandTreeAction->setIcon(gui_utility::getStyledSvgIcon(mActiveIconStyle, mExpandedIconPath)); + } + } + + void ModuleWidget::handleRenameClicked() + { + QModelIndex index = mTreeView->currentIndex(); + ModuleItem::TreeItemType type = getModuleItemFromIndex(index)->getType(); + + switch(type) + { + case ModuleItem::TreeItemType::Module: gNetlistRelay->changeModuleName(getModuleItemFromIndex(index)->id()); break; + case ModuleItem::TreeItemType::Gate: changeGateName(index); break; + case ModuleItem::TreeItemType::Net: changeNetName(index); break; } } @@ -144,8 +176,10 @@ namespace hal { toolbar->addAction(mToggleNetsAction); toolbar->addAction(mToggleGatesAction); + toolbar->addAction(mRenameAction); toolbar->addAction(mDeleteAction); toolbar->addAction(mSearchAction); + toolbar->addAction(mToggleExpandTreeAction); } QList ModuleWidget::createShortcuts() @@ -182,7 +216,7 @@ namespace hal if (regex->isValid()) { mModuleProxyModel->setFilterRegularExpression(*regex); - mTreeView->expandAll(); + mTreeView->expandAllModules(); QString output = "navigation regular expression '" + text + "' entered."; log_info("user", output.toStdString()); } @@ -561,6 +595,11 @@ namespace hal return mDisabledIconStyle; } + QString ModuleWidget::activeIconStyle() const + { + return mActiveIconStyle; + } + ModuleProxyModel* ModuleWidget::proxyModel() { return mModuleProxyModel; @@ -571,41 +610,21 @@ namespace hal return mShowNetsIconPath; } - QString ModuleWidget::showNetsIconStyle() const - { - return mShowNetsIconStyle; - } - QString ModuleWidget::hideNetsIconPath() const { return mHideNetsIconPath; } - QString ModuleWidget::hideNetsIconStyle() const - { - return mHideNetsIconStyle; - } - QString ModuleWidget::showGatesIconPath() const { return mShowGatesIconPath; } - QString ModuleWidget::showGatesIconStyle() const - { - return mShowGatesIconStyle; - } - QString ModuleWidget::hideGatesIconPath() const { return mHideGatesIconPath; } - QString ModuleWidget::hideGatesIconStyle() const - { - return mHideGatesIconStyle; - } - QString ModuleWidget::searchIconPath() const { return mSearchIconPath; @@ -626,44 +645,44 @@ namespace hal return mDeleteIconPath; } - QString ModuleWidget::deleteIconStyle() const + QString ModuleWidget::renameIconPath() const { - return mDeleteIconStyle; + return mRenameIconPath; } - void ModuleWidget::setDisabledIconStyle(const QString& style) + QString ModuleWidget::expandedIconPath() const { - mDisabledIconStyle = style; + return mExpandedIconPath; } - void ModuleWidget::setShowNetsIconPath(const QString& path) + QString ModuleWidget::collapsedIconPath() const { - mShowNetsIconPath = path; + return mCollapsedIconPath; } - void ModuleWidget::setShowNetsIconStyle(const QString& path) + void ModuleWidget::setDisabledIconStyle(const QString& style) { - mShowNetsIconStyle = path; + mDisabledIconStyle = style; } - void ModuleWidget::setHideNetsIconPath(const QString& path) + void ModuleWidget::setActiveIconStyle(const QString& style) { - mHideNetsIconPath = path; + mActiveIconStyle = style; } - void ModuleWidget::setHideNetsIconStyle(const QString& path) + void ModuleWidget::setShowNetsIconPath(const QString& path) { - mHideNetsIconStyle = path; + mShowNetsIconPath = path; } - void ModuleWidget::setShowGatesIconPath(const QString& path) + void ModuleWidget::setHideNetsIconPath(const QString& path) { - mShowGatesIconPath = path; + mHideNetsIconPath = path; } - void ModuleWidget::setShowGatesIconStyle(const QString& path) + void ModuleWidget::setShowGatesIconPath(const QString& path) { - mShowGatesIconStyle = path; + mShowGatesIconPath = path; } void ModuleWidget::setHideGatesIconPath(const QString& path) @@ -671,11 +690,6 @@ namespace hal mHideGatesIconPath = path; } - void ModuleWidget::setHideGatesIconStyle(const QString& path) - { - mHideGatesIconStyle = path; - } - void ModuleWidget::setSearchIconPath(const QString& path) { mSearchIconPath = path; @@ -696,9 +710,19 @@ namespace hal mDeleteIconPath = path; } - void ModuleWidget::setDeleteIconStyle(const QString& style) + void ModuleWidget::setRenameIconPath(const QString& path) + { + mRenameIconPath = path; + } + + void ModuleWidget::setExpandedIconPath(const QString& path) + { + mExpandedIconPath = path; + } + + void ModuleWidget::setCollapsedIconPath(const QString& path) { - mDeleteIconStyle = style; + mCollapsedIconPath = path; } void ModuleWidget::deleteSelectedItem()