Skip to content

Commit

Permalink
Better tree layout and algorithm buttons
Browse files Browse the repository at this point in the history
Refs #10377
  • Loading branch information
DanNixon committed Oct 23, 2014
1 parent 1426805 commit f6f9698
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 44 deletions.
136 changes: 109 additions & 27 deletions Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.cpp
@@ -1,3 +1,6 @@
//----------------------------------
// Includes
//----------------------------------
#include "MantidSampleMaterialDialog.h"

#include "MantidUI.h"
Expand All @@ -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);
Expand All @@ -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<QString, QString> 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<MatrixWorkspace>(workspaceName.toStdString());
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(m_wsName.toStdString());
const Material material = ws->sample().getMaterial();

QMap<QString, QString> 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<QString, QString> materialProps)
/**
* Creates a SetSampleMaterial dialog to set the sample material of the workspace.
*/
void MantidSampleMaterialDialog::handleSetMaterial()
{
m_uiForm.treeMaterialProperties->clear();
QHash<QString, QString> 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<QString, QString> 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();
}
23 changes: 8 additions & 15 deletions Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.h
Expand Up @@ -7,17 +7,10 @@
#include "ui_MantidSampleMaterialDialog.h"

#include <QDialog>
#include <QMap>
#include <QPair>
#include <QList>

//----------------------------------
// Forward declarations
//----------------------------------
class QTreeWidgetItem;
class QTreeWidget;
class QPushButton;
class QRadioButton;
class MantidUI;

/**
Expand Down Expand Up @@ -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<QString, QString> getMaterial(QString workspaceName);
void showPropsOnTree(QMap<QString, QString> 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;
Expand Down
14 changes: 14 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidSampleMaterialDialog.ui
Expand Up @@ -31,6 +31,20 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pbSetMaterial">
<property name="text">
<string>Set Material</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbCopyMaterial">
<property name="text">
<string>Copy Material</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Expand Up @@ -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 ***** //
Expand Down

0 comments on commit f6f9698

Please sign in to comment.