6#ifndef iqtinsp_TCommonSupplierGuiCompBase_included
7#define iqtinsp_TCommonSupplierGuiCompBase_included
11#include<QtCore/QtGlobal>
13#include <QtWidgets/QMessageBox>
38 I_ASSIGN(m_paramsLoaderCompPtr,
"ParamsLoader",
"Loads and saves parameters from and to file",
false,
"ParamsLoader");
39 I_ASSIGN(m_paramsSetGuiCompPtr,
"ParamsSetGui",
"Shows parameter set",
false,
"ParamsSetGui");
40 I_ASSIGN_TO(m_paramsSetObserverCompPtr, m_paramsSetGuiCompPtr,
false);
41 I_ASSIGN(m_connectParametersToEditorAttrPtr,
"ConnectParametersToEditor",
"If enabled, the parameter set of the supplier will be connected to the parameter editor",
true,
true);
154 I_ATTR(
bool, m_connectParametersToEditorAttrPtr);
156 bool m_areParamsEditable;
164 :m_paramsObserver(this),
165 m_statusObserver(this),
166 m_areParamsEditable(false)
178 return m_areParamsEditable;
186 if ((supplierPtr !=
nullptr) && m_paramsLoaderCompPtr !=
nullptr) {
188 if (paramsPtr !=
nullptr) {
189 if (m_paramsLoaderCompPtr->IsOperationSupported(
206 if ((supplierPtr !=
nullptr) && m_paramsLoaderCompPtr !=
nullptr) {
208 if (paramsPtr !=
nullptr) {
209 if (m_paramsLoaderCompPtr->IsOperationSupported(
226 if ((supplierPtr !=
nullptr) && m_paramsLoaderCompPtr !=
nullptr) {
228 if (paramsPtr !=
nullptr) {
229 auto loadState = m_paramsLoaderCompPtr->LoadFromFile(*paramsPtr,
"");
230 if (loadState.WaitForFinished() == iproc::CTaskState::Status::Ready) {
234 QMessageBox::warning(
235 BaseClass::GetQtWidget(),
236 QObject::tr(
"Error"),
237 QObject::tr(
"Cannot load parameters"));
250 if ((supplierPtr !=
nullptr) && m_paramsLoaderCompPtr !=
nullptr) {
252 if (paramsPtr !=
nullptr) {
253 auto saveState = m_paramsLoaderCompPtr->SaveToFile(*paramsPtr,
"");
254 if (saveState.WaitForFinished() != iproc::CTaskState::Status::Failed) {
258 QMessageBox::warning(
259 BaseClass::GetQtWidget(),
260 QObject::tr(
"Error"),
261 QObject::tr(
"Cannot save parameters"));
274 if (supplierPtr !=
nullptr) {
291 QString statusText =
"";
292 static QIcon unknownIcon(
":/IcfIcons/StateUnknown");
293 static QIcon warningIcon(
":/IcfIcons/StateWarning");
294 static QIcon invalidIcon(
":/IcfIcons/StateInvalid");
295 static QIcon okIcon(
":/IcfIcons/StateOk");
297 QIcon statusIcon = unknownIcon;
302 if (supplierPtr !=
nullptr) {
304 if (infoProviderPtr ==
nullptr) {
312 switch (workStatus) {
314 statusText = QObject::tr(
"Locked");
320 statusText = QObject::tr(
"Processing completed with warnings");
321 statusIcon = warningIcon;
325 statusText = QObject::tr(
"Processing completed with errors");
326 statusIcon = invalidIcon;
330 statusText = QObject::tr(
"Processing completed without errors");
337 statusText = QObject::tr(
"Processing canceled by user");
341 statusText = QObject::tr(
"Processing not possible");
342 statusIcon = invalidIcon;
351 BaseClass::SetStatusIcon(statusIcon);
352 BaseClass::SetStatusText(statusText);
373 BaseClass::OnGuiModelAttached();
376 Q_ASSERT(supplierPtr !=
nullptr);
381 m_areParamsEditable = !*m_connectParametersToEditorAttrPtr;
382 bool areParamsAttachedToEditor = !*m_connectParametersToEditorAttrPtr;
383 QWidget* paramsWidget = GetParamsWidget();
384 if (paramsWidget !=
nullptr) {
385 if (m_paramsSetGuiCompPtr !=
nullptr) {
386 m_paramsSetGuiCompPtr->CreateGui(paramsWidget);
389 if (*m_connectParametersToEditorAttrPtr && (paramsModelPtr !=
nullptr) && m_paramsSetObserverCompPtr !=
nullptr) {
390 areParamsAttachedToEditor = paramsModelPtr->
AttachObserver(m_paramsSetObserverCompPtr.get());
391 if (!areParamsAttachedToEditor) {
392 qWarning(
"Supplier parameters could not be connected to the editor");
395 m_areParamsEditable =
true;
402 paramsWidget->setVisible(m_areParamsEditable);
403 paramsWidget->setEnabled(areParamsAttachedToEditor);
407 if (statusModelPtr !=
nullptr) {
411 BaseClass::SetStatusIcon(QIcon(
":/IcfIcons/StateUnknown"));
419 Q_ASSERT(supplierPtr !=
nullptr);
424 if (m_paramsSetObserverCompPtr !=
nullptr &&
425 (paramsModelPtr !=
nullptr) &&
426 paramsModelPtr->
IsAttached(m_paramsSetObserverCompPtr.get())) {
430 if (m_paramsSetGuiCompPtr !=
nullptr && m_paramsSetGuiCompPtr->IsGuiCreated()) {
431 m_paramsSetGuiCompPtr->DestroyGui();
434 m_areParamsEditable =
false;
436 m_paramsObserver.EnsureModelDetached();
438 m_statusObserver.EnsureModelDetached();
440 BaseClass::OnGuiModelDetached();
450 BaseClass::AfterModelChange(modelPtr, changeSet);
455 UpdateVisualStatus();
457 BeforeSupplierGuiUpdated();
459 BaseClass::AfterModelChange(modelPtr, changeSet);
467 :m_parent(*parentPtr)
469 Q_ASSERT(parentPtr !=
nullptr);
478 m_parent.OnSupplierParamsChanged();
486 :m_parent(*parentPtr)
488 Q_ASSERT(parentPtr !=
nullptr);
497 m_parent.UpdateVisualStatus();
Dest * CompCastPtr(istd::IPolymorphic *objectPtr)
Cast to specified interface trying to use component interface query.
Interface providing loading and saving of data objects.
@ QF_ANONYMOUS
Operations without specified path (anonymous) should be considered.
@ QF_LOAD
Check for load operation.
@ QF_SAVE
Check for save operation.
Base interface for suppliers providing calculating of objects on demand ("pull data" model).
virtual void InvalidateSupplier()=0
Called to signalize that this supplier is invalid.
virtual int GetWorkStatus() const =0
Get status of last work.
virtual imod::IModel * GetWorkStatusModel() const =0
Get access to the status model of the supplier.
@ WS_OK
Work was done correctly and no error occure.
@ WS_CANCELED
Work was canceled.
@ WS_LOCKED
Supplier is locked becouse it is doing processing step.
@ WS_FAILED
Work couldn't be done.
virtual iprm::IParamsSet * GetModelParametersSet() const =0
Get parameter set using by this supplier.
virtual void EnsureWorkInitialized()=0
Force the supplier to initialize its work.
virtual void EnsureWorkFinished()=0
Ensure that all objects are produced.
ParamsObserver(TCommonSupplierGuiCompBase *parentPtr)
void OnUpdate(const istd::IChangeable::ChangeSet &changeSet) override
Called on update of observed model.
void OnUpdate(const istd::IChangeable::ChangeSet &changeSet) override
Called on update of observed model.
StatusObserver(TCommonSupplierGuiCompBase *parentPtr)
void AfterModelChange(imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
This function will be called after update of the observer contents occures.
virtual void OnSupplierParamsChanged()
Method will be called every time if the parameter set of the supplier has been changed.
bool AreParamsEditable() const
Check, if parameters are correct connected to GUI and can be editable.
virtual QWidget * GetParamsWidget() const =0
Get parameters widget object.
StatusObserver m_statusObserver
TCommonSupplierGuiCompBase()
virtual void UpdateVisualStatus()
Update visual status of supplier state.
bool IsLoadParamsSupported() const
Check if parameter loading is supported.
bool LoadParams()
Load parameters from external source (file).
istdgui::TDesignerGuiObserverCompBase< UI, iinsp::ISupplier > BaseClass
virtual void BeforeSupplierGuiUpdated()
This method will be called after the supplier's output has been changed and new results are available...
bool IsSaveParamsSupported() const
Check if parameter storing is supported.
ParamsObserver m_paramsObserver
void OnGuiModelDetached() override
Called when model is detached or GUI is destroyed.
void OnGuiModelAttached() override
Called when model is attached and GUI is created.
bool SaveParams()
Save parameters for example to file.
bool DoTest()
Do inspection test.
Basic implementation for a single model observer.
void EnsureModelDetached()
Make sure this observer is detached.
Common interface for model objects, that supports Model/Observer design pattern.
virtual void DetachObserver(IObserver *observerPtr)=0
Detaches model object from observer observerPtr.
virtual bool AttachObserver(IObserver *observerPtr)=0
Attaches model object to observer observerPtr.
virtual bool IsAttached(const IObserver *observerPtr) const =0
Returns true if observer observer is attached to this model object.
Common interface for all classes implementing the Observer functionality in the Model/Observer design...
iinsp::ISupplier * GetObservedObject() const
Set of general parameters.
Help class which provides the group of changes for update mechanism of the model.
Help class which provides the automatic update mechanism of the model.
Set of change flags (its IDs).
bool ContainsExplicit(int changeId, bool singleOnly=false) const
Check if there is specific change flag in the set explicit set by user.
@ CF_DESTROYING
Change flag indicate that model is during destruction.
void SetStatusText(const QString &text)
Set status text;.
imod::TModelWrap< VisualStatus > m_visualStatus
void SetStatusIcon(const QIcon &icon)
Set status icon;.
Common interface for GUI objects using in component context.
Base class for all Qt GUI components.
Contains Qt based implementations of inspection classes and components.