From deee9372216ca7e3f355e185d056d31c481b5e42 Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Mon, 15 Nov 2021 16:17:01 +0100 Subject: [PATCH] simplify ComponentTreeView actions --- .../PropertyEditor/ComponentTreeActions.cpp | 56 ------------------- .../PropertyEditor/ComponentTreeActions.h | 33 ----------- GUI/View/PropertyEditor/ComponentTreeView.cpp | 36 +++++++++++- GUI/View/PropertyEditor/ComponentTreeView.h | 2 - 4 files changed, 33 insertions(+), 94 deletions(-) delete mode 100644 GUI/View/PropertyEditor/ComponentTreeActions.cpp delete mode 100644 GUI/View/PropertyEditor/ComponentTreeActions.h diff --git a/GUI/View/PropertyEditor/ComponentTreeActions.cpp b/GUI/View/PropertyEditor/ComponentTreeActions.cpp deleted file mode 100644 index a2e55fd1cd4..00000000000 --- a/GUI/View/PropertyEditor/ComponentTreeActions.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PropertyEditor/ComponentTreeActions.cpp -//! @brief Implements class ComponentTreeActions -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/PropertyEditor/ComponentTreeActions.h" -#include "GUI/Model/Session/SessionItem.h" -#include <QAction> -#include <QMenu> - -ComponentTreeActions::ComponentTreeActions(QObject* parent) : QObject(parent) {} - -//! Creates right-mouse-click context menu on top of ComponentTreeView -//! which will allow user to switch between scientific notation and the notation -//! with a specified number of decimals. - -void ComponentTreeActions::onCustomContextMenuRequested(const QPoint& point, SessionItem& item) -{ - bool sc_editor = item.editorType() == "ScientificDouble"; - - QMenu menu; - QAction* scientificAction = menu.addAction("Scientific presentation"); - scientificAction->setCheckable(true); - auto* doubleMenu = menu.addMenu("Double presentation"); - - // To select scientific notation - scientificAction->setChecked(sc_editor); - connect(scientificAction, &QAction::triggered, [&]() { - if (scientificAction->isChecked()) - item.setEditorType("ScientificDouble"); - else - item.setEditorType("Default"); - }); - - // to select number of decimals - const int nmaxdigits = 8; - for (int i = 1; i <= nmaxdigits; ++i) { - auto* action = doubleMenu->addAction(QString("%1 digits").arg(i)); - if (!sc_editor && item.decimals() == i) - action->setChecked(true); - connect(action, &QAction::triggered, [i, &item] { - item.setEditorType("Default"); - item.setDecimals(i); - }); - } - menu.exec(point); -} diff --git a/GUI/View/PropertyEditor/ComponentTreeActions.h b/GUI/View/PropertyEditor/ComponentTreeActions.h deleted file mode 100644 index 015dace2960..00000000000 --- a/GUI/View/PropertyEditor/ComponentTreeActions.h +++ /dev/null @@ -1,33 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PropertyEditor/ComponentTreeActions.h -//! @brief Defines class ComponentTreeActions -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_COMPONENTTREEACTIONS_H -#define BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_COMPONENTTREEACTIONS_H - -#include <QObject> - -class SessionItem; - -//! Additional action for ComponentTreeView. - -class ComponentTreeActions : public QObject { - Q_OBJECT -public: - ComponentTreeActions(QObject* parent = nullptr); - -public slots: - void onCustomContextMenuRequested(const QPoint& point, SessionItem& item); -}; - -#endif // BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_COMPONENTTREEACTIONS_H diff --git a/GUI/View/PropertyEditor/ComponentTreeView.cpp b/GUI/View/PropertyEditor/ComponentTreeView.cpp index e511df813f6..6c3fba99c14 100644 --- a/GUI/View/PropertyEditor/ComponentTreeView.cpp +++ b/GUI/View/PropertyEditor/ComponentTreeView.cpp @@ -15,11 +15,12 @@ #include "GUI/View/PropertyEditor/ComponentTreeView.h" #include "GUI/Model/Component/ComponentProxyModel.h" #include "GUI/Model/Session/SessionModel.h" -#include "GUI/View/PropertyEditor/ComponentTreeActions.h" #include "GUI/View/PropertyEditor/CustomEventFilters.h" #include "GUI/View/PropertyEditor/SessionModelDelegate.h" #include "GUI/View/Tool/StyleUtils.h" +#include <QAction> #include <QBoxLayout> +#include <QMenu> #include <QStandardItemModel> #include <QTreeView> @@ -30,7 +31,6 @@ ComponentTreeView::ComponentTreeView(QWidget* parent) , m_proxyModel(new ComponentProxyModel(this)) , m_placeHolderModel(new QStandardItemModel(this)) , m_eventFilter(new RightMouseButtonEater) - , m_actions(new ComponentTreeActions(this)) , m_show_root_item(false) { auto* layout = new QVBoxLayout; @@ -120,5 +120,35 @@ void ComponentTreeView::onCustomContextMenuRequested(const QPoint& pos) if (item->value().type() != QVariant::Double) return; - m_actions->onCustomContextMenuRequested(point, *item); + const bool sc_editor = item->editorType() == "ScientificDouble"; + + // Creates right-mouse-click context menu on top of ComponentTreeView + // which will allow user to switch between scientific notation and the notation + // with a specified number of decimals. + QMenu menu; + QAction* scientificAction = menu.addAction("Scientific presentation"); + scientificAction->setCheckable(true); + auto* doubleMenu = menu.addMenu("Double presentation"); + + // To select scientific notation + scientificAction->setChecked(sc_editor); + connect(scientificAction, &QAction::triggered, [&]() { + if (scientificAction->isChecked()) + item->setEditorType("ScientificDouble"); + else + item->setEditorType("Default"); + }); + + // to select number of decimals + const int nmaxdigits = 8; + for (int i = 1; i <= nmaxdigits; ++i) { + auto* action = doubleMenu->addAction(QString("%1 digits").arg(i)); + if (!sc_editor && item->decimals() == i) + action->setChecked(true); + connect(action, &QAction::triggered, [i, &item] { + item->setEditorType("Default"); + item->setDecimals(i); + }); + } + menu.exec(point); } diff --git a/GUI/View/PropertyEditor/ComponentTreeView.h b/GUI/View/PropertyEditor/ComponentTreeView.h index b5f6f6d26b6..7223a5707db 100644 --- a/GUI/View/PropertyEditor/ComponentTreeView.h +++ b/GUI/View/PropertyEditor/ComponentTreeView.h @@ -26,7 +26,6 @@ class QModelIndex; class SessionItem; class QStandardItemModel; class RightMouseButtonEater; -class ComponentTreeActions; //! Component property tree for SessionItems. //! Shows only PropertyItems and current items of GroupProperties. @@ -54,7 +53,6 @@ private: ComponentProxyModel* m_proxyModel; QStandardItemModel* m_placeHolderModel; std::unique_ptr<RightMouseButtonEater> m_eventFilter; - ComponentTreeActions* m_actions; bool m_show_root_item; //!< Tree will starts from item itself, if true. }; -- GitLab