Skip to content

Commit

Permalink
Added horizontal expansion to algorithm drop down
Browse files Browse the repository at this point in the history
Also removed trailing whitespace

Refs #10158
  • Loading branch information
DanNixon committed Sep 2, 2014
1 parent b5d5816 commit a3ce684
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
79 changes: 39 additions & 40 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Expand Up @@ -69,7 +69,7 @@ MantidDockWidget::MantidDockWidget(MantidUI *mui, ApplicationWindow *parent) :
//

m_loadMenu = new QMenu(this);

QAction* loadFileAction = new QAction("File",this);
QAction *liveDataAction = new QAction("Live Data",this);
m_loadMapper = new QSignalMapper(this);
Expand Down Expand Up @@ -178,7 +178,7 @@ void MantidDockWidget::createWorkspaceMenuActions()
connect(m_showMDPlot, SIGNAL(activated()), m_mantidUI, SLOT(showMDPlot()));

m_showListData = new QAction(tr("List Data"), this);
connect(m_showListData, SIGNAL(activated()), m_mantidUI, SLOT(showListData()));
connect(m_showListData, SIGNAL(activated()), m_mantidUI, SLOT(showListData()));

m_showSpectrumViewer = new QAction(tr("Show Spectrum Viewer"), this);
connect(m_showSpectrumViewer, SIGNAL(activated()), m_mantidUI, SLOT(showSpectrumViewer()));
Expand All @@ -196,7 +196,7 @@ void MantidDockWidget::createWorkspaceMenuActions()

m_saveNexus = new QAction(tr("Save Nexus"),this);
connect(m_saveNexus,SIGNAL(activated()),m_mantidUI,SLOT(saveNexusWorkspace()));

m_rename = new QAction(tr("Rename"),this);
connect(m_rename,SIGNAL(activated()),this,SLOT(renameWorkspace()));

Expand Down Expand Up @@ -230,25 +230,25 @@ void MantidDockWidget::createSortMenuActions()
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);
Expand All @@ -258,7 +258,7 @@ void MantidDockWidget::createSortMenuActions()
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()));
Expand Down Expand Up @@ -647,7 +647,7 @@ void MantidDockWidget::clickedWorkspace(QTreeWidgetItem* item, int)
}

void MantidDockWidget::workspaceSelected()
{
{
QList<QTreeWidgetItem*> selectedItems=m_tree->selectedItems();
if(selectedItems.isEmpty()) return;
QString wsName=selectedItems[0]->text(0);
Expand All @@ -670,7 +670,7 @@ void MantidDockWidget::deleteWorkspaces()
if(m->workspaceName().isEmpty()) return;

if(m_ads.doesExist(m->workspaceName().toStdString()))
{
{
m_mantidUI->deleteWorkspace(m->workspaceName());
}
return;
Expand Down Expand Up @@ -741,9 +741,9 @@ void MantidDockWidget::saveToProgram(const QString & name)
//Assign a key to its value using the map
programKeysAndDetails[programKeys[i]] = (Mantid::Kernel::ConfigService::Instance().getString(("workspace.sendto." + programKeysAndDetails.find("name")->second + "." + programKeys[i])));
}

//Check to see if mandatory information is included
if ((programKeysAndDetails.count("name") != 0) && (programKeysAndDetails.count("target") != 0) && (programKeysAndDetails.count("saveusing") != 0))
if ((programKeysAndDetails.count("name") != 0) && (programKeysAndDetails.count("target") != 0) && (programKeysAndDetails.count("saveusing") != 0))
{
std::string expTarget = Poco::Path::expand(programKeysAndDetails.find("target")->second);

Expand Down Expand Up @@ -818,15 +818,15 @@ void MantidDockWidget::saveToProgram(const QString & name)
}
else
arguments.insert(0, savedFile);

//convert the list into a standard vector for compatibility with Poco
std::vector<std::string> argumentsV;

for (int i = 0; i<arguments.size(); i++)
{
argumentsV.assign(1, (arguments[i].toStdString()));
}

//Execute the program
try
{
Expand All @@ -848,7 +848,7 @@ void MantidDockWidget::saveToProgram(const QString & name)
}
}


void MantidDockWidget::renameWorkspace()
{
//get selected workspace
Expand Down Expand Up @@ -907,7 +907,7 @@ void MantidDockWidget::popupMenu(const QPoint & pos)
}

// Add the items that are appropriate for the type
if( MatrixWorkspace_const_sptr matrixWS = boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(ws) )
if( MatrixWorkspace_const_sptr matrixWS = boost::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(ws) )
{
addMatrixWorkspaceMenuItems(menu, matrixWS);
}
Expand All @@ -923,7 +923,7 @@ void MantidDockWidget::popupMenu(const QPoint & pos)
{
addPeaksWorkspaceMenuItems(menu, peaksWS);
}
else if( boost::dynamic_pointer_cast<const WorkspaceGroup>(ws) )
else if( boost::dynamic_pointer_cast<const WorkspaceGroup>(ws) )
{
addWorkspaceGroupMenuItems(menu);
}
Expand All @@ -932,7 +932,7 @@ void MantidDockWidget::popupMenu(const QPoint & pos)
addTableWorkspaceMenuItems(menu);
}
addClearMenuItems(menu, selectedWsName);

//Get the names of the programs for the send to option
std::vector<std::string> programNames = (Mantid::Kernel::ConfigService::Instance().getKeys("workspace.sendto.name"));
bool firstPass(true);
Expand Down Expand Up @@ -970,16 +970,16 @@ void MantidDockWidget::popupMenu(const QPoint & pos)
connect(m_program,SIGNAL(activated()),m_programMapper,SLOT(map()));
//Send name of program when clicked
m_programMapper->setMapping(m_program, name);
m_saveToProgram->addAction(m_program);
m_saveToProgram->addAction(m_program);

// Set first pass to false so that it doesn't set up another menu entry for all programs.
firstPass = false;
}
}
}
}

//Tell the button what to listen for and what to do once clicked (if there is anything to connect it will be set to false)
if (firstPass == false)
if (firstPass == false)
connect(m_programMapper, SIGNAL(mapped(const QString &)), this, SLOT(saveToProgram(const QString &)));

//Rename is valid for all workspace types
Expand Down Expand Up @@ -1025,7 +1025,7 @@ void MantidDockWidget::plotSpectraDistribution()
const QMultiMap<QString,std::set<int> > toPlot = m_tree->chooseSpectrumFromSelected();
// An empty map will be returned if the user clicks cancel in the spectrum selection
if (toPlot.empty()) return;

m_mantidUI->plot1D(toPlot, true, false, true );
}

Expand All @@ -1035,7 +1035,7 @@ void MantidDockWidget::plotSpectraErr()
const QMultiMap<QString,std::set<int> > toPlot = m_tree->chooseSpectrumFromSelected();
// An empty map will be returned if the user clicks cancel in the spectrum selection
if (toPlot.empty()) return;

m_mantidUI->plot1D(toPlot, true, true);
}

Expand All @@ -1045,7 +1045,7 @@ void MantidDockWidget::plotSpectraDistributionErr()
const QMultiMap<QString,std::set<int> > toPlot = m_tree->chooseSpectrumFromSelected();
// An empty map will be returned if the user clicks cancel in the spectrum selection
if (toPlot.empty()) return;

m_mantidUI->plot1D(toPlot, true, true, true );
}

Expand Down Expand Up @@ -1181,7 +1181,7 @@ void MantidTreeWidget::dragMoveEvent(QDragMoveEvent *de)
if (de->mimeData()->hasUrls())
de->accept();
}

/**
* Accept a drag enter event and selects whether to accept the action
* @param de :: The drag enter event
Expand All @@ -1194,19 +1194,19 @@ void MantidTreeWidget::dragEnterEvent(QDragEnterEvent *de)
}



/**
* Accept a drag drop event and process the data appropriately
* @param de :: The drag drop event
*/
void MantidTreeWidget::dropEvent(QDropEvent *de)
{
QStringList filenames;
const QMimeData *mimeData = de->mimeData();
if (mimeData->hasUrls())
const QMimeData *mimeData = de->mimeData();
if (mimeData->hasUrls())
{
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size(); ++i)
for (int i = 0; i < urlList.size(); ++i)
{
QString fName = urlList[i].toLocalFile();
if (fName.size()>0)
Expand All @@ -1217,7 +1217,7 @@ void MantidTreeWidget::dropEvent(QDropEvent *de)
}
de->acceptProposedAction();

for (int i = 0; i < filenames.size(); ++i)
for (int i = 0; i < filenames.size(); ++i)
{
try
{
Expand All @@ -1232,7 +1232,7 @@ void MantidTreeWidget::dropEvent(QDropEvent *de)
catch (std::runtime_error& error)
{
treelog.error()<<"Failed to Load the file "<<filenames[i].toStdString()<<" . The reason for failure is: "<< error.what()<<std::endl;
}
}
catch (std::logic_error& error)
{
treelog.error()<<"Failed to Load the file "<<filenames[i].toStdString()<<" . The reason for failure is: "<< error.what()<<std::endl;
Expand Down Expand Up @@ -1276,10 +1276,10 @@ void MantidTreeWidget::mouseMoveEvent(QMouseEvent *e)
if (importStatement.size() > 0) importStatement += "\n";
importStatement += prefix + wsname + " = mtd[\"" + wsname + "\"]";
}

mimeData->setText(importStatement);
mimeData->setObjectName("MantidWorkspace");

drag->setMimeData(mimeData);

Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
Expand Down Expand Up @@ -1318,7 +1318,7 @@ void MantidTreeWidget::mouseDoubleClickEvent(QMouseEvent *e)
QStringList MantidTreeWidget::getSelectedWorkspaceNames() const
{
QStringList names;

foreach( const auto selectedItem, this->selectedItems() )
{
if( selectedItem )
Expand Down Expand Up @@ -1403,7 +1403,7 @@ QMultiMap<QString,std::set<int> > MantidTreeWidget::chooseSpectrumFromSelected()
return spectrumToPlot;
}

// Else, one or more workspaces
// Else, one or more workspaces
MantidWSIndexDialog *dio = new MantidWSIndexDialog(m_mantidUI, 0, selectedMatrixWsNameList);
dio->exec();
return dio->getPlots();
Expand Down Expand Up @@ -1471,7 +1471,7 @@ bool MantidTreeWidgetItem::operator<(const QTreeWidgetItem &other)const
// If this and/or other has been set to have a Qt::UserRole, then
// it has an accompanying sort order that we must maintain, no matter
// what the user has seletected in terms of order or scheme.

bool thisShouldBeSorted = m_sortPos == 0;
const MantidTreeWidgetItem *mantidOther = dynamic_cast<const MantidTreeWidgetItem*>(&other);
int otherSortPos = mantidOther ? mantidOther->getSortPos() : 0;
Expand Down Expand Up @@ -1589,7 +1589,6 @@ QDockWidget(w),m_progressBar(NULL),m_algID(),m_mantidUI(mui)
layout->addLayout(m_runningLayout);

setWidget(f);

}

/** Update the list of algorithms in the dock */
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Expand Up @@ -104,14 +104,14 @@ private slots:
void addClearMenuItems(QMenu* menu, const QString& wsName);

void excludeItemFromSort(MantidTreeWidgetItem *item);

protected:
MantidTreeWidget * m_tree;
friend class MantidUI;

private:
QString selectedWsName;

MantidUI * const m_mantidUI;

QPushButton *m_loadButton;
Expand Down Expand Up @@ -176,7 +176,7 @@ class MantidTreeWidget:public QTreeWidget
MantidUI *m_mantidUI;
Mantid::API::AnalysisDataServiceImpl & m_ads;
MantidItemSortScheme m_sortScheme;
Qt::SortOrder m_sortOrder;
Qt::SortOrder m_sortOrder;
};

/**A class derived from QTreeWidgetItem, to accomodate
Expand Down
Expand Up @@ -31,6 +31,12 @@ namespace MantidWidgets
m_findAlg = new FindAlgComboBox;
m_findAlg->setEditable(true);
m_findAlg->completer()->setCompletionMode(QCompleter::PopupCompletion);

// Make the algorithm drop down use all the sapce it can horizontally
QSizePolicy expandHoriz;
expandHoriz.setHorizontalPolicy(QSizePolicy::Expanding);
m_findAlg->setSizePolicy(expandHoriz);

connect(m_findAlg,SIGNAL(enterPressed()),
this,SLOT(executeSelected()));
connect(m_findAlg,SIGNAL(editTextChanged(const QString&)),
Expand All @@ -42,7 +48,6 @@ namespace MantidWidgets
buttonLayout->addWidget(m_execButton);

buttonLayout->addWidget(m_findAlg);
buttonLayout->addStretch();

// Layout the tree and combo box
QVBoxLayout * layout = new QVBoxLayout(this, 0 /*border*/, 4 /*spacing*/);
Expand All @@ -56,15 +61,15 @@ namespace MantidWidgets
AlgorithmFactory::Instance().notificationCenter.addObserver(m_updateObserver);
connect(this, SIGNAL(algorithmFactoryUpdateReceived()), this, SLOT(update()));
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
AlgorithmSelectorWidget::~AlgorithmSelectorWidget()
{
AlgorithmFactory::Instance().notificationCenter.removeObserver(m_updateObserver);
}


/** Is the the execute button visible */
bool AlgorithmSelectorWidget::showExecuteButton() const
Expand Down Expand Up @@ -177,7 +182,7 @@ namespace MantidWidgets

/**
* The algorithm factory has been updated, refresh the widget
*
*
*/
void AlgorithmSelectorWidget::
handleAlgorithmFactoryUpdate(Mantid::API::AlgorithmFactoryUpdateNotification_ptr)
Expand Down

0 comments on commit a3ce684

Please sign in to comment.