From 91aacb1efdea227c1c2dadf819fb102cd90da658 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Wed, 9 Dec 2015 10:39:34 +0100 Subject: [PATCH] MaskEditor responsibility is moved to InstrumentView --- GUI/coregui/Views/InstrumentView.cpp | 56 ++++++++++++++----- GUI/coregui/Views/InstrumentView.h | 5 +- .../DetectorEditorWidget.cpp | 11 ++-- .../InstrumentWidgets/DetectorEditorWidget.h | 5 +- .../ExtendedDetectorDialog.cpp | 6 ++ .../ExtendedDetectorDialog.h | 7 ++- .../InstrumentComponentsWidget.cpp | 7 +++ .../InstrumentComponentsWidget.h | 3 + .../InstrumentEditorWidget.cpp | 36 ++++++++++-- .../InstrumentEditorWidget.h | 4 ++ .../InstrumentSelectorWidget.cpp | 28 +++++----- GUI/coregui/Views/MaskWidgets/MaskEditor.cpp | 13 ++--- GUI/coregui/Views/MaskWidgets/MaskEditor.h | 2 +- 13 files changed, 130 insertions(+), 53 deletions(-) diff --git a/GUI/coregui/Views/InstrumentView.cpp b/GUI/coregui/Views/InstrumentView.cpp index 4a21aab73a2..55d88ac3577 100644 --- a/GUI/coregui/Views/InstrumentView.cpp +++ b/GUI/coregui/Views/InstrumentView.cpp @@ -18,6 +18,8 @@ #include "InstrumentSelectorWidget.h" #include "InstrumentEditorWidget.h" #include "InstrumentItem.h" +#include "ExtendedDetectorDialog.h" +#include "DetectorItems.h" #include "styledbar.h" #include "minisplitter.h" #include <QBoxLayout> @@ -56,16 +58,8 @@ InstrumentView::InstrumentView(InstrumentModel *model, QWidget *parent) mainLayout->addLayout(horizontalLayout); setLayout(mainLayout); - connect(m_instrumentSelector, - SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ), - this, - SLOT( onSelectionChanged(const QItemSelection&, const QItemSelection&) ) - ); - - connect(m_instrumentModel, SIGNAL(modelAboutToBeReset()), this, SLOT(resetView())); - connect(m_instrumentModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int,int)), this, SLOT(onRowsAboutToBeRemoved(QModelIndex,int,int))); - - createActions(); + setupConnections(); + setupActions(); if(m_instrumentModel->rowCount(QModelIndex()) == 0) onAddInstrument(); @@ -111,6 +105,12 @@ void InstrumentView::onSelectionChanged(const QItemSelection &selected, const QI if( !widget) { widget = new InstrumentEditorWidget(); + connect(widget, + SIGNAL(extendedDetectorEditorRequest(DetectorItem *)), + this, + SLOT(onExtendedDetectorEditorRequest(DetectorItem *)) + ); + widget->setInstrumentItem(instrument); m_stackWidget->addWidget(widget); m_instrumentToEditor[instrument] = widget; @@ -166,8 +166,35 @@ void InstrumentView::onRowsAboutToBeRemoved(QModelIndex parent, int first, int / delete widget; } +void InstrumentView::onExtendedDetectorEditorRequest(DetectorItem *) +{ + ExtendedDetectorDialog *dialog = new ExtendedDetectorDialog(this); + dialog->show(); +} + +void InstrumentView::setupConnections() +{ + connect(m_instrumentSelector, + SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ), + this, + SLOT( onSelectionChanged(const QItemSelection&, const QItemSelection&) ) + ); + + connect(m_instrumentModel, + SIGNAL(modelAboutToBeReset()), + this, + SLOT(resetView()) + ); + + connect(m_instrumentModel, + SIGNAL(rowsAboutToBeRemoved(QModelIndex, int,int)), + this, + SLOT(onRowsAboutToBeRemoved(QModelIndex,int,int)) + ); +} + -void InstrumentView::createActions() +void InstrumentView::setupActions() { m_addInstrumentButton = new QToolButton; m_addInstrumentButton->setText("Add instrument"); @@ -193,10 +220,13 @@ void InstrumentView::createActions() m_toolBar->addSeparator(); m_toolBar->addWidget(new QLabel(" ")); - m_addInstrumentAction = new QAction(QIcon(":/images/toolbar_newitem_dark.png"), tr("Add new instrument"), this); + m_addInstrumentAction + = new QAction(QIcon(":/images/toolbar_newitem_dark.png"), tr("Add new instrument"), this); connect(m_addInstrumentAction, SIGNAL(triggered()), this, SLOT(onAddInstrument())); - m_removeInstrumentAction = new QAction(QIcon(":/SampleDesigner/images/toolbar_recycle_dark.png"), tr("Remove currently selected instrument"), this); + m_removeInstrumentAction + = new QAction(QIcon(":/SampleDesigner/images/toolbar_recycle_dark.png"), + tr("Remove currently selected instrument"), this); connect(m_removeInstrumentAction, SIGNAL(triggered()), this, SLOT(onRemoveInstrument())); Q_ASSERT(m_instrumentSelector->getListView()); diff --git a/GUI/coregui/Views/InstrumentView.h b/GUI/coregui/Views/InstrumentView.h index 91a700bdcd8..3f93b576267 100644 --- a/GUI/coregui/Views/InstrumentView.h +++ b/GUI/coregui/Views/InstrumentView.h @@ -32,6 +32,7 @@ class QItemSelection; class ParameterizedItem; class QToolBar; class QToolButton; +class DetectorItem; namespace Manhattan{ class StyledBar; @@ -51,9 +52,11 @@ public slots: void onAddInstrument(); void onRemoveInstrument(); void onRowsAboutToBeRemoved(QModelIndex,int,int); + void onExtendedDetectorEditorRequest(DetectorItem *); private: - void createActions(); + void setupConnections(); + void setupActions(); QString getNewInstrumentName(const QString &name); void updateMapOfNames(); diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp index 83503e8ad6b..48912a6b1b7 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.cpp @@ -35,7 +35,7 @@ DetectorEditorWidget::DetectorEditorWidget(QWidget *parent) QVBoxLayout *groupLayout = new QVBoxLayout; m_groupBox->setButtonToolTip("Gives access to the detector mask editor"); m_groupBox->setLayout(groupLayout); - connect(m_groupBox, SIGNAL(clicked()), this, SLOT(onExtendedEditorRequest())); + connect(m_groupBox, SIGNAL(clicked()), this, SLOT(onGroupBoxExtendedButton())); // whole content is represented as grid layout m_gridLayout = new QGridLayout; @@ -92,11 +92,8 @@ void DetectorEditorWidget::setDetectorItem(DetectorItem *detectorItem) AwesomePropertyEditor::INSERT_AFTER); } -void DetectorEditorWidget::onExtendedEditorRequest() +void DetectorEditorWidget::onGroupBoxExtendedButton() { - ExtendedDetectorDialog *dialog = new ExtendedDetectorDialog(this); -// dialog->setItem(item); -// dialog->setNameOfEditor(name); - dialog->show(); - + emit extendedDetectorEditorRequest(m_detectorItem); } + diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h index 61540ca3a7e..24e9f0d339f 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorEditorWidget.h @@ -34,8 +34,11 @@ public: QGridLayout *getGridLayout() { return m_gridLayout;} +signals: + void extendedDetectorEditorRequest(DetectorItem *); + private slots: - void onExtendedEditorRequest(); + void onGroupBoxExtendedButton(); private: GroupBox *m_groupBox; diff --git a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp index 8857f73471b..2b1eb4f095a 100644 --- a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.cpp @@ -15,6 +15,7 @@ #include "ExtendedDetectorDialog.h" #include "MaskEditor.h" +#include "SessionModel.h" #include <QPushButton> #include <QVBoxLayout> @@ -48,3 +49,8 @@ ExtendedDetectorDialog::ExtendedDetectorDialog(QWidget *parent) m_maskEditor->init_test_model(); } + +void ExtendedDetectorDialog::setModel(SessionModel *model, const QModelIndex &rootIndex) +{ + m_maskEditor->setModel(model, rootIndex); +} diff --git a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h index d94bb318fdd..5d2655880ca 100644 --- a/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h +++ b/GUI/coregui/Views/InstrumentWidgets/ExtendedDetectorDialog.h @@ -19,6 +19,8 @@ #include <QDialog> class MaskEditor; +class SetModel; +class SessionModel; //! The dialog which shows an editor to change parameters of DistributionItem class ExtendedDetectorDialog : public QDialog @@ -29,11 +31,10 @@ public: ExtendedDetectorDialog(QWidget *parent = 0); virtual ~ExtendedDetectorDialog(){} -// void setItem(ParameterizedItem *item); -// void setNameOfEditor(const QString &name); +public slots: + void setModel(SessionModel *model, const QModelIndex &rootIndex); private: -// ExtendedDetectorDialog *m_editor; MaskEditor *m_maskEditor; }; diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp index 52bbe96e4d2..0c418ada1b6 100644 --- a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.cpp @@ -39,6 +39,13 @@ InstrumentComponentsWidget::InstrumentComponentsWidget(QWidget *parent) m_columnResizer->addWidgetsFromGridLayout(m_detectorEditor->getGridLayout(), 0); m_columnResizer->addWidgetsFromGridLayout(m_detectorEditor->getGridLayout(), 1); m_columnResizer->addWidgetsFromGridLayout(m_detectorEditor->getGridLayout(), 2); + + connect(m_detectorEditor, + SIGNAL(extendedDetectorEditorRequest(DetectorItem *)), + this, + SIGNAL(extendedDetectorEditorRequest(DetectorItem *)) + ); + } void InstrumentComponentsWidget::setBeamItem(BeamItem *beamItem) diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h index 7453256b617..3890f53b6cc 100644 --- a/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentComponentsWidget.h @@ -34,6 +34,9 @@ public: void setBeamItem(BeamItem *beamItem); void setDetectorItem(DetectorItem *detectorItem); +signals: + void extendedDetectorEditorRequest(DetectorItem *); + private: BeamEditorWidget *m_beamEditor; DetectorEditorWidget *m_detectorEditor; diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp index 0d21800fe6e..19dcd94a0fb 100644 --- a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.cpp @@ -111,7 +111,17 @@ InstrumentEditorWidget::InstrumentEditorWidget(QWidget *parent) mainLayout->addWidget(instrumentGroup); setLayout(mainLayout); - connect(m_nameLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(onChangedEditor(const QString &))); + connect(m_nameLineEdit, + SIGNAL(textChanged(const QString &)), + this, + SLOT(onChangedEditor(const QString &)) + ); + + connect(m_instrumentComponents, + SIGNAL(extendedDetectorEditorRequest(DetectorItem *)), + this, + SIGNAL(extendedDetectorEditorRequest(DetectorItem *)) + ); } void InstrumentEditorWidget::setInstrumentItem(ParameterizedItem *instrument) @@ -120,14 +130,30 @@ void InstrumentEditorWidget::setInstrumentItem(ParameterizedItem *instrument) if(instrument != m_currentItem) { if(m_currentItem) { - disconnect(m_currentItem, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - disconnect(m_currentItem, SIGNAL(subItemChanged(QString)), this, SLOT(onPropertyChanged(QString))); + disconnect(m_currentItem, + SIGNAL(propertyChanged(QString)), + this, + SLOT(onPropertyChanged(QString)) + ); + disconnect(m_currentItem, + SIGNAL(subItemChanged(QString)), + this, + SLOT(onPropertyChanged(QString)) + ); } m_currentItem = instrument; - connect(m_currentItem, SIGNAL(propertyChanged(QString)), this, SLOT(onPropertyChanged(QString))); - connect(m_currentItem, SIGNAL(subItemChanged(QString)), this, SLOT(onPropertyChanged(QString))); + connect(m_currentItem, + SIGNAL(propertyChanged(QString)), + this, + SLOT(onPropertyChanged(QString)) + ); + connect(m_currentItem, + SIGNAL(subItemChanged(QString)), + this, + SLOT(onPropertyChanged(QString)) + ); updateWidgets(); } diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h index f4bbecaf9ec..79051ebd2dc 100644 --- a/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentEditorWidget.h @@ -28,6 +28,7 @@ class BeamEditorWidget; class QLineEdit; class QComboBox; class InstrumentComponentsWidget; +class DetectorItem; class BA_CORE_API_ InstrumentEditorWidget : public QWidget { @@ -39,6 +40,9 @@ public: void setInstrumentItem(ParameterizedItem *instrument); +signals: + void extendedDetectorEditorRequest(DetectorItem *); + public slots: void onChangedEditor(const QString &); void onPropertyChanged(const QString &); diff --git a/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp b/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp index f6af34929b4..a6bf9d778bc 100644 --- a/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/InstrumentSelectorWidget.cpp @@ -65,17 +65,18 @@ void InstrumentSelectorWidget::setInstrumentModel(InstrumentModel *model) Q_ASSERT(m_listView); if(model != m_instrumentModel) { - if(m_instrumentModel) { - disconnect(m_instrumentModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(onRowsInserted(const QModelIndex &,int,int))); - } m_instrumentModel = model; - m_listView->setModel(model); - connect(m_listView->selectionModel(), - SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ), - this, - SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ) - ); + if(m_instrumentModel) { + m_listView->setModel(model); + + connect(m_listView->selectionModel(), + SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ), + this, + SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ), + Qt::UniqueConnection + ); + } } } @@ -90,12 +91,9 @@ QItemSelectionModel *InstrumentSelectorWidget::getSelectionModel() //! select last item if no selection exists void InstrumentSelectorWidget::updateSelection() { - qDebug() << "InstrumentSelectorWidget::updateSelection()" << m_instrumentModel->rowCount(QModelIndex()); - if(!getSelectionModel()->hasSelection()) { - QModelIndex itemIndex = m_instrumentModel->index(m_instrumentModel->rowCount(QModelIndex()) - 1,0,QModelIndex()); - qDebug() << " InstrumentSelectorWidget::updateSelection()" << itemIndex; + if (!getSelectionModel()->hasSelection()) { + QModelIndex itemIndex = m_instrumentModel->index( + m_instrumentModel->rowCount(QModelIndex()) - 1, 0, QModelIndex()); getSelectionModel()->select(itemIndex, QItemSelectionModel::Select); } } - - diff --git a/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp b/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp index dc9d4a57b53..7c49d08ec57 100644 --- a/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp +++ b/GUI/coregui/Views/MaskWidgets/MaskEditor.cpp @@ -52,16 +52,9 @@ MaskEditor::MaskEditor(QWidget *parent) setCentralWidget(m_splitter); -// init_test_model(); - setup_connections(); } -void MaskEditor::onPropertyPanelRequest() -{ - m_editorPropertyPanel->setPanelHidden(!m_editorPropertyPanel->isHidden()); -} - void MaskEditor::setModel(SessionModel *model, const QModelIndex &rootIndex) { m_editorPropertyPanel->setModel(model, rootIndex); @@ -73,6 +66,12 @@ void MaskEditor::setModel(SessionModel *model, const QModelIndex &rootIndex) m_itemActions->setSelectionModel(m_editorPropertyPanel->selectionModel()); } +//! shows/hides right panel with properties +void MaskEditor::onPropertyPanelRequest() +{ + m_editorPropertyPanel->setPanelHidden(!m_editorPropertyPanel->isHidden()); +} + //! Context menu reimplemented to supress default menu void MaskEditor::contextMenuEvent(QContextMenuEvent *event) { diff --git a/GUI/coregui/Views/MaskWidgets/MaskEditor.h b/GUI/coregui/Views/MaskWidgets/MaskEditor.h index 1c9456be8f4..5081279f7eb 100644 --- a/GUI/coregui/Views/MaskWidgets/MaskEditor.h +++ b/GUI/coregui/Views/MaskWidgets/MaskEditor.h @@ -36,8 +36,8 @@ public: MaskEditor(QWidget *parent = 0); public slots: - void onPropertyPanelRequest(); void setModel(SessionModel *model, const QModelIndex &rootIndex); + void onPropertyPanelRequest(); void init_test_model(); protected: -- GitLab