diff --git a/GUI/View/SampleDesigner/SamplePropertyWidget.cpp b/GUI/View/SampleDesigner/SamplePropertyWidget.cpp deleted file mode 100644 index f3f7d76560e0ef596231bec56d0e432bb4fae979..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SamplePropertyWidget.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SamplePropertyWidget.cpp -//! @brief Implements class IntensityDataPropertyWidget -//! -//! @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/SampleDesigner/SamplePropertyWidget.h" -#include "GUI/Model/Session/SessionItem.h" -#include "GUI/View/PropertyEditor/ComponentTreeView.h" -#include <QItemSelection> -#include <QModelIndexList> -#include <QSortFilterProxyModel> -#include <QVBoxLayout> - -SamplePropertyWidget::SamplePropertyWidget(QItemSelectionModel* selection_model, QWidget* parent) - : QWidget(parent), m_selection_model(nullptr), m_propertyEditor(new ComponentTreeView) -{ - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - setWindowTitle(QLatin1String("Property Editor")); - setObjectName(QLatin1String("SamplePropertyWidget")); - - setSelectionModel(selection_model); - - m_propertyEditor->setShowRootItem(true); - - auto* mainLayout = new QVBoxLayout; - mainLayout->setMargin(0); - mainLayout->setSpacing(0); - mainLayout->addWidget(m_propertyEditor); - - setLayout(mainLayout); -} - -QSize SamplePropertyWidget::sizeHint() const -{ - return QSize(230, 256); -} - -QSize SamplePropertyWidget::minimumSizeHint() const -{ - return QSize(230, 64); -} - -void SamplePropertyWidget::setSelectionModel(QItemSelectionModel* selection_model) -{ - if (selection_model == m_selection_model) - return; - - if (m_selection_model) { - disconnect(m_selection_model, &QItemSelectionModel::selectionChanged, this, - &SamplePropertyWidget::selectionChanged); - } - - m_selection_model = selection_model; - - if (m_selection_model) { - connect(m_selection_model, &QItemSelectionModel::selectionChanged, this, - &SamplePropertyWidget::selectionChanged); - } -} - -// TODO Refactor this together with whole SampleView. Remove knowledge about proxy model. - -void SamplePropertyWidget::selectionChanged(const QItemSelection& selected, const QItemSelection&) -{ - QModelIndexList indices = selected.indexes(); - - if (!indices.empty()) { - QModelIndex index = indices.back(); - - if (auto* proxy = dynamic_cast<QSortFilterProxyModel*>( - const_cast<QAbstractItemModel*>(indices.front().model()))) - index = proxy->mapToSource(indices.back()); - - auto* item = static_cast<SessionItem*>(index.internalPointer()); - if (item) - m_propertyEditor->setItem(item); - - } else { - m_propertyEditor->setItem(nullptr); - } -} diff --git a/GUI/View/SampleDesigner/SamplePropertyWidget.h b/GUI/View/SampleDesigner/SamplePropertyWidget.h deleted file mode 100644 index 9ad4df4ae0aa64bffed3352397da581cc2e34a88..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SamplePropertyWidget.h +++ /dev/null @@ -1,45 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SamplePropertyWidget.h -//! @brief Defines class SamplePropertyWidget -//! -//! @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_SAMPLEDESIGNER_SAMPLEPROPERTYWIDGET_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEPROPERTYWIDGET_H - -#include <QWidget> - -class QItemSelectionModel; -class QItemSelection; -class ComponentTreeView; - -//! Property editor to modify property of the object currently selected on the -//! graphics scene. Located in the bottom right corner of SampleView. - -class SamplePropertyWidget : public QWidget { - Q_OBJECT -public: - SamplePropertyWidget(QItemSelectionModel* selection_model, QWidget* parent = nullptr); - - QSize sizeHint() const override; - QSize minimumSizeHint() const override; - - void setSelectionModel(QItemSelectionModel* selection_model); - -public slots: - void selectionChanged(const QItemSelection& selected, const QItemSelection&); - -private: - QItemSelectionModel* m_selection_model; - ComponentTreeView* m_propertyEditor; -}; - -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEPROPERTYWIDGET_H diff --git a/GUI/View/SampleDesigner/SampleToolBar.cpp b/GUI/View/SampleDesigner/SampleToolBar.cpp deleted file mode 100644 index c626816ad883deb716059a6c9a00f52ef78028ee..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBar.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBar.cpp -//! @brief Implements class SampleToolBar -//! -//! @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/SampleDesigner/SampleToolBar.h" -#include "GUI/Model/State/SessionData.h" -#include "GUI/View/Main/MainWindow.h" -#include "GUI/View/MaterialEditor/MaterialEditorDialog.h" -#include "GUI/View/SampleDesigner/DesignerView.h" -#include "GUI/View/SampleDesigner/SampleView.h" -#include <QAction> -#include <QButtonGroup> -#include <QComboBox> -#include <QIcon> -#include <QLabel> -#include <QMenu> -#include <QPushButton> -#include <QToolButton> - -//! main tool bar on top of SampleView window -SampleToolBar::SampleToolBar(SampleView* parent) : StyledToolBar(parent) -{ - // Select & Pan - auto* selectionPointerButton = new QToolButton; - selectionPointerButton->setCheckable(true); - selectionPointerButton->setChecked(true); - selectionPointerButton->setIcon(QIcon(":/SampleDesigner/images/arrow-top-left.svg")); - selectionPointerButton->setToolTip("Edit mode."); - - auto* handPointerButton = new QToolButton; - handPointerButton->setCheckable(true); - handPointerButton->setIcon(QIcon(":/SampleDesigner/images/hand-right.svg")); - handPointerButton->setToolTip("Pan mode (space)."); - - m_pointerModeGroup = new QButtonGroup(this); - m_pointerModeGroup->addButton(selectionPointerButton, DesignerView::RUBBER_SELECTION); - m_pointerModeGroup->addButton(handPointerButton, DesignerView::HAND_DRAG); -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - connect(m_pointerModeGroup, &QButtonGroup::idClicked, this, &SampleToolBar::selectionMode); -#else - connect(m_pointerModeGroup, - static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, - &SampleToolBar::selectionMode); -#endif - addWidget(selectionPointerButton); - addWidget(handPointerButton); - - addStyledSeparator(); - - // Remove item - m_removeButton = new QToolButton; - m_removeButton->setText("Remove item"); - m_removeButton->setIcon(QIcon(":/SampleDesigner/images/delete.svg")); - m_removeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - m_removeButton->setToolTip("Remove selected items and they child items (del)."); - connect(m_removeButton, &QToolButton::clicked, this, &SampleToolBar::deleteItems); - addWidget(m_removeButton); - - addStyledSeparator(); - - // Center view - m_centerViewButton = new QToolButton; - m_centerViewButton->setText("Center view"); - m_centerViewButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - m_centerViewButton->setIcon(QIcon(":/SampleDesigner/images/camera-metering-center.svg")); - m_centerViewButton->setToolTip("Center view."); - connect(m_centerViewButton, &QToolButton::clicked, this, &SampleToolBar::centerView); - addWidget(m_centerViewButton); - - // Zoom - addWidget(new QLabel(" ")); - m_scaleCombo = new QComboBox; - QStringList scales = QStringList() << "25%" - << "50%" - << "75%" - << "100%" - << "125%" - << "150%"; - m_scaleCombo->addItems(scales); - m_scaleCombo->setCurrentIndex(3); -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) - connect(m_scaleCombo, - static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this, - &SampleToolBar::onScaleComboChanged); -#else - connect(m_scaleCombo, - static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this, - &SampleToolBar::onScaleComboChanged); -#endif - - addWidget(m_scaleCombo); - addWidget(new QLabel(" Zoom ")); - - // MaterialEditor - addWidget(new QLabel(" ")); - m_materialEditorButton = new QToolButton; - m_materialEditorButton->setText("Material Editor"); - m_materialEditorButton->setIcon(QIcon(":/SampleDesigner/images/alpha-m-box.svg")); - m_materialEditorButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - m_materialEditorButton->setToolTip("Open material editor (m)."); - m_materialEditorButton->setShortcut(Qt::Key_M); - connect(m_materialEditorButton, &QToolButton::clicked, this, - &SampleToolBar::onMaterialEditorCall); - addWidget(m_materialEditorButton); - - addStyledSeparator(); - - // RealSpace 3D Viewer - addWidget(new QLabel(" ")); - addWidget(new QLabel(" ")); - m_RealSpaceViewerButton = new QToolButton; - m_RealSpaceViewerButton->setIcon(QIcon(":/SampleDesigner/images/rotate-3d.svg")); - m_RealSpaceViewerButton->setText("3D Viewer"); - m_RealSpaceViewerButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - m_RealSpaceViewerButton->setToolTip("Open real space 3D viewer."); - connect(m_RealSpaceViewerButton, &QToolButton::clicked, parent, - &SampleView::toggleRealSpaceView); - addWidget(m_RealSpaceViewerButton); -} - -void SampleToolBar::onViewSelectionMode(int mode) -{ - if (mode == DesignerView::RUBBER_SELECTION || mode == DesignerView::HAND_DRAG) - m_pointerModeGroup->button(mode)->setChecked(true); -} - -void SampleToolBar::onScaleComboChanged(const QString& scale_string) -{ - double scale = scale_string.left(scale_string.indexOf("%")).toDouble() / 100.0; - emit changeScale(scale); -} - -void SampleToolBar::onMaterialEditorCall() -{ - MaterialEditorDialog::editMaterials(baWin, gSessionData->projectDocument); -} diff --git a/GUI/View/SampleDesigner/SampleToolBar.h b/GUI/View/SampleDesigner/SampleToolBar.h deleted file mode 100644 index 02c57f3a49e688365ebca259de82d7bf2416c7ee..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBar.h +++ /dev/null @@ -1,59 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBar.h -//! @brief Defines class SampleToolBar -//! -//! @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_SAMPLEDESIGNER_SAMPLETOOLBAR_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBAR_H - -#include "GUI/View/Common/StyledToolBar.h" -#include <QTreeView> - -class QAction; -class QToolButton; -class QToolBar; -class QComboBox; -class QString; -class QButtonGroup; -class SampleModel; -class SampleView; - -//! The SampleToolBar class represents a main toolbar on top of SampleView window - -class SampleToolBar : public StyledToolBar { - Q_OBJECT - -public: - explicit SampleToolBar(SampleView* parent); - -signals: - void deleteItems(); - void selectionMode(int); - void centerView(); - void smartAlign(); - void changeScale(double); - -public slots: - void onViewSelectionMode(int); - void onScaleComboChanged(const QString&); - void onMaterialEditorCall(); - -private: - QButtonGroup* m_pointerModeGroup; - QToolButton* m_removeButton; - QToolButton* m_centerViewButton; - QComboBox* m_scaleCombo; - QToolButton* m_materialEditorButton; - QToolButton* m_RealSpaceViewerButton; -}; - -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBAR_H diff --git a/GUI/View/SampleDesigner/SampleToolBox.cpp b/GUI/View/SampleDesigner/SampleToolBox.cpp deleted file mode 100644 index 164ddadc87ef965a010afa1f57f8548faad91e88..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBox.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBox.cpp -//! @brief Implements class SampleToolBox -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/SampleDesigner/SampleToolBox.h" -#include "GUI/Model/Group/ItemCatalog.h" -#include "GUI/Model/Sample/GUIExamplesFactory.h" -#include "GUI/Model/Sample/LayerItem.h" -#include "GUI/Model/Sample/MultiLayerItem.h" -#include "GUI/Model/Sample/ParticleLayoutItem.h" -#include "GUI/Model/Trafo/TransformationItem.h" -#include "GUI/View/SampleDesigner/DesignerMimeData.h" -#include "GUI/View/SampleDesigner/SampleToolBoxTreeWidget.h" -#include <QApplication> -#include <QFocusEvent> -#include <QIcon> -#include <QLineEdit> -#include <QToolBar> -#include <QVBoxLayout> - -namespace { - -class FilterEdit : public QLineEdit { -public: - explicit FilterEdit(QWidget* parent = nullptr) : QLineEdit(parent) - { - setFocusPolicy(Qt::NoFocus); - } - -protected: - void mousePressEvent(QMouseEvent* event) override - { - if (!hasFocus()) // Explicitly focus on click. - setFocus(Qt::OtherFocusReason); - QLineEdit::mousePressEvent(event); - } - - void focusInEvent(QFocusEvent* e) override - { - // Refuse the focus if the mouse it outside. In addition to the mouse - // press logic, this prevents a re-focussing which occurs once - // we actually had focus - const Qt::FocusReason reason = e->reason(); - if (reason == Qt::ActiveWindowFocusReason || reason == Qt::PopupFocusReason) { - const QPoint mousePos = mapFromGlobal(QCursor::pos()); - const bool refuse = !geometry().contains(mousePos); - if (refuse) { - e->ignore(); - return; - } - } - QLineEdit::focusInEvent(e); - } -}; - -} // namespace - - -SampleToolBox::SampleToolBox(QWidget* parent) : QWidget(parent), m_view(new SampleToolBoxTreeWidget) -{ - setObjectName(QLatin1String("SampleToolBox")); - setWindowTitle("Items Toolbox"); - - // Prevent the filter from grabbing focus since Our view has Qt::NoFocus - auto* toolBar = new QToolBar(this); - QLineEdit* filterEdit = new FilterEdit(toolBar); - filterEdit->setPlaceholderText("Filter"); - filterEdit->setClearButtonEnabled(true); - connect(filterEdit, &QLineEdit::textChanged, m_view, &SampleToolBoxTreeWidget::filter); - toolBar->addWidget(filterEdit); - - auto* layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->setSpacing(0); - layout->addWidget(toolBar); - layout->addWidget(m_view); - setLayout(layout); - - connect(m_view, &SampleToolBoxTreeWidget::pressed, this, &SampleToolBox::handleMousePress); - - fill(); -} - -QSize SampleToolBox::minimumSizeHint() const -{ - return QSize(300, 300); -} - -void SampleToolBox::handleMousePress(const QString& /*title*/, const QString& className, - const QPoint&) -{ - if (QApplication::mouseButtons() != Qt::LeftButton) - return; - - DesignerMimeData::execDrag(className, this); -} - -void SampleToolBox::fill() -{ - const auto icon = [](const QString& iconName) { - return QIcon(":/SampleDesignerToolbox/images/" + iconName); - }; - - m_view->addGroup("Sample"); - m_view->addEntry(MultiLayerItem::M_TYPE, icon("MultiLayer.png"), "Multi Layer", - "A multilayer to hold stack of layers"); - - m_view->addGroup("Layers"); - m_view->addEntry(LayerItem::M_TYPE, icon("Layer.png"), "Layer", - "A layer with thickness and material"); - - m_view->addGroup("Particle layouts"); - m_view->addEntry(ParticleLayoutItem::M_TYPE, icon("ParticleLayout.png"), - "Basic particle layout", "A layout of particles"); - - m_view->addGroup("Interference functions"); - for (const auto& modelType : ItemCatalog::interferenceFunctionTypes()) { - const auto ui = ItemCatalog::instance().uiInfo(modelType); - m_view->addEntry(modelType, QIcon(ui.iconPath), ui.menuEntry, ui.description); - } - - m_view->addGroup("Hard particles"); - for (const auto& modelType : ItemCatalog::formFactorHardParticleTypes()) { - const auto ui = ItemCatalog::instance().uiInfo(modelType); - m_view->addEntry("FormFactor" + modelType, QIcon(ui.iconPath), ui.menuEntry, - ui.description); - } - - m_view->addGroup("Ripples"); - for (const auto& modelType : ItemCatalog::formFactorRippleTypes()) { - const auto ui = ItemCatalog::instance().uiInfo(modelType); - m_view->addEntry("FormFactor" + modelType, QIcon(ui.iconPath), ui.menuEntry, - ui.description); - } - - m_view->addGroup("Transformations"); - m_view->addEntry(TransformationItem::M_TYPE, icon("Transformation.png"), "Rotation", - "Rotation applied to particles"); - - m_view->addGroup("Particle assemblies"); - for (const auto& modelType : ItemCatalog::particleAssemblyTypes()) { - const auto ui = ItemCatalog::instance().uiInfo(modelType); - m_view->addEntry(modelType, QIcon(ui.iconPath), ui.menuEntry, ui.description); - } - - m_view->addGroup("Demo samples"); - for (const auto& exampleName : GUIExamplesFactory::exampleNames()) { - auto [title, description] = GUIExamplesFactory::exampleInfo(exampleName); - m_view->addEntry(exampleName, QIcon(":/SampleDesignerToolbox/images/sample_layers2.png"), - title, description); - } -} diff --git a/GUI/View/SampleDesigner/SampleToolBox.h b/GUI/View/SampleDesigner/SampleToolBox.h deleted file mode 100644 index 3f33f8ff5d6f4f236d3fc3a06f51d1377b333d19..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBox.h +++ /dev/null @@ -1,40 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBox.h -//! @brief Defines class SampleToolBox -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOX_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOX_H - -#include <QWidget> - -class SampleToolBoxTreeWidget; - -//! ToolBox on the left side of SampleView -class SampleToolBox : public QWidget { -public: - explicit SampleToolBox(QWidget* parent); - - QSize minimumSizeHint() const override; - -private: - void fill(); - -private slots: - void handleMousePress(const QString& title, const QString& className, - const QPoint& globalMousePos); - -private: - SampleToolBoxTreeWidget* m_view; -}; - -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOX_H diff --git a/GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp b/GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp deleted file mode 100644 index 25a6af0bef7edde1a6f306bd4f84f37415729691..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp +++ /dev/null @@ -1,212 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBoxGroupView.cpp -//! @brief Implements class SampleToolBoxGroupView -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/SampleDesigner/SampleToolBoxGroupView.h" - -#include <QIcon> -#include <QListView> -#include <QSortFilterProxyModel> - -namespace { -enum { FILTER_ROLE = Qt::UserRole + 11 }; -} // namespace - -// ************************************************************************************************ -// auxiliary class SampleToolBoxGroupModel -// ************************************************************************************************ - -//! Represents a list of group entries. Uses a -//! QAbstractListModel since the behaviour depends on the view mode of the list -//! view, it does not return text in the case of IconMode. -class SampleToolBoxGroupModel : public QAbstractListModel { -public: - explicit SampleToolBoxGroupModel(QObject* parent = nullptr); - - //! Entry of the model list - struct Entry { - QString title; - QString className; - QString toolTip; - QString filter; - QIcon icon; - }; - - // QAbstractListModel - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - Qt::ItemFlags flags(const QModelIndex& index) const override; - - // The model returns no text in icon mode, so, it also needs to know the view mode - void setViewMode(QListView::ViewMode viewMode); - - void addEntry(const QString& title, const QIcon& icon, const QString& className, - const QString& tooltip); - - Entry entryAt(const QModelIndex& index) const; - Entry entryAt(int row) const; - -private: - QList<Entry> m_items; - QListView::ViewMode m_viewMode; -}; - -SampleToolBoxGroupModel::SampleToolBoxGroupModel(QObject* parent) - : QAbstractListModel(parent), m_viewMode(QListView::ListMode) -{ -} - -void SampleToolBoxGroupModel::setViewMode(QListView::ViewMode viewMode) -{ - if (m_viewMode == viewMode) - return; - const bool empty = m_items.isEmpty(); - if (!empty) - beginResetModel(); - m_viewMode = viewMode; - if (!empty) - endResetModel(); -} - -QVariant SampleToolBoxGroupModel::data(const QModelIndex& index, int role) const -{ - const int row = index.row(); - if (row < 0 || row >= m_items.size()) - return QVariant(); - - const Entry& item = m_items.at(row); - switch (role) { - case Qt::DisplayRole: - // No text in icon mode - return QVariant(m_viewMode == QListView::ListMode ? item.title : QString()); - case Qt::DecorationRole: - return QVariant(item.icon); - case Qt::ToolTipRole: { - if (m_viewMode == QListView::ListMode) - return QVariant(item.toolTip); - // Icon mode tooltip should contain the title of the entry - QString tt = item.title; - if (!item.toolTip.isEmpty()) { - tt += QLatin1Char('\n'); - tt += item.toolTip; - } - return QVariant(tt); - } - case FILTER_ROLE: - return item.filter; - default: - return {}; - } -} - -Qt::ItemFlags SampleToolBoxGroupModel::flags(const QModelIndex& /*index*/) const -{ - return Qt::ItemIsEnabled; -} - -int SampleToolBoxGroupModel::rowCount(const QModelIndex& /*parent*/) const -{ - return m_items.size(); -} - -void SampleToolBoxGroupModel::addEntry(const QString& title, const QIcon& icon, - const QString& className, const QString& tooltip) -{ - Entry item; - item.title = title; - item.toolTip = tooltip; - item.icon = icon; - item.filter = title; - if (!item.filter.contains(className)) - item.filter += className; - item.className = className; - - // insert - const int row = m_items.size(); - beginInsertRows(QModelIndex(), row, row); - m_items.push_back(item); - endInsertRows(); -} - -SampleToolBoxGroupModel::Entry SampleToolBoxGroupModel::entryAt(const QModelIndex& index) const -{ - return entryAt(index.row()); -} - -SampleToolBoxGroupModel::Entry SampleToolBoxGroupModel::entryAt(int row) const -{ - if (row < 0 || row >= m_items.size()) - return Entry(); - - return m_items.at(row); -} - -// ************************************************************************************************ -// class SampleToolBoxGroupView -// ************************************************************************************************ - -SampleToolBoxGroupView::SampleToolBoxGroupView(QWidget* parent) - : QListView(parent) - , m_proxyModel(new QSortFilterProxyModel(this)) - , m_model(new SampleToolBoxGroupModel(this)) -{ - setFocusPolicy(Qt::NoFocus); - setFrameShape(QFrame::NoFrame); - setIconSize(QSize(32, 32)); - setSpacing(1); - setTextElideMode(Qt::ElideMiddle); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setResizeMode(QListView::Adjust); - setUniformItemSizes(true); - - connect(this, &QListView::pressed, this, &SampleToolBoxGroupView::slotPressed); - - m_proxyModel->setSourceModel(m_model); - m_proxyModel->setFilterRole(FILTER_ROLE); - setModel(m_proxyModel); -} - -void SampleToolBoxGroupView::addEntry(const QString& title, const QIcon& icon, - const QString& className, const QString& tooltip) -{ - m_model->addEntry(title, icon, className, tooltip); -} - -void SampleToolBoxGroupView::setViewMode(ViewMode vm) -{ - QListView::setViewMode(vm); - m_model->setViewMode(vm); -} - -void SampleToolBoxGroupView::slotPressed(const QModelIndex& index) -{ - const auto entry = m_model->entryAt(m_proxyModel->mapToSource(index)); - emit pressed(entry.title, entry.className, QCursor::pos()); -} - -int SampleToolBoxGroupView::count(AccessMode accessMode) const -{ - return accessMode == FILTERED ? m_proxyModel->rowCount() : m_model->rowCount(); -} - -int SampleToolBoxGroupView::mapRowToSource(int filterRow) const -{ - const QModelIndex filterIndex = m_proxyModel->index(filterRow, 0); - return m_proxyModel->mapToSource(filterIndex).row(); -} - -void SampleToolBoxGroupView::filter(const QRegExp& re) -{ - m_proxyModel->setFilterRegExp(re); -} diff --git a/GUI/View/SampleDesigner/SampleToolBoxGroupView.h b/GUI/View/SampleDesigner/SampleToolBoxGroupView.h deleted file mode 100644 index 959e057d2d02b26699ab96bed9dafe4d827604b2..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBoxGroupView.h +++ /dev/null @@ -1,56 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBoxGroupView.h -//! @brief Defines class SampleToolBoxGroupView -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOXGROUPVIEW_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOXGROUPVIEW_H - -#include <QListView> - -class QSortFilterProxyModel; -class SampleToolBoxGroupModel; - -// View of a group inside the SampleToolBox, switchable between icon and list mode. -// Provides also a filtered view. -class SampleToolBoxGroupView : public QListView { - Q_OBJECT -public: - // Whether to access the filtered or unfiltered view - enum AccessMode { FILTERED, UNFILTERED }; - - explicit SampleToolBoxGroupView(QWidget* parent = nullptr); - void setViewMode(ViewMode vm); - - using QListView::contentsSize; - - // These method operates on the filtered/unfiltered model according to accessmode - int count(AccessMode accessmode) const; - - void addEntry(const QString& title, const QIcon& icon, const QString& className, - const QString& tooltip); - - void filter(const QRegExp& re); - -signals: - void pressed(const QString& name, const QString& className, const QPoint& globalPos); - -private: - void slotPressed(const QModelIndex& index); - int mapRowToSource(int filterRow) const; - -private: - QSortFilterProxyModel* m_proxyModel; - SampleToolBoxGroupModel* m_model; -}; - -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOXGROUPVIEW_H diff --git a/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp b/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp deleted file mode 100644 index 1ecec3370cccdb015472f3c81a26bc386e9c4166..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp +++ /dev/null @@ -1,291 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBoxTreeWidget.cpp -//! @brief Implements class SampleToolBoxTreeWidget -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/SampleDesigner/SampleToolBoxTreeWidget.h" -#include "Base/Util/Assert.h" -#include "GUI/View/SampleDesigner/SampleToolBoxGroupView.h" - -#include <QAction> -#include <QActionGroup> -#include <QApplication> -#include <QContextMenuEvent> -#include <QHeaderView> -#include <QItemDelegate> -#include <QMenu> -#include <QPainter> -#include <QTreeWidgetItem> - -namespace { - -//! Draws the group title items as buttons with an arrow to show "collapsed/expanded". -//! This work is based on qdesigner_internal::SheetDelegate -class GroupTitleDelegate : public QItemDelegate { -public: - GroupTitleDelegate(QTreeView* view, QWidget* parent) : QItemDelegate(parent), m_view(view) {} - - void paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const override - { - const QAbstractItemModel* model = index.model(); - const bool isGroupTitleItem = !model->parent(index).isValid(); - - if (!isGroupTitleItem) { - QItemDelegate::paint(painter, option, index); - return; - } - - painter->save(); - QColor buttonColor(230, 230, 230); - const QBrush buttonBrush = option.palette.button(); - if (!buttonBrush.gradient() && buttonBrush.texture().isNull()) - buttonColor = buttonBrush.color(); - QColor outlineColor = buttonColor.darker(150); - QColor highlightColor = buttonColor.lighter(130); - - // Only draw topline if the previous item is expanded - const QModelIndex previousIndex = model->index(index.row() - 1, index.column()); - const bool drawTopline = (index.row() > 0 && m_view->isExpanded(previousIndex)); - const int highlightOffset = drawTopline ? 1 : 0; - - QLinearGradient gradient(option.rect.topLeft(), option.rect.bottomLeft()); - gradient.setColorAt(0, buttonColor.lighter(102)); - gradient.setColorAt(1, buttonColor.darker(106)); - - painter->setPen(Qt::NoPen); - painter->setBrush(gradient); - painter->drawRect(option.rect); - painter->setPen(highlightColor); - painter->drawLine(option.rect.topLeft() + QPoint(0, highlightOffset), - option.rect.topRight() + QPoint(0, highlightOffset)); - painter->setPen(outlineColor); - if (drawTopline) - painter->drawLine(option.rect.topLeft(), option.rect.topRight()); - painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); - painter->restore(); - - QStyleOption branchOption; - static const int i = 9; - const QRect r = option.rect; - branchOption.rect = QRect(r.left() + i / 2, r.top() + (r.height() - i) / 2, i, i); - branchOption.palette = option.palette; - branchOption.state = QStyle::State_Children; - - if (m_view->isExpanded(index)) - branchOption.state |= QStyle::State_Open; - - m_view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, m_view); - - // draw text - const QRect textrect = - QRect(r.left() + i * 2, r.top(), r.width() - ((5 * i) / 2), r.height()); - const QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, - model->data(index, Qt::DisplayRole).toString()); - m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter, option.palette, - m_view->isEnabled(), text); - } - - QSize sizeHint(const QStyleOptionViewItem& opt, const QModelIndex& index) const override - { - return QItemDelegate::sizeHint(opt, index) + QSize(2, 2); - } - -private: - QTreeView* m_view; -}; - -} // namespace - - -SampleToolBoxTreeWidget::SampleToolBoxTreeWidget(QWidget* parent) - : QTreeWidget(parent), m_iconMode(false) -{ - setFocusPolicy(Qt::NoFocus); - setIndentation(0); - setRootIsDecorated(false); - setColumnCount(1); - header()->hide(); -#if QT_VERSION >= 0x050000 - header()->setSectionResizeMode(QHeaderView::Stretch); -#endif - setTextElideMode(Qt::ElideMiddle); - setVerticalScrollMode(ScrollPerPixel); - - setItemDelegate(new GroupTitleDelegate(this, this)); - - connect(this, &QTreeWidget::itemPressed, this, &SampleToolBoxTreeWidget::handleMousePress); -} - -SampleToolBoxGroupView* SampleToolBoxTreeWidget::groupViewAt(int idx) const -{ - SampleToolBoxGroupView* rc = nullptr; - if (QTreeWidgetItem* groupItem = topLevelItem(idx)) - if (QTreeWidgetItem* embedItem = groupItem->child(0)) - rc = qobject_cast<SampleToolBoxGroupView*>(itemWidget(embedItem, 0)); - ASSERT(rc); - return rc; -} - -void SampleToolBoxTreeWidget::handleMousePress(QTreeWidgetItem* item) -{ - if (item == nullptr) - return; - - if (QApplication::mouseButtons() != Qt::LeftButton) - return; - - if (item->parent() == nullptr) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) - item->setExpanded(!item->isExpanded()); -#else - setItemExpanded(item, !isItemExpanded(item)); -#endif - return; - } -} - -void SampleToolBoxTreeWidget::addGroupView(QTreeWidgetItem* parent, bool iconMode) -{ - auto* embed_item = new QTreeWidgetItem(parent); - embed_item->setFlags(Qt::ItemIsEnabled); - auto* view = new SampleToolBoxGroupView(this); - view->setViewMode(iconMode ? QListView::IconMode : QListView::ListMode); - connect(view, &SampleToolBoxGroupView::pressed, this, &SampleToolBoxTreeWidget::pressed); - setItemWidget(embed_item, 0, view); -} - -void SampleToolBoxTreeWidget::adjustSubListSize(QTreeWidgetItem* groupItem) -{ - QTreeWidgetItem* embedItem = groupItem->child(0); - if (embedItem == nullptr) - return; - - auto* list_widget = dynamic_cast<SampleToolBoxGroupView*>(itemWidget(embedItem, 0)); - list_widget->setFixedWidth(header()->width()); - list_widget->doItemsLayout(); - const int height = qMax(list_widget->contentsSize().height(), 1); - list_widget->setFixedHeight(height); - embedItem->setSizeHint(0, QSize(-1, height - 1)); -} - -void SampleToolBoxTreeWidget::slotListMode() -{ - m_iconMode = false; - updateViewMode(); -} - -void SampleToolBoxTreeWidget::slotIconMode() -{ - m_iconMode = true; - updateViewMode(); -} - -void SampleToolBoxTreeWidget::updateViewMode() -{ - if (const int numTopLevels = topLevelItemCount()) { - for (int i = numTopLevels - 1; i >= 0; --i) { - const QListView::ViewMode viewMode = - m_iconMode ? QListView::IconMode : QListView::ListMode; - SampleToolBoxGroupView* view = groupViewAt(i); - if (viewMode != view->viewMode()) { - view->setViewMode(viewMode); - adjustSubListSize(topLevelItem(i)); - } - } - } - updateGeometries(); -} - -void SampleToolBoxTreeWidget::resizeEvent(QResizeEvent* e) -{ - QTreeWidget::resizeEvent(e); - if (const int numTopLevels = topLevelItemCount()) { - for (int i = numTopLevels - 1; i >= 0; --i) - adjustSubListSize(topLevelItem(i)); - } -} - -void SampleToolBoxTreeWidget::contextMenuEvent(QContextMenuEvent* e) -{ - QMenu menu; - menu.addAction("Expand all", this, SLOT(expandAll())); - menu.addAction("Collapse all", this, SLOT(collapseAll())); - menu.addSeparator(); - - QAction* listModeAction = menu.addAction("List View"); - QAction* iconModeAction = menu.addAction("Icon View"); - listModeAction->setCheckable(true); - iconModeAction->setCheckable(true); - auto* viewModeGroup = new QActionGroup(&menu); - viewModeGroup->addAction(listModeAction); - viewModeGroup->addAction(iconModeAction); - if (m_iconMode) - iconModeAction->setChecked(true); - else - listModeAction->setChecked(true); - connect(listModeAction, &QAction::triggered, this, &SampleToolBoxTreeWidget::slotListMode); - connect(iconModeAction, &QAction::triggered, this, &SampleToolBoxTreeWidget::slotIconMode); - - e->accept(); - menu.exec(mapToGlobal(e->pos())); -} - -void SampleToolBoxTreeWidget::filter(const QString& f) -{ - const bool empty = f.isEmpty(); - QRegExp re = empty ? QRegExp() : QRegExp(f, Qt::CaseInsensitive, QRegExp::FixedString); - const int numTopLevels = topLevelItemCount(); - bool changed = false; - for (int i = 0; i < numTopLevels; i++) { - QTreeWidgetItem* tl = topLevelItem(i); - SampleToolBoxGroupView* groupView = groupViewAt(i); - // Anything changed? -> Enable the group - const int oldCount = groupView->count(SampleToolBoxGroupView::FILTERED); - groupView->filter(re); - const int newCount = groupView->count(SampleToolBoxGroupView::FILTERED); - if (oldCount != newCount) { - changed = true; - const bool groupEnabled = newCount > 0 || empty; - if (groupEnabled) { - groupView->adjustSize(); - adjustSubListSize(tl); - } - setRowHidden(i, QModelIndex(), !groupEnabled); - } - } - if (changed) - updateGeometries(); -} - -void SampleToolBoxTreeWidget::addGroup(const QString& title) -{ - auto* groupItem = new QTreeWidgetItem(); - groupItem->setText(0, title); - addTopLevelItem(groupItem); -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) - groupItem->setExpanded(true); -#else - setItemExpanded(groupItem, true); -#endif - - addGroupView(groupItem, m_iconMode); - adjustSubListSize(groupItem); -} - -void SampleToolBoxTreeWidget::addEntry(const QString& modelType, const QIcon& icon, - const QString& title, const QString& tooltip) -{ - const auto groupIndex = topLevelItemCount() - 1; - groupViewAt(groupIndex)->addEntry(title, icon, modelType, tooltip); - adjustSubListSize(topLevelItem(groupIndex)); -} diff --git a/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.h b/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.h deleted file mode 100644 index c13f7dfe6a5827921bcdcd60adda02089267b4f0..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleToolBoxTreeWidget.h +++ /dev/null @@ -1,60 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleToolBoxTreeWidget.h -//! @brief Defines class SampleToolBoxTreeWidget -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOXTREEWIDGET_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOXTREEWIDGET_H - -#include <QTreeWidget> - -class SampleToolBoxGroupView; - -//! A tree of groups inside the Sample Designer's Sample toolbox. -//! The toolbox is the selection are at the left side of the Sample Designer. -class SampleToolBoxTreeWidget : public QTreeWidget { - Q_OBJECT - -public: - explicit SampleToolBoxTreeWidget(QWidget* parent = nullptr); - - //! Adds a group at the end of the list - void addGroup(const QString& title); - - //! Adds an entry in the last group - void addEntry(const QString& modelType, const QIcon& icon, const QString& title, - const QString& tooltip); - - void filter(const QString&); - -signals: - void pressed(QString name, QString dom_xml, const QPoint& global_mouse_pos); - -protected: - void contextMenuEvent(QContextMenuEvent* e) override; - void resizeEvent(QResizeEvent* e) override; - -private: - void handleMousePress(QTreeWidgetItem* item); - void slotListMode(); - void slotIconMode(); - - void addGroupView(QTreeWidgetItem* parent, bool iconMode); - SampleToolBoxGroupView* groupViewAt(int idx) const; - void adjustSubListSize(QTreeWidgetItem* groupItem); - void updateViewMode(); - -private: - bool m_iconMode; -}; - -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETOOLBOXTREEWIDGET_H diff --git a/GUI/View/SampleDesigner/SampleTreeWidget.cpp b/GUI/View/SampleDesigner/SampleTreeWidget.cpp deleted file mode 100644 index d5c4dc96d35f353d97710374c92697629cf23298..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleTreeWidget.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleTreeWidget.cpp -//! @brief Implements class SampleTreeWidget -//! -//! @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/SampleDesigner/SampleTreeWidget.h" -#include "GUI/Model/Group/FilterPropertyProxy.h" -#include "GUI/Model/Group/ItemCatalog.h" -#include "GUI/Model/Sample/SampleModel.h" -#include "GUI/View/SampleDesigner/ItemTreeView.h" -#include <QAction> -#include <QMenu> -#include <QVBoxLayout> - -SampleTreeWidget::SampleTreeWidget(QWidget* parent, SampleModel* model) - : QWidget(parent), m_treeView(new ItemTreeView), m_sampleModel(model) -{ - setWindowTitle("Sample Tree"); - setObjectName(QLatin1String("SampleTreeWidget")); - - auto* mainLayout = new QVBoxLayout; - mainLayout->setMargin(0); - mainLayout->setSpacing(0); - mainLayout->setContentsMargins(0, 0, 0, 0); - mainLayout->addWidget(m_treeView); - setLayout(mainLayout); - - auto* proxy = new FilterPropertyProxy(1, parent); - proxy->setSourceModel(m_sampleModel); - m_treeView->setModel(proxy); - m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false); - - connect(m_treeView, &ItemTreeView::customContextMenuRequested, this, - &SampleTreeWidget::showContextMenu); - - m_delete_item_action = new QAction("Delete", this); - m_delete_item_action->setStatusTip("Delete current object"); - connect(m_delete_item_action, &QAction::triggered, this, &SampleTreeWidget::deleteItem); - - m_treeView->expandAll(); - connect(m_treeView->model(), &QAbstractItemModel::rowsInserted, this, - [this]() { m_treeView->expandAll(); }); -} - -QTreeView* SampleTreeWidget::treeView() -{ - return m_treeView; -} - -void SampleTreeWidget::showContextMenu(const QPoint& pnt) -{ - QMenu menu; - QMenu add_menu("Add"); - QVector<QString> addItemNames; - QModelIndex parent_index = FilterPropertyProxy::toSourceIndex(treeView()->indexAt(pnt)); - treeView()->setCurrentIndex(parent_index); - if (!parent_index.isValid()) { - addItemNames = ItemCatalog::validTopItemTypes().toVector(); - } else { - addItemNames = m_sampleModel->acceptableDefaultItemTypes(parent_index); - } - if (!addItemNames.empty()) { - for (const QString& item_name : addItemNames) { - QAction* add_action = nullptr; - if (m_add_action_map.contains(item_name)) { - add_action = m_add_action_map[item_name]; - } else { - add_action = new QAction(item_name, this); - m_add_action_map[item_name] = add_action; - connect(add_action, &QAction::triggered, [=] { addItem(item_name); }); - } - add_menu.addAction(add_action); - } - menu.addMenu(&add_menu); - } - if (parent_index.isValid()) { - menu.addAction(m_delete_item_action); - } - if (!menu.isEmpty()) { - menu.exec(treeView()->mapToGlobal(pnt)); - } -} - -void SampleTreeWidget::addItem(const QString& item_name) -{ - QModelIndex currentIndex = FilterPropertyProxy::toSourceIndex(treeView()->currentIndex()); - - QModelIndex currentIndexAtColumnZero = getIndexAtColumnZero(currentIndex); - SessionItem* new_item = m_sampleModel->insertNewItem(item_name, currentIndexAtColumnZero); - if (new_item) { - QModelIndex new_index = m_sampleModel->indexOfItem(new_item); - scrollToIndex(new_index); - } -} - -void SampleTreeWidget::deleteItem() -{ - QModelIndex currentIndex = FilterPropertyProxy::toSourceIndex(treeView()->currentIndex()); - - if (!currentIndex.isValid()) - return; - QModelIndex parent_index = m_sampleModel->parent(currentIndex); - int row = currentIndex.row(); - if (currentIndex.isValid()) { - m_sampleModel->removeRows(row, 1, parent_index); - } -} - -void SampleTreeWidget::scrollToIndex(const QModelIndex& index) -{ - if (index.isValid()) { - treeView()->scrollTo(index); - } -} - -QModelIndex SampleTreeWidget::getIndexAtColumnZero(const QModelIndex& index) -{ - if (index == QModelIndex() || index.column() == 0) - return index; - QModelIndex parent_index = m_sampleModel->parent(index); - return m_sampleModel->index(index.row(), 0, parent_index); -} diff --git a/GUI/View/SampleDesigner/SampleTreeWidget.h b/GUI/View/SampleDesigner/SampleTreeWidget.h deleted file mode 100644 index 0d5659e4e0fce00d2390c18997f0ee63216d8100..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleTreeWidget.h +++ /dev/null @@ -1,52 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleTreeWidget.h -//! @brief Defines class SampleTreeWidget -//! -//! @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_SAMPLEDESIGNER_SAMPLETREEWIDGET_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETREEWIDGET_H - -#include <QMap> -#include <QWidget> - -class ItemTreeView; -class SampleModel; -class QTreeView; -class QPoint; -class QAction; - -//! Holds tree to select top level sample items. Part of SampleView. - -class SampleTreeWidget : public QWidget { - Q_OBJECT -public: - SampleTreeWidget(QWidget* parent, SampleModel* model); - - QTreeView* treeView(); - -protected slots: - void showContextMenu(const QPoint& pnt); - void addItem(const QString& item_name); - void deleteItem(); - -private: - void scrollToIndex(const QModelIndex& index); - QModelIndex getIndexAtColumnZero(const QModelIndex& index); - - QMap<QString, QAction*> m_add_action_map; - QAction* m_delete_item_action; - - ItemTreeView* m_treeView; - SampleModel* m_sampleModel; -}; - -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLETREEWIDGET_H