Skip to content

Commit

Permalink
Hook new MessageDisplay to MantidPlot. Refs #6202
Browse files Browse the repository at this point in the history
No colours and the old stuff is still in the code.
  • Loading branch information
martyngigg committed Apr 9, 2013
1 parent fc9f523 commit 707e916
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 66 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/src/FrameworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ FrameworkManagerImpl::FrameworkManagerImpl() : g_log(Kernel::Logger::get("Framew
_set_output_format(_TWO_DIGIT_EXPONENT);
#endif

g_log.notice() << Mantid::welcomeMessage() << std::endl;
loadAllPlugins();
disableNexusOutput();
setNumOMPThreadsToConfigValue();
Expand Down
68 changes: 37 additions & 31 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtAPI/AlgorithmInputHistory.h"
#include "MantidQtAPI/ManageUserDirectories.h"
#include "MantidQtAPI/MessageDisplay.h"
#include "MantidQtAPI/Message.h"

#include "MantidQtMantidWidgets/ICatSearch.h"
#include "MantidQtMantidWidgets/ICatMyDataSearch.h"
Expand Down Expand Up @@ -259,21 +261,44 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
{
QCoreApplication::setOrganizationName("ISIS");
QCoreApplication::setApplicationName("MantidPlot");
#ifdef SHARED_MENUBAR
setAttribute(Qt::WA_DeleteOnClose);

#ifdef SHARED_MENUBAR
m_sharedMenuBar = new QMenuBar(NULL);
//setMenuBar(m_sharedMenuBar);
m_sharedMenuBar->setNativeMenuBar(true);
#endif
mantidUI = new MantidUI(this);
setAttribute(Qt::WA_DeleteOnClose);

setWindowTitle(tr("MantidPlot - untitled"));//Mantid
setObjectName("main application");
initGlobalConstants();
QPixmapCache::setCacheLimit(20*QPixmapCache::cacheLimit ());

tablesDepend = new QMenu(this);
// Logging as early as possible
logWindow = new QDockWidget(this);
logWindow->hide();
logWindow->setObjectName("logWindow"); // this is needed for QMainWindow::restoreState()
logWindow->setWindowTitle(tr("Results Log"));
addDockWidget( Qt::TopDockWidgetArea, logWindow );
using MantidQt::API::MessageDisplay;
resultsLog = new MantidQt::API::MessageDisplay(MessageDisplay::EnableLogLevelControl, logWindow);
logWindow->setWidget(resultsLog);
using MantidQt::API::Message;
qRegisterMetaType<Message>(); // Required to use it in signals-slots

// Start Mantid
// Set the Paraview path BEFORE libaries are loaded. Doing it here prevents
// the logs being poluted with library loading errors.
trySetParaviewPath(args);
using Mantid::Kernel::ConfigService;
ConfigService::Instance(); // Starts logging
resultsLog->attachLoggingChannel(); // Must be done after logging starts
using Mantid::API::FrameworkManager;
FrameworkManager::Instance(); // Starts logging

// Create UI object
mantidUI = new MantidUI(this);

// Everything else...
tablesDepend = new QMenu(this);
explorerWindow = new QDockWidget( this );
explorerWindow->setWindowTitle(tr("Project Explorer"));
explorerWindow->setObjectName("explorerWindow"); // this is needed for QMainWindow::restoreState()
Expand Down Expand Up @@ -331,18 +356,12 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
explorerSplitter->setSizes( splitterSizes << 45 << 45);
explorerWindow->hide();

logWindow = new QDockWidget(this);
logWindow->setObjectName("logWindow"); // this is needed for QMainWindow::restoreState()
logWindow->setWindowTitle(tr("Results Log"));
addDockWidget( Qt::TopDockWidgetArea, logWindow );

results=new QTextEdit(logWindow);
results->setReadOnly (true);
results->setContextMenuPolicy(Qt::CustomContextMenu);
connect(results, SIGNAL(customContextMenuRequested(const QPoint &)), this,
SLOT(showLogWindowContextMenu(const QPoint &)));
logWindow->setWidget(results);
logWindow->hide();
results->hide();
// results->setContextMenuPolicy(Qt::CustomContextMenu);
// connect(results, SIGNAL(customContextMenuRequested(const QPoint &)), this,
// SLOT(showLogWindowContextMenu(const QPoint &)));

consoleWindow = new QDockWidget(this);
consoleWindow->setObjectName("consoleWindow"); // this is needed for QMainWindow::restoreState()
Expand Down Expand Up @@ -374,17 +393,6 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
undoStackWindow->setWidget(d_undo_view);
undoStackWindow->hide();

/*
If applicable, set the Paraview path BEFORE libaries are loaded. Doing it here, before the call to MantidUI::init() prevents
the logs being poluted with library loading errors.
*/
trySetParaviewPath(args);

//Initialize Mantid
// MG: 01/02/2009 - Moved this to before scripting so that the logging is connected when
// we register Python algorithms
mantidUI->init();

// Needs to be done after initialization of dock windows,
// because we now use QDockWidget::toggleViewAction()
createActions();
Expand Down Expand Up @@ -415,8 +423,6 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
insertTranslatedStrings();
disableToolbars();

// assistant = new QAssistantClient( QString(), this );

actionNextWindow = new QAction(QIcon(getQPixmap("next_xpm")), tr("&Next","next window"), this);
actionNextWindow->setShortcut( tr("F5","next window shortcut") );
connect(actionNextWindow, SIGNAL(activated()), d_workspace, SLOT(activateNextSubWindow()));
Expand Down Expand Up @@ -448,7 +454,6 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
this, SLOT(renameWindow(Q3ListViewItem *, int, const QString &)));

connect(recent, SIGNAL(activated(int)), this, SLOT(openRecentProject(int)));
//connect(&http, SIGNAL(done(bool)), this, SLOT(receivedVersionFile(bool)));

//apply user settings
updateAppFonts();
Expand All @@ -475,7 +480,8 @@ void ApplicationWindow::init(bool factorySettings, const QStringList& args)
actionIPythonConsole->setVisible(testForIPython());

// Need to show first time setup dialog?
Mantid::Kernel::ConfigServiceImpl& config = Mantid::Kernel::ConfigService::Instance();
using Mantid::Kernel::ConfigServiceImpl;
ConfigServiceImpl& config = ConfigService::Instance();
std::string facility = config.getString("default.facility");
std::string instrument = config.getString("default.instrument");
if ( facility.empty() || instrument.empty() )
Expand Down
15 changes: 10 additions & 5 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ class MantidTable;

namespace MantidQt
{
namespace MantidWidgets
{
class FitPropertyBrowser;
}}

namespace API
{
class MessageDisplay;
}
namespace MantidWidgets
{
class FitPropertyBrowser;
}
}
//Mantid
class MantidUI;
class ScriptingWindow;
Expand Down Expand Up @@ -1396,6 +1400,7 @@ public slots:
Script *m_iface_script;
QTranslator *appTranslator, *qtTranslator;
QDockWidget *explorerWindow, *undoStackWindow;
MantidQt::API::MessageDisplay *resultsLog;
QTextEdit *results;
QDockWidget *consoleWindow;
QTextEdit *console;
Expand Down
31 changes: 14 additions & 17 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ m_finishedLoadDAEObserver(*this, &MantidUI::handleLoadDAEFinishedNotification),
m_appWindow(aw), m_vatesSubWindow(NULL),
g_log(Mantid::Kernel::Logger::get("MantidUI"))
{

// To be able to use them in queued signals they need to be registered
static bool registered_addtional_types = false;
if( !registered_addtional_types )
Expand Down Expand Up @@ -160,31 +161,27 @@ m_finishedLoadDAEObserver(*this, &MantidUI::handleLoadDAEFinishedNotification),

menuMantidMatrix = new QMenu(m_appWindow);
connect(menuMantidMatrix, SIGNAL(aboutToShow()), this, SLOT(menuMantidMatrixAboutToShow()));

init();
}

// Should it be moved to the constructor?
void MantidUI::init()
{
Mantid::Kernel::ConfigService::Instance();
// Echo Mantid's welcome message to the logger
m_appWindow->writeToLogWindow(QString::fromStdString(Mantid::welcomeMessage()));
MantidLog::connect(this);
FrameworkManager::Instance();

AnalysisDataService::Instance().notificationCenter.addObserver(m_addObserver);
AnalysisDataService::Instance().notificationCenter.addObserver(m_replaceObserver);
AnalysisDataService::Instance().notificationCenter.addObserver(m_deleteObserver);
AnalysisDataService::Instance().notificationCenter.addObserver(m_clearADSObserver);
AnalysisDataService::Instance().notificationCenter.addObserver(m_renameObserver);
AnalysisDataService::Instance().notificationCenter.addObserver(m_groupworkspacesObserver);
AnalysisDataService::Instance().notificationCenter.addObserver(m_ungroupworkspaceObserver);
AnalysisDataService::Instance().notificationCenter.addObserver(m_workspaceGroupUpdateObserver);

// Now that the framework is initialized we need to populate the algorithm tree
AnalysisDataServiceImpl &dataStore = AnalysisDataService::Instance();
dataStore.notificationCenter.addObserver(m_addObserver);
dataStore.notificationCenter.addObserver(m_replaceObserver);
dataStore.notificationCenter.addObserver(m_deleteObserver);
dataStore.notificationCenter.addObserver(m_clearADSObserver);
dataStore.notificationCenter.addObserver(m_renameObserver);
dataStore.notificationCenter.addObserver(m_groupworkspacesObserver);
dataStore.notificationCenter.addObserver(m_ungroupworkspaceObserver);
dataStore.notificationCenter.addObserver(m_workspaceGroupUpdateObserver);

m_exploreAlgorithms->update();
try
{
m_fitFunction = new MantidQt::MantidWidgets::FitPropertyBrowser(m_appWindow, m_appWindow->mantidUI);
m_fitFunction = new MantidQt::MantidWidgets::FitPropertyBrowser(m_appWindow, this);
m_fitFunction->init();
// this make the progress bar work with Fit algorithm running form the fit browser
connect(m_fitFunction,SIGNAL(executeFit(QString,QMap<QString,QString>,Mantid::API::AlgorithmObserver*)),
Expand Down
13 changes: 9 additions & 4 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ class AlgorithmMonitor;
class InstrumentWindow;
namespace MantidQt
{
namespace MantidWidgets
{
class FitPropertyBrowser;
}}
namespace API
{
class Message;
}
namespace MantidWidgets
{
class FitPropertyBrowser;
}
}

namespace Ui
{
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidQt/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set ( SRC_FILES
src/MantidQwtIMDWorkspaceData.cpp
src/MantidQwtMatrixWorkspaceData.cpp
src/MantidWidget.cpp
src/Message.cpp
src/MessageDisplay.cpp
src/OptionsPropertyWidget.cpp
src/PropertyWidget.cpp
Expand Down
16 changes: 9 additions & 7 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//----------------------------------
// Includes
//----------------------------------
#include <QMetaType>
#include <QObject>
#include <QString>

Expand All @@ -29,26 +30,27 @@ namespace MantidQt
/// Priority matches Mantid Logger priority
typedef Mantid::Kernel::Logger::Priority Priority;

/// Default constuctor required by Qt meta-type system
Message();
/// Construct a message from a string with a given priority (default=notice)
Message(const QString & text, Priority priority=Priority::PRIO_NOTICE)
: m_text(text), m_priority(priority)
{}
Message(const QString & text, Priority priority=Priority::PRIO_NOTICE);
/// Copy constructor
Message(const Message & msg);

public:

/// @returns The message text
inline QString text() const {return m_text;}
/// @returns The message priority
inline Priority priority() const {return m_priority;}

private:
DISABLE_DEFAULT_CONSTRUCT(Message);

QString m_text;
Priority m_priority;
};

}
}

/// Required to operate in signals/slots
Q_DECLARE_METATYPE(MantidQt::API::Message);

#endif //MESSAGE_H_
35 changes: 35 additions & 0 deletions Code/Mantid/MantidQt/API/src/Message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//-------------------------------------------
// Includes
//-------------------------------------------
#include "MantidQtAPI/Message.h"

namespace MantidQt
{
namespace API
{
//-----------------------------------------------------------------------------------
// Public member functions
//-----------------------------------------------------------------------------------
/**
* Constructs a blank message with notice priority
* (here to satisfy Qt meta-type system)
*/
Message::Message() : QObject(), m_text(), m_priority(Priority::PRIO_NOTICE)
{}

/// Construct a message from a string with a given priority (default=notice)
Message::Message(const QString & text, Priority priority)
: QObject(), m_text(text), m_priority(priority)
{}

/**
* Construct a message from another object
*/
Message::Message(const Message & msg)
: QObject(), m_text(msg.text()), m_priority(msg.priority())
{
}


}
}
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/API/src/MessageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ namespace MantidQt
Poco::Logger::setChannel(rootLogger.name(), m_logChannel);
}

connect(m_logChannel, SIGNAL(messageReceived(const API::Message&)),
this, SLOT(append(const QString &)));
connect(m_logChannel, SIGNAL(messageReceived(const Message&)),
this, SLOT(append(const Message &)));
}

/**
Expand Down

0 comments on commit 707e916

Please sign in to comment.