Skip to content

Commit

Permalink
Use the correct pointer to the parent dock widget.
Browse files Browse the repository at this point in the history
Re #7525. Parent widget of MantidTreeWidget wasn't the MantidDockWidget so static cast didn't work.
  • Loading branch information
mantid-roman committed Jul 29, 2013
1 parent 9a60808 commit 5d13ab7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 22 additions & 5 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ MantidDockWidget::MantidDockWidget(MantidUI *mui, ApplicationWindow *parent) :
QFrame *f = new QFrame(this);
setWidget(f);

m_tree = new MantidTreeWidget(f,m_mantidUI);
m_tree = new MantidTreeWidget(this,m_mantidUI);
m_tree->setHeaderLabel("Workspaces");

FlowLayout * buttonLayout = new FlowLayout();
Expand Down Expand Up @@ -462,6 +462,7 @@ void MantidDockWidget::updateTree()
entry->setExpanded( true );
}
}
m_tree->sort();
}

/**
Expand Down Expand Up @@ -1075,7 +1076,7 @@ void MantidDockWidget::convertMDHistoToMatrixWorkspace()

//------------ MantidTreeWidget -----------------------//

MantidTreeWidget::MantidTreeWidget(QWidget *w, MantidUI *mui):QTreeWidget(w),m_mantidUI(mui),m_sortScheme()
MantidTreeWidget::MantidTreeWidget(MantidDockWidget *w, MantidUI *mui):QTreeWidget(w),m_dockWidget(w),m_mantidUI(mui),m_sortScheme()
{
setObjectName("WorkspaceTree");
setSelectionMode(QAbstractItemView::ExtendedSelection);
Expand Down Expand Up @@ -1150,14 +1151,14 @@ QStringList MantidTreeWidget::getSelectedWorkspaceNames() const
/// This relies on the item descriptions being up-to-date
/// so ensure that they are or if something was
/// replaced then it might not be correct.
static_cast<MantidDockWidget*>(parentWidget())->populateChildData(*it);
m_dockWidget->populateChildData(*it);

// Look for children (workspace groups)
QTreeWidgetItem *child = (*it)->child(0);
if ( child && child->text(0) == "WorkspaceGroup" )
{
// Have to populate the group's children if it hasn't been expanded
if (!(*it)->isExpanded()) static_cast<MantidDockWidget*>(parentWidget())->populateChildData(*it);
if (!(*it)->isExpanded()) m_dockWidget->populateChildData(*it);
const int count = (*it)->childCount();
for ( int i=1; i < count; ++i )
{
Expand Down Expand Up @@ -1247,6 +1248,22 @@ MantidItemSortScheme MantidTreeWidget::getSortScheme() const
return m_sortScheme;
}

/**
* Sort the items according to the current sort scheme and order.
*/
void MantidTreeWidget::sort()
{
sortItems(sortColumn(), m_sortOrder);
}

/**
* Log a warning message.
* @param msg :: A message to log.
*/
void MantidTreeWidget::logWarningMessage(const std::string& msg)
{
logObject.warning( msg );
}

//-------------------- MantidTreeWidgetItem ----------------------//
/**Constructor.
Expand Down Expand Up @@ -1326,7 +1343,7 @@ bool MantidTreeWidgetItem::operator<(const QTreeWidgetItem &other)const
}
catch(std::out_of_range &e)
{
QMessageBox::warning(m_parent, "Error", e.what());
m_parent->logWarningMessage( e.what() );
return false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MantidTreeWidget:public QTreeWidget
Q_OBJECT

public:
MantidTreeWidget(QWidget *w, MantidUI *mui);
MantidTreeWidget(MantidDockWidget *w, MantidUI *mui);
void mousePressEvent (QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseDoubleClickEvent(QMouseEvent *e);
Expand All @@ -149,9 +149,11 @@ class MantidTreeWidget:public QTreeWidget
Qt::SortOrder getSortOrder() const;
void logWarningMessage(const std::string&);
void disableNodes(bool);
void sort();

private:
QPoint m_dragStartPosition;
MantidDockWidget *m_dockWidget;
MantidUI *m_mantidUI;
static Mantid::Kernel::Logger& logObject;
MantidItemSortScheme m_sortScheme;
Expand Down

0 comments on commit 5d13ab7

Please sign in to comment.