logic: code controller

- Renamed MessageActivateTokenLocation to MessageActivateToken, since it uses the Token id (not the TokenLocation id).
- Implemented CodeController to add one snippet for each location where the activated token occurred.
- Added Semaphore to QtThreadedFunctor to prevent an evil race-condition.
- CodeView dispatches message when a token is clicked.
This commit is contained in:
malte_langkabel
2014-07-03 16:03:06 +02:00
parent 4c7bbbe28e
commit 4ae6f4a04a
17 changed files with 183 additions and 44 deletions
+5
View File
@@ -3,6 +3,7 @@
#include <functional>
#include <QObject>
#include <QSemaphore>
class QtThreadedFunctorHelper: public QObject
{
@@ -15,22 +16,26 @@ private slots:
void execute()
{
m_callback();
m_freeCallbacks.release();
}
public:
QtThreadedFunctorHelper()
: m_freeCallbacks(1)
{
QObject::connect(this, SIGNAL(signalExecution()), this, SLOT(execute()));
}
void operator()(std::function<void(void)> callback)
{
m_freeCallbacks.acquire();
m_callback = callback;
signalExecution();
}
private:
std::function<void(void)> m_callback;
QSemaphore m_freeCallbacks;
};
template <typename T1 = void, typename T2 = void, typename T3 = void>
+3 -1
View File
@@ -8,6 +8,7 @@
#include "qt/QtWidgetWrapper.h"
#include "qt/utility/QtHighLighter.h"
#include "qt/utility/utilityQt.h"
#include "utility/messaging/type/MessageActivateToken.h"
QtCodeView::QtCodeView(ViewLayout* viewLayout)
: CodeView(viewLayout)
@@ -52,7 +53,8 @@ void QtCodeView::clearCodeSnippets()
void QtCodeView::activateToken(Id tokenId) const
{
std::cout << "TODO: activate Token: " << tokenId << std::endl;
MessageActivateToken message(tokenId);
message.dispatch();
}
void QtCodeView::doAddCodeSnippet(const std::string& str, const TokenLocationFile& locationFile, int startLineNumber)