logic: code controller communication

- Replaced CodeAccess with LocationAccess.
- Implemented basic functionality for CodeController.
- Added messaging to the project.
- Added QtThreadedFunctor to enable our Messaging thread to invoke calls on the QtThread.
- Added GraphController.

fortune cookie message = Good news from someone dear is coming soon.
This commit is contained in:
malte_langkabel
2014-07-02 16:42:33 +02:00
parent a8e32af5dd
commit 400e2629d2
37 changed files with 441 additions and 78 deletions
+1
View File
@@ -6,6 +6,7 @@ add_files(
qt/utility/QtHighLighter.cpp
qt/utility/QtHighLighter.h
qt/utility/QtThreadedFunctor.h
qt/utility/utilityQt.cpp
qt/utility/utilityQt.h
+100
View File
@@ -0,0 +1,100 @@
#ifndef QT_THREADED_FUCTOR_H
#define QT_THREADED_FUCTOR_H
#include <functional>
#include <QObject>
class QtThreadedFunctorHelper: public QObject
{
Q_OBJECT
signals:
void signalExecution();
private slots:
void execute()
{
m_callback();
}
public:
QtThreadedFunctorHelper()
{
QObject::connect(this, SIGNAL(signalExecution()), this, SLOT(execute()));
}
void operator()(std::function<void(void)> callback)
{
m_callback = callback;
signalExecution();
}
private:
std::function<void(void)> m_callback;
};
template <typename T1 = void, typename T2 = void, typename T3 = void>
class QtThreadedFunctor
{
public:
QtThreadedFunctor(std::function<void(T1, T2, T3)> callback) : m_callback(callback) {}
void operator()(T1 p1, T2 p2, T3 p3)
{
m_helper(std::bind(m_callback, p1, p2, p3));
}
private:
QtThreadedFunctorHelper m_helper;
std::function<void(T1, T2, T3)> m_callback;
};
template <typename T1, typename T2>
class QtThreadedFunctor<T1, T2, void>
{
public:
QtThreadedFunctor(std::function<void(T1, T2)> callback) : m_callback(callback) {}
void operator()(T1 p1, T2 p2)
{
m_helper(std::bind(m_callback, p1, p2));
}
private:
QtThreadedFunctorHelper m_helper;
std::function<void(T1, T2)> m_callback;
};
template <typename T1>
class QtThreadedFunctor<T1, void, void>
{
public:
QtThreadedFunctor(std::function<void(T1)> callback) : m_callback(callback) {}
void operator()(T1 p1)
{
m_helper(std::bind(m_callback, p1));
}
private:
QtThreadedFunctorHelper m_helper;
std::function<void(T1)> m_callback;
};
template <>
class QtThreadedFunctor<void, void, void>
{
public:
QtThreadedFunctor(std::function<void(void)> callback) : m_callback(callback) {}
void operator()()
{
m_helper(m_callback);
}
private:
QtThreadedFunctorHelper m_helper;
std::function<void(void)> m_callback;
};
#endif // QT_THREADED_FUCTOR_H
+13 -1
View File
@@ -8,6 +8,8 @@
QtCodeView::QtCodeView(ViewLayout* viewLayout)
: CodeView(viewLayout)
, m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this))
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
{
}
@@ -36,6 +38,16 @@ void QtCodeView::initGui()
}
void QtCodeView::addCodeSnippet(std::string str)
{
m_addCodeSnippetFunctor(str);
}
void QtCodeView::clearCodeSnippets()
{
m_clearCodeSnippetsFunctor();
}
void QtCodeView::doAddCodeSnippet(std::string str)
{
std::shared_ptr<Snippet> snippet = std::make_shared<Snippet>();
@@ -53,7 +65,7 @@ void QtCodeView::addCodeSnippet(std::string str)
m_snippets.push_back(snippet);
}
void QtCodeView::clearCodeSnippets()
void QtCodeView::doClearCodeSnippets()
{
m_snippets.clear();
}
+7
View File
@@ -7,6 +7,7 @@
#include <QFont>
#include "component/view/CodeView.h"
#include "qt/utility/QtThreadedFunctor.h"
class QtHighlighter;
class QTextEdit;
@@ -33,7 +34,13 @@ private:
};
std::vector<std::shared_ptr<Snippet>> m_snippets;
void doAddCodeSnippet(std::string str);
void doClearCodeSnippets();
QFont m_font;
QtThreadedFunctor<void> m_clearCodeSnippetsFunctor;
QtThreadedFunctor<std::string> m_addCodeSnippetFunctor;
};
# endif // QT_CODE_VIEW_H