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

InstrumentView is cleaned from obsolete actions and buttons.

parent 1dfb23f8
No related branches found
No related tags found
No related merge requests found
...@@ -19,68 +19,43 @@ ...@@ -19,68 +19,43 @@
#include "InstrumentEditorWidget.h" #include "InstrumentEditorWidget.h"
#include "InstrumentModel.h" #include "InstrumentModel.h"
#include "InstrumentSelectorWidget.h" #include "InstrumentSelectorWidget.h"
#include "StyledToolBar.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "DetectorItems.h" #include "InstrumentViewToolBar.h"
#include <QAction> #include "InstrumentViewActions.h"
#include <QLabel>
#include <QBoxLayout> #include <QBoxLayout>
#include <QListView>
#include <QStackedWidget>
#include <QToolButton>
InstrumentView::InstrumentView(MainWindow *mainWindow) InstrumentView::InstrumentView(MainWindow* mainWindow)
: QWidget(mainWindow) : QWidget(mainWindow), m_actions(new InstrumentViewActions),
, m_instrumentModel(mainWindow->instrumentModel()) m_toolBar(new InstrumentViewToolBar(m_actions, this)),
, m_toolBar(new StyledToolBar(this)) m_instrumentSelector(new InstrumentSelectorWidget),
, m_instrumentSelector(new InstrumentSelectorWidget(m_instrumentModel, this)) m_instrumentEditor(new ItemStackPresenter<InstrumentEditorWidget>(true)),
, m_instrumentEditor(new ItemStackPresenter<InstrumentEditorWidget>(true)) m_instrumentModel(mainWindow->instrumentModel())
, m_addInstrumentAction(0)
, m_removeInstrumentAction(0)
, m_addInstrumentButton(0)
, m_removeInstrumentButton(0)
{ {
QVBoxLayout *mainLayout = new QVBoxLayout; QHBoxLayout* horizontalLayout = new QHBoxLayout;
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(m_instrumentSelector); horizontalLayout->addWidget(m_instrumentSelector);
horizontalLayout->addWidget(m_instrumentEditor, 1); horizontalLayout->addWidget(m_instrumentEditor, 1);
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->addWidget(m_toolBar); mainLayout->addWidget(m_toolBar);
mainLayout->addLayout(horizontalLayout); mainLayout->addLayout(horizontalLayout);
setLayout(mainLayout); setLayout(mainLayout);
setupActions(); m_instrumentSelector->setModel(m_instrumentModel);
m_actions->setModel(m_instrumentModel);
m_actions->setSelectionModel(m_instrumentSelector->selectionModel());
if(m_instrumentModel->rowCount(QModelIndex()) == 0) connect(m_instrumentSelector, SIGNAL(contextMenuRequest(const QPoint&, const QModelIndex&)),
onAddInstrument(); m_actions, SLOT(onContextMenuRequest(const QPoint&, const QModelIndex&)));
connect(m_instrumentSelector, SIGNAL(selectionChanged(SessionItem*)), connect(m_instrumentSelector, SIGNAL(selectionChanged(SessionItem*)), this,
this, SLOT(onItemSelectionChanged(SessionItem*))); SLOT(onItemSelectionChanged(SessionItem*)));
} }
void InstrumentView::onExtendedDetectorEditorRequest(DetectorItem* detectorItem)
void InstrumentView::onAddInstrument()
{ {
SessionItem *instrument = m_instrumentModel->insertNewItem(Constants::InstrumentType); auto dialog = new ExtendedDetectorDialog(this);
instrument->setItemName(getNewInstrumentName("Default GISAS"));
m_instrumentSelector->updateSelection();
}
void InstrumentView::onRemoveInstrument()
{
QModelIndex currentIndex = m_instrumentSelector->selectionModel()->currentIndex();
if(currentIndex.isValid())
m_instrumentModel->removeRows(currentIndex.row(), 1, QModelIndex());
m_instrumentSelector->updateSelection();
}
void InstrumentView::onExtendedDetectorEditorRequest(DetectorItem *detectorItem)
{
ExtendedDetectorDialog *dialog = new ExtendedDetectorDialog(this);
dialog->setDetectorContext(m_instrumentModel, detectorItem); dialog->setDetectorContext(m_instrumentModel, detectorItem);
dialog->show(); dialog->show();
} }
...@@ -89,7 +64,7 @@ void InstrumentView::onItemSelectionChanged(SessionItem* instrumentItem) ...@@ -89,7 +64,7 @@ void InstrumentView::onItemSelectionChanged(SessionItem* instrumentItem)
{ {
m_instrumentEditor->setItem(instrumentItem); m_instrumentEditor->setItem(instrumentItem);
if(auto widget = m_instrumentEditor->currentWidget()) if (auto widget = m_instrumentEditor->currentWidget())
widget->setInstrumentItem(instrumentItem); widget->setInstrumentItem(instrumentItem);
} }
...@@ -97,83 +72,3 @@ void InstrumentView::showEvent(QShowEvent*) ...@@ -97,83 +72,3 @@ void InstrumentView::showEvent(QShowEvent*)
{ {
m_instrumentSelector->updateSelection(); m_instrumentSelector->updateSelection();
} }
void InstrumentView::setupActions()
{
m_addInstrumentButton = new QToolButton;
m_addInstrumentButton->setText("Add instrument");
m_addInstrumentButton->setIcon(QIcon(":/images/toolbar_newitem.png"));
m_addInstrumentButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_addInstrumentButton->setToolTip("Add new instrument");
connect(m_addInstrumentButton, SIGNAL(clicked()), this, SLOT(onAddInstrument()));
m_toolBar->addWidget(m_addInstrumentButton);
m_toolBar->addWidget(new QLabel(" "));
m_toolBar->addSeparator();
m_toolBar->addWidget(new QLabel(" "));
m_removeInstrumentButton = new QToolButton;
m_removeInstrumentButton->setText("Remove instrument");
m_removeInstrumentButton->setIcon(QIcon(":/SampleDesigner/images/toolbar_recycle.png"));
m_removeInstrumentButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_removeInstrumentButton->setToolTip("Remove currently selected instrument");
connect(m_removeInstrumentButton, SIGNAL(clicked()), this, SLOT(onRemoveInstrument()));
m_toolBar->addWidget(m_removeInstrumentButton);
m_toolBar->addWidget(new QLabel(" "));
m_toolBar->addSeparator();
m_toolBar->addWidget(new QLabel(" "));
m_addInstrumentAction
= new QAction(QIcon(":/images/toolbar_newitem_dark.png"), "Add new instrument", this);
connect(m_addInstrumentAction, SIGNAL(triggered()), this, SLOT(onAddInstrument()));
m_removeInstrumentAction
= new QAction(QIcon(":/SampleDesigner/images/toolbar_recycle_dark.png"),
"Remove currently selected instrument", this);
connect(m_removeInstrumentAction, SIGNAL(triggered()), this, SLOT(onRemoveInstrument()));
m_instrumentSelector->listView()->setContextMenuPolicy(Qt::ActionsContextMenu);
m_instrumentSelector->listView()->addAction(m_addInstrumentAction);
m_instrumentSelector->listView()->addAction(m_removeInstrumentAction);
}
//! returns name of instrument which is based on suggested name
//! If "Default GISAS" name already exists, then "Default GISAS (2)" will be proposed.
QString InstrumentView::getNewInstrumentName(const QString &name)
{
updateMapOfNames();
int ncopies = m_name_to_copy[name];
if(ncopies == 0) {
m_name_to_copy[name]=1;
return name;
}
else {
m_name_to_copy[name]++;
return QString("%1 (%2)").arg(name).arg(m_name_to_copy[name]);
}
}
//! construct map of instrument names defined in the model together with number
//! of copies
void InstrumentView::updateMapOfNames()
{
m_name_to_copy.clear();
QModelIndex parentIndex;
for( int i_row = 0; i_row < m_instrumentModel->rowCount( parentIndex ); ++i_row) {
QModelIndex itemIndex = m_instrumentModel->index( i_row, 0, parentIndex );
QString name = m_instrumentModel->itemForIndex(itemIndex)->itemName();
int ncopy(1);
QRegExp regexp("\\((.*)\\)");
if(regexp.indexIn(name) >= 0) {
ncopy = regexp.cap(1).toInt();
}
name.replace(regexp.cap(0),"");
name = name.trimmed();
m_name_to_copy[name] = ncopy;
}
}
...@@ -19,30 +19,25 @@ ...@@ -19,30 +19,25 @@
#include "WinDllMacros.h" #include "WinDllMacros.h"
#include "ItemStackPresenter.h" #include "ItemStackPresenter.h"
#include <QMap>
#include <QWidget> #include <QWidget>
class MainWindow; class MainWindow;
class DetectorItem;
class InstrumentViewActions;
class InstrumentViewToolBar;
class InstrumentSelectorWidget; class InstrumentSelectorWidget;
class InstrumentEditorWidget; class InstrumentEditorWidget;
class InstrumentModel; class InstrumentModel;
class QItemSelection;
class SessionItem;
class QToolButton;
class DetectorItem;
class ShowEvent;
class BA_CORE_API_ InstrumentView : public QWidget class BA_CORE_API_ InstrumentView : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
InstrumentView(MainWindow *mainWindow); InstrumentView(MainWindow* mainWindow);
public slots: public slots:
void onAddInstrument(); void onExtendedDetectorEditorRequest(DetectorItem* detectorItem);
void onRemoveInstrument();
void onExtendedDetectorEditorRequest(DetectorItem *detectorItem);
private slots: private slots:
void onItemSelectionChanged(SessionItem* instrumentItem); void onItemSelectionChanged(SessionItem* instrumentItem);
...@@ -51,23 +46,11 @@ protected: ...@@ -51,23 +46,11 @@ protected:
void showEvent(QShowEvent*); void showEvent(QShowEvent*);
private: private:
void setupActions(); InstrumentViewActions* m_actions;
QString getNewInstrumentName(const QString &name); InstrumentViewToolBar* m_toolBar;
void updateMapOfNames(); InstrumentSelectorWidget* m_instrumentSelector;
ItemStackPresenter<InstrumentEditorWidget>* m_instrumentEditor;
InstrumentModel *m_instrumentModel; InstrumentModel* m_instrumentModel;
class StyledToolBar *m_toolBar;
InstrumentSelectorWidget *m_instrumentSelector;
ItemStackPresenter<InstrumentEditorWidget> *m_instrumentEditor;
QAction *m_addInstrumentAction;
QAction *m_removeInstrumentAction;
QToolButton *m_addInstrumentButton;
QToolButton *m_removeInstrumentButton;
QMap<QString, int> m_name_to_copy;
}; };
#endif // INSTRUMENTVIEW_H #endif // INSTRUMENTVIEW_H
...@@ -28,7 +28,7 @@ class BA_CORE_API_ InstrumentSelectorWidget : public ItemSelectorWidget ...@@ -28,7 +28,7 @@ class BA_CORE_API_ InstrumentSelectorWidget : public ItemSelectorWidget
Q_OBJECT Q_OBJECT
public: public:
InstrumentSelectorWidget(InstrumentModel* model, QWidget* parent = 0); InstrumentSelectorWidget(InstrumentModel* model = 0, QWidget* parent = 0);
QSize sizeHint() const; QSize sizeHint() const;
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
......
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