From f6f9698e9235663eaf00241627c0cca375af59c2 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Thu, 23 Oct 2014 09:29:57 +0100 Subject: [PATCH] Better tree layout and algorithm buttons Refs #10377 --- .../src/Mantid/MantidSampleMaterialDialog.cpp | 136 ++++++++++++++---- .../src/Mantid/MantidSampleMaterialDialog.h | 23 ++- .../src/Mantid/MantidSampleMaterialDialog.ui | 14 ++ .../Mantid/MantidPlot/src/Mantid/MantidUI.cpp | 4 +- 4 files changed, 133 insertions(+), 44 deletions(-) diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.cpp index 8c8369756e73..b5f566c5544a 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.cpp @@ -1,3 +1,6 @@ +//---------------------------------- +// Includes +//---------------------------------- #include "MantidSampleMaterialDialog.h" #include "MantidUI.h" @@ -13,8 +16,16 @@ using namespace Mantid; using namespace Mantid::API; using namespace Mantid::Kernel; -MantidSampleMaterialDialog::MantidSampleMaterialDialog(MantidUI* mtdUI, Qt::WFlags flags): +/** + * Constructs a sample material dialog. + * + * @param wsName Name of workspace to show material for + * @param mtdUI Pointer to the MantidUI object + * @param flags Window flags + */ +MantidSampleMaterialDialog::MantidSampleMaterialDialog(const QString & wsName, MantidUI* mtdUI, Qt::WFlags flags): QDialog(mtdUI->appWindow(), flags), + m_wsName(wsName), m_mantidUI(mtdUI) { m_uiForm.setupUi(this); @@ -24,42 +35,113 @@ MantidSampleMaterialDialog::MantidSampleMaterialDialog(MantidUI* mtdUI, Qt::WFla m_uiForm.treeMaterialProperties->setHeaderLabels(titles); connect(m_uiForm.pbClose, SIGNAL(clicked()), this, SLOT(close())); -} -void MantidSampleMaterialDialog::showWorkspace(const QString wsName) -{ - auto materialInfo = getMaterial(wsName); - showPropsOnTree(materialInfo); + connect(m_uiForm.pbSetMaterial, SIGNAL(clicked()), this, SLOT(handleSetMaterial())); + connect(m_uiForm.pbCopyMaterial, SIGNAL(clicked()), this, SLOT(handleCopyMaterial())); } -QMap MantidSampleMaterialDialog::getMaterial(const QString workspaceName) +/** + * Gets the sample material for a workspace and displays its properties in the tree. + */ +void MantidSampleMaterialDialog::updateMaterial() { - MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS(workspaceName.toStdString()); + MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS(m_wsName.toStdString()); const Material material = ws->sample().getMaterial(); - QMap materialInfo; + m_uiForm.treeMaterialProperties->clear(); + + QTreeWidgetItem *item; + QTreeWidgetItem *subItem; + QTreeWidgetItem *subSubItem; + + item = new QTreeWidgetItem(); + item->setText(0, "Name"); + item->setText(1, QString::fromStdString(material.name())); + m_uiForm.treeMaterialProperties->addTopLevelItem(item); + + item = new QTreeWidgetItem(); + item->setText(0, "Number Density"); + item->setText(1, QString::number(material.numberDensity())); + m_uiForm.treeMaterialProperties->addTopLevelItem(item); + + item = new QTreeWidgetItem(); + item->setText(0, "Temperature"); + item->setText(1, QString::number(material.temperature())); + m_uiForm.treeMaterialProperties->addTopLevelItem(item); + + item = new QTreeWidgetItem(); + item->setText(0, "Pressure"); + item->setText(1, QString::number(material.pressure())); + m_uiForm.treeMaterialProperties->addTopLevelItem(item); + + item = new QTreeWidgetItem(); + item->setText(0, "Cross Sections"); + m_uiForm.treeMaterialProperties->addTopLevelItem(item); + + subItem = new QTreeWidgetItem(); + subItem->setText(0, "Absorption"); + subItem->setText(1, QString::number(material.absorbXSection())); + item->addChild(subItem); + + subItem = new QTreeWidgetItem(); + subItem->setText(0, "Scattering"); + item->addChild(subItem); - materialInfo["Name"] = QString::fromStdString(material.name()); - materialInfo["Number Density"] = QString::number(material.numberDensity()); - materialInfo["Temperature"] = QString::number(material.temperature()); - materialInfo["Pressure"] = QString::number(material.pressure()); - materialInfo["Coh scatter cross section"] = QString::number(material.cohScatterXSection()); - materialInfo["Incoh scatter cross section"] = QString::number(material.incohScatterXSection()); - materialInfo["Total scatter cross section"] = QString::number(material.totalScatterXSection()); - materialInfo["Absorb cross section"] = QString::number(material.absorbXSection()); + // Expand the Cross Sections section + item->setExpanded(true); - return materialInfo; + subSubItem = new QTreeWidgetItem(); + subSubItem->setText(0, "Total"); + subSubItem->setText(1, QString::number(material.totalScatterXSection())); + subItem->addChild(subSubItem); + + subSubItem = new QTreeWidgetItem(); + subSubItem->setText(0, "Coherent"); + subSubItem->setText(1, QString::number(material.cohScatterXSection())); + subItem->addChild(subSubItem); + + subSubItem = new QTreeWidgetItem(); + subSubItem->setText(0, "Incoherent"); + subSubItem->setText(1, QString::number(material.incohScatterXSection())); + subItem->addChild(subSubItem); + + // Expand the Scattering section + subItem->setExpanded(true); + + // Resize Property column to names + m_uiForm.treeMaterialProperties->resizeColumnToContents(0); } -void MantidSampleMaterialDialog::showPropsOnTree(QMap materialProps) +/** + * Creates a SetSampleMaterial dialog to set the sample material of the workspace. + */ +void MantidSampleMaterialDialog::handleSetMaterial() { - m_uiForm.treeMaterialProperties->clear(); + QHash presets; + presets["InputWorkspace"] = m_wsName; + + m_mantidUI->showAlgorithmDialog("SetSampleMaterial", presets); + + //TODO + updateMaterial(); +} + +/** + * Creates a CopySample dialog with pre filled input to copy the sample material. + */ +void MantidSampleMaterialDialog::handleCopyMaterial() +{ + QHash presets; + presets["InputWorkspace"] = m_wsName; + presets["CopyName"] = "0"; + presets["CopyMaterial"] = "1"; + presets["CopyEnvironment"] = "0"; + presets["CopyShape"] = "0"; + presets["CopyLattice"] = "0"; + presets["CopyOrientationOnly"] = "0"; + + m_mantidUI->showAlgorithmDialog("CopySample", presets); - for(auto it = materialProps.begin(); it != materialProps.end(); ++it) - { - QTreeWidgetItem *treeItem = new QTreeWidgetItem(); - treeItem->setText(0, it.key()); - treeItem->setText(1, it.value()); - m_uiForm.treeMaterialProperties->addTopLevelItem(treeItem); - } + //TODO + updateMaterial(); } diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.h b/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.h index 6f4ad0d69b68..8672b3a6919b 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.h +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.h @@ -7,17 +7,10 @@ #include "ui_MantidSampleMaterialDialog.h" #include -#include -#include -#include //---------------------------------- // Forward declarations //---------------------------------- -class QTreeWidgetItem; -class QTreeWidget; -class QPushButton; -class QRadioButton; class MantidUI; /** @@ -53,18 +46,18 @@ class MantidSampleMaterialDialog : public QDialog Q_OBJECT public: - MantidSampleMaterialDialog(MantidUI* mtdUI, Qt::WFlags flags = 0); + MantidSampleMaterialDialog(const QString & wsName, MantidUI* mtdUI, Qt::WFlags flags = 0); - void showWorkspace(const QString wsName); +public slots: + void updateMaterial(); + void handleSetMaterial(); + void handleCopyMaterial(); private: - QMap getMaterial(QString workspaceName); - void showPropsOnTree(QMap materialProps); + /// Name of displayed workspace + QString m_wsName; - /// The workspace name - std::string m_wsname; - - ///A pointer to the MantidUI object + /// A pointer to the MantidUI object MantidUI* m_mantidUI; Ui::MantidSampleMaterialDialog m_uiForm; diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.ui b/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.ui index 0c4a774acb36..ea188f2c77fb 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.ui +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.ui @@ -31,6 +31,20 @@ + + + + Set Material + + + + + + + Copy Material + + + diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp index 368c98da6c1b..c56801d06085 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp @@ -2697,12 +2697,12 @@ void MantidUI::showLogFileWindow() void MantidUI::showSampleMaterialWindow() { - MantidSampleMaterialDialog *dlg = new MantidSampleMaterialDialog(this); + MantidSampleMaterialDialog *dlg = new MantidSampleMaterialDialog(getSelectedWorkspaceName(), this); dlg->setModal(false); dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->show(); dlg->setFocus(); - dlg->showWorkspace(getSelectedWorkspaceName()); + dlg->updateMaterial(); } // ***** Plotting Methods ***** //