forked from Sepanta/console-emulator
commit
a039c4f8f3
24 changed files with 566 additions and 0 deletions
@ -0,0 +1,57 @@ |
|||||
|
# C++ objects and libs |
||||
|
*.slo |
||||
|
*.lo |
||||
|
*.o |
||||
|
*.a |
||||
|
*.la |
||||
|
*.lai |
||||
|
*.so |
||||
|
*.dll |
||||
|
*.dylib |
||||
|
|
||||
|
# Qt-es |
||||
|
object_script.*.Release |
||||
|
object_script.*.Debug |
||||
|
*_plugin_import.cpp |
||||
|
/.qmake.cache |
||||
|
/.qmake.stash |
||||
|
*.pro.user |
||||
|
*.pro.user.* |
||||
|
*.qbs.user |
||||
|
*.qbs.user.* |
||||
|
*.moc |
||||
|
moc_*.cpp |
||||
|
moc_*.h |
||||
|
qrc_*.cpp |
||||
|
ui_*.h |
||||
|
*.qmlc |
||||
|
*.jsc |
||||
|
Makefile* |
||||
|
*build-* |
||||
|
|
||||
|
# Qt unit tests |
||||
|
target_wrapper.* |
||||
|
|
||||
|
# QtCreator |
||||
|
*.autosave |
||||
|
|
||||
|
# QtCreator Qml |
||||
|
*.qmlproject.user |
||||
|
*.qmlproject.user.* |
||||
|
|
||||
|
# QtCreator CMake |
||||
|
CMakeLists.txt.user* |
||||
|
|
||||
|
# QtCreator 4.8< compilation database |
||||
|
compile_commands.json |
||||
|
|
||||
|
# QtCreator local machine specific files for imported projects |
||||
|
*creator.user* |
||||
|
|
||||
|
#added be H-4nd-H to the template to comply with project needs |
||||
|
|
||||
|
*.pro.dummy |
||||
|
|
||||
|
bin/ |
||||
|
doc/ |
||||
|
*.lupdate |
@ -0,0 +1,11 @@ |
|||||
|
TEMPLATE = subdirs |
||||
|
|
||||
|
SUBDIRS += \ |
||||
|
logic \ |
||||
|
network \ |
||||
|
test \ |
||||
|
ui |
||||
|
|
||||
|
logic.depends += network |
||||
|
ui.depends += logic |
||||
|
test.depends += logic |
@ -0,0 +1,18 @@ |
|||||
|
#ifndef CONSOLE_H |
||||
|
#define CONSOLE_H |
||||
|
|
||||
|
|
||||
|
class DataSender; |
||||
|
|
||||
|
class Console |
||||
|
{ |
||||
|
private: |
||||
|
DataSender* _dataSender; |
||||
|
|
||||
|
public: |
||||
|
Console(); |
||||
|
void injectDataSender(DataSender* sender); |
||||
|
void test(); |
||||
|
}; |
||||
|
|
||||
|
#endif // CONSOLE_H
|
@ -0,0 +1,13 @@ |
|||||
|
#ifndef DATASENDER_H |
||||
|
#define DATASENDER_H |
||||
|
|
||||
|
#include <QByteArray> |
||||
|
|
||||
|
class DataSender |
||||
|
{ |
||||
|
public: |
||||
|
virtual int send(const QByteArray& data) = 0; |
||||
|
virtual ~DataSender(){} |
||||
|
}; |
||||
|
|
||||
|
#endif // DATASENDER_H
|
@ -0,0 +1,21 @@ |
|||||
|
#ifndef CONSOLEEMULATORAPP_H |
||||
|
#define CONSOLEEMULATORAPP_H |
||||
|
|
||||
|
#include <QtMvvmCore/CoreApp> |
||||
|
|
||||
|
class ConsoleEmulatorApp : public QtMvvm::CoreApp |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
explicit ConsoleEmulatorApp(QObject *parent = nullptr); |
||||
|
|
||||
|
protected: |
||||
|
void performRegistrations() override; |
||||
|
int startApp(const QStringList &arguments) override; |
||||
|
}; |
||||
|
|
||||
|
#undef coreApp |
||||
|
#define coreApp static_cast<consoleEmulatorApp*>(CoreApp::instance()) |
||||
|
|
||||
|
#endif // CONSOLEEMULATORAPP_H
|
@ -0,0 +1,29 @@ |
|||||
|
#ifndef MAINVIEWMODEL_H |
||||
|
#define MAINVIEWMODEL_H |
||||
|
|
||||
|
#include <QtMvvmCore/ViewModel> |
||||
|
|
||||
|
class MainViewModel : public QtMvvm::ViewModel |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) |
||||
|
|
||||
|
public: |
||||
|
Q_INVOKABLE explicit MainViewModel(QObject *parent = nullptr); |
||||
|
|
||||
|
QString text() const; |
||||
|
|
||||
|
public Q_SLOTS: |
||||
|
void showSettings(); |
||||
|
|
||||
|
void setText(const QString &text); |
||||
|
|
||||
|
Q_SIGNALS: |
||||
|
void textChanged(const QString &text); |
||||
|
|
||||
|
private: |
||||
|
QString _text; |
||||
|
}; |
||||
|
|
||||
|
#endif // MAINVIEWMODEL_H
|
@ -0,0 +1,20 @@ |
|||||
|
TEMPLATE = lib |
||||
|
|
||||
|
QT += mvvmcore |
||||
|
# Creating a static library is typically more efficient. You can still create a shared library if you want to |
||||
|
CONFIG += c++14 static |
||||
|
|
||||
|
TARGET = logic |
||||
|
|
||||
|
DEFINES += QT_DEPRECATED_WARNINGS |
||||
|
|
||||
|
SOURCES += $$files(src/*.cpp, true) |
||||
|
|
||||
|
HEADERS += $$files(include/*.h, true) |
||||
|
|
||||
|
INCLUDEPATH += $$PWD/include/ |
||||
|
INCLUDEPATH += $$PWD/../network/ |
||||
|
|
||||
|
_never_true_condition: SOURCES += $$files($$PWD/.ts-dummy/*) |
||||
|
# Uncomment the following line to automatically generated and update settings translations when building |
||||
|
#PRE_TARGETDEPS += qtmvvm-tsgen |
@ -0,0 +1,22 @@ |
|||||
|
#include "model/Console.h" |
||||
|
|
||||
|
#include <model/DataSender.h> |
||||
|
|
||||
|
Console::Console() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void Console::injectDataSender(DataSender *sender) |
||||
|
{ |
||||
|
_dataSender = sender; |
||||
|
} |
||||
|
|
||||
|
void Console::test() |
||||
|
{ |
||||
|
QByteArray arr; |
||||
|
arr.append(0x01); |
||||
|
arr.append(0x03); |
||||
|
arr.append(0x05); |
||||
|
_dataSender->send(arr); |
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
#include "mvvmCore/ConsoleEmulatorApp.h" |
||||
|
#include "viewModel/MainViewModel.h" |
||||
|
|
||||
|
#include <QtCore/QCommandLineParser> |
||||
|
|
||||
|
ConsoleEmulatorApp::ConsoleEmulatorApp(QObject *parent) : |
||||
|
CoreApp(parent) |
||||
|
{ |
||||
|
QCoreApplication::setApplicationName(QStringLiteral("consoleEmulator")); |
||||
|
QCoreApplication::setApplicationVersion(QStringLiteral("1.0.0")); |
||||
|
QCoreApplication::setOrganizationName(QStringLiteral("Example Organization")); |
||||
|
} |
||||
|
|
||||
|
void ConsoleEmulatorApp::performRegistrations() |
||||
|
{ |
||||
|
//if you are using a qt resource (e.g. "consoleemulatorcore.qrc"), initialize it here
|
||||
|
} |
||||
|
|
||||
|
int ConsoleEmulatorApp::startApp(const QStringList &arguments) |
||||
|
{ |
||||
|
QCommandLineParser parser; |
||||
|
parser.addVersionOption(); |
||||
|
parser.addHelpOption(); |
||||
|
|
||||
|
//add more options
|
||||
|
|
||||
|
//shows help or version automatically
|
||||
|
if(!autoParse(parser, arguments)) |
||||
|
return EXIT_SUCCESS; |
||||
|
|
||||
|
//show a viewmodel to complete the startup
|
||||
|
show<MainViewModel>(); |
||||
|
return EXIT_SUCCESS; |
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
#include "viewModel/MainViewModel.h" |
||||
|
|
||||
|
#include <QtMvvmCore/SettingsViewModel> |
||||
|
|
||||
|
#include "model/Console.h" |
||||
|
#include "UdpDataSender.h" |
||||
|
|
||||
|
MainViewModel::MainViewModel(QObject *parent) : |
||||
|
ViewModel(parent), |
||||
|
_text(QStringLiteral("hello world")) |
||||
|
{ |
||||
|
Console c; |
||||
|
auto u = new UdpDataSender; |
||||
|
c.injectDataSender(u); |
||||
|
c.test(); |
||||
|
} |
||||
|
|
||||
|
QString MainViewModel::text() const |
||||
|
{ |
||||
|
return _text; |
||||
|
} |
||||
|
|
||||
|
void MainViewModel::showSettings() |
||||
|
{ |
||||
|
show<QtMvvm::SettingsViewModel>(); |
||||
|
} |
||||
|
|
||||
|
void MainViewModel::setText(const QString &text) |
||||
|
{ |
||||
|
if (_text == text) |
||||
|
return; |
||||
|
|
||||
|
_text = text; |
||||
|
emit textChanged(_text); |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
#include "Network.h" |
||||
|
|
||||
|
Network::Network() |
||||
|
{ |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
#ifndef NETWORK_H |
||||
|
#define NETWORK_H |
||||
|
|
||||
|
class Network |
||||
|
{ |
||||
|
public: |
||||
|
Network(); |
||||
|
}; |
||||
|
|
||||
|
#endif // NETWORK_H
|
@ -0,0 +1,12 @@ |
|||||
|
#include "UdpDataSender.h" |
||||
|
#include <QDebug> |
||||
|
|
||||
|
int UdpDataSender::send(const QByteArray &data) |
||||
|
{ |
||||
|
qDebug() << "Just a little test"; |
||||
|
} |
||||
|
|
||||
|
UdpDataSender::~UdpDataSender() |
||||
|
{ |
||||
|
|
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
#ifndef UDPDATASENDER_H |
||||
|
#define UDPDATASENDER_H |
||||
|
|
||||
|
#include "model/DataSender.h" |
||||
|
|
||||
|
class UdpDataSender : public DataSender |
||||
|
{ |
||||
|
public: |
||||
|
int send(const QByteArray &data) override; |
||||
|
~UdpDataSender() override; |
||||
|
}; |
||||
|
|
||||
|
#endif // UDPDATASENDER_H
|
@ -0,0 +1,30 @@ |
|||||
|
QT -= gui |
||||
|
|
||||
|
TEMPLATE = lib |
||||
|
CONFIG += staticlib |
||||
|
|
||||
|
CONFIG += c++11 |
||||
|
|
||||
|
TARGET = network |
||||
|
|
||||
|
# The following define makes your compiler emit warnings if you use |
||||
|
# any Qt feature that has been marked deprecated (the exact warnings |
||||
|
# depend on your compiler). Please consult the documentation of the |
||||
|
# deprecated API in order to know how to port your code away from it. |
||||
|
DEFINES += QT_DEPRECATED_WARNINGS |
||||
|
|
||||
|
# You can also make your code fail to compile if it uses deprecated APIs. |
||||
|
# In order to do so, uncomment the following line. |
||||
|
# You can also select to disable deprecated APIs only up to a certain version of Qt. |
||||
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 |
||||
|
|
||||
|
SOURCES += \ |
||||
|
Network.cpp \ |
||||
|
UdpDataSender.cpp |
||||
|
|
||||
|
HEADERS += \ |
||||
|
Network.h \ |
||||
|
UdpDataSender.h |
||||
|
|
||||
|
INCLUDEPATH += $$PWD/../logic/include |
||||
|
DEPENDPATH += $$PWD/../logic/include |
@ -0,0 +1,24 @@ |
|||||
|
INCLUDEPATH += $$PWD/../logic/include |
||||
|
DEPENDPATH += $$PWD/../logic/include |
||||
|
|
||||
|
# Link with core project |
||||
|
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../logic/release/ -llogic |
||||
|
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../logic/debug/ -llogic |
||||
|
else:unix: LIBS += -L$$OUT_PWD/../logic/ -llogic |
||||
|
|
||||
|
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/release/liblogic.a |
||||
|
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/debug/liblogic.a |
||||
|
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/release/logic.lib |
||||
|
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/debug/logic.lib |
||||
|
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../logic/liblogic.a |
||||
|
|
||||
|
# Link with core project |
||||
|
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../network/release/ -lnetwork |
||||
|
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../network/debug/ -lnetwork |
||||
|
else:unix: LIBS += -L$$OUT_PWD/../network/ -lnetwork |
||||
|
|
||||
|
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../network/release/libnetwork.a |
||||
|
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../network/debug/libnetwork.a |
||||
|
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../network/release/network.lib |
||||
|
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../network/debug/network.lib |
||||
|
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../network/libnetwork.a |
@ -0,0 +1,18 @@ |
|||||
|
#ifndef TESTDATASENDER_H |
||||
|
#define TESTDATASENDER_H |
||||
|
|
||||
|
#include "model/DataSender.h" |
||||
|
|
||||
|
class TestDataSender : public DataSender |
||||
|
{ |
||||
|
public: |
||||
|
QByteArray consoleData; |
||||
|
|
||||
|
int send(const QByteArray &data) override |
||||
|
{ |
||||
|
consoleData = data; |
||||
|
return data.length(); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
#endif // TESTDATASENDER_H
|
@ -0,0 +1,26 @@ |
|||||
|
QT += testlib |
||||
|
QT -= gui |
||||
|
|
||||
|
CONFIG += qt console warn_on depend_includepath testcase |
||||
|
CONFIG -= app_bundle |
||||
|
|
||||
|
TEMPLATE = app |
||||
|
|
||||
|
SOURCES += tst_console.cpp |
||||
|
|
||||
|
INCLUDEPATH += $$PWD/../logic/include |
||||
|
DEPENDPATH += $$PWD/../logic/include |
||||
|
|
||||
|
# Link with core project |
||||
|
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../logic/release/ -llogic |
||||
|
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../logic/debug/ -llogic |
||||
|
else:unix: LIBS += -L$$OUT_PWD/../logic/ -llogic |
||||
|
|
||||
|
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/release/liblogic.a |
||||
|
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/debug/liblogic.a |
||||
|
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/release/logic.lib |
||||
|
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../logic/debug/logic.lib |
||||
|
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../logic/liblogic.a |
||||
|
|
||||
|
HEADERS += \ |
||||
|
TestDataSender.h |
@ -0,0 +1,45 @@ |
|||||
|
#include <QtTest> |
||||
|
|
||||
|
#include "TestDataSender.h" |
||||
|
#include "model/Console.h" |
||||
|
|
||||
|
class ConsoleTest : public QObject |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
|
||||
|
public: |
||||
|
ConsoleTest(); |
||||
|
~ConsoleTest(); |
||||
|
|
||||
|
private slots: |
||||
|
void test_case1(); |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
ConsoleTest::ConsoleTest() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
ConsoleTest::~ConsoleTest() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void ConsoleTest::test_case1() |
||||
|
{ |
||||
|
Console c; |
||||
|
auto t = new TestDataSender; |
||||
|
c.injectDataSender(t); |
||||
|
c.test(); |
||||
|
|
||||
|
QByteArray arr; |
||||
|
arr.append(0x01); |
||||
|
arr.append(0x04); |
||||
|
arr.append(0x05); |
||||
|
QCOMPARE(t->consoleData, arr); |
||||
|
} |
||||
|
|
||||
|
QTEST_APPLESS_MAIN(ConsoleTest) |
||||
|
|
||||
|
#include "tst_console.moc" |
@ -0,0 +1,6 @@ |
|||||
|
import QtQuick 2.10 |
||||
|
import de.skycoder42.QtMvvm.Quick 1.0 |
||||
|
|
||||
|
QtMvvmApp { |
||||
|
title: qsTr("consoleEmulator") |
||||
|
} |
@ -0,0 +1,70 @@ |
|||||
|
import QtQuick 2.10 |
||||
|
import QtQuick.Controls 2.3 |
||||
|
import QtQuick.Layouts 1.3 |
||||
|
import de.skycoder42.QtMvvm.Core 1.0 |
||||
|
import de.skycoder42.QtMvvm.Quick 1.0 |
||||
|
import com.example.consoleemulator 1.0 |
||||
|
|
||||
|
Page { |
||||
|
id: mainView |
||||
|
property MainViewModel viewModel: null |
||||
|
|
||||
|
header: ContrastToolBar { |
||||
|
RowLayout { |
||||
|
anchors.fill: parent |
||||
|
spacing: 0 |
||||
|
|
||||
|
ToolBarLabel { |
||||
|
text: qsTr("MainViewModel") |
||||
|
Layout.fillWidth: true |
||||
|
} |
||||
|
|
||||
|
MenuButton { |
||||
|
MenuItem { |
||||
|
id: settings |
||||
|
text: qsTr("Settings") |
||||
|
onClicked: viewModel.showSettings() |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
PresenterProgress {} |
||||
|
|
||||
|
Pane { |
||||
|
anchors.fill: parent |
||||
|
|
||||
|
ColumnLayout { |
||||
|
anchors.fill: parent |
||||
|
|
||||
|
TextField { |
||||
|
id: textEdit |
||||
|
Layout.fillWidth: true |
||||
|
|
||||
|
MvvmBinding { |
||||
|
viewModel: mainView.viewModel |
||||
|
viewModelProperty: "text" |
||||
|
view: textEdit |
||||
|
viewProperty: "text" |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Label { |
||||
|
id: textLabel |
||||
|
Layout.fillWidth: true |
||||
|
|
||||
|
MvvmBinding { |
||||
|
viewModel: mainView.viewModel |
||||
|
viewModelProperty: "text" |
||||
|
view: textLabel |
||||
|
viewProperty: "text" |
||||
|
type: MvvmBinding.OneWayToView |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Item { |
||||
|
Layout.fillHeight: true |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
#include <QtGui/QGuiApplication> |
||||
|
#include <QtQml/QQmlApplicationEngine> |
||||
|
#include <QuickPresenter> |
||||
|
#include <mvvmCore/ConsoleEmulatorApp.h> |
||||
|
#include <viewModel/MainViewModel.h> |
||||
|
|
||||
|
QTMVVM_REGISTER_CORE_APP(ConsoleEmulatorApp) |
||||
|
|
||||
|
int main(int argc, char *argv[]) |
||||
|
{ |
||||
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
||||
|
// If you want to support file dialogs on platforms other then android, use a QApplication instead (and add QT += widgets to the pro file)
|
||||
|
QGuiApplication app(argc, argv); |
||||
|
|
||||
|
QtMvvm::QuickPresenter::getInputViewFactory(); //Workaround for QTBUG-69963
|
||||
|
qmlRegisterUncreatableType<MainViewModel>("com.example.consoleemulator", 1, 0, "MainViewModel", "ViewModels cannot be created!"); |
||||
|
|
||||
|
QQmlApplicationEngine engine; |
||||
|
engine.load(QUrl(QStringLiteral("qrc:/App.qml"))); |
||||
|
if (engine.rootObjects().isEmpty()) |
||||
|
return -1; |
||||
|
|
||||
|
return app.exec(); |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
TEMPLATE = app |
||||
|
|
||||
|
QT += quick mvvmquick |
||||
|
CONFIG += c++14 |
||||
|
|
||||
|
TARGET = ConsoleEmulator |
||||
|
|
||||
|
DEFINES += QT_DEPRECATED_WARNINGS |
||||
|
|
||||
|
SOURCES += main.cpp |
||||
|
|
||||
|
RESOURCES += \ |
||||
|
ui.qrc |
||||
|
|
||||
|
include(../pri/core.pri) |
@ -0,0 +1,8 @@ |
|||||
|
<RCC> |
||||
|
<qresource prefix="/"> |
||||
|
<file>App.qml</file> |
||||
|
</qresource> |
||||
|
<qresource prefix="/qtmvvm/views"> |
||||
|
<file>MainView.qml</file> |
||||
|
</qresource> |
||||
|
</RCC> |
Loading…
Reference in new issue