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

RealDataSelectorToolBar switched to new actions.

parent 29cd95b3
No related branches found
No related tags found
No related merge requests found
......@@ -56,6 +56,7 @@ void RealDataSelectorActions::setSelectionModel(QItemSelectionModel* selectionMo
void RealDataSelectorActions::onImportDataAction()
{
Q_ASSERT(m_realDataModel);
Q_ASSERT(m_selectionModel);
ImportDataAssistant assistant;
QString baseNameOfImportedFile;
......
......@@ -35,7 +35,7 @@ public:
void setRealDataModel(RealDataModel* model);
void setSelectionModel(QItemSelectionModel* selectionModel);
private slots:
public slots:
void onImportDataAction();
void onRemoveDataAction();
......
......@@ -15,86 +15,30 @@
// ************************************************************************** //
#include "RealDataSelectorToolBar.h"
#include "ComboProperty.h"
#include "DetectorItems.h"
#include "IDetector2D.h"
#include "IDetector2D.h"
#include "ImportDataAssistant.h"
#include "InstrumentItem.h"
#include "InstrumentModel.h"
#include "IntensityDataItem.h"
#include "JobItemUtils.h"
#include "RealDataItem.h"
#include "RealDataModel.h"
#include "RectangularDetectorItem.h"
#include "SessionItem.h"
#include "SphericalDetectorItem.h"
#include <QAction>
#include <QItemSelectionModel>
#include "RealDataSelectorActions.h"
#include <QToolButton>
RealDataSelectorToolBar::RealDataSelectorToolBar(QWidget* parent)
: StyledToolBar(parent), m_importDataAction(0), m_removeDataAction(0), m_realDataModel(0),
m_instrumentModel(0), m_selectionModel(0)
RealDataSelectorToolBar::RealDataSelectorToolBar(RealDataSelectorActions* actions, QWidget* parent)
: StyledToolBar(parent)
, m_importDataButton(new QToolButton)
, m_removeDataButton(new QToolButton)
{
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_importDataAction = new QAction(QStringLiteral("Import"), parent);
m_importDataAction->setIcon(QIcon(":/images/toolbar16light_newitem.svg"));
m_importDataAction->setToolTip(QStringLiteral("Import data"));
addAction(m_importDataAction);
connect(m_importDataAction, SIGNAL(triggered()), this, SLOT(onImportDataAction()));
m_removeDataAction = new QAction(QStringLiteral("Remove"), parent);
m_removeDataAction->setIcon(QIcon(":/images/toolbar16light_recycle.svg"));
m_removeDataAction->setToolTip(QStringLiteral("Remove selected data"));
addAction(m_removeDataAction);
connect(m_removeDataAction, SIGNAL(triggered()), this, SLOT(onRemoveDataAction()));
}
void RealDataSelectorToolBar::setRealDataModel(RealDataModel* model) { m_realDataModel = model; }
void RealDataSelectorToolBar::setInstrumentModel(InstrumentModel* model) { m_instrumentModel = model; }
void RealDataSelectorToolBar::setSelectionModel(QItemSelectionModel* selectionModel)
{
m_selectionModel = selectionModel;
}
//! Sets action to toolbar, preserving own toolbar's actions.
void RealDataSelectorToolBar::setActionList(const QList<QAction*>& actionList)
{
clear();
addAction(m_importDataAction);
addAction(m_removeDataAction);
addStyledSeparator();
foreach (QAction* action, actionList)
addAction(action);
}
void RealDataSelectorToolBar::onImportDataAction()
{
Q_ASSERT(m_realDataModel);
ImportDataAssistant assistant;
QString baseNameOfImportedFile;
std::unique_ptr<OutputData<double>> data(assistant.importData(baseNameOfImportedFile));
if (data) {
RealDataItem* realDataItem
= dynamic_cast<RealDataItem*>(m_realDataModel->insertNewItem(Constants::RealDataType));
realDataItem->setItemName(baseNameOfImportedFile);
realDataItem->setOutputData(data.release());
m_selectionModel->clearSelection();
m_selectionModel->select(realDataItem->index(), QItemSelectionModel::Select);
}
}
void RealDataSelectorToolBar::onRemoveDataAction()
{
QModelIndex currentIndex = m_selectionModel->currentIndex();
if (currentIndex.isValid())
m_realDataModel->removeRows(currentIndex.row(), 1, currentIndex.parent());
setMinimumSize(minimumHeight(), minimumHeight());
m_importDataButton->setText(QStringLiteral("Import"));
m_importDataButton->setIcon(QIcon(":/images/toolbar16light_newitem.svg"));
m_importDataButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_importDataButton->setToolTip("Import data");
addWidget(m_importDataButton);
m_removeDataButton->setText("Remove");
m_removeDataButton->setIcon(QIcon(":/images/toolbar16light_recycle.svg"));
m_removeDataButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_removeDataButton->setToolTip("Remove selected data.");
addWidget(m_removeDataButton);
connect(m_importDataButton, &QToolButton::clicked, actions,
&RealDataSelectorActions::onImportDataAction);
connect(m_removeDataButton, &QToolButton::clicked, actions,
&RealDataSelectorActions::onRemoveDataAction);
}
......@@ -19,11 +19,8 @@
#include "StyledToolBar.h"
class QAction;
class RealDataModel;
class InstrumentModel;
class QItemSelectionModel;
class RealDataItem;
class RealDataSelectorActions;
class QToolButton;
//! The RealDataSelectorToolBar class represents a narrow toolbar on top of
//! RealDataSelectorWidget (ImportDataView)
......@@ -32,24 +29,11 @@ class BA_CORE_API_ RealDataSelectorToolBar : public StyledToolBar
{
Q_OBJECT
public:
RealDataSelectorToolBar(QWidget* parent = 0);
void setRealDataModel(RealDataModel* model);
void setInstrumentModel(InstrumentModel* model);
void setSelectionModel(QItemSelectionModel* selectionModel);
void setActionList(const QList<QAction*>& actionList);
private slots:
void onImportDataAction();
void onRemoveDataAction();
RealDataSelectorToolBar(RealDataSelectorActions* actions, QWidget* parent = 0);
private:
QAction* m_importDataAction;
QAction* m_removeDataAction;
RealDataModel* m_realDataModel;
InstrumentModel* m_instrumentModel;
QItemSelectionModel* m_selectionModel;
QToolButton* m_importDataButton;
QToolButton* m_removeDataButton;
};
#endif // REALDATASELECTORTOOLBAR_H
......@@ -27,7 +27,7 @@
RealDataSelectorWidget::RealDataSelectorWidget(QWidget* parent)
: QWidget(parent)
, m_selectorActions(new RealDataSelectorActions(this))
, m_toolBar(new RealDataSelectorToolBar(this))
, m_toolBar(new RealDataSelectorToolBar(m_selectorActions, this))
, m_splitter(new Manhattan::MiniSplitter)
, m_selectorWidget(new ItemSelectorWidget)
, m_propertiesWidget(new RealDataPropertiesWidget)
......@@ -49,8 +49,6 @@ RealDataSelectorWidget::RealDataSelectorWidget(QWidget* parent)
mainLayout->addWidget(m_splitter);
setLayout(mainLayout);
m_selectorActions->setSelectionModel(m_selectorWidget->selectionModel());
connect(m_selectorWidget, &ItemSelectorWidget::selectionChanged,
this, &RealDataSelectorWidget::onSelectionChanged);
}
......@@ -72,10 +70,7 @@ void RealDataSelectorWidget::setModels(InstrumentModel* instrumentModel,
m_propertiesWidget->setModels(instrumentModel, realDataModel);
m_selectorActions->setRealDataModel(realDataModel);
m_toolBar->setRealDataModel(realDataModel);
m_toolBar->setInstrumentModel(instrumentModel);
m_toolBar->setSelectionModel(m_selectorWidget->selectionModel());
m_selectorActions->setSelectionModel(m_selectorWidget->selectionModel());
}
void RealDataSelectorWidget::onSelectionChanged(SessionItem* item)
......
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