Skip to content

Commit

Permalink
Added remaining columns, fixed multiple deletion
Browse files Browse the repository at this point in the history
Refs #10802
  • Loading branch information
DanNixon committed Jan 14, 2015
1 parent fded6de commit 51e85db
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
Expand Up @@ -45,6 +45,15 @@ namespace CustomInterfaces
void clearDiff();

private:
/// Enumeration for column index
enum Column
{
COLOUR,
WORKSPACE_NAME,
SPEC_OFFSET,
CURRENT_SPEC
};

/// Initialize the layout
virtual void initLayout();

Expand Down
Expand Up @@ -78,9 +78,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="columnCount">
<number>3</number>
</property>
</widget>
</item>
<item row="1" column="0">
Expand Down
41 changes: 30 additions & 11 deletions Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp
Expand Up @@ -53,9 +53,13 @@ void DataComparison::initLayout()
connect(m_uiForm.pbDiffSelected, SIGNAL(clicked()), this, SLOT(diffSelected()));
connect(m_uiForm.pbClearDiff, SIGNAL(clicked()), this, SLOT(clearDiff()));

// Replot spectra when the spectrum index is changed
connect(m_uiForm.sbSpectrum, SIGNAL(currentIndexChanged(int)), this, SLOT(plotWorkspaces()));

// Add headers to data table
QStringList headerLabels;
headerLabels << "Workspace" << "Offset" << "Colour";
headerLabels << "Colour" << "Workspace" << "Offset" << "Spec.";
m_uiForm.twCurrentData->setColumnCount(headerLabels.size());
m_uiForm.twCurrentData->setHorizontalHeaderLabels(headerLabels);

// Select entire rows when a cell is selected
Expand All @@ -80,12 +84,22 @@ void DataComparison::addData()
// Insert the workspace name
QTableWidgetItem *wsNameItem = new QTableWidgetItem(tr(dataName));
wsNameItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_uiForm.twCurrentData->setItem(currentRows, 0, wsNameItem);
m_uiForm.twCurrentData->setItem(currentRows, WORKSPACE_NAME, wsNameItem);

// Insert the colour
QTableWidgetItem *colourItem = new QTableWidgetItem(tr(""));
colourItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_uiForm.twCurrentData->setItem(currentRows, COLOUR, colourItem);

// Insert the spectra offset
QTableWidgetItem *offsetItem = new QTableWidgetItem(tr("0"));
offsetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
m_uiForm.twCurrentData->setItem(currentRows, 1, offsetItem);
m_uiForm.twCurrentData->setItem(currentRows, SPEC_OFFSET, offsetItem);

// Insert the current displayed spectra
QTableWidgetItem *currentSpecItem = new QTableWidgetItem(tr(""));
currentSpecItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_uiForm.twCurrentData->setItem(currentRows, CURRENT_SPEC, currentSpecItem);

// Fit columns
m_uiForm.twCurrentData->resizeColumnsToContents();
Expand All @@ -100,12 +114,15 @@ void DataComparison::addData()
*/
void DataComparison::removeSelectedData()
{
QList<QTableWidgetItem *> items = m_uiForm.twCurrentData->selectedItems();
for(auto it = items.begin(); it != items.end(); ++it)
QList<QTableWidgetItem *> selectedItems = m_uiForm.twCurrentData->selectedItems();

while(!selectedItems.isEmpty())
{
// Get the row number of the item
int row = selectedItems[0]->row();

// Get workspace name
int row = m_uiForm.twCurrentData->row(*it);
QString workspaceName = m_uiForm.twCurrentData->item(row, 0)->text();
QString workspaceName = m_uiForm.twCurrentData->item(row, WORKSPACE_NAME)->text();

// Remove from data tabel
m_uiForm.twCurrentData->removeRow(row);
Expand All @@ -114,9 +131,11 @@ void DataComparison::removeSelectedData()
if(m_curves.contains(workspaceName))
m_curves[workspaceName]->attach(NULL);

// Replot the workspaces
plotWorkspaces();
selectedItems = m_uiForm.twCurrentData->selectedItems();
}

// Replot the workspaces
plotWorkspaces();
}


Expand All @@ -129,7 +148,7 @@ void DataComparison::removeAllData()
for(int row = 0; row < numRows; row++)
{
// Get workspace name
QString workspaceName = m_uiForm.twCurrentData->item(0, 0)->text();
QString workspaceName = m_uiForm.twCurrentData->item(0, WORKSPACE_NAME)->text();

// Remove from data tabel
m_uiForm.twCurrentData->removeRow(0);
Expand All @@ -155,7 +174,7 @@ void DataComparison::plotWorkspaces()
int specIndex = 0; //TODO

// Get workspace
QString workspaceName = m_uiForm.twCurrentData->item(row, 0)->text();
QString workspaceName = m_uiForm.twCurrentData->item(row, WORKSPACE_NAME)->text();
MatrixWorkspace_const_sptr workspace =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(workspaceName.toStdString());

Expand Down

0 comments on commit 51e85db

Please sign in to comment.