diff --git a/MantidPlot/src/ApplicationWindow.cpp b/MantidPlot/src/ApplicationWindow.cpp index 70b7e943dd670ca97bf156fcbb605d5e401bd049..85cee739b7068f8295d34fb244d258744e1af243 100644 --- a/MantidPlot/src/ApplicationWindow.cpp +++ b/MantidPlot/src/ApplicationWindow.cpp @@ -378,6 +378,9 @@ void ApplicationWindow::init(bool factorySettings, const QStringList &args) { ConfigService::Instance(); // Starts logging resultsLog->attachLoggingChannel(); // Must be done after logging starts + // Read settings early so that the log level is set before the framework + // starts + resultsLog->readSettings(settings); // Load Mantid core libraries by starting the framework FrameworkManager::Instance(); #ifdef MAKE_VATES @@ -4819,12 +4822,6 @@ void ApplicationWindow::readSettings() { changeAppStyle(settings.value("/Style", appStyle).toString()); autoSave = settings.value("/AutoSave", false).toBool(); autoSaveTime = settings.value("/AutoSaveTime", 15).toInt(); - // set logging level to the last saved level - int lastLoggingLevel = - settings.value("/LastLoggingLevel", - Mantid::Kernel::Logger::Priority::PRIO_NOTICE).toInt(); - Mantid::Kernel::Logger::setLevelForAll(lastLoggingLevel); - d_backup_files = settings.value("/BackupProjects", true).toBool(); d_init_window_type = (WindowType)settings.value("/InitWindow", NoWindow).toInt(); @@ -5346,9 +5343,11 @@ void ApplicationWindow::saveSettings() { //"ProIndependent", "MantidPlot"); #endif - /* ---------------- group General --------------- */ - settings.beginGroup("/General"); + // Root level is named "General" by Qt + resultsLog->writeSettings(&settings); + // Our named group General, displayed as %General in the file + settings.beginGroup("/General"); settings.beginGroup("/ApplicationGeometry"); d_app_rect = QRect(this->pos(), this->size()); if (this->isMaximized()) @@ -5368,9 +5367,6 @@ void ApplicationWindow::saveSettings() { settings.setValue("/Style", appStyle); settings.setValue("/AutoSave", autoSave); settings.setValue("/AutoSaveTime", autoSaveTime); - // save current logger level from the root logger "" - int lastLoggingLevel = Mantid::Kernel::Logger("").getLevel(); - settings.setValue("/LastLoggingLevel", lastLoggingLevel); settings.setValue("/BackupProjects", d_backup_files); settings.setValue("/InitWindow", static_cast<int>(d_init_window_type)); diff --git a/qt/widgets/common/CMakeLists.txt b/qt/widgets/common/CMakeLists.txt index da0c5c53983b8743abf4314730519131d31ea5b4..af6fce19acad7e60b550a325e262c78661bded2b 100644 --- a/qt/widgets/common/CMakeLists.txt +++ b/qt/widgets/common/CMakeLists.txt @@ -244,8 +244,9 @@ set ( INC_FILES inc/MantidQtWidgets/Common/AlgorithmInputHistory.h inc/MantidQtWidgets/Common/AlgorithmRunner.h inc/MantidQtWidgets/Common/BatchAlgorithmRunner.h + inc/MantidQtWidgets/Common/Configurable.h inc/MantidQtWidgets/Common/DllOption.h - inc/MantidQtWidgets/Common/DropEventHelper.h + inc/MantidQtWidgets/Common/DropEventHelper.h inc/MantidQtWidgets/Common/FileDialogHandler.h inc/MantidQtWidgets/Common/FlowLayout.h inc/MantidQtWidgets/Common/GraphOptions.h diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/Configurable.h b/qt/widgets/common/inc/MantidQtWidgets/Common/Configurable.h new file mode 100644 index 0000000000000000000000000000000000000000..4e5251c61e8b0ee1755a6fdc90b9f053c8c45c8e --- /dev/null +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/Configurable.h @@ -0,0 +1,48 @@ +#ifndef MANTIDQT_MANTIDWIDGETS_CONFIGURABLE_H +#define MANTIDQT_MANTIDWIDGETS_CONFIGURABLE_H +/* + Copyright © 2011 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid>. + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +#include "MantidQtWidgets/Common/DllOption.h" + +class QSettings; + +namespace MantidQt { +namespace MantidWidgets { + +/** + * Defines an interface for an object to load and store + * any configuration settings that should persist between objects. A widget + * should inherit from this class and define the loadSettings and saveSettings + * member functions. These functions are expected to be called by the client + * along with a QSettings instance, opened at the correct group, which will + * either give access or receive the values. + */ +class EXPORT_OPT_MANTIDQT_COMMON Configurable { +public: + virtual void readSettings(const QSettings &) = 0; + virtual void writeSettings(QSettings *) = 0; +}; +} +} + +#endif // MANTIDQT_MANTIDWIDGETS_CONFIGURABLE_H diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h b/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h index a98b337bb9cf168bae076409eb6f54e0327d351c..0e7b2a520855e7d82a8febca00649532449c0240 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/MessageDisplay.h @@ -6,6 +6,7 @@ //---------------------------------- #include "DllOption.h" #include "MantidKernel/FilterChannel.h" +#include "MantidQtWidgets/Common/Configurable.h" #include "MantidQtWidgets/Common/Message.h" #include "MantidQtWidgets/Common/QtSignalChannel.h" @@ -19,10 +20,11 @@ //---------------------------------------------------------- class QAction; class QActionGroup; +class QPlainTextEdit; class QPoint; +class QSettings; class QShowEvent; class QSignalMapper; -class QPlainTextEdit; namespace MantidQt { namespace MantidWidgets { @@ -33,10 +35,16 @@ namespace MantidWidgets { * a message is a framework Poco message or a simple string. * It can connect to the Mantid logging framework if required */ -class EXPORT_OPT_MANTIDQT_COMMON MessageDisplay : public QWidget { +class EXPORT_OPT_MANTIDQT_COMMON MessageDisplay : public QWidget, + public Configurable { Q_OBJECT Q_PROPERTY(QString source READ source WRITE setSource) +public: + // Configurable interface + void readSettings(const QSettings &storage) override; + void writeSettings(QSettings *storage) override; + public: /// Controls whether the display is allowed to set the log levels enum LogLevelControl { EnableLogLevelControl = 0, DisableLogLevelControl }; diff --git a/qt/widgets/common/src/MessageDisplay.cpp b/qt/widgets/common/src/MessageDisplay.cpp index 0de032513f95517908c24abfc63838b1ccc75a5b..7ecaed61dcf5c01ee529fed3eef2a7defeb66d15 100644 --- a/qt/widgets/common/src/MessageDisplay.cpp +++ b/qt/widgets/common/src/MessageDisplay.cpp @@ -26,26 +26,39 @@ namespace MantidWidgets { //------------------------------------------- // Public member functions //------------------------------------------- + +/** + * Load settings from the persistent store. The client is expected to call + * this method with the QSettings object opened at the approriate group + * @param storage A pointer to an existing QSettings instance opened + * at the group containing the values + */ +void MessageDisplay::readSettings(const QSettings &storage) { + Mantid::Kernel::ConfigService::Instance().setFilterChannelLogLevel( + m_filterChannelName, + storage.value("MessageDisplayPriority", Message::Priority::PRIO_NOTICE) + .toInt(), + true); +} + +/** + * Load settings from the persistent store. The client is expected to call + * this method with the QSettings object opened at the approriate group + * @param storage A pointer to an existing QSettings instance opened + * at the group where the values should be stored. + */ +void MessageDisplay::writeSettings(QSettings *storage) { + Q_ASSERT(storage); + storage->setValue("MessageDisplayPriority", + static_cast<int>(m_filterChannel->getPriority())); +} + /** * Constructs a widget that does not allow control over the global log level * @param parent An optional parent widget */ MessageDisplay::MessageDisplay(QWidget *parent) - : QWidget(parent), m_logLevelControl(DisableLogLevelControl), - m_logChannel(new QtSignalChannel), - m_filterChannel(new Poco::FilterChannel), - m_textDisplay(new QPlainTextEdit(this)), m_formats(), - m_loglevels(new QActionGroup(this)), - m_logLevelMapping(new QSignalMapper(this)), - m_error(new QAction(tr("&Error"), this)), - m_warning(new QAction(tr("&Warning"), this)), - m_notice(new QAction(tr("&Notice"), this)), - m_information(new QAction(tr("&Information"), this)), - m_debug(new QAction(tr("&Debug"), this)) { - initActions(); - initFormats(); - setupTextArea(); -} + : MessageDisplay(DisableLogLevelControl, parent) {} /** * @param logLevelControl Controls whether this display shows the right-click @@ -57,7 +70,7 @@ MessageDisplay::MessageDisplay(LogLevelControl logLevelControl, QWidget *parent) : QWidget(parent), m_logLevelControl(logLevelControl), m_logChannel(new QtSignalChannel), m_filterChannel(new Poco::FilterChannel), - m_textDisplay(new QPlainTextEdit(this)), + m_textDisplay(new QPlainTextEdit(this)), m_formats(), m_loglevels(new QActionGroup(this)), m_logLevelMapping(new QSignalMapper(this)), m_error(new QAction(tr("&Error"), this)), @@ -73,9 +86,6 @@ MessageDisplay::MessageDisplay(LogLevelControl logLevelControl, QWidget *parent) /** */ MessageDisplay::~MessageDisplay() { - QSettings settings; - settings.setValue("MessageDisplayPriority", - static_cast<int>(m_filterChannel->getPriority())); // The Channel class is ref counted and will // delete itself when required m_filterChannel->release(); @@ -99,9 +109,6 @@ void MessageDisplay::attachLoggingChannel() { } m_filterChannel->addChannel(m_logChannel); - QSettings settings; - int priority = settings.value(QString::fromStdString(m_FilterChannelName), - Message::Priority::PRIO_NOTICE).toInt(); auto &configService = Mantid::Kernel::ConfigService::Instance(); configService.registerLoggingFilterChannel(m_FilterChannelName, @@ -239,9 +246,9 @@ void MessageDisplay::scrollToBottom() { m_textDisplay->verticalScrollBar()->maximum()); } -//---------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // Protected members -//---------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------ //----------------------------------------------------------------------------- // Private slot member functions @@ -362,10 +369,9 @@ void MessageDisplay::setupTextArea() { m_textDisplay->setMouseTracking(true); m_textDisplay->setUndoRedoEnabled(false); - this->setLayout(new QHBoxLayout(this)); - QLayout *layout = this->layout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(m_textDisplay); + auto layoutBox = new QHBoxLayout(this); + layoutBox->setContentsMargins(0, 0, 0, 0); + layoutBox->addWidget(m_textDisplay); this->setFocusProxy(m_textDisplay); m_textDisplay->setContextMenuPolicy(Qt::CustomContextMenu);