Skip to content

Commit

Permalink
Refs #3985. Group functions in a QTreeWidget.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Whitley committed Apr 2, 2012
1 parent 1cdb487 commit b06a486
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
8 changes: 7 additions & 1 deletion Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17109,7 +17109,9 @@ void ApplicationWindow::closeGraph(const QString & wsName)


/**
*
* Hide all the graphs apart from the exception. Default not to have exception.
*
* @params exception :: The workspace not to be hidden. Default is no exception ("").
*/
void ApplicationWindow::hideGraphs(const QString & exception)
{
Expand All @@ -17128,6 +17130,10 @@ void ApplicationWindow::hideGraphs(const QString & exception)
}
}


/**
* Show all the graphs that are hidden
*/
void ApplicationWindow::showGraphs()
{
QList<MdiSubWindow *> windows = windowsList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class QComboBox;
class QSignalMapper;
class QMenu;
class QAction;
class QTreeWidget;

namespace Mantid
{
Expand Down Expand Up @@ -276,6 +277,8 @@ private slots:
void saveFunction();
void loadFunction();
void loadFunctionFromString();
void acceptFit();
void closeFit();

void copy();///< Copy the function string to the clipboard
void paste();///< Paste a function string from the clipboard
Expand Down Expand Up @@ -375,7 +378,6 @@ private slots:
/// To keep a copy of the initial parameters in case for undo fit
std::vector<double> m_initialParameters;


private:
/// load and save function
void loadFunction(const QString& funcString);
Expand Down Expand Up @@ -431,6 +433,11 @@ private slots:

/// To display a tip text
QLabel* m_tip;

// The widget for choosing the fit function.
QDialog* m_fitSelector;
// The tree widget containing the fit functions.
QTreeWidget* m_fitTree;

/// String property managers for special case attributes such as Filename or Formula
/// <attribute_name,string_manager>
Expand Down
79 changes: 74 additions & 5 deletions Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <QClipboard>
#include <QSignalMapper>
#include <QMetaMethod>
#include <QTreeWidget>

#include <algorithm>

Expand Down Expand Up @@ -521,16 +522,84 @@ void FitPropertyBrowser::addFunction()
if ( !cf ) return;
int i = m_registeredFunctions.indexOf(QString::fromStdString(m_defaultFunction));
bool ok = false;
QString fnName =
QInputDialog::getItem(this, "MantidPlot - Fit", "Select function type", m_registeredFunctions,i,false,&ok);
if (ok)

// Declare new widget for picking fit functions
m_fitSelector = new QDialog();
m_fitSelector->setModal(true);
//QTreeWidget *m_fitTree = new QTreeWidget();
m_fitTree = new QTreeWidget;

// Add functions to each of the categories. If it appears in more than one category then add to both
// Store in a map. Key = category. Value = vector of fit functions belonging to that category.
std::map<std::string, std::vector<std::string> > categories;
for (int i=0; i<m_registeredFunctions.size(); ++i)
{
boost::shared_ptr<Mantid::API::IFitFunction> f = boost::shared_ptr<Mantid::API::IFitFunction>(Mantid::API::FunctionFactory::Instance().createFitFunction(m_registeredFunctions[i].toStdString()));
std::vector<std::string> tempCategories = f->categories();
for (int j=0; j<tempCategories.size(); ++j)
{
categories[tempCategories[j] ].push_back(m_registeredFunctions[i].toStdString());
}
}

// Construct the QTreeWidget based on the map information of categories and their respective fit functions.
std::map<std::string, std::vector<std::string> >::const_iterator sItr = categories.end();
for (std::map<std::string, std::vector<std::string> >::const_iterator itr = categories.begin(); itr != sItr; ++itr)
{
PropertyHandler* h = getHandler()->findHandler(cf);
h->addFunction(fnName.toStdString());
QTreeWidgetItem *category = new QTreeWidgetItem(m_fitTree);
category->setText(0, QString::fromStdString(itr->first) );

std::vector<std::string>::const_iterator fitItrEnd = itr->second.end();
for (std::vector<std::string>::const_iterator fitItrBegin = itr->second.begin(); fitItrBegin != fitItrEnd; ++fitItrBegin)
{
QTreeWidgetItem *fit = new QTreeWidgetItem(category);
int num(std::distance(itr->second.begin(), fitItrBegin));
fit->setText(0, QString::fromStdString(fitItrBegin[0]) );
}
}

//Set the layout of the widget.
m_fitTree->setToolTip("Select a function type and press OK.");
m_fitTree->setHeaderLabel("Fit - Select function type");
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptFit()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(closeFit()));
connect(m_fitTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(acceptFit()));
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(m_fitTree);
layout->addWidget(buttonBox);
m_fitSelector->setLayout(layout);
m_fitSelector->show();
}


void FitPropertyBrowser::acceptFit()
{
QtBrowserItem * ci = m_browser->currentItem();
const Mantid::API::CompositeFunction* cf = getHandler()->findCompositeFunction(ci);
if ( !cf )
return;

QList<QTreeWidgetItem*> items(m_fitTree->selectedItems() );
if (items.size() != 1)
return;

if (items[0]->parent() == NULL)
return;

PropertyHandler* h = getHandler()->findHandler(cf);
h->addFunction(items[0]->text(0).toStdString());
emit functionChanged();

closeFit();
}

void FitPropertyBrowser::closeFit()
{
m_fitSelector->close();
}


/// Create CompositeFunction
void FitPropertyBrowser::createCompositeFunction(const QString& str)
{
Expand Down

0 comments on commit b06a486

Please sign in to comment.