Skip to content

Commit

Permalink
Added boost::di. Removed redundant code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vt4a2h committed Jan 21, 2017
1 parent 5df566f commit 736eb62
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "boost-di"]
path = boost-di
url = git://github.com/boost-experimental/di.git
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(REL ${ROOT}/relationship)
set(TRANSLATION ${ROOT}/translation)
set(UTIL ${ROOT}/utility)
set(COMMON ${ROOT}/common)
set(BOOST_DI ${ROOT}/boost-di/include)

file(GLOB APP_SRC ${APP}/*.cpp)
file(GLOB CMD_SRC ${CMD}/*.cpp)
Expand All @@ -50,11 +51,31 @@ set(RESOURCES ${GUI}/main.qrc)

include_directories(${Qt5Widgets_INCLUDES} ${Boost_INCLUDE_DIRS} ${ROOT} ${APP} ${CMD} ${DB} ${ENTITY}
${ENTITY_COMPONENTS} ${GEN} ${GUI} ${GUI_GRAPHICS} ${HELPERS} ${MODELS}
${PROJECT} ${REL} ${TRANSLATION} ${UTIL} ${COMMON})
${PROJECT} ${REL} ${TRANSLATION} ${UTIL} ${COMMON} ${BOOST_DI})

add_executable(uml-tool main.cpp ${APP_SRC} ${CMD_SRC} ${DB_SRC} ${ENTITY_SRC}
${ENTITY_COMPONENTS_SRC} ${GEN_SRC} ${GUI_SRC} ${GUI_GRAPHICS_SRC} ${HELPERS_SRC}
${MODELS_SRC} ${PROJECT_SRC} ${REL_SRC} ${TRANSLATION_SRC} ${UTIL_SRC}
${COMMON_SRC} ${RESOURCES})
target_link_libraries(uml-tool ${Boost_LIBRARIES})
set_property(TARGET uml-tool PROPERTY CXX_STANDARD 14)
qt5_use_modules(uml-tool Widgets Core)

# TODO: move to the separate file
#enable_testing()
#find_package(GTest REQUIRED)

#set(TEST ${ROOT}/tests/test)
#set(TEST_CASES ${TEST}/cases)

#include_directories(${TEST} ${TEST_CASES} ${GTEST_INCLUDE_DIRS})

#add_executable(uml-tool-tests tests/test/main.cpp ${APP_SRC} ${CMD_SRC} ${DB_SRC} ${ENTITY_SRC}
# ${ENTITY_COMPONENTS_SRC} ${GEN_SRC} ${GUI_SRC} ${GUI_GRAPHICS_SRC} ${HELPERS_SRC}
# ${MODELS_SRC} ${PROJECT_SRC} ${REL_SRC} ${TRANSLATION_SRC} ${UTIL_SRC}
# ${COMMON_SRC} ${RESOURCES})
#target_link_libraries(uml-tool-tests ${GTEST_BOTH_LIBRARIES})
#set_property(TARGET uml-tool-tests PROPERTY CXX_STANDARD 14)
#qt5_use_modules(uml-tool-tests Widgets Core)

#add_test(AllTestsInUMLTool uml-tool-tests)
28 changes: 10 additions & 18 deletions application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace application {
db->load(errors);

if (!errors.isEmpty()) {
QMessageBox::warning(m_MainWindow.get(), tr("Problems with loading global database"), errors.join("\n"),
QMessageBox::Ok);
QMessageBox::warning(m_MainWindow.get(), tr("Problems with loading global database"),
errors.join("\n"), QMessageBox::Ok);
db->clear();
errors.clear();

Expand All @@ -73,8 +73,8 @@ namespace application {
db->load(errors);

if (!errors.isEmpty()) {
QMessageBox::critical(m_MainWindow.get(), tr("Database reading error"), errors.join("\n"),
QMessageBox::Ok);
QMessageBox::critical(m_MainWindow.get(), tr("Database reading error"),
errors.join("\n"), QMessageBox::Ok);
return false;
}
} else {
Expand All @@ -91,7 +91,8 @@ namespace application {
settings::setGlobalDbPath(db->path());
settings::setGlobalDbName(db->name());
} else {
QMessageBox::information(m_MainWindow.get(), tr("Ohh"), tr("You cannot run application without database!"),
QMessageBox::information(m_MainWindow.get(), tr("Ohh"),
tr("You cannot run application without database!"),
QMessageBox::Ok );
return false;
}
Expand Down Expand Up @@ -119,10 +120,10 @@ namespace application {
/**
* @brief Application::Application
*/
Application::Application(QObject *parent)
: QObject(parent)
, m_ApplicationModel(std::make_shared<models::ApplicationModel>())
, m_MainWindow(std::make_unique<gui::MainWindow>(m_ApplicationModel))
Application::Application(models::SharedApplicationModel const& appModel,
gui::UniqueMainWindow mainWindow)
: m_ApplicationModel(appModel)
, m_MainWindow(std::move(mainWindow))
{
G_CONNECT(m_ApplicationModel.get(), &models::ApplicationModel::currentProjectChanged,
&helpers::GeneratorID::instance(), &helpers::GeneratorID::onCurrentProjectChanged);
Expand All @@ -131,15 +132,6 @@ namespace application {
setUpFactory(entity::EntityFactory::instance(), m_ApplicationModel, m_MainWindow->scene());
setUpFactory(relationship::RelationFactory::instance(), m_ApplicationModel,
m_MainWindow->scene());

qRegisterMetaTypeStreamOperators<application::settings::TstType>("application::settings::TstType");
}

/**
* @brief Application::~Application
*/
Application::~Application()
{
}

} // namespace application
13 changes: 6 additions & 7 deletions application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
** along with Q-UML. If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************************/

#pragma once

#include <QObject>
#include <QCoreApplication>

#include <models/models_types.hpp>
#include <gui/gui_types.hpp>
#include <models/models_types.hpp>

/**
* @brief namespace application
Expand All @@ -36,16 +35,16 @@ namespace application {
/**
* @brief The Application class
*/
class Application : public QObject
class Application
{
Q_OBJECT
Q_DECLARE_TR_FUNCTIONS(Application)

public:
explicit Application(QObject *parent = nullptr);
~Application();
Application(models::SharedApplicationModel const& appModel, gui::UniqueMainWindow mainWindow);

bool run();

private:
models::SharedApplicationModel m_ApplicationModel;
gui::UniqueMainWindow m_MainWindow;
};
Expand Down
10 changes: 0 additions & 10 deletions application/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,6 @@ namespace application {
write(elGroup, marker, color);
}

TstType get(const QString &marker)
{
return read("tst", marker, TstType(-1, -1));
}

void set(const QString &marker, const TstType &color)
{
write("tst", marker, QVariant::fromValue(color));
}

} // namespace settings

} // namespace application
6 changes: 0 additions & 6 deletions application/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ namespace application {
// Elements
QColor elementColor(const QString &marker);
void setElementColor(const QString &marker, const QColor &color);

typedef QPair<int, int> TstType;
TstType get(const QString &marker);
void set(const QString &marker, const TstType &color);
}

} // namespace application

Q_DECLARE_METATYPE(application::settings::TstType)
1 change: 1 addition & 0 deletions boost-di
Submodule boost-di added at cf5842
6 changes: 2 additions & 4 deletions gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ namespace gui {
* @brief MainWindow::MainWindow
* @param parent
*/
MainWindow::MainWindow(const models::SharedApplicationModel &applicationModel, QWidget *parent)
: QMainWindow(parent)
, ui(std::make_unique<Ui::MainWindow>())
MainWindow::MainWindow(const models::SharedApplicationModel &applicationModel)
: ui(std::make_unique<Ui::MainWindow>())
, m_MainScene(std::make_unique<graphics::Scene>())
, m_ProjectTreeMenu(new QMenu(this))
, m_ProjectTreeView(new QTreeView(this))
Expand Down Expand Up @@ -421,7 +420,6 @@ namespace gui {
void MainWindow::writeSettings()
{
application::settings::writeMainWindowGeometry(geometry());
application::settings::set("tst", application::settings::TstType(100, 200));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ namespace gui {
public:
Q_DISABLE_COPY(MainWindow)

explicit MainWindow(const models::SharedApplicationModel &applicationModel,
QWidget *parent = 0);
explicit MainWindow(const models::SharedApplicationModel &applicationModel);
~MainWindow();

QPointer<QGraphicsScene> scene() const;
Expand Down
11 changes: 9 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@
** along with Q-UML. If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************************/

#include <QApplication>

#include <application/Application.h>
#include <gui/MainWindow.h>
#include <models/ApplicationModel.h>

#include "boost-di/include/boost/di.hpp"

namespace di = boost::di;

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setOrganizationName("QUml");
QApplication::setApplicationName("QUml tools");

application::Application app;
auto injector = di::make_injector();
auto app = injector.create<application::Application>();
return app.run() ? a.exec() : 0;
}
4 changes: 2 additions & 2 deletions models/ApplicationModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace models {
* @brief ApplicationModal::ApplicationModal
* @param parent
*/
ApplicationModel::ApplicationModel(QObject *parent)
: QObject(parent)
ApplicationModel::ApplicationModel()
: QObject(nullptr)
, m_GlobalDatabase(std::make_shared<db::Database>())
, m_TreeModel(std::make_shared<ProjectTreeModel>())
{
Expand Down
2 changes: 1 addition & 1 deletion models/ApplicationModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace models {
Q_OBJECT

public:
explicit ApplicationModel(QObject *parent = 0);
explicit ApplicationModel();
~ApplicationModel();

// TODO: move to some database class
Expand Down
6 changes: 3 additions & 3 deletions qthelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
#define G_DISCONNECT(arg, ...) G_ASSERT(QObject::disconnect(arg, ##__VA_ARGS__))

// Guarded condition, assert in debug mode if condition is false
#define G_ASSERT(c) qthelpers::detail::g_assert(c, Q_FUNC_INFO, #c, __FILE__, __LINE__)
#define G_ASSERT(c) qthelpers::details::g_assert(c, Q_FUNC_INFO, #c, __FILE__, __LINE__)

// Conditional G_ASSERT
#define G_ASSERT_C(c, cond) qthelpers::detail::g_assert_c(c, !!cond, Q_FUNC_INFO, \
#define G_ASSERT_C(c, cond) qthelpers::details::g_assert_c(c, !!cond, Q_FUNC_INFO, \
#c, __FILE__, __LINE__)

namespace qthelpers
{
namespace detail
namespace details
{
template <class Condition>
inline decltype(auto) g_assert(Condition &&c, const char *where,
Expand Down

0 comments on commit 736eb62

Please sign in to comment.