maincontroller: move all views, models and presenters to controller. 73/90173/4
authorRadoslaw Czerski <r.czerski@samsung.com>
Mon, 26 Sep 2016 13:14:03 +0000 (15:14 +0200)
committerRadoslaw Czerski <r.czerski@samsung.com>
Fri, 30 Sep 2016 13:08:45 +0000 (15:08 +0200)
Objects deletion added.

Change-Id: Icd00dcdd41e8da6a2deeea2de4a9c933277dabba
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
clock/inc/Controller/MainController.h
clock/inc/Model/WorldClock.h
clock/inc/View/MainView.h
clock/src/Controller/MainController.cpp
clock/src/View/MainView.cpp

index 20bc60d..2ca57c4 100644 (file)
 
 #include "Utils/EventBus.h"
 
+#include "View/AlarmView.h"
+#include "View/StopWatchView.h"
+#include "View/TimerView.h"
+#include "View/WorldClockView.h"
+
+#include "Model/AlarmProvider.h"
+#include "Model/StopWatch.h"
+#include "Model/Timer.h"
+#include "Model/WorldClock.h"
+
+#include "Presenter/AlarmPresenter.h"
+#include "Presenter/StopWatchPresenter.h"
+#include "Presenter/TimerPresenter.h"
+#include "Presenter/WorldClockPresenter.h"
+
+
 /**
  * @file MainController.h
  */
@@ -97,6 +113,16 @@ namespace controller {
                         * @brief Creates new "Delete" alarm page.
                         */
                        void CreateNewDeleteAlarmsPage(utils::Event *e);
+
+                       model::WorldClock *world_clock_model_;
+                       model::StopWatch *stop_watch_model_;
+                       model::Timer *timer_model_;
+
+                       presenter::AlarmPresenter *alarm_presenter_;
+                       presenter::WorldClockPresenter *world_clock_presenter_;
+                       presenter::StopWatchPresenter *stop_watch_presenter_;
+                       presenter::TimerPresenter *timer_presenter_;
+
        };
 }
 
index 26c8711..d60e2b5 100644 (file)
@@ -45,10 +45,7 @@ namespace model {
                         * @brief Constructs the WorldClock object. It will also load UserLocation list from preferences.
                         */
                        WorldClock();
-
-                       /*
-                        * @brief Locations list made of locations(cities) chosen by user.
-                        */
+                       ~WorldClock(){};
                        std::vector<model::Location> UserLocations;
 
                        /*
index 7c7498e..98b87de 100644 (file)
 
 namespace view {
 
+       enum ViewType {
+               ALARM,
+               WORLD_CLOCK,
+               STOP_WATCH,
+               TIMER
+       };
+
        /**
         * @brief Application main view class
         * @remarks This is singleton class.
@@ -76,6 +83,13 @@ namespace view {
                         * @remarks Customized for singleton purpose - make no effect.
                         */
                        void operator=(MainView const&) = delete;
+
+                       /**
+                        * @brief Retrieves view by its type
+                        * @param[in] type type of the view
+                        * @return view
+                        */
+                       IView *GetView(ViewType type);
                private:
 
                        /**
index bfe5e53..9f0c03f 100644 (file)
@@ -54,9 +54,18 @@ void MainController::Resume()
 
 int MainController::Init()
 {
-       MainView::GetInstance();
+       world_clock_model_ = new model::WorldClock();
+       stop_watch_model_ = new model::StopWatch();
+       timer_model_ = new model::Timer();
+
        MainView::GetInstance().CreateContent();
 
+       alarm_presenter_ = new AlarmPresenter((AlarmView *)MainView::GetInstance().GetView(ALARM), AlarmProvider::GetInstance());
+       world_clock_presenter_ = new WorldClockPresenter((WorldClockView *)MainView::GetInstance().GetView(WORLD_CLOCK), world_clock_model_);
+       stop_watch_presenter_ = new StopWatchPresenter((StopWatchView *)MainView::GetInstance().GetView(STOP_WATCH), stop_watch_model_);
+       timer_presenter_ = new TimerPresenter((TimerView *)MainView::GetInstance().GetView(TIMER), timer_model_);
+
+
        EventBus::RegisterHandler(AlarmCreateRequestEvent::EventType(),
                        std::bind(&MainController::CreateNewAlarmPage, this, _1));
        EventBus::RegisterHandler(AlarmDeleteRequestEvent::EventType(),
@@ -69,6 +78,17 @@ int MainController::Init()
 
 void MainController::Deinit()
 {
+       delete alarm_presenter_;
+
+       delete world_clock_presenter_;
+       delete world_clock_model_;
+
+       delete stop_watch_presenter_;
+       delete stop_watch_model_;
+
+       delete timer_presenter_;
+       delete timer_model_;
+
        EventBus::DeregisterHandler(AlarmCreateRequestEvent::EventType(),
                        std::bind(&MainController::CreateNewAlarmPage, this, _1));
        EventBus::DeregisterHandler(AlarmDeleteRequestEvent::EventType(),
index ca390ce..fb4d36c 100644 (file)
@@ -109,6 +109,10 @@ MainView::MainView()
 
 MainView::~MainView()
 {
+       delete alarm_;
+       delete world_clock_;
+       delete stop_watch_;
+       delete timer_ ;
 }
 
 void MainView::ConformantAdd()
@@ -145,32 +149,16 @@ void MainView::NaviframeAdd()
        DBG("NaviframeAdd END");
 }
 
-
 void MainView::CreatePages()
 {
-       AlarmView *alarm = new AlarmView();
-       new AlarmPresenter(alarm, AlarmProvider::GetInstance());
-       alarm_ = alarm;
-
-       WorldClockView *worldClock = new WorldClockView();
-       model::WorldClock *worldClockModel = new model::WorldClock();
-       new WorldClockPresenter(worldClock, worldClockModel);
-       world_clock_ = worldClock;
-
-       StopWatchView *stopWatch = new StopWatchView();
-       model::StopWatch *stopWatchModel = new model::StopWatch();
-       new StopWatchPresenter(stopWatch, stopWatchModel);
-       stop_watch_ = stopWatch;
-
+       alarm_ = new AlarmView();
+       world_clock_ = new WorldClockView();
+       stop_watch_ = new StopWatchView();
        timer_ = new TimerView();
-
-       TimerView *timer = new TimerView();
-       model::Timer *timerModel = new model::Timer();
-       new TimerPresenter(timer, timerModel);
-       timer_ = timer;
 }
 
 
+
 void MainView::CreateToolbarButtons()
 {
        elm_toolbar_item_append(toolbar_, Utils::GetAppResourcePath(Utils::APP_DIR_RESOURCE,
@@ -221,3 +209,19 @@ Evas_Object *MainView::GetEvasObject()
        return naviframe_;
 }
 
+ui::IView *MainView::GetView(ViewType type)
+{
+       switch (type){
+               case ALARM:
+                       return alarm_;
+               case WORLD_CLOCK:
+                       return world_clock_;
+               case STOP_WATCH:
+                       return stop_watch_;
+               case TIMER:
+                       return timer_;
+               default:
+                       ERR("Wrong view type!");
+                       return NULL;
+       }
+}