Skip to content
Snippets Groups Projects
Commit 23a4d326 authored by Dan Nixon's avatar Dan Nixon
Browse files

Load data, display on table, plot

Refs #10802
parent d6aa3c1b
No related branches found
No related tags found
No related merge requests found
......@@ -8,54 +8,59 @@
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidAPI/MatrixWorkspace.h"
#include <QPointer>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
namespace MantidQt
{
namespace CustomInterfaces
{
class DataComparison : public MantidQt::API::UserSubWindow
{
Q_OBJECT
public:
/// The name of the interface as registered into the factory
static std::string name() { return "Data Comparison"; }
// This interface's categories.
static QString categoryInfo() { return "General"; }
public:
/// Default Constructor
DataComparison(QWidget *parent = 0);
private slots:
/// Add selected data to plot
void addData();
/// Remove selected data from plot
void removeSelectedData();
/// Remove all data from plot
void removeAllData();
/// Create a diff of the two selected workspaces
void diffSelected();
/// Remove the diff from the plot
void clearDiff();
private:
/// Initialize the layout
virtual void initLayout();
private:
// The form generated by Qt Designer
Ui::DataComparison m_uiForm;
// The plot object
QwtPlot *m_plot;
// Vector of curves shown on plot
std::vector<QwtPlotCurve *> m_curves;
// Pointer to the current diff workspace
Mantid::API::MatrixWorkspace_sptr m_diffWorkspace;
};
class DataComparison : public MantidQt::API::UserSubWindow
{
Q_OBJECT
public:
/// The name of the interface as registered into the factory
static std::string name() { return "Data Comparison"; }
// This interface's categories.
static QString categoryInfo() { return "General"; }
public:
/// Default Constructor
DataComparison(QWidget *parent = 0);
private slots:
/// Add selected data to plot
void addData();
/// Remove selected data from plot
void removeSelectedData();
/// Remove all data from plot
void removeAllData();
/// Create a diff of the two selected workspaces
void diffSelected();
/// Remove the diff from the plot
void clearDiff();
private:
/// Initialize the layout
virtual void initLayout();
void plotWorkspaces();
private:
// The form generated by Qt Designer
Ui::DataComparison m_uiForm;
// The plot object
QwtPlot *m_plot;
// Curves shown on plot, indexed by workspace name
QMap<QString, boost::shared_ptr<QwtPlotCurve>> m_curves;
// Pointer to the current diff workspace
Mantid::API::MatrixWorkspace_sptr m_diffWorkspace;
};
}
}
......
......@@ -43,14 +43,6 @@
<property name="autoLoad" stdset="0">
<bool>true</bool>
</property>
<property name="loadLabelText" stdset="0">
<string/>
</property>
<property name="fileBrowserSuffixes" stdset="0">
<stringlist>
<string>.nxs</string>
</stringlist>
</property>
<property name="showLoad" stdset="0">
<bool>false</bool>
</property>
......@@ -79,13 +71,16 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QTableWidget" name="tableWidget">
<widget class="QTableWidget" name="twCurrentData">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="columnCount">
<number>3</number>
</property>
</widget>
</item>
<item row="1" column="0">
......@@ -117,23 +112,30 @@
<string>Tools</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<item row="0" column="0">
<widget class="QLabel" name="lbSpectrum">
<property name="text">
<string>Spectrum:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="sbSpectrum"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pbDiffSelected">
<property name="text">
<string>Diff Selected</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="QPushButton" name="pbClearDiff">
<property name="text">
<string>Clear Diff</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="sbSpectrum"/>
</item>
</layout>
</widget>
</item>
......
......@@ -3,6 +3,14 @@
//----------------------
#include "MantidQtCustomInterfaces/DataComparison.h"
#include "MantidQtAPI/QwtWorkspaceSpectrumData.h"
namespace
{
Mantid::Kernel::Logger g_log("DataComparison");
}
//Add this class to the list of specialised dialogs in this namespace
namespace MantidQt
{
......@@ -13,6 +21,8 @@ namespace CustomInterfaces
}
using namespace MantidQt::CustomInterfaces;
using namespace Mantid::API;
//----------------------
// Public member functions
......@@ -24,6 +34,7 @@ DataComparison::DataComparison(QWidget *parent) :
{
}
/// Set up the dialog layout
void DataComparison::initLayout()
{
......@@ -41,29 +52,125 @@ void DataComparison::initLayout()
connect(m_uiForm.pbDiffSelected, SIGNAL(clicked()), this, SLOT(diffSelected()));
connect(m_uiForm.pbClearDiff, SIGNAL(clicked()), this, SLOT(clearDiff()));
// Add headers to data table
QStringList headerLabels;
headerLabels << "Workspace" << "Offset" << "Colour";
m_uiForm.twCurrentData->setHorizontalHeaderLabels(headerLabels);
}
/**
* Adds the data currently selected by the data selector to the plot.
*/
void DataComparison::addData()
{
QString dataName = m_uiForm.dsData->getCurrentDataName();
// Append a new row to the data table
int currentRows = m_uiForm.twCurrentData->rowCount();
m_uiForm.twCurrentData->insertRow(currentRows);
// Insert the workspace name
QTableWidgetItem *wsNameItem = new QTableWidgetItem(tr(dataName));
wsNameItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_uiForm.twCurrentData->setItem(currentRows, 0, wsNameItem);
// Insert the spectra offset
QTableWidgetItem *offsetItem = new QTableWidgetItem(tr("0"));
offsetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
m_uiForm.twCurrentData->setItem(currentRows, 1, offsetItem);
plotWorkspaces();
}
/**
* Removes the data currently selected in the table from the plot.
*/
void DataComparison::removeSelectedData()
{
QList<QTableWidgetItem *> items = m_uiForm.twCurrentData->selectedItems();
for(auto it = items.begin(); it != items.end(); ++it)
{
// Get workspace name
int row = m_uiForm.twCurrentData->row(*it);
QString workspaceName = m_uiForm.twCurrentData->item(row, 0)->text();
// Remove from data tabel
m_uiForm.twCurrentData->removeRow(row);
// Detach the old curve from the plot if it exists
if(m_curves.contains(workspaceName))
m_curves[workspaceName]->attach(NULL);
plotWorkspaces();
}
}
/**
* Removed all loaded data from the plot.
*/
void DataComparison::removeAllData()
{
int numRows = m_uiForm.twCurrentData->rowCount();
for(int row = 0; row < numRows; row++)
{
// Get workspace name
QString workspaceName = m_uiForm.twCurrentData->item(0, 0)->text();
// Remove from data tabel
m_uiForm.twCurrentData->removeRow(0);
// Detach the old curve from the plot if it exists
if(m_curves.contains(workspaceName))
m_curves[workspaceName]->attach(NULL);
plotWorkspaces();
}
}
void DataComparison::plotWorkspaces()
{
int numRows = m_uiForm.twCurrentData->rowCount();
for(int row = 0; row < numRows; row++)
{
int specIndex = 0; //TODO
// Get workspace
QString workspaceName = m_uiForm.twCurrentData->item(row, 0)->text();
MatrixWorkspace_const_sptr workspace =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(workspaceName.toStdString());
// Create the curve data
const bool logScale(false), distribution(false);
QwtWorkspaceSpectrumData wsData(*workspace, static_cast<int>(specIndex), logScale, distribution);
// Check the spectrum index is in range
int numSpec = static_cast<int>(workspace->getNumberHistograms());
if(specIndex >= numSpec)
{
g_log.debug() << "Workspace " << workspaceName.toStdString() << ", spectrum index out of range.";
continue;
}
// Detach the old curve from the plot if it exists
if(m_curves.contains(workspaceName))
m_curves[workspaceName]->attach(NULL);
// Create a new curve and attach it to the plot
boost::shared_ptr<QwtPlotCurve> curve(new QwtPlotCurve);
curve->setData(wsData);
curve->attach(m_plot);
m_curves[workspaceName] = curve;
}
m_plot->replot();
}
/**
* Creates a diff workspace of the two currently selected workspaces in the table
* and plots it on the plot.
......@@ -72,8 +179,10 @@ void DataComparison::removeAllData()
*/
void DataComparison::diffSelected()
{
//TODO
}
/**
* Removes the diff workspace form the plot.
*
......@@ -81,4 +190,5 @@ void DataComparison::diffSelected()
*/
void DataComparison::clearDiff()
{
//TODO
}
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