From aac99f372982b3f0b6439a6b967a3b0e085dc3a9 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Wed, 29 Nov 2017 15:28:50 +0100
Subject: [PATCH] Cleanup in some method renaming in MaterialEditor.

---
 GUI/coregui/Models/ComponentProxyModel.cpp    | 46 ++-------------
 GUI/coregui/Models/ComponentProxyModel.h      |  6 --
 .../Views/MaterialEditor/MaterialEditor.cpp   | 11 ++--
 .../Views/MaterialEditor/MaterialEditor.h     |  6 +-
 .../MaterialEditor/MaterialEditorDialog.cpp   |  8 +--
 .../MaterialEditor/MaterialEditorDialog.h     |  4 +-
 .../MaterialEditor/MaterialEditorToolBar.cpp  | 59 ++++++++-----------
 .../MaterialEditor/MaterialEditorToolBar.h    | 21 +++----
 .../MaterialEditor/MaterialItemUtils.cpp      |  4 +-
 9 files changed, 56 insertions(+), 109 deletions(-)

diff --git a/GUI/coregui/Models/ComponentProxyModel.cpp b/GUI/coregui/Models/ComponentProxyModel.cpp
index b244bee1af5..0efe56a0a86 100644
--- a/GUI/coregui/Models/ComponentProxyModel.cpp
+++ b/GUI/coregui/Models/ComponentProxyModel.cpp
@@ -19,7 +19,7 @@
 #include "ModelUtils.h"
 #include "ComponentProxyStrategy.h"
 #include <functional>
-#include <QDebug>
+#include <QSet>
 
 ComponentProxyModel::ComponentProxyModel(QObject* parent)
     : QAbstractProxyModel(parent)
@@ -36,12 +36,6 @@ void ComponentProxyModel::setSessionModel(SessionModel* model)
     if (sourceModel()) {
         disconnect(sourceModel(), &QAbstractItemModel::dataChanged,
                    this, &ComponentProxyModel::sourceDataChanged);
-        disconnect(sourceModel(), &QAbstractItemModel::layoutAboutToBeChanged,
-                   this, &ComponentProxyModel::sourceLayoutAboutToBeChanged);
-        disconnect(sourceModel(), &QAbstractItemModel::layoutChanged,
-                   this, &ComponentProxyModel::sourceLayoutChanged);
-        disconnect(sourceModel(), &QAbstractItemModel::rowsAboutToBeInserted,
-                   this, &ComponentProxyModel::sourceRowsAboutToBeInserted);
         disconnect(sourceModel(), &QAbstractItemModel::rowsInserted,
                    this, &ComponentProxyModel::sourceRowsInserted);
         disconnect(sourceModel(), &QAbstractItemModel::rowsRemoved,
@@ -54,12 +48,6 @@ void ComponentProxyModel::setSessionModel(SessionModel* model)
     if (sourceModel()) {
         connect(sourceModel(), &QAbstractItemModel::dataChanged,
                    this, &ComponentProxyModel::sourceDataChanged);
-        connect(sourceModel(), &QAbstractItemModel::layoutAboutToBeChanged,
-                   this, &ComponentProxyModel::sourceLayoutAboutToBeChanged);
-        connect(sourceModel(), &QAbstractItemModel::layoutChanged,
-                   this, &ComponentProxyModel::sourceLayoutChanged);
-        connect(sourceModel(), &QAbstractItemModel::rowsAboutToBeInserted,
-                   this, &ComponentProxyModel::sourceRowsAboutToBeInserted);
         connect(sourceModel(), &QAbstractItemModel::rowsInserted,
                    this, &ComponentProxyModel::sourceRowsInserted);
         connect(sourceModel(), &QAbstractItemModel::rowsRemoved,
@@ -171,45 +159,19 @@ void ComponentProxyModel::sourceDataChanged(const QModelIndex& topLeft,
     dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight), roles);
 }
 
-void ComponentProxyModel::sourceLayoutAboutToBeChanged(
-    const QList<QPersistentModelIndex>& sourceParents, QAbstractItemModel::LayoutChangeHint hint)
-{
-    Q_UNUSED(sourceParents);
-    Q_UNUSED(hint);
-    qDebug() << "ComponentProxyModel::sourceLayoutAboutToBeChanged";
-}
-
-void ComponentProxyModel::sourceLayoutChanged(const QList<QPersistentModelIndex>& sourceParents,
-                                              QAbstractItemModel::LayoutChangeHint hint)
-{
-    Q_UNUSED(sourceParents);
-    Q_UNUSED(hint);
-    qDebug() << "ComponentProxyModel::sourceLayoutChanged";
-}
-
-void ComponentProxyModel::sourceRowsAboutToBeInserted(const QModelIndex& parent, int start, int end)
-{
-    Q_UNUSED(parent);
-    Q_UNUSED(start);
-    Q_UNUSED(end);
-
-    qDebug() << "ComponentProxyModel::sourceRowsAboutToBeInserted";
-//    buildModelMap();
-}
-
 void ComponentProxyModel::sourceRowsInserted(const QModelIndex& parent, int start, int end)
 {
     Q_UNUSED(parent);
     Q_UNUSED(start);
     Q_UNUSED(end);
-
-    qDebug() << "ComponentProxyModel::sourceRowsInserted";
     buildModelMap();
 }
 
 void ComponentProxyModel::sourceRowsRemoved(const QModelIndex& parent, int start, int end)
 {
-    qDebug() << "ComponentProxyModel::sourceRowsRemoved";
+    Q_UNUSED(parent);
+    Q_UNUSED(start);
+    Q_UNUSED(end);
     buildModelMap();
 }
 
diff --git a/GUI/coregui/Models/ComponentProxyModel.h b/GUI/coregui/Models/ComponentProxyModel.h
index 786077b0ae6..8ecd5b7a84c 100644
--- a/GUI/coregui/Models/ComponentProxyModel.h
+++ b/GUI/coregui/Models/ComponentProxyModel.h
@@ -60,12 +60,6 @@ public:
 private slots:
     void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
                              const QVector<int> &roles = QVector<int>());
-    void sourceLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &sourceParents,
-                                      QAbstractItemModel::LayoutChangeHint hint);
-    void sourceLayoutChanged(const QList<QPersistentModelIndex> &sourceParents,
-                             QAbstractItemModel::LayoutChangeHint hint);
-
-    void sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
     void sourceRowsInserted(const QModelIndex &parent, int start, int end);
     void sourceRowsRemoved(const QModelIndex &parent, int start, int end);
 
diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp b/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp
index 3f7b5a1386e..682308a5062 100644
--- a/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp
+++ b/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp
@@ -60,10 +60,10 @@ QItemSelectionModel* MaterialEditor::selectionModel()
     return m_listView->selectionModel();
 }
 
-MaterialItem* MaterialEditor::getSelectedMaterial()
+MaterialItem* MaterialEditor::selectedMaterial()
 {
-    QModelIndexList selected = selectionModel()->selectedIndexes();
-    return selected.empty() ? nullptr : m_materialModel->getMaterial(selected.front());
+    auto selected = selectionModel()->currentIndex();
+    return selected.isValid() ? m_materialModel->getMaterial(selected) : nullptr;
 }
 
 //! Sets selection corresponding to initial material property
@@ -75,7 +75,7 @@ void MaterialEditor::setInitialMaterialProperty(const MaterialProperty& matPrope
     }
 }
 
-bool MaterialEditor::isModelWasModified() const
+bool MaterialEditor::modelWasChanged() const
 {
     return m_model_was_modified;
 }
@@ -115,7 +115,6 @@ void MaterialEditor::contextMenuEvent(QContextMenuEvent* event)
 
 void MaterialEditor::init_views()
 {
-    // connecting to the model
     connect(m_materialModel, &MaterialModel::dataChanged, this, &MaterialEditor::onDataChanged);
     connect(m_materialModel, &MaterialModel::rowsInserted, this, &MaterialEditor::onRowsInserted);
     connect(m_materialModel, &MaterialModel::rowsRemoved, this, &MaterialEditor::onRowsRemoved);
@@ -135,7 +134,7 @@ void MaterialEditor::init_views()
     // making first material selected
     if (!selectionModel()->hasSelection()) {
         QModelIndex itemIndex = m_materialModel->index(0, 0, QModelIndex());
-        selectionModel()->select(itemIndex, QItemSelectionModel::Select);
+        selectionModel()->select(itemIndex, QItemSelectionModel::ClearAndSelect);
     }
 
     connect(m_listView, &QListView::customContextMenuRequested,
diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditor.h b/GUI/coregui/Views/MaterialEditor/MaterialEditor.h
index 54275ab0f9c..a2063c507bc 100644
--- a/GUI/coregui/Views/MaterialEditor/MaterialEditor.h
+++ b/GUI/coregui/Views/MaterialEditor/MaterialEditor.h
@@ -41,14 +41,14 @@ public:
 
     QItemSelectionModel* selectionModel();
 
-    MaterialItem* getSelectedMaterial();
+    MaterialItem* selectedMaterial();
 
     void setInitialMaterialProperty(const MaterialProperty& matProperty);
 
-    bool isModelWasModified() const;
+    bool modelWasChanged() const;
 
 private slots:
-    void onSelectionChanged(const QItemSelection& selected, const QItemSelection&);
+    void onSelectionChanged(const QItemSelection&selected, const QItemSelection&);
     void onDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&);
     void onRowsInserted(const QModelIndex&, int, int);
     void onRowsRemoved(const QModelIndex&, int, int);
diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp
index a87cca40065..99876da4e3a 100644
--- a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp
+++ b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.cpp
@@ -53,7 +53,7 @@ MaterialEditorDialog::MaterialEditorDialog(MaterialModel* materialModel, QWidget
 //! replaces original material model with the model modified by MaterialEditor
 void MaterialEditorDialog::onOKButton()
 {
-    if (m_materialEditor->isModelWasModified()) {
+    if (m_materialEditor->modelWasChanged()) {
         m_origMaterialModel->clear();
         m_origMaterialModel->initFrom(m_tmpMaterialModel.get(), 0);
     }
@@ -116,16 +116,16 @@ void MaterialEditorDialog::writeSettings()
     settings.endGroup();
 }
 
-MaterialProperty MaterialEditorDialog::getSelectedMaterialProperty()
+MaterialProperty MaterialEditorDialog::selectedMaterialProperty()
 {
-    if (MaterialItem* material = m_materialEditor->getSelectedMaterial())
+    if (MaterialItem* material = m_materialEditor->selectedMaterial())
         return MaterialItemUtils::materialProperty(*material);
 
     return MaterialProperty();
 }
 
 //!
-void MaterialEditorDialog::setInitialMaterialProperty(const MaterialProperty& matProperty)
+void MaterialEditorDialog::setMaterialProperty(const MaterialProperty& matProperty)
 {
     Q_ASSERT(m_materialEditor);
 
diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h
index 12f85164c65..3bb080e93bc 100644
--- a/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h
+++ b/GUI/coregui/Views/MaterialEditor/MaterialEditorDialog.h
@@ -37,9 +37,9 @@ class BA_CORE_API_ MaterialEditorDialog : public QDialog
 public:
     MaterialEditorDialog(MaterialModel* materialModel, QWidget* parent = nullptr);
 
-    MaterialProperty getSelectedMaterialProperty();
+    MaterialProperty selectedMaterialProperty();
 
-    void setInitialMaterialProperty(const MaterialProperty& matProperty);
+    void setMaterialProperty(const MaterialProperty& matProperty);
 
 public slots:
     void onOKButton();
diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.cpp b/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.cpp
index 7f083300f87..42fcd4a2bbf 100644
--- a/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.cpp
+++ b/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.cpp
@@ -27,15 +27,13 @@ namespace {
 const int toolbar_icon_size = 32;
 }
 
-MaterialEditorToolBar::MaterialEditorToolBar(MaterialModel *materialModel,
-                                             QWidget *parent)
+MaterialEditorToolBar::MaterialEditorToolBar(MaterialModel* materialModel, QWidget* parent)
     : QToolBar(parent)
     , m_materialModel(materialModel)
-    , m_selectionModel(0)
-    , m_newMaterialAction(0)
-    , m_cloneMaterialAction(0)
-    , m_removeMaterialAction(0)
-
+    , m_selectionModel(nullptr)
+    , m_newMaterialAction(nullptr)
+    , m_cloneMaterialAction(nullptr)
+    , m_removeMaterialAction(nullptr)
 {
     setIconSize(QSize(toolbar_icon_size, toolbar_icon_size));
     setProperty("_q_custom_style_disabled", QVariant(true));
@@ -43,42 +41,37 @@ MaterialEditorToolBar::MaterialEditorToolBar(MaterialModel *materialModel,
     m_newMaterialAction = new QAction(QStringLiteral("Add new material"), parent);
     m_newMaterialAction->setIcon(QIcon(":/images/toolbar32dark_newitem.svg"));
     m_newMaterialAction->setToolTip(QStringLiteral("Add new material"));
-    connect(m_newMaterialAction, SIGNAL(triggered()), this,
-            SLOT(onNewMaterialAction()));
+    connect(m_newMaterialAction, &QAction::triggered,
+            this, &MaterialEditorToolBar::onNewMaterialAction);
     addAction(m_newMaterialAction);
 
     m_cloneMaterialAction = new QAction(QStringLiteral("Clone material"), parent);
-    m_cloneMaterialAction->setIcon(
-        QIcon(":/images/toolbar32dark_cloneitem.svg"));
+    m_cloneMaterialAction->setIcon(QIcon(":/images/toolbar32dark_cloneitem.svg"));
     m_cloneMaterialAction->setToolTip(QStringLiteral("Clone selected material"));
-    connect(m_cloneMaterialAction, SIGNAL(triggered()), this,
-            SLOT(onCloneMaterialAction()));
+    connect(m_cloneMaterialAction, &QAction::triggered,
+            this, &MaterialEditorToolBar::onCloneMaterialAction);
     addAction(m_cloneMaterialAction);
 
     m_removeMaterialAction = new QAction(QStringLiteral("Remove selected material"), parent);
     m_removeMaterialAction->setIcon(QIcon(":/images/toolbar32dark_remove.svg"));
     m_removeMaterialAction->setToolTip(QStringLiteral("Remove selected material"));
-    connect(m_removeMaterialAction, SIGNAL(triggered()), this,
-            SLOT(onRemoveMaterialAction()));
+    connect(m_removeMaterialAction, &QAction::triggered,
+            this, &MaterialEditorToolBar::onRemoveMaterialAction);
     addAction(m_removeMaterialAction);
 }
 
-void MaterialEditorToolBar::setSelectionModel(QItemSelectionModel *selectionModel)
+void MaterialEditorToolBar::setSelectionModel(QItemSelectionModel* selectionModel)
 {
     m_selectionModel = selectionModel;
 }
 
-void MaterialEditorToolBar::onCustomContextMenuRequested(const QPoint &point)
+void MaterialEditorToolBar::onCustomContextMenuRequested(const QPoint& point)
 {
-    QListView *listView = qobject_cast<QListView *>(sender());
+    QListView* listView = qobject_cast<QListView*>(sender());
     Q_ASSERT(listView);
-    QPoint global = listView->mapToGlobal(point);
-
     QMenu menu;
     initItemContextMenu(menu);
-    menu.exec(global);
-//    setAllActionsEnabled(true);
-
+    menu.exec(listView->mapToGlobal(point));
 }
 
 void MaterialEditorToolBar::onNewMaterialAction()
@@ -88,11 +81,10 @@ void MaterialEditorToolBar::onNewMaterialAction()
 
 void MaterialEditorToolBar::onCloneMaterialAction()
 {
-    QModelIndexList selected = m_selectionModel->selectedIndexes();
-    if(selected.size()) {
-        QModelIndex selectedIndex = selected.front();
-        m_materialModel->cloneMaterial(selectedIndex);
-    }
+    auto selected = m_selectionModel->currentIndex();
+
+    if (selected.isValid())
+        m_materialModel->cloneMaterial(selected);
 }
 
 void MaterialEditorToolBar::onRemoveMaterialAction()
@@ -100,17 +92,16 @@ void MaterialEditorToolBar::onRemoveMaterialAction()
     Q_ASSERT(m_materialModel);
     Q_ASSERT(m_selectionModel);
 
-    QModelIndexList selected = m_selectionModel->selectedIndexes();
-    if(selected.size()) {
-        m_materialModel->removeRows(selected.front().row(), 1, selected.back().parent());
-    }
+    auto selected = m_selectionModel->currentIndex();
+
+    if (selected.isValid())
+        m_materialModel->removeRows(selected.row(), 1, selected.parent());
 }
 
-void MaterialEditorToolBar::initItemContextMenu(QMenu &menu)
+void MaterialEditorToolBar::initItemContextMenu(QMenu& menu)
 {
     menu.addAction(m_newMaterialAction);
     menu.addAction(m_cloneMaterialAction);
     menu.addSeparator();
     menu.addAction(m_removeMaterialAction);
-
 }
diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.h b/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.h
index 74871999969..1302e882819 100644
--- a/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.h
+++ b/GUI/coregui/Views/MaterialEditor/MaterialEditorToolBar.h
@@ -26,17 +26,18 @@ class QItemSelectionModel;
 class QPoint;
 class QMenu;
 
-//! Main widget of MaterialEditor
+//! Toolbar for MaterialEditor.
+
 class BA_CORE_API_ MaterialEditorToolBar : public QToolBar
 {
     Q_OBJECT
 public:
-    MaterialEditorToolBar(MaterialModel *materialModel, QWidget *parent = 0);
+    MaterialEditorToolBar(MaterialModel* materialModel, QWidget* parent = nullptr);
 
-    void setSelectionModel(QItemSelectionModel *selectionModel);
+    void setSelectionModel(QItemSelectionModel* selectionModel);
 
 public slots:
-    void onCustomContextMenuRequested(const QPoint &point);
+    void onCustomContextMenuRequested(const QPoint& point);
 
 private slots:
     void onNewMaterialAction();
@@ -44,13 +45,13 @@ private slots:
     void onRemoveMaterialAction();
 
 private:
-    void initItemContextMenu(QMenu &menu);
+    void initItemContextMenu(QMenu& menu);
 
-    MaterialModel *m_materialModel;
-    QItemSelectionModel *m_selectionModel;
-    QAction *m_newMaterialAction;
-    QAction *m_cloneMaterialAction;
-    QAction *m_removeMaterialAction;
+    MaterialModel* m_materialModel;
+    QItemSelectionModel* m_selectionModel;
+    QAction* m_newMaterialAction;
+    QAction* m_cloneMaterialAction;
+    QAction* m_removeMaterialAction;
 };
 
 #endif // MATERIALEDITORTOOLBAR_H
diff --git a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp
index 2bf12a2d6d3..14e42f1e9b4 100644
--- a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp
+++ b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp
@@ -109,9 +109,9 @@ MaterialProperty MaterialItemUtils::materialProperty(const SessionItem& material
 MaterialProperty MaterialItemUtils::selectMaterialProperty(const MaterialProperty& previousMaterial)
 {
     MaterialEditorDialog dialog(AppSvc::materialModel());
-    dialog.setInitialMaterialProperty(previousMaterial);
+    dialog.setMaterialProperty(previousMaterial);
     if(dialog.exec() == QDialog::Accepted) {
-        return dialog.getSelectedMaterialProperty();
+        return dialog.selectedMaterialProperty();
     }
 
     return MaterialProperty();
-- 
GitLab