Skip to content
Snippets Groups Projects
Commit 91aacb1e authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

MaskEditor responsibility is moved to InstrumentView

parent 3a102b26
No related branches found
No related tags found
No related merge requests found
Showing
with 130 additions and 53 deletions
......@@ -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());
......
......@@ -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();
......
......@@ -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);
}
......@@ -34,8 +34,11 @@ public:
QGridLayout *getGridLayout() { return m_gridLayout;}
signals:
void extendedDetectorEditorRequest(DetectorItem *);
private slots:
void onExtendedEditorRequest();
void onGroupBoxExtendedButton();
private:
GroupBox *m_groupBox;
......
......@@ -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);
}
......@@ -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;
};
......
......@@ -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)
......
......@@ -34,6 +34,9 @@ public:
void setBeamItem(BeamItem *beamItem);
void setDetectorItem(DetectorItem *detectorItem);
signals:
void extendedDetectorEditorRequest(DetectorItem *);
private:
BeamEditorWidget *m_beamEditor;
DetectorEditorWidget *m_detectorEditor;
......
......@@ -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();
}
......
......@@ -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 &);
......
......@@ -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);
}
}
......@@ -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)
{
......
......@@ -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:
......
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