Skip to content

Commit

Permalink
Changed Sort menu to define sorting options. Re #7525
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jul 29, 2013
1 parent 5d13ab7 commit f7b5879
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 38 deletions.
94 changes: 57 additions & 37 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,41 +105,7 @@ MantidDockWidget::MantidDockWidget(MantidUI *mui, ApplicationWindow *parent) :
m_loadButton->setMenu(m_loadMenu);

// SET UP SORT
chooseByName();
m_sortMenu = new QMenu(this);
m_choiceMenu = new QMenu(m_sortMenu);

m_choiceMenu->setTitle(tr("Sort by"));

QAction* m_ascendingSortAction = new QAction("Ascending", this);
QAction* m_descendingSortAction = new QAction("Descending", this);
QAction* m_byNameChoice = new QAction("Name", this);
QAction* m_byLastModifiedChoice = new QAction("Last Modified", this);

m_byNameChoice->setCheckable(true);
m_byNameChoice->setEnabled(true);
m_byNameChoice->setToggleAction(true);

m_byLastModifiedChoice->setCheckable(true);
m_byLastModifiedChoice->setEnabled(true);
m_byLastModifiedChoice->setToggleAction(true);

m_sortChoiceGroup = new QActionGroup(m_sortMenu);
m_sortChoiceGroup->addAction(m_byNameChoice);
m_sortChoiceGroup->addAction(m_byLastModifiedChoice);
m_sortChoiceGroup->setExclusive(true);
m_byNameChoice->setChecked(true);

connect(m_ascendingSortAction, SIGNAL(activated()), this, SLOT(sortAscending()));
connect(m_descendingSortAction, SIGNAL(activated()), this, SLOT(sortDescending()));
connect(m_byNameChoice, SIGNAL(activated()), this, SLOT(chooseByName()));
connect(m_byLastModifiedChoice, SIGNAL(activated()), this, SLOT(chooseByLastModified()));
m_sortMenu->addAction(m_ascendingSortAction);
m_sortMenu->addAction(m_descendingSortAction);
m_sortMenu->addSeparator();
m_sortMenu->addMenu(m_choiceMenu);
m_choiceMenu->addActions(m_sortChoiceGroup->actions());
m_sortButton->setMenu(m_sortMenu);
createSortMenuActions();
createWorkspaceMenuActions();

connect(m_deleteButton,SIGNAL(clicked()),this,SLOT(deleteWorkspaces()));
Expand Down Expand Up @@ -301,6 +267,58 @@ void MantidDockWidget::createWorkspaceMenuActions()
connect(m_convertMDHistoToMatrixWorkspace,SIGNAL(triggered()),this,SLOT(convertMDHistoToMatrixWorkspace()));
}

/**
* Create actions for sorting.
*/
void MantidDockWidget::createSortMenuActions()
{
chooseByName();
m_sortMenu = new QMenu(this);

QAction* m_ascendingSortAction = new QAction("Ascending", this);
QAction* m_descendingSortAction = new QAction("Descending", this);
QAction* m_byNameChoice = new QAction("Name", this);
QAction* m_byLastModifiedChoice = new QAction("Last Modified", this);

m_ascendingSortAction->setCheckable(true);
m_ascendingSortAction->setEnabled(true);
m_ascendingSortAction->setToggleAction(true);

m_descendingSortAction->setCheckable(true);
m_descendingSortAction->setEnabled(true);
m_descendingSortAction->setToggleAction(true);

QActionGroup *sortDirectionGroup = new QActionGroup(m_sortMenu);
sortDirectionGroup->addAction(m_ascendingSortAction);
sortDirectionGroup->addAction(m_descendingSortAction);
sortDirectionGroup->setExclusive(true);
m_ascendingSortAction->setChecked(true);

m_byNameChoice->setCheckable(true);
m_byNameChoice->setEnabled(true);
m_byNameChoice->setToggleAction(true);

m_byLastModifiedChoice->setCheckable(true);
m_byLastModifiedChoice->setEnabled(true);
m_byLastModifiedChoice->setToggleAction(true);

m_sortChoiceGroup = new QActionGroup(m_sortMenu);
m_sortChoiceGroup->addAction(m_byNameChoice);
m_sortChoiceGroup->addAction(m_byLastModifiedChoice);
m_sortChoiceGroup->setExclusive(true);
m_byNameChoice->setChecked(true);

connect(m_ascendingSortAction, SIGNAL(activated()), this, SLOT(sortAscending()));
connect(m_descendingSortAction, SIGNAL(activated()), this, SLOT(sortDescending()));
connect(m_byNameChoice, SIGNAL(activated()), this, SLOT(chooseByName()));
connect(m_byLastModifiedChoice, SIGNAL(activated()), this, SLOT(chooseByLastModified()));

m_sortMenu->addActions(sortDirectionGroup->actions());
m_sortMenu->addSeparator();
m_sortMenu->addActions(m_sortChoiceGroup->actions());
m_sortButton->setMenu(m_sortMenu);
}

/**
* Check if the given workspace is part of a known group
*/
Expand Down Expand Up @@ -649,23 +667,25 @@ void MantidDockWidget::deleteWorkspaces()
void MantidDockWidget::sortAscending()
{
m_tree->setSortOrder(Qt::Ascending);
m_tree->sortItems(m_tree->sortColumn(), Qt::Ascending);
m_tree->sort();
}

void MantidDockWidget::sortDescending()
{
m_tree->setSortOrder(Qt::Descending);
m_tree->sortItems(m_tree->sortColumn(), Qt::Descending);
m_tree->sort();
}

void MantidDockWidget::chooseByName()
{
m_tree->setSortScheme(ByName);
m_tree->sort();
}

void MantidDockWidget::chooseByLastModified()
{
m_tree->setSortScheme(ByLastModified);
m_tree->sort();
}

void MantidDockWidget::excludeItemFromSort(MantidTreeWidgetItem *item)
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private slots:

private:
void createWorkspaceMenuActions();
void createSortMenuActions();
QString findParentName(const QString & ws_name, Mantid::API::Workspace_sptr workspace);
void setItemIcon(QTreeWidgetItem* ws_item, Mantid::API::Workspace::InfoNode::IconType iconType);

Expand All @@ -106,7 +107,7 @@ private slots:
QSet<QString> m_known_groups;

QPushButton *m_loadButton;
QMenu *m_loadMenu, *m_saveToProgram, *m_sortMenu, *m_choiceMenu;
QMenu *m_loadMenu, *m_saveToProgram, *m_sortMenu;
QPushButton *m_deleteButton;
QPushButton *m_groupButton;
QPushButton *m_sortButton;
Expand Down

0 comments on commit f7b5879

Please sign in to comment.