diff --git a/Code/Mantid/Kernel/src/ConfigService.cpp b/Code/Mantid/Kernel/src/ConfigService.cpp index ed7eef6bfca5265fb7e5f186ce9dd82b20ae29a2..74bb42ed2e4960dcf0fdf728a264092058b467b8 100644 --- a/Code/Mantid/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Kernel/src/ConfigService.cpp @@ -602,15 +602,22 @@ namespace Kernel } // Any remaining keys within the changed key store weren't present in the current user properties so append them - updated_file += "\n"; - std::set<std::string>::iterator key_end = m_changed_keys.end(); - for( std::set<std::string>::iterator key_itr = m_changed_keys.begin(); - key_itr != key_end; ++key_itr ) + if( !m_changed_keys.empty() ) { - updated_file += *key_itr + "="; - updated_file += getString(*key_itr, false) + "\n"; + updated_file += "\n"; + std::set<std::string>::iterator key_end = m_changed_keys.end(); + for( std::set<std::string>::iterator key_itr = m_changed_keys.begin(); + key_itr != key_end;) + { + updated_file += *key_itr + "="; + updated_file += getString(*key_itr, false); + if( ++key_itr != key_end ) + { + updated_file += "\n"; + } + } + m_changed_keys.clear(); } - m_changed_keys.clear(); // Write out the new file std::ofstream writer(filename.c_str(), std::ios_base::trunc); diff --git a/Code/qtiplot/qtiplot/src/ConfigDialog.cpp b/Code/qtiplot/qtiplot/src/ConfigDialog.cpp index 0523ea6ad1d138a19e44d21370178a4acdc72544..f0809fd451694743c2be3f35f65a0369a14eb62a 100644 --- a/Code/qtiplot/qtiplot/src/ConfigDialog.cpp +++ b/Code/qtiplot/qtiplot/src/ConfigDialog.cpp @@ -66,7 +66,8 @@ #include <QMouseEvent> #include "MantidKernel/ConfigService.h" - +#include "MantidAPI/FunctionFactory.h" +#include "MantidAPI/IBackgroundFunction.h" static const char* choose_folder_xpm[]={ "16 16 11 1", @@ -670,13 +671,18 @@ void ConfigDialog::initMantidPage() } instrPrefix->setCurrentIndex(index); - /// Init Directories tab + initDirSearchTab(); + initCurveFittingTab(); + +} +void ConfigDialog::initDirSearchTab() +{ directoriesPage = new QWidget(); QVBoxLayout *dirTabLayout = new QVBoxLayout(directoriesPage); - frame = new QGroupBox(); + QGroupBox *frame = new QGroupBox(); dirTabLayout->addWidget(frame); - grid = new QGridLayout(frame); + QGridLayout *grid = new QGridLayout(frame); mtdTabWidget->addTab(directoriesPage, "Directories"); /// datasearch.directories @@ -769,14 +775,76 @@ void ConfigDialog::initMantidPage() button = new QPushButton(); button->setIcon(QIcon(QPixmap(choose_folder_xpm))); grid->addWidget(button, 5, 2); - button->setEnabled(false); - leParameterDir->setEnabled(false); connect( button, SIGNAL(clicked()), this, SLOT(addParameterDir()) ); - grid->setRowStretch(6,1); } +void ConfigDialog::initCurveFittingTab() +{ + curveFittingPage = new QWidget(); + QVBoxLayout *curveTabLayout = new QVBoxLayout(curveFittingPage); + QGroupBox *frame = new QGroupBox(); + curveTabLayout->addWidget(frame); + QGridLayout *grid = new QGridLayout(frame); + mtdTabWidget->addTab(curveFittingPage, "Curve Fitting"); + + // Background functions list + grid->addWidget(new QLabel(tr("Auto background")),0,0); + backgroundFunctions = new QComboBox(); + grid->addWidget(backgroundFunctions, 0, 1); + + grid->addWidget(new QLabel(tr("Background arguments")),1,0); + functionArguments = new QLineEdit(); + grid->addWidget(functionArguments, 1,1); + + grid->setRowStretch(2,1); + + // Find list of background functions + // Add none option + backgroundFunctions->addItem("None"); + Mantid::API::FunctionFactoryImpl & function_creator = Mantid::API::FunctionFactory::Instance(); + std::vector<std::string> allfunctions = function_creator.getKeys(); + size_t nfuncs = allfunctions.size(); + for( size_t i = 0; i < nfuncs; ++i ) + { + std::string name = allfunctions[i]; + Mantid::API::IFunction* function = function_creator.createUnwrapped(name); + if( dynamic_cast<Mantid::API::IBackgroundFunction*>(function) ) + { + backgroundFunctions->addItem(QString::fromStdString(name)); + } + } + + // Set the correct default property + QString setting = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("CurveFitting.AutoBackground")); + QStringList value = setting.split(' '); + int index(-1); + if( value.isEmpty() ) + { + index = 0; + } + else + { + index = backgroundFunctions->findText(value[0], Qt::MatchFixedString);// Case insensitive + if( value.size() > 1 ) + { + value.removeFirst(); + QString args = value.join(" "); + functionArguments->setText(args); + } + } + if( index < 0 ) + { + backgroundFunctions->setCurrentIndex(0); + } + else + { + backgroundFunctions->setCurrentIndex(index); + } +} + + void ConfigDialog::initOptionsPage() { ApplicationWindow *app = (ApplicationWindow *)parentWidget(); @@ -1590,7 +1658,26 @@ void ConfigDialog::apply() setting.replace(QRegExp("\\W+"), QString(";")); mantid_config.setString("instrument.prefixes." + cur_facility, setting.toStdString()); - setting = leDataSearchDirs->text(); + updateDirSearchSettings(); + updateCurveFitSettings(); + + try + { + mantid_config.saveConfig(mantid_config.getUserFilename()); + } + catch(std::runtime_error&) + { + QMessageBox::warning(this, "MantidPlot", + "Unable to update Mantid user properties file.\n" + "Configuration will not be saved."); + } +} + +void ConfigDialog::updateDirSearchSettings() +{ + Mantid::Kernel::ConfigServiceImpl& mantid_config = Mantid::Kernel::ConfigService::Instance(); + + QString setting = leDataSearchDirs->text(); setting.replace('\\','/'); mantid_config.setString("datasearch.directories",setting.toStdString()); @@ -1614,18 +1701,26 @@ void ConfigDialog::apply() setting.replace('\\','/'); mantid_config.setString("parameterDefinition.directory",setting.toStdString()); - try - { - mantid_config.saveConfig(mantid_config.getUserFilename()); - } - catch(std::runtime_error&) - { - QMessageBox::warning(this, "MantidPlot", - "Unable to update Mantid user properties file.\n" - "Configuration will not be saved."); - } } +void ConfigDialog::updateCurveFitSettings() +{ + Mantid::Kernel::ConfigServiceImpl& mantid_config = Mantid::Kernel::ConfigService::Instance(); + + // Form setting string from function name and parameters + QString fname = backgroundFunctions->currentText(); + std::string setting = fname.toStdString(); + //Ignore parameters for none + if( fname != "None" ) + { + QString args = functionArguments->text(); + setting += std::string(" ") + args.toStdString(); + } + + mantid_config.setString("CurveFitting.AutoBackground", setting); +} + + int ConfigDialog::curveStyle() { int style = 0; diff --git a/Code/qtiplot/qtiplot/src/ConfigDialog.h b/Code/qtiplot/qtiplot/src/ConfigDialog.h index 58d2d3c4d374c96d683cd959168bc9aac4115a92..64fd0bfa7efa70bf5f1b9228ce404cdb24fece9a 100644 --- a/Code/qtiplot/qtiplot/src/ConfigDialog.h +++ b/Code/qtiplot/qtiplot/src/ConfigDialog.h @@ -115,18 +115,24 @@ private slots: private: void initPlotsPage(); - void initOptionsPage(); - void initAxesPage(); + void initOptionsPage(); + void initAxesPage(); void initAppPage(); - // Mantid - void initMantidPage(); - void initCurvesPage(); + // Mantid + void initMantidPage(); + void initDirSearchTab(); + void initCurveFittingTab(); + + void initCurvesPage(); void initPlots3DPage(); void initTablesPage(); void initConfirmationsPage(); void initFileLocationsPage(); void initFittingPage(); + void updateDirSearchSettings(); + void updateCurveFitSettings(); + QFont textFont, headerFont, axesFont, numbersFont, legendFont, titleFont, appFont; QFont plot3DTitleFont, plot3DNumbersFont, plot3DAxesFont; @@ -154,6 +160,10 @@ private: QLineEdit* lePythonAlgorithmsDirs;///< pythonalgorithms.directories QLineEdit* leInstrumentDir;///< instrumentDefinition.directory QLineEdit* leParameterDir;///< parameterDefinition.directory + // Mantid curve fitting page + QWidget *curveFittingPage; + QComboBox *backgroundFunctions; + QLineEdit *functionArguments; QPushButton* buttonAxesFont, *buttonNumbersFont, *buttonLegendFont, *buttonTitleFont, *fontsBtn; QCheckBox *boxSearchUpdates, *boxOrthogonal, *logBox, *plotLabelBox, *scaleErrorsBox;