TSupplierGuiCompBase.h
Go to the documentation of this file.
1 #ifndef iqtinsp_TSupplierGuiCompBase_included
2 #define iqtinsp_TSupplierGuiCompBase_included
3 
4 
5 // Qt includes
6 #include<QtCore/QtGlobal>
7 #if QT_VERSION >= 0x050000
8 #include <QtWidgets/QMessageBox>
9 #else
10 #include <QtGui/QMessageBox>
11 #endif
12 
13 // ACF includes
14 #include "istd/TChangeNotifier.h"
15 #include "istd/TOptDelPtr.h"
16 #include "ifile/IFilePersistence.h"
17 #include "imod/IObserver.h"
18 #include "iprm/IParamsSet.h"
20 #include "iproc/ISupplier.h"
21 #include "iqtgui/IGuiObject.h"
24 
25 // ACF-Solutions includes
26 #include "iqtinsp/iqtinsp.h"
27 
28 
29 namespace iqtinsp
30 {
31 
32 
33 template <class UI, class WidgetType = QWidget>
36  iqtgui::TDesignerGuiObserverCompBase<UI, iproc::ISupplier> >
37 {
38 public:
41 
42  I_BEGIN_BASE_COMPONENT(TSupplierGuiCompBase);
43  I_ASSIGN(m_paramsLoaderCompPtr, "ParamsLoader", "Loads and saves parameters from and to file", false, "ParamsLoader");
44  I_ASSIGN(m_paramsSetGuiCompPtr, "ParamsSetGui", "Shows parameter set", false, "ParamsSetGui");
45  I_ASSIGN_TO(m_paramsSetObserverCompPtr, m_paramsSetGuiCompPtr, false);
46  I_ASSIGN_TO(m_paramsSetExtenderCompPtr, m_paramsSetGuiCompPtr, false);
47  I_ASSIGN(m_connectParametersToEditorAttrPtr, "ConnectParametersToEditor", "If enabled, the parameter set of the supplier will be connected to the parameter editor", true, true);
48  I_ASSIGN(m_viewCalibrationModeAttrPtr, "ViewCalibrationMode", "Control when calibration from supplier will be set to view\n\t0 - never use calibration\n\t1 - only indirect (used as slave)\n\t2 - allways set calibration if available", true, 0);
49  I_END_COMPONENT;
50 
52 
53  // reimplemented (iqt2d::IViewExtender)
54  virtual void AddItemsToScene(iqt2d::IViewProvider* providerPtr, int flags);
55  virtual void RemoveItemsFromScene(iqt2d::IViewProvider* providerPtr);
56 
57 protected:
58  typedef typename BaseClass::Shapes Shapes;
59 
60  using BaseClass::GetObjectPtr;
61 
65  bool AreParamsEditable() const;
66 
70  bool IsLoadParamsSupported() const;
71 
75  bool IsSaveParamsSupported() const;
76 
80  bool LoadParams();
81 
85  bool SaveParams();
86 
90  bool DoTest();
91 
96  virtual void OnSupplierParamsChanged();
97 
98  // reimplemented (iqtgui::TGuiObserverWrap)
99  virtual void OnGuiModelAttached();
100  virtual void OnGuiModelDetached();
101 
102  // reimplemented (iqt2d::TViewExtenderCompBase)
103  virtual void CreateShapes(int sceneId, Shapes& result);
104 
105  // reimplemented (imod::IObserver)
106  virtual void AfterUpdate(imod::IModel* modelPtr, int updateFlags, istd::IPolymorphic* updateParamsPtr);
107 
108  // abstract methods
114  virtual QWidget* GetParamsWidget() const = 0;
115 
116 protected:
118  {
119  public:
121 
122  using imod::CSingleModelObserverBase::EnsureModelDetached;
123 
124  protected:
125  // reimplemented (imod::CSingleModelObserverBase)
126  virtual void OnUpdate(int updateFlags, istd::IPolymorphic* updateParamsPtr);
127 
128  private:
129  TSupplierGuiCompBase& m_parent;
130  };
131 
133 
134 protected:
135  using BaseClass::m_visualStatus;
136 
137 private:
141  enum ViewCalibrationMode
142  {
146  VCM_NONE,
150  VCM_INDIRECT,
154  VCM_ALWAYS
155  };
156 
157  I_REF(ifile::IFilePersistence, m_bitmapLoaderCompPtr);
158  I_REF(ifile::IFilePersistence, m_paramsLoaderCompPtr);
159 
160  I_REF(iqtgui::IGuiObject, m_paramsSetGuiCompPtr);
161  I_REF(imod::IObserver, m_paramsSetObserverCompPtr);
162  I_REF(iqt2d::IViewExtender, m_paramsSetExtenderCompPtr);
163 
164  I_ATTR(bool, m_connectParametersToEditorAttrPtr);
165  I_ATTR(int, m_viewCalibrationModeAttrPtr);
166 
167  bool m_areParamsEditable;
168  istd::TOptDelPtr<i2d::ICalibration2d> m_storedCalibrationPtr;
169 };
170 
171 
172 // public methods
173 
174 template <class UI, class WidgetType>
176  :m_paramsObserver(this),
177  m_areParamsEditable(false)
178 {
179 }
180 
181 
182 // reimplemented (iqt2d::IViewExtender)
183 
184 template <class UI, class WidgetType>
186 {
187  if (*m_viewCalibrationModeAttrPtr > VCM_NONE){
188  if ((*m_viewCalibrationModeAttrPtr >= VCM_ALWAYS) || ((flags & iqt2d::IViewExtender::SF_DIRECT) == 0)){
189  const i2d::ICalibrationProvider* calibrationProviderPtr = dynamic_cast<const i2d::ICalibrationProvider*>(GetObjectPtr());
190  iview::CCalibratedViewBase* viewPtr = dynamic_cast<iview::CCalibratedViewBase*>(providerPtr->GetView());
191 
192  if ((calibrationProviderPtr != NULL) && (viewPtr != NULL)){
193  const i2d::ICalibration2d* calibrationPtr = calibrationProviderPtr->GetCalibration();
194  if (calibrationPtr != NULL){
195  m_storedCalibrationPtr.SetCastedOrRemove(calibrationPtr->CloneMe(), true);
196  viewPtr->SetDisplayCalibration(m_storedCalibrationPtr.GetPtr());
197  }
198  }
199  }
200  }
201 
202  BaseClass::AddItemsToScene(providerPtr, flags);
203 
204  if ((flags & iqt2d::IViewExtender::SF_DIRECT) != 0){
205  if (m_paramsSetExtenderCompPtr.IsValid()){
206  m_paramsSetExtenderCompPtr->AddItemsToScene(providerPtr, flags);
207  }
208  }
209 }
210 
211 
212 template <class UI, class WidgetType>
214 {
215  if (m_paramsSetExtenderCompPtr.IsValid()){
216  m_paramsSetExtenderCompPtr->RemoveItemsFromScene(providerPtr);
217  }
218 
219  BaseClass::RemoveItemsFromScene(providerPtr);
220 }
221 
222 
223 // protected methods
224 
225 template <class UI, class WidgetType>
227 {
228  return m_areParamsEditable;
229 }
230 
231 
232 template <class UI, class WidgetType>
234 {
235  const iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
236  if ((supplierPtr != NULL) && m_paramsLoaderCompPtr.IsValid()){
237  const iprm::IParamsSet* paramsPtr = supplierPtr->GetModelParametersSet();
238  if (paramsPtr != NULL){
239  if (m_paramsLoaderCompPtr->IsOperationSupported(
240  paramsPtr,
241  NULL,
242  ifile::IFilePersistence::QF_LOAD | ifile::IFilePersistence::QF_ANONYMOUS)){
243  return true;
244  }
245  }
246  }
247 
248  return false;
249 }
250 
251 
252 template <class UI, class WidgetType>
254 {
255  const iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
256  if ((supplierPtr != NULL) && m_paramsLoaderCompPtr.IsValid()){
257  const iprm::IParamsSet* paramsPtr = supplierPtr->GetModelParametersSet();
258  if (paramsPtr != NULL){
259  if (m_paramsLoaderCompPtr->IsOperationSupported(
260  paramsPtr,
261  NULL,
262  ifile::IFilePersistence::QF_SAVE | ifile::IFilePersistence::QF_ANONYMOUS)){
263  return true;
264  }
265  }
266  }
267 
268  return false;
269 }
270 
271 
272 template <class UI, class WidgetType>
274 {
275  iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
276  if ((supplierPtr != NULL) && m_paramsLoaderCompPtr.IsValid()){
277  iprm::IParamsSet* paramsPtr = supplierPtr->GetModelParametersSet();
278  if (paramsPtr != NULL){
279  if (m_paramsLoaderCompPtr->LoadFromFile(*paramsPtr, "") != ifile::IFilePersistence::OS_FAILED){
280  return true;
281  }
282  else{
283  QMessageBox::warning(
284  BaseClass::GetQtWidget(),
285  QObject::tr("Error"),
286  QObject::tr("Cannot load parameters"));
287  }
288  }
289  }
290 
291  return false;
292 }
293 
294 
295 template <class UI, class WidgetType>
297 {
298  const iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
299  if ((supplierPtr != NULL) && m_paramsLoaderCompPtr.IsValid()){
300  const iprm::IParamsSet* paramsPtr = supplierPtr->GetModelParametersSet();
301  if (paramsPtr != NULL){
302  if (m_paramsLoaderCompPtr->SaveToFile(*paramsPtr, "") != ifile::IFilePersistence::OS_FAILED){
303  return true;
304  }
305  else{
306  QMessageBox::warning(
307  BaseClass::GetQtWidget(),
308  QObject::tr("Error"),
309  QObject::tr("Cannot save parameters"));
310  }
311  }
312  }
313 
314  return false;
315 }
316 
317 
318 template <class UI, class WidgetType>
320 {
321  iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
322  if (supplierPtr != NULL){
323  supplierPtr->InvalidateSupplier();
324  supplierPtr->EnsureWorkInitialized();
325  supplierPtr->EnsureWorkFinished();
326 
327  return supplierPtr->GetWorkStatus() < iproc::ISupplier::WS_ERROR;
328  }
329 
330  return false;
331 }
332 
333 
334 template <class UI, class WidgetType>
336 {
337 }
338 
339 
340 // reimplemented (iqtgui::TGuiObserverWrap)
341 
342 template <class UI, class WidgetType>
344 {
345  BaseClass::OnGuiModelAttached();
346 
347  iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
348  Q_ASSERT(supplierPtr != NULL); // model must be attached
349 
350  iprm::IParamsSet* paramsPtr = const_cast<iprm::IParamsSet*>(supplierPtr->GetModelParametersSet());
351  imod::IModel* paramsModelPtr = dynamic_cast<imod::IModel*>(paramsPtr);
352 
353  m_areParamsEditable = !*m_connectParametersToEditorAttrPtr;
354  bool areParamsAttachedToEditor = !*m_connectParametersToEditorAttrPtr;
355  QWidget* paramsWidget = GetParamsWidget();
356  if (paramsWidget != NULL){
357  if (m_paramsSetGuiCompPtr.IsValid()){
358  m_paramsSetGuiCompPtr->CreateGui(paramsWidget);
359  }
360 
361  if (*m_connectParametersToEditorAttrPtr && (paramsModelPtr != NULL) && m_paramsSetObserverCompPtr.IsValid()){
362  areParamsAttachedToEditor = paramsModelPtr->AttachObserver(m_paramsSetObserverCompPtr.GetPtr());
363  if (!areParamsAttachedToEditor){
364  qWarning("Supplier parameters could not be connected to the editor");
365  }
366 
367  m_areParamsEditable = true;
368 
369 
370  // Attach internal parameter observer:
371  paramsModelPtr->AttachObserver(&m_paramsObserver);
372  }
373 
374  paramsWidget->setVisible(m_areParamsEditable);
375  paramsWidget->setEnabled(areParamsAttachedToEditor);
376  }
377 
378  BaseClass::SetStatusIcon(QIcon(":/Icons/StateUnknown.svg"));
379 }
380 
381 
382 template <class UI, class WidgetType>
384 {
385  iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
386  Q_ASSERT(supplierPtr != NULL); // model must be attached
387 
388  iprm::IParamsSet* paramsPtr = const_cast<iprm::IParamsSet*>(supplierPtr->GetModelParametersSet());
389  imod::IModel* paramsModelPtr = dynamic_cast<imod::IModel*>(paramsPtr);
390 
391  if ( m_paramsSetObserverCompPtr.IsValid() &&
392  (paramsModelPtr != NULL) &&
393  paramsModelPtr->IsAttached(m_paramsSetObserverCompPtr.GetPtr())){
394  paramsModelPtr->DetachObserver(m_paramsSetObserverCompPtr.GetPtr());
395  }
396 
397  if (m_paramsSetGuiCompPtr.IsValid() && m_paramsSetGuiCompPtr->IsGuiCreated()){
398  m_paramsSetGuiCompPtr->DestroyGui();
399  }
400 
401  m_areParamsEditable = false;
402 
403  m_paramsObserver.EnsureModelDetached();
404 
405  BaseClass::OnGuiModelDetached();
406 }
407 
408 
409 // reimplemented (iqt2d::TViewExtenderCompBase)
410 
411 template <class UI, class WidgetType>
413 {
414 }
415 
416 
417 // reimplemented (imod::IObserver)
418 
419 template <class UI, class WidgetType>
421 {
422  if (!BaseClass::IsGuiCreated()){
423  BaseClass::AfterUpdate(modelPtr, updateFlags, updateParamsPtr);
424 
425  return;
426  }
427 
428  QString statusText = "";
429  QIcon statusIcon = QIcon(":/Icons/StateUnknown.svg");
430 
431  QString description;
432 
433  const iproc::ISupplier* supplierPtr = BaseClass::GetObjectPtr();
434  if (supplierPtr != NULL){
435  const istd::IInformationProvider* infoProviderPtr = dynamic_cast<const istd::IInformationProvider*>(supplierPtr);
436  int category = infoProviderPtr == NULL ?
437  istd::IInformationProvider::IC_INFO:
438  infoProviderPtr->GetInformationCategory();
439 
440  int workStatus = supplierPtr->GetWorkStatus();
441 
442  switch (workStatus){
444  statusText = QObject::tr("Locked");
445  break;
446 
448  switch (category){
449  case istd::IInformationProvider::IC_WARNING:
450  statusText = QObject::tr("Processing completed with warnings");
451  statusIcon = QIcon(":/Icons/StateWarning.svg");
452  break;
453 
454  case istd::IInformationProvider::IC_ERROR:
455  statusText = QObject::tr("Processing completed with errors");
456  statusIcon = QIcon(":/Icons/StateInvalid.svg");
457  break;
458 
459  default:
460  statusText = QObject::tr("Processing completed without errors");
461  statusIcon = QIcon(":/Icons/StateOk.svg");
462  break;
463  }
464  break;
465 
467  statusText = QObject::tr("Processing canceled by user");
468  break;
469 
471  statusText = QObject::tr("Processing not possible");
472  statusIcon = QIcon(":/Icons/StateInvalid.svg");
473  break;
474 
476  statusText = QObject::tr("Critical error occurred, application problem");
477  statusIcon = QIcon(":/Icons/Error.svg");
478  break;
479 
480  default:
481  break;
482  }
483  }
484 
485  istd::CChangeNotifier visualStatusNotifier(&m_visualStatus);
486  BaseClass::SetStatusIcon(statusIcon);
487  BaseClass::SetStatusText(statusText);
488 
489  BaseClass::AfterUpdate(modelPtr, updateFlags, updateParamsPtr);
490 }
491 
492 
493 // public methods of embedded class ParamsObserver
494 
495 template <class UI, class WidgetType>
497  :m_parent(*parentPtr)
498 {
499  Q_ASSERT(parentPtr != NULL);
500 }
501 
502 
503 // reimplemented (imod::CSingleModelObserverBase)
504 template <class UI, class WidgetType>
506 {
507  if ((updateFlags & istd::IChangeable::CF_MODEL) != 0){
508  m_parent.OnSupplierParamsChanged();
509  }
510 }
511 
512 } // namespace iqtinsp
513 
514 
515 #endif // !iqtinsp_TSupplierGuiCompBase_included
516 
517 
virtual void OnSupplierParamsChanged()
Method will be called every time if the parameter set of the supplier has been changed.
virtual QWidget * GetParamsWidget() const =0
Get parameters widget object.
virtual void AfterUpdate(imod::IModel *modelPtr, int updateFlags, istd::IPolymorphic *updateParamsPtr)
virtual void EnsureWorkFinished()=0
Ensure that all objects are produced.
virtual void EnsureWorkInitialized()=0
Force the supplier to initialize its work.
Work cannot be done.
Definition: ISupplier.h:54
Work was canceled.
Definition: ISupplier.h:46
virtual void InvalidateSupplier()=0
Called to signalize that this supplier is invalid.
virtual bool IsAttached(const IObserver *observerPtr) const =0
iqt2d::TViewExtenderCompBase< iqtgui::TDesignerGuiObserverCompBase< UI, iproc::ISupplier > > BaseClass
bool DoTest()
Do inspection test.
Work was done correctly and no error occure.
Definition: ISupplier.h:42
virtual int GetWorkStatus() const =0
Get status of last work.
ParamsObserver(TSupplierGuiCompBase *parentPtr)
bool IsSaveParamsSupported() const
Check if parameter storing is supported.
virtual void CreateShapes(int sceneId, Shapes &result)
bool LoadParams()
Load parameters from external source (file).
virtual InformationCategory GetInformationCategory() const =0
virtual iprm::IParamsSet * GetModelParametersSet() const =0
Get parameter set using by this supplier.
virtual void AddItemsToScene(iqt2d::IViewProvider *providerPtr, int flags)
virtual void OnUpdate(int updateFlags, istd::IPolymorphic *updateParamsPtr)
void SetDisplayCalibration(const i2d::ICalibration2d *calibrationPtr)
Supplier is locked becouse it is doing processing step.
Definition: ISupplier.h:38
Base interface for suppliers providing synchrone processing of single object with "pull data" model...
Definition: ISupplier.h:22
I_ASSIGN_TO(m_paramsSetObserverCompPtr, m_paramsSetGuiCompPtr, false)
bool SaveParams()
Save parameters for example to file.
Work was done, but there were errors.
Definition: ISupplier.h:50
virtual iview::IShapeView * GetView() const =0
#define NULL
bool AreParamsEditable() const
Check, if parameters are correct connected to GUI and can be editable.
virtual bool AttachObserver(IObserver *observerPtr)=0
virtual void RemoveItemsFromScene(iqt2d::IViewProvider *providerPtr)
bool IsLoadParamsSupported() const
Check if parameter loading is supported.
virtual const ICalibration2d * GetCalibration() const =0
virtual void DetachObserver(IObserver *observerPtr)=0

© 2007-2011 Witold Gantzke and Kirill Lepskiy