当前位置: 首页 > news >正文

个人网站设计首页重庆市城市建设投资公司网站

个人网站设计首页,重庆市城市建设投资公司网站,网站开发有多少种,在线单页网站制作TouchGFX用户接口遵循Model-View-Presenter#xff08;MVP#xff09;架构模式#xff0c;它是Model-View-Controller#xff08;MVC#xff09;模式的派生模式。 两者都广泛用于构建用户接口应用。 MVP模式的主要优势是#xff1a; 关注点分离#xff1a;将代码分成不…TouchGFX用户接口遵循Model-View-PresenterMVP架构模式它是Model-View-ControllerMVC模式的派生模式。 两者都广泛用于构建用户接口应用。 MVP模式的主要优势是 关注点分离将代码分成不同的部分提供每部分有自己的任务。 这使得代码更简单、可重复使用性更高且更易于维护。单元测试由于UI的逻辑Presenter独立于视图View因此单独测试这些部分会容易很多。 MVP中定义了下列三个类 Model是一种接口用于定义要在用户界面上显示或有其他形式操作的数据。View是一种被动接口用于显示数据来自Model并将用户指令事件传给Presenter以便根据该数据进行操作。Presenter的操作取决于Model和View。 它从存储库Model检索数据并将其格式化以便在视图中显示。 在TouchGFX中从Model类执行与应用非UI部分这里称为后端系统的通信。 后端系统是从UI接收事件和将事件输入UI的软件组件例如采集传感器的新测量值。 后端系统可作为单独的任务在同一MCU、单独的处理器、云模块或其他硬件上运行。 从TouchGFX的角度来看这并不十分重要只要它是能够与之通信的组件。 使用的特定通信协议不受TouchGFX管理。 它只提供一个在每个TouchGFX嘀嗒时间调用一次的函数可以在其中处理需要的通信。  从上节内容已知touchgfx中只有一个Model的实例对象但每一个屏幕都对应一个View和Presenter的实例对象。 从MVP类的代码可以看出 Model实例对象可以绑定一个ModelListener用户端Presenter的基类之一实例对象指针即Model实例对象可以通过该指针查询到Presenter实例对象。 每个View实例对象可以绑定一个Presenter实例对象指针即View实例对象可以通过该指针查询到Presenter实例对象。 每个用户端Presenter实例对象基于ModelListener类可以绑定Model实例对象指针即用户端Presenter实例对象可以通过该指针查询到Model实例对象。 用户端Presenter类中包含View实例对象的引用即用户端Presenter实例对象可以通过该引用查询到View实例对象。 #ifndef MODEL_HPP #define MODEL_HPPclass ModelListener;/* Model类 */ class Model { public:Model();/* 将给定的Presenter对象指针与Model关联起来 */void bind(ModelListener *listener){modelListener listener;}/* 节拍函数 */void tick();protected:ModelListener *modelListener; //当前Presenter对象指针 };#endif#ifndef TOUCHGFX_VIEW_HPP #define TOUCHGFX_VIEW_HPP#include touchgfx/Screen.hppnamespace touchgfx { /* View类 */ template class T class View : public Screen { public:/* 构造函数 */View() : presenter(0){}/* 将给定的Presenter实例与View关联起来 */void bind(T newPresenter){presenter newPresenter;}protected:T *presenter; //指向与此View关联的presenter的指针 };}#endif#ifndef TOUCHGFX_PRESENTER_HPP #define TOUCHGFX_PRESENTER_HPPnamespace touchgfx { /* Presenter类 */ class Presenter { public:/* 当Presenter由于屏幕进入而变为活动状态时会自动调用此函数。它通常用于初始化Presenter */virtual void activate(){}/* 当Presenter由于屏幕退出而变为非活动状态时会自动调用此函数。它通常用于清理Presenter */virtual void deactivate(){}/* 析构函数 */virtual ~Presenter(){}protected:/* 构造函数 */Presenter(){} };}#endif#ifndef MODELLISTENER_HPP #define MODELLISTENER_HPP#include gui/model/Model.hpp/* ModelListener类 */ class ModelListener { public:/* 构造函数 */ModelListener() : model(0) {}/* 析构函数 */virtual ~ModelListener() {}/* 将Model与Presenter实例关联起来 */void bind(Model *m){model m;}protected:Model *model; //Model实例指针 };#endif#ifndef SCREENPRESENTER_HPP #define SCREENPRESENTER_HPP #include gui/model/ModelListener.hpp #include mvp/Presenter.hppusing namespace touchgfx;class screenView;/* 用户端某screen对应的Presenter类 */ class screenPresenter : public touchgfx::Presenter, public ModelListener { public:...private:...screenView view; };#endif通过MVPApplication类的代码可以大概看出引擎是怎么通过MVP切换屏幕的 首先pendingScreenTransitionCallback不为空引擎将调用evaluatePendingScreenTransition函数执行切换回调函数用户需要在切换回调函数中会调用makeTransition来实现屏幕切换 #ifndef TOUCHGFX_MVPAPPLICATION_HPP #define TOUCHGFX_MVPAPPLICATION_HPP #include new #include common/AbstractPartition.hpp #include mvp/MVPHeap.hpp #include mvp/Presenter.hpp #include touchgfx/Application.hpp #include touchgfx/Callback.hpp #include touchgfx/Screen.hpp #include touchgfx/hal/Types.hpp #include touchgfx/transitions/Transition.hppnamespace touchgfx { class Presenter;/* MVP应用类 */ class MVPApplication : public Application { public:/* 构造函数 */MVPApplication() : currentPresenter(0), pendingScreenTransitionCallback(0){instance this;}/* 执行挂起的屏幕转换回调 */virtual void handlePendingScreenTransition(){evaluatePendingScreenTransition();}protected:Presenter *currentPresenter; //指向当前活动的Presenter对象的指针GenericCallback* pendingScreenTransitionCallback; //指向挂起的屏幕转换回调指针/* 执行挂起的屏幕转换回调 */void evaluatePendingScreenTransition(){if(pendingScreenTransitionCallback pendingScreenTransitionCallback-isValid()){pendingScreenTransitionCallback-execute();pendingScreenTransitionCallback 0; //调用完后将指针清空等待下一次注册}} };/* 准备屏幕转换当退出当前屏幕前需要清理正在活动的一些数据 */ FORCE_INLINE_FUNCTION static void prepareTransition(Screen **currentScreen, Presenter **currentPresenter, Transition **currentTrans) {/* 卸载屏幕中所有定时的控件 */Application::getInstance()-clearAllTimerWidgets();/* 清理当前Transition */if(*currentTrans){(*currentTrans)-tearDown();}/* 析构当前Transition */if(*currentTrans){(*currentTrans)-~Transition();}/* 清理当前View */if(*currentScreen){(*currentScreen)-tearDownScreen();}/* 清理当前Presenter */if(*currentPresenter){(*currentPresenter)-deactivate();}/* 析构当前View */if(*currentScreen){(*currentScreen)-~Screen();}/* 析构当前Presenter */if(*currentPresenter){(*currentPresenter)-~Presenter();} }/* 完成屏幕转换当进入新屏幕后需要初始化新屏幕的一些数据。然后重绘新屏幕 */ FORCE_INLINE_FUNCTION static void finalizeTransition(Screen *newScreen, Presenter *newPresenter, Transition *newTransition) {/* 初始化新的View */newScreen-setupScreen();/* 初始化新的Presenter */newPresenter-activate();/* 将新给定的Transition实例与新的View关联起来 */newScreen-bindTransition(*newTransition);/* 初始化新的Transition */newTransition-init();/* 重绘整个屏幕 */newTransition-invalidate(); }/* 用于实现屏幕转换的功能 */ template class ScreenType, class PresenterType, class TransType, class ModelType PresenterType *makeTransition(Screen **currentScreen, Presenter **currentPresenter, MVPHeap heap, Transition **currentTrans, ModelType *model) {assert(sizeof(ScreenType) heap.screenStorage.element_size() View allocation error: Check that all views are added to FrontendHeap::ViewTypes);assert(sizeof(PresenterType) heap.presenterStorage.element_size() Presenter allocation error: Check that all presenters are added to FrontendHeap::PresenterTypes);assert(sizeof(TransType) heap.transitionStorage.element_size() Transition allocation error: Check that all transitions are added to FrontendHeap::TransitionTypes);/* 准备屏幕转换当退出当前屏幕前需要清理正在活动的一些数据 */prepareTransition(currentScreen, currentPresenter, currentTrans);/* 在相应的内存分区中构建新的Transition、View、Presenter实例 */TransType *newTransition new (heap.transitionStorage.atTransType(0)) TransType;ScreenType *newScreen new (heap.screenStorage.atScreenType(0)) ScreenType;PresenterType *newPresenter new (heap.presenterStorage.atPresenterType(0)) PresenterType(*newScreen);/* 返回新的Transition、View、Presenter实例对象指针 */*currentTrans newTransition;*currentPresenter newPresenter;*currentScreen newScreen;/* 将新给定的Presenter实例与Model关联起来 */model-bind(newPresenter);/* 将Model与新的Presenter实例关联起来 */newPresenter-bind(model);/* 将新给定的Presenter实例与新的View关联起来 */newScreen-bind(*newPresenter);/* 完成屏幕转换当进入新屏幕后需要初始化新屏幕的一些数据。然后重绘新屏幕 */finalizeTransition((Screen *)newScreen, (Presenter *)newPresenter, (Transition *)newTransition);return newPresenter; }}#endif在前端应用基类FrontendApplicationBase中实现了对各种屏幕切换函数的封装 #ifndef FRONTENDAPPLICATIONBASE_HPP #define FRONTENDAPPLICATIONBASE_HPP #include mvp/MVPApplication.hpp #include gui/model/Model.hppclass FrontendHeap;/* 前端应用基类 */ class FrontendApplicationBase : public touchgfx::MVPApplication { public:/* 构造函数 */FrontendApplicationBase(Model m, FrontendHeap heap);/* 析构函数 */virtual ~FrontendApplicationBase() { }/* 切换到起始屏幕 */virtual void changeToStartScreen(){gotoscreenScreenNoTransition();}/* 不带任何切换动画切换到screen屏幕 */void gotoscreenScreenNoTransition();protected:touchgfx::CallbackFrontendApplicationBase transitionCallback; //切换回调FrontendHeap frontendHeap; //前端内存堆引用Model model; //Model引用void gotoscreenScreenNoTransitionImpl(); //不带任何切换动画切换到screen屏幕回调执行函数 };#endif#include new #include gui_generated/common/FrontendApplicationBase.hpp #include gui/common/FrontendHeap.hpp #include touchgfx/transitions/NoTransition.hpp #include texts/TextKeysAndLanguages.hpp #include touchgfx/Texts.hpp #include touchgfx/hal/HAL.hpp #include platform/driver/lcd/LCD16bpp.hpp #include gui/screen_screen/screenView.hpp #include gui/screen_screen/screenPresenter.hppusing namespace touchgfx;FrontendApplicationBase::FrontendApplicationBase(Model m, FrontendHeap heap): touchgfx::MVPApplication(),transitionCallback(),frontendHeap(heap),model(m) {touchgfx::HAL::getInstance()-setDisplayOrientation(touchgfx::ORIENTATION_LANDSCAPE);reinterpret_casttouchgfx::LCD16bpp(touchgfx::HAL::lcd()).enableTextureMapperAll();reinterpret_casttouchgfx::LCD16bpp(touchgfx::HAL::lcd()).enableDecompressorL8_All(); }/* 不带任何切换动画切换到screen屏幕 */ void FrontendApplicationBase::gotoscreenScreenNoTransition() {/* 设置切换屏幕回调 */transitionCallback touchgfx::CallbackFrontendApplicationBase(this, FrontendApplicationBase::gotoscreenScreenNoTransitionImpl);/* 将该切换行为注册到pendingScreenTransitionCallback */pendingScreenTransitionCallback transitionCallback; }/* 不带任何切换动画切换到screen屏幕回调执行函数 */ void FrontendApplicationBase::gotoscreenScreenNoTransitionImpl() {/* 实现屏幕转换的功能 */touchgfx::makeTransitionscreenView, screenPresenter, touchgfx::NoTransition, Model (currentScreen, currentPresenter, frontendHeap, currentTransition, model); }在前端应用类FrontendApplication中调用model.tick()。即为model提供周期节拍用来采样UI所需要的数据 #ifndef FRONTENDAPPLICATION_HPP #define FRONTENDAPPLICATION_HPP #include gui_generated/common/FrontendApplicationBase.hppclass FrontendHeap;using namespace touchgfx;class FrontendApplication : public FrontendApplicationBase { public:FrontendApplication(Model m, FrontendHeap heap);virtual ~FrontendApplication() { }/* 定时事件 */virtual void handleTickEvent(){model.tick(); //调用model定时事件FrontendApplicationBase::handleTickEvent(); //调用基类定时事件} private: };#endif#include gui/common/FrontendApplication.hppFrontendApplication::FrontendApplication(Model m, FrontendHeap heap): FrontendApplicationBase(m, heap) {}
http://www.zqtcl.cn/news/999445/

相关文章:

  • 网站基本常识wordpress怎么使用插件
  • 无锡高端网站制作广州装修公司排名
  • 做h5商城网站pc网站建设哪
  • 顺企网萍乡网站建设自己如何开自己的商城
  • 怎样做当地网站推广平顶山车祸最新新闻事件
  • 重庆网站制作1000客户营销
  • 视频播放网站 模板潍坊网站建设首荐创美网络
  • 网站静态页面模板网页设计案例代码
  • 网站开发的ie兼容做到9网站开发具体问题
  • 企业建站业务还能做吗园林景观网站模板
  • 建筑招聘网站有哪些电商商城app制作开发
  • 做网站开发 用什么在进行网站设计时
  • 21dove谁做的的网站新媒体营销论文
  • 做电影网站配什么公众号网站新闻发布系统模板
  • 网站风格发展趋势wordpress悬浮音乐插件
  • 做网站前期费用新注册公司网站建设
  • 建站平台在线提交表格功能检测站点是否使用wordpress
  • 谁能做网站开发免费软件看电视剧
  • 深圳的网站建设网站建设网页设计做网站
  • 广州网站建设网页设计贵阳网站建设宏思锐达
  • 洪栾单页网站建设象山县城乡和住房建设局网站
  • 网站留言发送到邮箱潍坊商城网站建设
  • 四川省的住房和城乡建设厅网站首页产品设计是冷门专业吗
  • 北仑建设银行网站网站设计 导航条
  • 如何做网站宣传片单位做网站费用怎么记账
  • 西安网站建设现状购物app开发
  • 2019年做网站还有前景吗手机制作表格教程
  • 校园网站html模板南昌网站建设优化
  • 网站的建立目的来宾网站优化
  • 建设国家游戏网站网站建设规范方案