0% found this document useful (0 votes)
8 views7 pages

View Manager CPP

The document is a C++ source file for the ViewManager class, which manages all views in a software application. It includes functions for initialization, handling user interactions, and updating UI components, as well as managing memory and resources. The file also contains conditional compilation for workstation-specific functionalities and logging for debugging purposes.

Uploaded by

Anurag Ji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

View Manager CPP

The document is a C++ source file for the ViewManager class, which manages all views in a software application. It includes functions for initialization, handling user interactions, and updating UI components, as well as managing memory and resources. The file also contains conditional compilation for workstation-specific functionalities and logging for debugging purposes.

Uploaded by

Anurag Ji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1 /*!

2 * @file viewmanager.cpp
3 * @author Agiliad
4 * @brief This file contains functions related to ViewManager
5 * which managing all views.
6 * @date Sep, 26 2016
7 *
8 */
9
10 #include <analogic/ws/uihandler/view.h>
11 #include <analogic/ws/uihandler/viewmanager.h>
12 #ifdef WORKSTATION
13 #include <analogic/ws/common/faults/bhspickupnotificationdata.h>
14 #endif
15
16 //For supervisor workstation - to add data into charts
17 #include <QtCharts/QXYSeries>
18
19 namespace analogic
20 {
21 namespace ws
22 {
23 /*!
24 * @fn ViewManager(QObject* parent = NULL);
25 * @param QObject* - parent
26 * @return None
27 * @brief Constructor responsible for initialization of class members, memory and
resources.
28 */
29 ViewManager::ViewManager(QObject* parent):QObject(parent)
30 {
31 DEBUG_LOG("Creating instance of View and connection signals with resp slots");
32
33 m_hView.reset(new View(this));
34 THROW_IF_FAILED((m_hView.use_count() == 0) ? Errors::E_OUTOFMEMORY : Errors::S_OK);
35 #ifdef WORKSTATION
36 BHSPickupNotificationData::insertBhsPickupData();
37
38 if(WorkstationConfig::getInstance()->getCurrentLanuage() == "English")
39 {
40 std::string sFilePath = WorkstationConfig::getInstance()->getexecutablePath() + "/"
+ BHS_WARNING_MESSAGE_FILE_NAME;
41 QList<FaultMapXMLDataStruct> bhsWarningList =
Utility::updateScannerFaultWarningData(sFilePath);
42 QMap <QString, BhsTrayPickupInfo> *bhsPickupInfo =
BHSPickupNotificationData::getBhsPickupData();
43 for(int i = 0; i < bhsWarningList.count(); i++)
44 {
45 FaultMapXMLDataStruct updatedWarningStructure= bhsWarningList.at(i);
46
47 BhsTrayPickupInfo faultInfo =
bhsPickupInfo->value(updatedWarningStructure.faultid);
48 if((faultInfo.useraction != updatedWarningStructure.faultAction)
49 || (faultInfo.description != updatedWarningStructure.faultMessage))
50 {
51 faultInfo.description = updatedWarningStructure.faultMessage;
52 faultInfo.useraction = updatedWarningStructure.faultAction.remove("\\n");
53 bhsPickupInfo->insert(updatedWarningStructure.faultid, faultInfo);
54 }
55 }
56 }
57 #endif
58 }
59
60 /*!
61 * @fn ~ViewManager
62 * @param None
63 * @return None
64 * @brief Destructor responsible for deinitialization of members, memory and resources.
65 */
66 ViewManager::~ViewManager()
67 {
68 DEBUG_LOG("Destroying members");
69 m_hView.reset();
70 }
71
72 /*!
73 * @fn Initialize
74 * @param None
75 * @return None
76 * @brief Responsible for intialization of managers and controllers.
77 */
78 void ViewManager::initialize()
79 {
80 DEBUG_LOG("Start of ViewManager::initialize()");
81 DEBUG_LOG("Initialize View");
82 m_hView->initialize();
83 DEBUG_LOG("Initialize Screen Map");
84 intializeScreenMap();
85
86 connect(m_hView.get(), &View::setAuthenticatedUserDetailsToScanner,
87 this, &ViewManager::setAuthenticatedUserDetailsToScanner);
88 connect(m_hView.get(), &View::notifyBagIsPickedUpsig, this,
&ViewManager::notifyBagIsPickedUpsig);
89 connect(m_hView.get(), SIGNAL(currentViewChanged(int)), this,
SLOT(onScreenChanged(int)));
90 connect(m_hView.get(), SIGNAL(commandButtonEvent(QMLEnums::ModelEnum, QString)),
91 this, SLOT(onCommandButton(QMLEnums::ModelEnum, QString)));
92 connect(m_hView.get(), &View::exit, this, &ViewManager::onExit);
93 connect(m_hView.get(), SIGNAL(bagListCommand(QMLEnums::ArchiveFilterSrchLoc,
94 QMLEnums::BagsListAndBagDataCommands,
QVariant)), this, SIGNAL(
95 bagListCommand(QMLEnums::ArchiveFilterSrchLoc,
QMLEnums::BagsListAndBagDataCommands,
96 QVariant)), Qt::QueuedConnection);
97
98 #ifdef WORKSTATION
99 connect(m_hView.get(), SIGNAL(updateChartsCordinates(QAbstractSeries*,int)),
100 this, SLOT(onUpdateChartsCordinates(QAbstractSeries*,int)));
101 #endif
102 connect(m_hView.get(), SIGNAL(selectedAgentTypeChanged(int)),
103 this, SIGNAL(selectedAgentTypeChanged(int)));
104
105 connect(m_hView.get(), SIGNAL(updateScannerParamChanged()),
106 this, SIGNAL(updateScannerParamChanged()));
107
108 connect(m_hView.get(), SIGNAL(requestToVersionInfoAPI()),
109 this, SIGNAL(requestToVersionInfoAPI()));
110
111 #ifdef WORKSTATION
112 connect(m_hView.get(), &View::startScannerHeartBeat, this,
&ViewManager::onStartScannerHeartBeat);
113 #endif
114 connect(this, &ViewManager::notifyWSConfigUpdated, m_hView.get(),
115 &View::onUpdateConfigParameters);
116 connect(this, &ViewManager::bagListCommandResults, m_hView.get(),
117 &View::bagListCommandResults, Qt::QueuedConnection);
118
119 connect(this, &ViewManager::bagRetain, m_hView.get(),
120 &View::bagRetain, Qt::QueuedConnection);
121
122 // Connections for SearchWorkstation
123 connect(this, SIGNAL(notifyToChangeOrNotScreen(bool, QString, int)), m_hView.get(),
124 SIGNAL(notifyToChangeOrNotScreen(bool, QString, int)), Qt::QueuedConnection);
125 connect(this, SIGNAL(updateBagReceivedStatus(int)), m_hView.get(),
126 SIGNAL(updateBagReceivedStatus(int)), Qt::QueuedConnection);
127
128 INFO_LOG("Qml File Load success");
129 DEBUG_LOG("End of ViewManager::initialize()");
130 }
131
132 /*!
133 * @fn getViewObject();
134 * @param None
135 * @return boost::shared_ptr<View>
136 * @brief This function responsible for getting view object
137 */
138 boost::shared_ptr<View> ViewManager::getViewObject()
139 {
140 DEBUG_LOG("Returning handle to view object");
141 return m_hView;
142 }
143
144 /*!
145 * @fn onModelDataChanged();
146 * @param QVariantList model data
147 * @param QMLEnums::ModelEnum
148 * @return None
149 * @brief This function responsible for changing model data.
150 */
151 void ViewManager::onModelDataChanged(QVariantList oData, QMLEnums::ModelEnum sModelName)
152 {
153 DEBUG_LOG("Request to update modellist for modelname: "<< sModelName);
154 m_hView->updatemodellist(sModelName, oData);
155 }
156
157 /*!
158 * @fn getModelNames();
159 * @param None
160 * @return ModelList model names
161 * @brief This function responsible for getting model names.
162 */
163 ModelList ViewManager::getModelNames()
164 {
165 DEBUG_LOG("Getting model name list");
166 THROW_IF_FAILED((m_hView.use_count() == 0)?Errors::E_POINTER:Errors::S_OK);
167 QMLEnums::ScreenEnum sCurrentView = (QMLEnums::ScreenEnum )m_hView->getCurrentView();
168 if(sCurrentView == QMLEnums::SCANNERADMIN_SCREEN)
169 {
170 QMLEnums::ScannerAdminScreenEnum sCurrentView =
171 (QMLEnums::ScannerAdminScreenEnum )m_hView->getScanneradminview();
172 if (m_screenModelMap.find(sCurrentView)!= m_screenModelMap.end())
173 return m_screenModelMap[sCurrentView];
174 }
175 return ModelList();
176 }
177
178 /*!
179 * @fn onScreenChanged();
180 * @param None
181 * @return None
182 * @brief This function responsible for changing views.
183 */
184 void ViewManager::onScreenChanged(int currentView)
185 {
186 Q_UNUSED(currentView);
187 DEBUG_LOG("Notify about the screen change event.")
188 ModelList oModelNames = getModelNames();
189 DEBUG_LOG("Changed screen have model count: "<< oModelNames.count());
190 emit screenChanged( oModelNames );
191 }
192
193 /*!
194 * @fn onCommandButton();
195 * @param QMLEnums::ModelEnum
196 * @param QString
197 * @return None
198 * @brief This function responsible for sending signals.
199 */
200 void ViewManager::onCommandButton(QMLEnums::ModelEnum modelname, QString data)
201 {
202 if(((modelname == QMLEnums::NETWORK_AUTHENTICATION_MODEL) ||
203 (modelname == QMLEnums::RERUN_EMULATOR_AUTHENTICATION_MODEL)) && (data ==
"logout"))
204 {
205 DEBUG_LOG("Request to reauthenticate.");
206 emit deAuthenticate();
207 }
208 else
209 {
210 DEBUG_LOG("Notify about command button clciked event and process the data for
modelname: "<< modelname);
211 emit commandButtonEvent(modelname, data);
212 }
213 }
214
215 /*!
216 * @fn onDataTimerTick();
217 * @param None
218 * @return None
219 * @brief This function responsible for timer.
220 */
221 void ViewManager::onDataTimerTick()
222 {
223 DEBUG_LOG("Requesting refresh ui models");
224 m_hView->refreshUiModels();
225 }
226
227 #ifdef WORKSTATION
228 /*!
229 * @fn updateChartsCordinates
230 * @param QAbstractSeries
231 * @return None
232 * @brief This function is responsible for updating the received supervisor webservice
data to the lineseries(QAbstractSeries)
233 */
234 void ViewManager::onUpdateChartsCordinates(QtCharts::QAbstractSeries *series, int
modelnum)
235 {
236 emit updateChartsCordinates(series, modelnum);
237 }
238 #endif
239
240 /*!
241 * @fn onauthstatuschanged
242 * @param int - error
243 * @param QString - status
244 * @param int - modelno
245 * @return None
246 * @brief called on authentication status changed
247 */
248 void ViewManager::onauthstatuschanged(int hr, QString status, int modelno)
249 {
250 DEBUG_LOG("Autherization status changed. hr: "<<hr <<" Status: "<<
status.toStdString() << "modelno :" << modelno);
251 m_hView->onauthstatuschanged(hr, status, modelno);
252 }
253 #if defined WORKSTATION || defined RERUN
254 /*!
255 * @fn onsslerrorreceived
256 * @param int - error
257 * @param QString - status
258 * @param int - modelno
259 * @return None
260 * @brief called on ssl received
261 */
262 void ViewManager::onsslerrorreceived(int hr, QString status, int modelno)
263 {
264 DEBUG_LOG("onsslerrorreceived. hr: "<<hr <<" Status: "<< status.toStdString() <<
"modelno :" << modelno);
265 m_hView->onsslerrorreceived(hr, status, modelno);
266 }
267 #endif
268 /*!
269 * @fn initializeScreenMap();
270 * @param None
271 * @return None
272 * @brief This function responsible for initializing screen map.
273 */
274 void ViewManager::intializeScreenMap()
275 {
276 TRACE_LOG("");
277 m_screenModelMap[QMLEnums::STATUS_SCREEN] = ModelList();
278 m_screenModelMap[QMLEnums::STATUS_SCREEN] << QMLEnums::KEYCONSOLE_MODEL
279 << QMLEnums::ACCESSPANEL_MODEL
280 << QMLEnums::ESTOPS_MODEL
281 << QMLEnums::SAFETYCONTROLLERFAULTS_MODEL
282 <<
QMLEnums::POWERLINKINVERTERDISCRETESTATUS_MOD
EL
283 << QMLEnums::POWERLINKINVERTERSTATUS_MODEL
284 << QMLEnums::XRAYDATA_MODEL
285 << QMLEnums::XRAYSTATUS_MODEL
286 << QMLEnums::XRAYTIME_MODEL
287 << QMLEnums::XRAYFAULTS_MODEL
288 << QMLEnums::MOTIONCONTROLDATA_MODEL
289 << QMLEnums::SCANNERTEMPHUMIDITY_MODEL
290 << QMLEnums::CONVEYORANDGANTRY_MODEL
291 << QMLEnums::SCANNERBAGPROCESSEDMODEL
292 << QMLEnums::MISCELLANEOUS_MODEL;
293
294 m_screenModelMap[QMLEnums::RADIATIONSURVEY_SCREEN] = ModelList();
295 m_screenModelMap[QMLEnums::RADIATIONSURVEY_SCREEN] << QMLEnums::XRAYDATA_MODEL
296 << QMLEnums::XRAYTIME_MODEL;
297 }
298
299 /*!
300 * @fn onExit();
301 * @param isShutdown - whether shutdown is done or restart
302 * @return None
303 * @brief Slot will call on close application
304 */
305 void ViewManager::onExit(bool isShutdown)
306 {
307 DEBUG_LOG("Notifiying application exit");
308 emit exit(isShutdown);
309 }
310
311 /*!
312 * @fn onfileDatadownloadFinished();
313 * @param QString - sDownloadPath
314 * @param QString - sDownloadError
315 * @param QMLEnums::ModelEnum modelnum
316 * @return None
317 * @brief Slot will call on when filedatadownload is finished
318 */
319 void ViewManager::onfileDatadownloadFinished(QString sDownloadPath, QString
sDownloadError,
320 QMLEnums::ModelEnum modelnum)
321 {
322 DEBUG_LOG("Notify qml models about file data download is finished.");
323 m_hView->sendfileDownloadfinshedSignal(sDownloadPath, sDownloadError, modelnum);
324 }
325
326
327 /*!
328 * @fn onUpdateModelsig
329 * @param QList<QObject*> qlist
330 * @return None
331 * @brief Slot will call when model list is updated according to current view.
332 */
333 void ViewManager::onUpdateModelsig(QList<QObject*> qlist)
334 {
335 DEBUG_LOG("Request to initalize ulm data list with the contents of qlist provided.");
336 m_hView->setUlmDataList(qlist);
337 }
338
339 /*!
340 * @fn onNetworkStatus
341 * @param QMLEnums::NetworkState
342 * @return None
343 * @brief Slot calls on notification about status of network from workstationManager.
344 */
345 void ViewManager::onNetworkStatus(QMLEnums::NetworkState status)
346 {
347 DEBUG_LOG("Notify qml models about network status.");
348 QDateTime now = QDateTime::currentDateTime();
349 qDebug()<<"Anurag::Anurag :: Netowrk status received as " << status << " At time: "<<
now.toString("yyyy-MM-dd'T'hh:mm:ss.zzz");
350 INFO_LOG("Anurag::Anurag :: Netowrk status received as " << status << " At time: "<<
now.toString("yyyy-MM-dd'T'hh:mm:ss.zzz").toStdString());
351 emit m_hView->networkStatus(status);
352 }
353
354 #ifdef WORKSTATION
355 /*!
356 * @fn onRequestBagPickup
357 * @param std::string id_assigning_authority
358 * @param const std::string primary bag ID
359 * @param const std::string rfid
360 * @param const QString pickup_type
361 * @param QMLEnums::BhsDiverterDecision
362 * @param const std::string diverter decision string
363 * @return None
364 * @brief Slot called when bag is ready for picked up.
365 */
366 void ViewManager::onRequestBagPickup(const std::string& id_assigning_authority, const
string &primary_bag_id, const string &rfid, const std::string& pickup_type,
QMLEnums::BhsDiverterDecision
367 diverter_decision_code, const string
&diverter_decision_string)
368 {
369 BhsTrayPickupInfo bhsPickInfo =
BHSPickupNotificationData::getBhsPickupData()->value(pickup_type.c_str());
370 const QString message = bhsPickInfo.description;
371 const QString userAction = bhsPickInfo.useraction;
372 m_hView->requestBagPickupsig(id_assigning_authority.c_str(), primary_bag_id.c_str(),
rfid.c_str(), pickup_type.c_str(), diverter_decision_code,
diverter_decision_string.c_str(), message, userAction);
373 }
374
375 /*!
376 * @fn onStartScannerHeartBeat
377 * @param bool start - enable/disable heart beat
378 * @return None
379 * @brief Slot call to start heart beat request on scanner server.
380 */
381 void ViewManager::onStartScannerHeartBeat(bool start)
382 {
383 ModelList oModelNames = getModelNames();
384 if(start)
385 oModelNames<<QMLEnums::SDSW_HEARTBEAT_MODEL;
386 emit screenChanged( oModelNames );
387 }
388
389 /*!
390 * @fn onSdswClientExited
391 * @param int exitCode
392 * @return None
393 * @brief Slot call on sdswclient logout/exit.
394 */
395 void ViewManager::onSdswClientExited(int exitCode)
396 {
397 m_hView.get()->setMaintenanceMode(false);
398 }
399 #endif
400 } // namespace ws
401 } // namespace analogic
402

You might also like