diff --git a/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.cpp b/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.cpp index 3b3dafca378a0e009b38c3bf81bb68e24474611a..4c9efc1b4bd787fc9ffa7e0ab3e25c093b020f21 100644 --- a/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.cpp +++ b/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.cpp @@ -38,9 +38,9 @@ QuickSimulationWidget::QuickSimulationWidget(SampleModel *sampleModel, Instrumen setLayout(mainLayout); } -void QuickSimulationWidget::updateViews() +void QuickSimulationWidget::updateViews(const QString &instrument, const QString &sample) { - m_sampleTuningWidget->updateTreeView(); + m_sampleTuningWidget->updateTreeView(instrument, sample); } diff --git a/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.h b/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.h index 5366a8ad7b510f14ac9714f5fede1e9c9a1e346d..860a3dc1a0472603877cecb61cea1dc3a6d656e6 100644 --- a/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.h +++ b/GUI/coregui/Views/Components/SimulationWidgets/QuickSimulationWidget.h @@ -2,6 +2,7 @@ #define QUICKSIMULATIONWIDGET_H #include <QWidget> +#include <QString> class SampleModel; class InstrumentModel; class SampleTuningWidget; @@ -13,7 +14,7 @@ class QuickSimulationWidget : public QWidget public: QuickSimulationWidget(SampleModel *sampleModel, InstrumentModel *instrumentModel, QWidget *parent = 0); - void updateViews(); + void updateViews(const QString &instrument, const QString &sample); private: SampleModel *m_sampleModel; diff --git a/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.cpp b/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.cpp index a25a1a49db2a65a15c09ada9920960e3f2c0f671..7869c3801bc42d9d50ba3ae307e2849908c42d5e 100644 --- a/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.cpp +++ b/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.cpp @@ -3,10 +3,13 @@ #include "InstrumentModel.h" #include "PropertyAttribute.h" #include "SampleTuningDelegate.h" +#include "GUIHelpers.h" #include "ItemLink.h" #include <QItemSelectionModel> #include <QDebug> + + SampleTuningWidget::SampleTuningWidget(SampleModel *sampleModel, InstrumentModel *instrumentModel, QWidget *parent) : QWidget(parent) , m_parameterModel(0) @@ -245,24 +248,59 @@ void SampleTuningWidget::insertRowIntoItem(QStandardItem *parentItem, QString ti //} -void SampleTuningWidget::updateTreeView() +void SampleTuningWidget::updateTreeView(const QString &instrument, const QString &sample) { - m_treeView->setModel(0); + if(instrument != m_instrument_name || sample != m_sample_name) { + m_instrument_name = instrument; + m_sample_name = sample; - delete m_parameterModel; - m_parameterModel = createParameterModel(); + m_treeView->setModel(0); - m_treeView->setModel(m_parameterModel); - m_treeView->expandAll(); + delete m_parameterModel; + m_parameterModel = createParameterModel(); + + m_treeView->setModel(m_parameterModel); + m_treeView->expandAll(); + } } + QStandardItemModel *SampleTuningWidget::createParameterModel() { QStandardItemModel *result(0); result = new QStandardItemModel(this); result->setHorizontalHeaderItem( 0, new QStandardItem( "Property" ) ); result->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ) ); - result->setItem(0, iterateSessionModel()); + + QStandardItem *multiLayerItem = new QStandardItem(m_sample_name); + + QModelIndex multiLayerIndex = getMultiLayerIndex(m_sample_name); + + result->setItem(0, iterateSessionModel(multiLayerIndex, multiLayerItem)); + return result; +} + + +//! returns parent index of MultiLayer with given name +QModelIndex SampleTuningWidget::getMultiLayerIndex(const QString &name) +{ + Q_ASSERT(m_sampleModel); + + QModelIndex result; + for( int i_row = 0; i_row < m_sampleModel->rowCount( QModelIndex()); ++i_row) { + QModelIndex itemIndex = m_sampleModel->index( i_row, 0, QModelIndex() ); + + if (ParameterizedItem *item = m_sampleModel->itemForIndex(itemIndex)){ + if(item->modelType() == Constants::MultiLayerType && item->itemName() == name) { + result = itemIndex; + } + } + } + + if(!result.isValid()) { + throw GUIHelpers::Error("SampleTuningWidget::getParentSampleIndex() -> Can't find the sample with given name" + name); + } + return result; } diff --git a/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.h b/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.h index 84a8b7275ea7e8b157fc0f698c33a52fc936d6e8..8168751cd5c691aca43682ecc8f38062a21288c3 100644 --- a/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.h +++ b/GUI/coregui/Views/Components/SimulationWidgets/SampleTuningWidget.h @@ -22,23 +22,29 @@ class SampleTuningWidget : public QWidget public: SampleTuningWidget(SampleModel *sampleModel, InstrumentModel *instrumentModel, QWidget *parent = 0); - void updateTreeView(); + void updateTreeView(const QString &instrument, const QString &sample); private: //QStandardItemModel *getItemModelFromSessionModel(); // QStandardItemModel *getTestItemModel(); - QStandardItem *iterateSessionModel(const QModelIndex &parentIndex = QModelIndex(), QStandardItem *parentItem = NULL); - void insertRowIntoItem(QStandardItem *parentItem, QStandardItem *childTitleItem, QStandardItem *childValueItem = NULL); + QStandardItem *iterateSessionModel(const QModelIndex &parentIndex = QModelIndex(), QStandardItem *parentItem = 0); + void insertRowIntoItem(QStandardItem *parentItem, QStandardItem *childTitleItem, QStandardItem *childValueItem = 0); void insertRowIntoItem(QStandardItem *parentItem, QString title, QVariant value, ParameterizedItem *parameterizedItem); QStandardItemModel *createParameterModel(); + QModelIndex getMultiLayerIndex(const QString &name); + QStandardItemModel *m_parameterModel; QTreeView *m_treeView; SampleTuningDelegate *m_delegate; SampleModel *m_sampleModel; InstrumentModel *m_instrumentModel; + + QString m_instrument_name; + QString m_sample_name; + }; diff --git a/GUI/coregui/Views/SimulationView.cpp b/GUI/coregui/Views/SimulationView.cpp index fca409b79895fafd9a2dc2a2f52d011f92a2d2cb..02b7b91d864fd00c5f042a07dfcda7709aa83b00 100644 --- a/GUI/coregui/Views/SimulationView.cpp +++ b/GUI/coregui/Views/SimulationView.cpp @@ -39,7 +39,7 @@ SimulationView::SimulationView(MainWindow *mainWindow) void SimulationView::updateSimulationViewElements() { m_simulationSetupWidget->updateViewElements(); - m_quickSimulationWidget->updateViews(); + m_quickSimulationWidget->updateViews(m_simulationSetupWidget->getInstrumentSelection(), m_simulationSetupWidget->getSampleSelection()); } void SimulationView::onChangeTabWidget(int index) @@ -50,6 +50,6 @@ void SimulationView::onChangeTabWidget(int index) } else if(index == QuickSimulationTab) { - m_quickSimulationWidget->updateViews(); + m_quickSimulationWidget->updateViews(m_simulationSetupWidget->getInstrumentSelection(), m_simulationSetupWidget->getSampleSelection()); } }