Imported existing sources
This commit is contained in:
102
.gitignore
vendored
102
.gitignore
vendored
@@ -1,43 +1,73 @@
|
|||||||
# C++ objects and libs
|
# This file is used to ignore files which are generated
|
||||||
*.slo
|
# ----------------------------------------------------------------------------
|
||||||
*.lo
|
|
||||||
*.o
|
|
||||||
*.a
|
|
||||||
*.la
|
|
||||||
*.lai
|
|
||||||
*.so
|
|
||||||
*.dll
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Qt-es
|
*~
|
||||||
object_script.*.Release
|
*.autosave
|
||||||
object_script.*.Debug
|
*.a
|
||||||
*_plugin_import.cpp
|
*.core
|
||||||
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*_pch.h.cpp
|
||||||
|
*_resource.rc
|
||||||
|
*.qm
|
||||||
|
.#*
|
||||||
|
*.*#
|
||||||
|
core
|
||||||
|
!core/
|
||||||
|
tags
|
||||||
|
.DS_Store
|
||||||
|
.directory
|
||||||
|
*.debug
|
||||||
|
Makefile*
|
||||||
|
*.prl
|
||||||
|
*.app
|
||||||
|
moc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
Thumbs.db
|
||||||
|
*.res
|
||||||
|
*.rc
|
||||||
/.qmake.cache
|
/.qmake.cache
|
||||||
/.qmake.stash
|
/.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
|
# qtcreator generated files
|
||||||
target_wrapper.*
|
*.pro.user*
|
||||||
|
|
||||||
# QtCreator
|
# xemacs temporary files
|
||||||
*.autosave
|
*.flc
|
||||||
|
|
||||||
# QtCreator Qml
|
# Vim temporary files
|
||||||
*.qmlproject.user
|
.*.swp
|
||||||
*.qmlproject.user.*
|
|
||||||
|
# Visual Studio generated files
|
||||||
|
*.ib_pdb_index
|
||||||
|
*.idb
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.vcproj
|
||||||
|
*vcproj.*.*.user
|
||||||
|
*.ncb
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.vcxproj
|
||||||
|
*vcxproj.*
|
||||||
|
|
||||||
|
# MinGW generated files
|
||||||
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
|
||||||
|
# Python byte code
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
# --------
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
|
||||||
# QtCreator CMake
|
|
||||||
CMakeLists.txt.user*
|
|
||||||
|
8
DbMsgLib.pro
Normal file
8
DbMsgLib.pro
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
TEMPLATE = subdirs
|
||||||
|
|
||||||
|
SUBDIRS += messagingclient \
|
||||||
|
messagingcorelib \
|
||||||
|
messagingserver
|
||||||
|
|
||||||
|
messagingclient.depends += messagingcorelib
|
||||||
|
messagingserver.depends += messagingcorelib
|
8
main.cpp
Normal file
8
main.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
24
messagingclient/main.cpp
Normal file
24
messagingclient/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "mymessage.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
|
MyMessage message("Daniel", QDate(1996, 11, 12), QDateTime::currentDateTime(), 21, 80);
|
||||||
|
message.debug();
|
||||||
|
|
||||||
|
qDebug() << "changing name...";
|
||||||
|
|
||||||
|
message.setName("Peter");
|
||||||
|
message.debug();
|
||||||
|
|
||||||
|
qDebug() << "clearing touched...";
|
||||||
|
|
||||||
|
message.setTouched(false);
|
||||||
|
message.debug();
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
24
messagingclient/messagingclient.pro
Normal file
24
messagingclient/messagingclient.pro
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
QT += core network
|
||||||
|
|
||||||
|
TARGET = messagingclient
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
PROJECT_ROOT = ..
|
||||||
|
|
||||||
|
DESTDIR = $${OUT_PWD}/$${PROJECT_ROOT}/bin
|
||||||
|
|
||||||
|
DBLIBS += core
|
||||||
|
|
||||||
|
SOURCES += main.cpp
|
||||||
|
|
||||||
|
HEADERS +=
|
||||||
|
|
||||||
|
FORMS +=
|
||||||
|
|
||||||
|
RESOURCES +=
|
||||||
|
|
||||||
|
TRANSLATIONS +=
|
||||||
|
|
||||||
|
include($${PROJECT_ROOT}/project.pri)
|
23
messagingcorelib/messagingcorelib.pro
Normal file
23
messagingcorelib/messagingcorelib.pro
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
QT += core network
|
||||||
|
QT -= gui widgets
|
||||||
|
|
||||||
|
TARGET = messagingcorelib
|
||||||
|
TEMPLATE = lib
|
||||||
|
|
||||||
|
PROJECT_ROOT = ..
|
||||||
|
|
||||||
|
DEFINES += MESSAGINGCORELIB_LIBRARY
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
mymessage.cpp
|
||||||
|
|
||||||
|
HEADERS += messagingcorelib_global.h \
|
||||||
|
mymessage.h
|
||||||
|
|
||||||
|
FORMS +=
|
||||||
|
|
||||||
|
RESOURCES +=
|
||||||
|
|
||||||
|
TRANSLATIONS +=
|
||||||
|
|
||||||
|
include($${PROJECT_ROOT}/project.pri)
|
9
messagingcorelib/messagingcorelib_global.h
Normal file
9
messagingcorelib/messagingcorelib_global.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#if defined(MESSAGINGCORELIB_LIBRARY)
|
||||||
|
# define MESSAGINGCORELIBSHARED_EXPORT Q_DECL_EXPORT
|
||||||
|
#else
|
||||||
|
# define MESSAGINGCORELIBSHARED_EXPORT Q_DECL_IMPORT
|
||||||
|
#endif
|
9
messagingcorelib/mymessage.cpp
Normal file
9
messagingcorelib/mymessage.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "mymessage.h"
|
||||||
|
|
||||||
|
const QMap<QString, MyMessage::FieldGetterMethod> MyMessage::m_fields {
|
||||||
|
{ "name", &MyMessage::nameFieldBase },
|
||||||
|
{ "birthday", &MyMessage::birthdayFieldBase },
|
||||||
|
{ "sendTimestamp", &MyMessage::sendTimestampFieldBase },
|
||||||
|
{ "age", &MyMessage::ageFieldBase },
|
||||||
|
{ "weight", &MyMessage::weightFieldBase }
|
||||||
|
};
|
149
messagingcorelib/mymessage.h
Normal file
149
messagingcorelib/mymessage.h
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class DbMsgFieldBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DbMsgFieldBase() : m_touched(false) {}
|
||||||
|
|
||||||
|
bool touched() const { return m_touched; }
|
||||||
|
void setTouched(bool touched) { m_touched = touched; }
|
||||||
|
|
||||||
|
virtual QVariant getVariant() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_touched;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class DbMsgField : public DbMsgFieldBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DbMsgField() : DbMsgFieldBase(), m_hasValue(false) {}
|
||||||
|
DbMsgField(const T &value) : DbMsgFieldBase(), m_value(value), m_hasValue(true) {}
|
||||||
|
|
||||||
|
T &getValue() { return m_value; }
|
||||||
|
const T &getValue() const { return m_value; }
|
||||||
|
void setValue(const T &value) { m_hasValue = true; m_value = value; setTouched(true); }
|
||||||
|
|
||||||
|
bool hasValue() const { return m_hasValue; }
|
||||||
|
|
||||||
|
QVariant getVariant() const { return getValue(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
T m_value;
|
||||||
|
bool m_hasValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DbMsgBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DbMsgBase() {}
|
||||||
|
|
||||||
|
bool touched() const
|
||||||
|
{
|
||||||
|
const auto fields = getFields();
|
||||||
|
return std::any_of(fields.cbegin(), fields.cend(), [](const DbMsgFieldBase *field) { return field->touched(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTouched(bool touched)
|
||||||
|
{
|
||||||
|
for(DbMsgFieldBase *field : getFields())
|
||||||
|
field->setTouched(touched);
|
||||||
|
}
|
||||||
|
|
||||||
|
void debug() const
|
||||||
|
{
|
||||||
|
const auto fields = getFields();
|
||||||
|
for(auto iter = fields.cbegin(); iter != fields.cend(); iter++)
|
||||||
|
qDebug() << iter.key() << iter.value()->getVariant() << iter.value()->touched();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QMap<QString, DbMsgFieldBase*> getFields() = 0;
|
||||||
|
virtual QMap<QString, const DbMsgFieldBase*> getFields() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyMessage : public DbMsgBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyMessage() : DbMsgBase() {}
|
||||||
|
|
||||||
|
MyMessage(const QString &name, const QDate &birthday, const QDateTime &sendTimestamp, int age, double weight) :
|
||||||
|
DbMsgBase(),
|
||||||
|
m_name(name), m_birthday(birthday), m_sendTimestamp(sendTimestamp), m_age(age), m_weight(weight)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QString getName() const { return m_name.getValue(); }
|
||||||
|
void setName(const QString &name) { m_name.setValue(name); }
|
||||||
|
DbMsgField<QString> &nameField() { return m_name; }
|
||||||
|
const DbMsgField<QString> &nameField() const { return m_name; }
|
||||||
|
DbMsgFieldBase &nameFieldBase() { return m_name; }
|
||||||
|
const DbMsgFieldBase &nameFieldBase() const { return m_name; }
|
||||||
|
|
||||||
|
QDate getBirthday() const { return m_birthday.getValue(); }
|
||||||
|
void setBirthday(const QDate &birthday) { m_birthday.setValue(birthday); }
|
||||||
|
DbMsgField<QDate> &birthdayField() { return m_birthday; }
|
||||||
|
const DbMsgField<QDate> &birthdayField() const { return m_birthday; }
|
||||||
|
DbMsgFieldBase &birthdayFieldBase() { return m_birthday; }
|
||||||
|
const DbMsgFieldBase &birthdayFieldBase() const { return m_birthday; }
|
||||||
|
|
||||||
|
QDateTime getSendTimestamp() const { return m_sendTimestamp.getValue(); }
|
||||||
|
void setSendTimestamp(const QDateTime &sendTimestamp) { m_sendTimestamp.setValue(sendTimestamp); }
|
||||||
|
DbMsgField<QDateTime> &sendTimestampField() { return m_sendTimestamp; }
|
||||||
|
const DbMsgField<QDateTime> &sendTimestampField() const { return m_sendTimestamp; }
|
||||||
|
DbMsgFieldBase &sendTimestampFieldBase() { return m_sendTimestamp; }
|
||||||
|
const DbMsgFieldBase &sendTimestampFieldBase() const { return m_sendTimestamp; }
|
||||||
|
|
||||||
|
int getAge() const { return m_age.getValue(); }
|
||||||
|
void setAge(const int &age) { m_age.setValue(age); }
|
||||||
|
DbMsgField<int> &ageField() { return m_age; }
|
||||||
|
const DbMsgField<int> &ageField() const { return m_age; }
|
||||||
|
DbMsgFieldBase &ageFieldBase() { return m_age; }
|
||||||
|
const DbMsgFieldBase &ageFieldBase() const { return m_age; }
|
||||||
|
|
||||||
|
double getWeight() const { return m_weight.getValue(); }
|
||||||
|
void setWeight(const double &weight) { m_weight.setValue(weight); }
|
||||||
|
DbMsgField<double> &weightField() { return m_weight; }
|
||||||
|
const DbMsgField<double> &weightField() const { return m_weight; }
|
||||||
|
DbMsgFieldBase &weightFieldBase() { return m_weight; }
|
||||||
|
const DbMsgFieldBase &weightFieldBase() const { return m_weight; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QMap<QString, DbMsgFieldBase*> getFields() override
|
||||||
|
{
|
||||||
|
QMap<QString, DbMsgFieldBase*> fields;
|
||||||
|
|
||||||
|
for(auto iter = m_fields.cbegin(); iter != m_fields.cend(); iter++)
|
||||||
|
fields.insert(iter.key(), &(this->*iter.value())());
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, const DbMsgFieldBase*> getFields() const override
|
||||||
|
{
|
||||||
|
QMap<QString, const DbMsgFieldBase*> fields;
|
||||||
|
|
||||||
|
for(auto iter = m_fields.cbegin(); iter != m_fields.cend(); iter++)
|
||||||
|
fields.insert(iter.key(), &(const_cast<MyMessage*>(this)->*iter.value())());
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef DbMsgFieldBase &(MyMessage::*FieldGetterMethod)();
|
||||||
|
static const QMap<QString, FieldGetterMethod> m_fields;
|
||||||
|
|
||||||
|
DbMsgField<QString> m_name;
|
||||||
|
DbMsgField<QDate> m_birthday;
|
||||||
|
DbMsgField<QDateTime> m_sendTimestamp;
|
||||||
|
DbMsgField<int> m_age;
|
||||||
|
DbMsgField<double> m_weight;
|
||||||
|
};
|
11
messagingserver/main.cpp
Normal file
11
messagingserver/main.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
|
qDebug() << "hello from server";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
24
messagingserver/messagingserver.pro
Normal file
24
messagingserver/messagingserver.pro
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
QT += core network
|
||||||
|
|
||||||
|
TARGET = messagingserver
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
PROJECT_ROOT = ..
|
||||||
|
|
||||||
|
DESTDIR = $${OUT_PWD}/$${PROJECT_ROOT}/bin
|
||||||
|
|
||||||
|
DBLIBS += core
|
||||||
|
|
||||||
|
SOURCES += main.cpp
|
||||||
|
|
||||||
|
HEADERS +=
|
||||||
|
|
||||||
|
FORMS +=
|
||||||
|
|
||||||
|
RESOURCES +=
|
||||||
|
|
||||||
|
TRANSLATIONS +=
|
||||||
|
|
||||||
|
include($${PROJECT_ROOT}/project.pri)
|
34
project.pri
Normal file
34
project.pri
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
CONFIG += c++14
|
||||||
|
|
||||||
|
DEFINES += QT_DEPRECATED_WARNINGS \
|
||||||
|
QT_DISABLE_DEPRECATED_BEFORE=0x060000 \
|
||||||
|
QT_MESSAGELOGCONTEXT
|
||||||
|
|
||||||
|
equals(TEMPLATE, "lib") {
|
||||||
|
win32: DESTDIR = $${OUT_PWD}/$${PROJECT_ROOT}/bin
|
||||||
|
else: DESTDIR = $${OUT_PWD}/$${PROJECT_ROOT}/lib
|
||||||
|
}
|
||||||
|
|
||||||
|
!isEmpty(DBLIBS) {
|
||||||
|
win32: LIBS += -L$${OUT_PWD}/$${PROJECT_ROOT}/bin
|
||||||
|
else: LIBS += -Wl,-rpath=\\\$$ORIGIN/../lib -L$${OUT_PWD}/$${PROJECT_ROOT}/lib
|
||||||
|
}
|
||||||
|
|
||||||
|
contains(DBLIBS, core) {
|
||||||
|
LIBS += -lmessagingcorelib
|
||||||
|
|
||||||
|
INCLUDEPATH += $$PWD/messagingcorelib
|
||||||
|
DEPENDPATH += $$PWD/messagingcorelib
|
||||||
|
}
|
||||||
|
|
||||||
|
isEmpty(QMAKE_LRELEASE) {
|
||||||
|
win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe
|
||||||
|
else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
|
||||||
|
}
|
||||||
|
|
||||||
|
lrelease.input = TRANSLATIONS
|
||||||
|
lrelease.output = $${OUT_PWD}/$${PROJECT_ROOT}/bin/translations/${QMAKE_FILE_BASE}.qm
|
||||||
|
lrelease.commands = $${QMAKE_LRELEASE} ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_OUT}
|
||||||
|
lrelease.CONFIG += no_link
|
||||||
|
QMAKE_EXTRA_COMPILERS += lrelease
|
||||||
|
PRE_TARGETDEPS += compiler_lrelease_make_all
|
Reference in New Issue
Block a user