Skip to content

Commit

Permalink
More tests added. Reopen tree items after update.
Browse files Browse the repository at this point in the history
Re #7253.
  • Loading branch information
mantid-roman committed Jun 24, 2013
1 parent 0b2907b commit c133062
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 7 deletions.
19 changes: 19 additions & 0 deletions Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,25 @@ class MatrixWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->getXMax(), 1.0);
}

void test_InfoNode()
{
Mantid::API::Workspace::InfoNode rootNode( *ws );
ws->addInfoNodeTo( rootNode );
auto &node = *rootNode.nodes()[0];
TS_ASSERT_EQUALS( node.nodes().size(), 0 );
TS_ASSERT_EQUALS( node.lines().size(), 8 );
TS_ASSERT_EQUALS( node.lines()[0], "WorkspaceTester" );
TS_ASSERT_EQUALS( node.lines()[1], "Title: " );
TS_ASSERT_EQUALS( node.lines()[2], "Histograms: 1" );
TS_ASSERT_EQUALS( node.lines()[3], "Bins: 1" );
TS_ASSERT_EQUALS( node.lines()[4], "Data points" );
TS_ASSERT_EQUALS( node.lines()[5], "X axis: / " );
TS_ASSERT_EQUALS( node.lines()[6], "Y axis: something per " );
TS_ASSERT_EQUALS( node.lines()[7].substr(0,11), "Instrument:" );
TS_ASSERT_EQUALS( node.workspaceName(), "" );
TS_ASSERT_EQUALS( node.getMemorySize(), 304 );
}

private:
boost::shared_ptr<MatrixWorkspace> ws;

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataObjects/src/MaskWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace DataObjects
API::Workspace::InfoNode *MaskWorkspace::createInfoNode() const
{
auto node = SpecialWorkspace2D::createInfoNode();
node->addLine( "Mased: " + boost::lexical_cast<std::string>(getNumberMasked()) );
node->addLine( "Masked: " + boost::lexical_cast<std::string>(getNumberMasked()) );
return node;
}

Expand Down
19 changes: 19 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/EventWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,25 @@ class EventWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_DELTA(wksp->getEventXMin(), 500, .01);
TS_ASSERT_DELTA(wksp->getEventXMax(), 1023500, .01);
}

void test_InfoNode()
{
Mantid::API::Workspace::InfoNode rootNode( *ew );
ew->addInfoNodeTo( rootNode );
auto &node = *rootNode.nodes()[0];
TS_ASSERT_EQUALS( node.nodes().size(), 0 );
TS_ASSERT_EQUALS( node.lines().size(), 9 );
TS_ASSERT_EQUALS( node.lines()[0], "EventWorkspace" );
TS_ASSERT_EQUALS( node.lines()[1], "Title: " );
TS_ASSERT_EQUALS( node.lines()[2], "Histograms: 500" );
TS_ASSERT_EQUALS( node.lines()[3], "Bins: 1024" );
TS_ASSERT_EQUALS( node.lines()[4], "Histogram" );
TS_ASSERT_EQUALS( node.lines()[5], "X axis: / " );
TS_ASSERT_EQUALS( node.lines()[6], "Y axis: " );
TS_ASSERT_EQUALS( node.lines()[7].substr(0,11), "Instrument:" );
TS_ASSERT_EQUALS( node.lines()[8], "Events: 1024000" );
}

};

#endif /* EVENTWORKSPACETEST_H_ */
16 changes: 16 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/MaskWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ class MaskWorkspaceTest : public CxxTest::TestSuite
detIds.insert(2);
TS_ASSERT_EQUALS(maskWS->isMasked(detIds), true);
}

void test_InfoNode()
{
Mantid::DataObjects::MaskWorkspace* ws = new Mantid::DataObjects::MaskWorkspace(10);
ws->initialize(100, 1, 1);

Mantid::API::Workspace::InfoNode rootNode( *ws );
ws->addInfoNodeTo( rootNode );
auto &node = *rootNode.nodes()[0];
TS_ASSERT_EQUALS( node.nodes().size(), 0 );
TS_ASSERT_EQUALS( node.lines().size(), 4 );
TS_ASSERT_EQUALS( node.lines()[0], "MaskWorkspace" );
TS_ASSERT_EQUALS( node.lines()[1], "Title: " );
TS_ASSERT_EQUALS( node.lines()[2], "Histograms: 100" );
TS_ASSERT_EQUALS( node.lines()[3], "Masked: 0" );
}
};

#endif // MANTID_DATAOBJECTS_MASKWORKSPACETEST_H
14 changes: 14 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/SpecialWorkspace2DTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ class SpecialWorkspace2DTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS("SpecialWorkspace2D", Mantid::Kernel::getUnmangledTypeName(*property.type_info()));
}

void test_InfoNode()
{
SpecialWorkspace2D_sptr ws(new SpecialWorkspace2D());
ws->initialize(100, 1, 1);

Mantid::API::Workspace::InfoNode rootNode( *ws );
ws->addInfoNodeTo( rootNode );
auto &node = *rootNode.nodes()[0];
TS_ASSERT_EQUALS( node.nodes().size(), 0 );
TS_ASSERT_EQUALS( node.lines().size(), 3 );
TS_ASSERT_EQUALS( node.lines()[0], "SpecialWorkspace2D" );
TS_ASSERT_EQUALS( node.lines()[1], "Title: " );
TS_ASSERT_EQUALS( node.lines()[2], "Histograms: 100" );
}
};


Expand Down
17 changes: 17 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/TableWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,23 @@ class TableWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS("TableWorkspace", Mantid::Kernel::getUnmangledTypeName(*property.type_info()));
}

void testInfoNode()
{
TableWorkspace tw(2);
tw.addColumn("int","Number");
tw.addColumn("double","Ratio");
tw.addColumn("str","Name");
tw.addColumn("bool","OK");
Mantid::API::Workspace::InfoNode rootNode( tw );
tw.addInfoNodeTo( rootNode );
auto &node = *rootNode.nodes()[0];
TS_ASSERT_EQUALS( node.nodes().size(), 0 );
TS_ASSERT_EQUALS( node.lines().size(), 3 );
TS_ASSERT_EQUALS( node.lines()[0], "TableWorkspace" );
TS_ASSERT_EQUALS( node.lines()[1], "Columns: 4" );
TS_ASSERT_EQUALS( node.lines()[2], "Rows: 2" );
}

};


Expand Down
19 changes: 19 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDEventWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,25 @@ class MDEventWorkspaceTest : public CxxTest::TestSuite
ws->setCoordinateSystem(Mantid::API::QLab);
TS_ASSERT_EQUALS(Mantid::API::QLab, ws->getSpecialCoordinateSystem());
}

void test_InfoNode()
{
MDEventWorkspace1Lean::sptr ws = MDEventsTestHelper::makeMDEW<1>(10, 0.0, 10.0, 1 /*event per box*/);

Mantid::API::Workspace::InfoNode rootNode( *ws );
ws->addInfoNodeTo( rootNode );
auto &node = *rootNode.nodes()[0];
TS_ASSERT_EQUALS( node.nodes().size(), 0 );
TS_ASSERT_EQUALS( node.lines().size(), 7 );
TS_ASSERT_EQUALS( node.lines()[0], "MDEventWorkspace<MDLeanEvent,1>" );
TS_ASSERT_EQUALS( node.lines()[1], "Title: " );
TS_ASSERT_EQUALS( node.lines()[2], "Dim 0: (Axis0) 0 to 10 in 10 bins" );
TS_ASSERT_EQUALS( node.lines()[3], "10 MDBoxes (1 kB)" );
TS_ASSERT_EQUALS( node.lines()[4], "1 MDGridBoxes (0 kB)" );
TS_ASSERT_EQUALS( node.lines()[5], "Not file backed." );
TS_ASSERT_EQUALS( node.lines()[6], "Events: 10" );
}

};


Expand Down
13 changes: 13 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDHistoWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,19 @@ class MDHistoWorkspaceTest : public CxxTest::TestSuite
}


void test_InfoNode()
{
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1);

Mantid::API::Workspace::InfoNode rootNode( *ws );
ws->addInfoNodeTo( rootNode );
auto &node = *rootNode.nodes()[0];
TS_ASSERT_EQUALS( node.nodes().size(), 0 );
TS_ASSERT_EQUALS( node.lines().size(), 3 );
TS_ASSERT_EQUALS( node.lines()[0], "MDHistoWorkspace" );
TS_ASSERT_EQUALS( node.lines()[1], "Title: " );
TS_ASSERT_EQUALS( node.lines()[2], "Dim 0: (x) 0 to 10 in 10 bins" );
}



Expand Down
22 changes: 20 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Mantid::API::Workspace_sptr MantidDockWidget::getSelectedWorkspace() const
* @param node :: An InfoNode of the workspace to display.
* @param parentItem :: A pointer to the parent item to add to. If NULL the item is added at top level.
*/
void MantidDockWidget::addWorkspaceTreeEntry( Workspace::InfoNode &node, QTreeWidgetItem *parentItem )
QTreeWidgetItem *MantidDockWidget::addWorkspaceTreeEntry( Workspace::InfoNode &node, QTreeWidgetItem *parentItem )
{
// name of a top-level item == workspace name
QString wsName = QString::fromStdString(node.workspaceName());
Expand All @@ -223,6 +223,7 @@ void MantidDockWidget::addWorkspaceTreeEntry( Workspace::InfoNode &node, QTreeWi
{
m_tree->addTopLevelItem( wsItem );
}
return wsItem;
}

/**
Expand Down Expand Up @@ -436,13 +437,30 @@ void MantidDockWidget::updateTree()
// do not update until the counter is zero
if ( m_updateCount.deref() ) return;

// find all expanded top-level entries
QStringList expanded;
int n = m_tree->topLevelItemCount();
for(int i = 0; i < n; ++i)
{
auto item = m_tree->topLevelItem(i);
if ( item->isExpanded() )
{
expanded << item->text(0);
}
}

// create a new tree
m_tree->clear();
if ( m_rootInfoNode ) delete m_rootInfoNode;
m_rootInfoNode = Mantid::API::AnalysisDataService::Instance().createInfoTree();
auto &nodes = m_rootInfoNode->nodes();
for( size_t i = 0; i < nodes.size(); ++i )
{
addWorkspaceTreeEntry( *nodes[i] );
auto entry = addWorkspaceTreeEntry( *nodes[i] );
if ( expanded.contains( entry->text(0) ) )
{
entry->setExpanded( true );
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class MantidDockWidget: public QDockWidget
QString getSelectedWorkspaceName() const;
Mantid::API::Workspace_sptr getSelectedWorkspace() const;

signals:
void rerunFindAbandonedWorkspaces();

public slots:
void clickedWorkspace(QTreeWidgetItem*, int);
void deleteWorkspaces();
Expand All @@ -70,7 +67,7 @@ protected slots:
void workspaceSelected();

private slots:
void addWorkspaceTreeEntry(Mantid::API::Workspace::InfoNode &node, QTreeWidgetItem* parentItem = NULL);
QTreeWidgetItem *addWorkspaceTreeEntry(Mantid::API::Workspace::InfoNode &node, QTreeWidgetItem* parentItem = NULL);
void treeSelectionChanged();
void groupingButtonClick();
void plotSpectra();
Expand Down

0 comments on commit c133062

Please sign in to comment.