Skip to main content
LBend.1
Associate III
June 7, 2021
Solved

How to retain ScrollWheel Indices between model and view for screen changes.

  • June 7, 2021
  • 6 replies
  • 1893 views

Hi,

I'm trying to use a scroll wheel with a custom container to select the number of seconds an output will be on. The scroll wheel is on it's own screen which is accessed from a main screen. The scroll wheel index information is used as a system initialization/setup variable and needs to be able to be retained in the model when switching screens, so when the scroll wheel screen is reopened, the scroll wheel(s) show the previously selected value.

In the view I'm using the following base scroll wheel functions.

//Zone 1 Purge
void PurgeSetupView::scrollWheelZone1PrePurgeUpdateItem(textScrollContainer& item, int16_t itemIndex)
{
	item.updateText(itemIndex);
	presenter->userSetZone1PrePurge(itemIndex);
}
void PurgeSetupView::scrollWheelZone1PrePurgeUpdateCenterItem(textScrollCenterContainer& item, int16_t itemIndex)
{
 item.updateText(itemIndex);
 presenter->userSetZone1PrePurge(itemIndex);
}
void PurgeSetupView::setZone1PrePurge(int16_t itemIndex)
{
	zone1prepurge = itemIndex; //test variable
	scrollWheelZone1PrePurge.animateToItem(itemIndex, 0); //animate to the previously set item.
	scrollWheelZone1PrePurge.invalidate();
}

In the presenter I'm passing the itemIndex to the model and storing (all seems correct here when stepping through).

#ifndef PURGESETUPPRESENTER_HPP
#define PURGESETUPPRESENTER_HPP
 
#include <gui/model/ModelListener.hpp>
#include <mvp/Presenter.hpp>
 
using namespace touchgfx;
 
class PurgeSetupView;
 
class PurgeSetupPresenter : public touchgfx::Presenter, public ModelListener
{
public:
 PurgeSetupPresenter(PurgeSetupView& v);
 
 //Pre Purge Model Updates
 void userSetZone1PrePurge(int16_t countIndex)
	{
		model->userSetZone1PrePurge(countIndex);
	}
 
 /**
 * The activate function is called automatically when this screen is "switched in"
 * (ie. made active). Initialization logic can be placed here.
 */
 virtual void activate();
 
 /**
 * The deactivate function is called automatically when this screen is "switched out"
 * (ie. made inactive). Teardown functionality can be placed here.
 */
 virtual void deactivate();
 
 virtual ~PurgeSetupPresenter() {};
 
private:
 PurgeSetupPresenter();
 
 PurgeSetupView& view;
};
 
#endif // PURGESETUPPRESENTER_HPP
//Model.cpp
 
/*Zone Pre Purge Model State Values*/
void Model::userSetZone1PrePurge(int16_t countIndex)
{
	zone1PrePurgeValue = countIndex;
}

On the scroll wheel screen the updating of the scroll wheel value indicates properly. When I go back to the main screen and reopen the scroll wheel screen I call the 'view' function 'setZone1PrePurge' on activate to update, but the 'itemIndex/presented value' always reverts to 1.

#include <gui/purgesetup_screen/PurgeSetupView.hpp>
#include <gui/purgesetup_screen/PurgeSetupPresenter.hpp>
 
PurgeSetupPresenter::PurgeSetupPresenter(PurgeSetupView& v)
 : view(v)
{
 
}
 
void PurgeSetupPresenter::activate()
{
 
	view.setZone1PrePurge(model->getZone1PrePurge());
 
}
 
void PurgeSetupPresenter::deactivate()
{
 
}

It seems that the value gets overwritten somewhere, but I can't figure out where. Or when the purge screen opens it reinitializes to the list through the 'setupScreen();'

PurgeSetupViewBase::setupScreen();
 
/*******Following within PurgeSetupViewBase***********************/
 
scrollWheelZone1PostPurge.initialize();
 for (int i = 0; i < scrollWheelZone1PostPurgeListItems.getNumberOfDrawables(); i++)
 {
 scrollWheelZone1PostPurgeListItems[i].initialize();
 }
 for (int i = 0; i < scrollWheelZone1PostPurgeSelectedListItems.getNumberOfDrawables(); i++)
 {
 scrollWheelZone1PostPurgeSelectedListItems[i].initialize();
 }

How can I accomplish saving of the scroll wheel value/location so upon screen initialization it pulls the indices from the model and updates properly?

Thanks!

This topic has been closed for replies.
Best answer by MM..1

Setter need call only in tearDownScreen(), but you need in view get actual marked index.

6 replies

MM..1
Super User
June 7, 2021

I mean your idea use activate presenter is fail. You need do setup in screen setup call for example symbolic

void Screen3View::setupScreen() {
 Screen3ViewBase::setupScreen();
 xxindex = presenter->getsomevalue(); // this need one getter in presenter and second in model
setZone1PrePurge(xxindex);
}

LBend.1
LBend.1Author
Associate III
June 7, 2021

I think I already tried that as well, but maybe I'm missing something? It always returns 1 for this.

ScreenView:

void PurgeSetupView::setupScreen()
{
	PurgeSetupViewBase::setupScreen();
 
	zone1prepurge = presenter->getZone1PrePurge();
	setZone1PrePurge(zone1prepurge);
}

Presenter:

#ifndef PURGESETUPPRESENTER_HPP
#define PURGESETUPPRESENTER_HPP
 
#include <gui/model/ModelListener.hpp>
#include <mvp/Presenter.hpp>
 
using namespace touchgfx;
 
class PurgeSetupView;
 
class PurgeSetupPresenter : public touchgfx::Presenter, public ModelListener
{
public:
 PurgeSetupPresenter(PurgeSetupView& v);
 
 //Pre Purge Model Updates
 void userSetZone1PrePurge(int16_t countIndex)
	{
		model->userSetZone1PrePurge(countIndex);
	}
	int16_t getZone1PrePurge()
	{
		return model->getZone1PrePurge();
	}
 
 /**
 * The activate function is called automatically when this screen is "switched in"
 * (ie. made active). Initialization logic can be placed here.
 */
 virtual void activate();
 
 /**
 * The deactivate function is called automatically when this screen is "switched out"
 * (ie. made inactive). Teardown functionality can be placed here.
 */
 virtual void deactivate();
 
 virtual ~PurgeSetupPresenter() {};
 
private:
 PurgeSetupPresenter();
 
 PurgeSetupView& view;
};
 
#endif // PURGESETUPPRESENTER_HPP

Model.hpp:

	/******************************
	 * Purge Setup Model Callbacks
	 ******************************/
 
	int16_t getZone1PrePurge() const
	{
		return zone1PrePurgeValue;
	}

MM..1
Super User
June 7, 2021

As first check and debug one direction for example in model hpp

public:
...
 virtual int16_t getZone1PrePurge();
protected:
 int zone1PrePurgeValue;

and code place in model cpp

	int16_t getZone1PrePurge()
	{
		return zone1PrePurgeValue;
	}

and init model with value for test

Model::Model() :
		zone1PrePurgeValue(2),
 modelListener(0) {
}

comment out calls setter...