Skip to content
Snippets Groups Projects
Commit deee9372 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

simplify ComponentTreeView actions

parent 7ab0ce34
No related branches found
No related tags found
1 merge request!462simplify code; remove test code
// ************************************************************************************************
//
// 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);
}
// ************************************************************************************************
//
// 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
......@@ -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);
}
......@@ -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.
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment