logic: initially parse source on message thread and add more StatusBar messages
This change puts the initial project loading into a MessageLoadProject so that the UI thread is still responding. Also the StatusBar is now responding to more Messages and it's MessageListeners get added to the MessageQueue in front of other listeners so that the StatusBar UI can announce actions.
This commit is contained in:
@@ -26,7 +26,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
QtViewFactory viewFactory;
|
||||
std::shared_ptr<Application> app = Application::create(&viewFactory);
|
||||
app->loadProject("data/ProjectSettings.xml");
|
||||
|
||||
return qtApp.exec();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
QtStatusBar::QtStatusBar()
|
||||
: m_text(this)
|
||||
{
|
||||
m_text.setText("hallo test test");
|
||||
m_text.setText("");
|
||||
addWidget(&m_text);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,4 +17,4 @@ private:
|
||||
QLabel m_text;
|
||||
};
|
||||
|
||||
#endif // !QT_STATUS_BAR_H
|
||||
#endif // QT_STATUS_BAR_H
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "qt/view/QtMainView.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
|
||||
QtStatusBarView::QtStatusBarView( ViewLayout* viewLayout )
|
||||
QtStatusBarView::QtStatusBarView(ViewLayout* viewLayout)
|
||||
: StatusBarView(viewLayout)
|
||||
, m_showMessageFunctor(std::bind(&QtStatusBarView::doShowMessage, this, std::placeholders::_1, std::placeholders::_2))
|
||||
{
|
||||
@@ -26,20 +26,18 @@ void QtStatusBarView::createWidgetWrapper()
|
||||
|
||||
void QtStatusBarView::initView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QtStatusBarView::refreshView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QtStatusBarView::doShowMessage( const std::string& message, bool isError )
|
||||
void QtStatusBarView::doShowMessage(const std::string& message, bool isError)
|
||||
{
|
||||
m_widget->setText(message, isError);
|
||||
}
|
||||
|
||||
void QtStatusBarView::showMessage( const std::string& message, bool isError )
|
||||
void QtStatusBarView::showMessage(const std::string& message, bool isError)
|
||||
{
|
||||
m_showMessageFunctor(message, isError);
|
||||
}
|
||||
|
||||
@@ -28,4 +28,4 @@ private:
|
||||
QtThreadedFunctor<const std::string&, bool> m_showMessageFunctor;
|
||||
};
|
||||
|
||||
#endif // !QT_STATUS_BAR_VIEW_H
|
||||
#endif // !QT_STATUS_BAR_VIEW_H
|
||||
|
||||
@@ -25,6 +25,8 @@ std::shared_ptr<Application> Application::create(ViewFactory* viewFactory)
|
||||
ptr->m_componentManager->setup();
|
||||
ptr->m_mainView->loadLayout();
|
||||
|
||||
MessageLoadProject("data/ProjectSettings.xml").dispatch();
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
#include "utility/messaging/type/MessageLoadSource.h"
|
||||
#include "utility/messaging/type/MessageSaveProject.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
#include "utility/messaging/type/MessageSaveProject.h"
|
||||
|
||||
class ViewFactory;
|
||||
class MainView;
|
||||
|
||||
@@ -3,8 +3,13 @@
|
||||
#include "component/view/StatusBarView.h"
|
||||
|
||||
StatusBarController::StatusBarController()
|
||||
: MessageListener<MessageError>(true)
|
||||
, MessageListener<MessageFinishedParsing>(true)
|
||||
, MessageListener<MessageLoadProject>(true)
|
||||
, MessageListener<MessageLoadSource>(true)
|
||||
, MessageListener<MessageRefresh>(true)
|
||||
, MessageListener<MessageStatus>(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StatusBarController::~StatusBarController()
|
||||
@@ -28,12 +33,28 @@ void StatusBarController::handleMessage(MessageStatus* message)
|
||||
|
||||
void StatusBarController::handleMessage(MessageError* message)
|
||||
{
|
||||
setStatus(message->error, true);
|
||||
setStatus(message->error, true);
|
||||
}
|
||||
|
||||
void StatusBarController::handleMessage(MessageLoadProject* message)
|
||||
{
|
||||
setStatus("Loading Project: " + message->projectSettingsFilePath);
|
||||
}
|
||||
|
||||
void StatusBarController::handleMessage(MessageLoadSource* message)
|
||||
{
|
||||
setStatus("Loading Source: " + message->sourceDirectoryPath);
|
||||
}
|
||||
|
||||
void StatusBarController::handleMessage(MessageRefresh* message)
|
||||
{
|
||||
setStatus("Refreshing Project");
|
||||
}
|
||||
|
||||
void StatusBarController::setStatus(const std::string& status, bool isError)
|
||||
{
|
||||
if(!status.empty())
|
||||
getView()->showMessage(status, isError);
|
||||
if (!status.empty())
|
||||
{
|
||||
getView()->showMessage(status, isError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,28 +8,37 @@
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageError.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
#include "utility/messaging/type/MessageLoadSource.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
|
||||
class StatusBarView;
|
||||
|
||||
class StatusBarController
|
||||
: public Controller
|
||||
, public MessageListener<MessageError>
|
||||
, public MessageListener<MessageFinishedParsing>
|
||||
, public MessageListener<MessageStatus>
|
||||
: public Controller
|
||||
, public MessageListener<MessageError>
|
||||
, public MessageListener<MessageFinishedParsing>
|
||||
, public MessageListener<MessageLoadProject>
|
||||
, public MessageListener<MessageLoadSource>
|
||||
, public MessageListener<MessageRefresh>
|
||||
, public MessageListener<MessageStatus>
|
||||
{
|
||||
public:
|
||||
|
||||
StatusBarController(void);
|
||||
~StatusBarController(void);
|
||||
virtual ~StatusBarController(void);
|
||||
|
||||
StatusBarView* getView();
|
||||
private:
|
||||
void setStatus(const std::string& status, bool isError = false);
|
||||
|
||||
virtual void handleMessage(MessageError* message);
|
||||
private:
|
||||
virtual void handleMessage(MessageError* message);
|
||||
virtual void handleMessage(MessageFinishedParsing* message);
|
||||
virtual void handleMessage(MessageLoadProject* message);
|
||||
virtual void handleMessage(MessageLoadSource* message);
|
||||
virtual void handleMessage(MessageRefresh* message);
|
||||
virtual void handleMessage(MessageStatus* message);
|
||||
|
||||
void setStatus(const std::string& status, bool isError = false);
|
||||
};
|
||||
|
||||
#endif // STATUS_BAR_CONTROLLER_H
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
StatusBarView::StatusBarView(ViewLayout* viewLayout)
|
||||
: View(viewLayout, Vec2i(100,100))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StatusBarView::~StatusBarView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string StatusBarView::getName() const
|
||||
@@ -21,4 +19,4 @@ std::string StatusBarView::getName() const
|
||||
StatusBarController* StatusBarView::getController()
|
||||
{
|
||||
return View::getController<StatusBarController>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@ template<typename MessageType>
|
||||
class MessageListener: public MessageListenerBase
|
||||
{
|
||||
public:
|
||||
MessageListener(bool toFront = false)
|
||||
: MessageListenerBase(toFront)
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string getType() const
|
||||
{
|
||||
return MessageType::getStaticType();
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
class MessageListenerBase
|
||||
{
|
||||
public:
|
||||
MessageListenerBase()
|
||||
MessageListenerBase(bool toFront)
|
||||
{
|
||||
MessageQueue::getInstance()->registerListener(this);
|
||||
MessageQueue::getInstance()->registerListener(this, toFront);
|
||||
}
|
||||
|
||||
virtual ~MessageListenerBase()
|
||||
|
||||
@@ -16,10 +16,20 @@ std::shared_ptr<MessageQueue> MessageQueue::getInstance()
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void MessageQueue::registerListener(MessageListenerBase* listener)
|
||||
void MessageQueue::registerListener(MessageListenerBase* listener, bool toFront)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_listenersMutex);
|
||||
m_listeners.push_back(listener);
|
||||
|
||||
if (toFront)
|
||||
{
|
||||
m_listeners.insert(m_listeners.begin(), listener);
|
||||
m_listenersLength++;
|
||||
m_currentListenerIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_listeners.push_back(listener);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageQueue::unregisterListener(MessageListenerBase* listener)
|
||||
|
||||
@@ -13,7 +13,7 @@ class MessageQueue
|
||||
public:
|
||||
static std::shared_ptr<MessageQueue> getInstance();
|
||||
|
||||
void registerListener(MessageListenerBase* listener);
|
||||
void registerListener(MessageListenerBase* listener, bool toFront = false);
|
||||
void unregisterListener(MessageListenerBase* listener);
|
||||
|
||||
void pushMessage(std::shared_ptr<MessageBase> message);
|
||||
|
||||
@@ -107,6 +107,28 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void test_listener_registration_to_front_and_back_within_message_handling(void)
|
||||
{
|
||||
MessageQueue::getInstance()->startMessageLoopThreaded();
|
||||
|
||||
Test5MessageListener listener;
|
||||
|
||||
TestMessage().dispatch();
|
||||
TestMessage().dispatch();
|
||||
TestMessage().dispatch();
|
||||
|
||||
waitForThread();
|
||||
|
||||
MessageQueue::getInstance()->stopMessageLoop();
|
||||
|
||||
TS_ASSERT_EQUALS(5, listener.m_listeners.size());
|
||||
TS_ASSERT_EQUALS(2, listener.m_listeners[0]->m_messageCount);
|
||||
TS_ASSERT_EQUALS(2, listener.m_listeners[1]->m_messageCount);
|
||||
TS_ASSERT_EQUALS(2, listener.m_listeners[2]->m_messageCount);
|
||||
TS_ASSERT_EQUALS(2, listener.m_listeners[3]->m_messageCount);
|
||||
TS_ASSERT_EQUALS(2, listener.m_listeners[4]->m_messageCount);
|
||||
}
|
||||
|
||||
private:
|
||||
class TestMessage: public Message<TestMessage>
|
||||
{
|
||||
@@ -129,8 +151,9 @@ private:
|
||||
class TestMessageListener: public MessageListener<TestMessage>
|
||||
{
|
||||
public:
|
||||
TestMessageListener()
|
||||
: m_messageCount(0)
|
||||
TestMessageListener(bool toFront = false)
|
||||
: MessageListener<TestMessage>(toFront)
|
||||
, m_messageCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -195,6 +218,25 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
class Test5MessageListener:
|
||||
public MessageListener<TestMessage>
|
||||
{
|
||||
public:
|
||||
std::vector<std::shared_ptr<TestMessageListener>> m_listeners;
|
||||
|
||||
private:
|
||||
virtual void handleMessage(TestMessage* message)
|
||||
{
|
||||
if (!m_listeners.size())
|
||||
{
|
||||
for (size_t i = 0; i < 5; i++)
|
||||
{
|
||||
m_listeners.push_back(std::make_shared<TestMessageListener>(i % 2 == 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void waitForThread() const
|
||||
{
|
||||
static const int THREAD_WAIT_TIME_MS = 5;
|
||||
|
||||
Reference in New Issue
Block a user