6#ifndef iqtgui_TGuiObserverWrap_included
7#define iqtgui_TGuiObserverWrap_included
11#include <QtCore/QtGlobal>
12#include <QtWidgets/QWidget>
28template <
class Gui,
class Observer>
125 bool m_disableUiIfReadOnly;
126 mutable int m_ignoreUpdatesCounter;
131 bool m_isUpdatePending;
142template <
class Gui,
class Observer>
144: m_isReadOnly(false),
145 m_disableUiIfReadOnly(true),
146 m_ignoreUpdatesCounter(0),
147 m_isUpdatePending(true),
148 m_onShowChangeIds(
istd::IChangeable::GetAllChanges())
155template <
class Gui,
class Observer>
163 retVal = Observer::OnModelAttached(modelPtr, changeMask);
166 if (retVal && Gui::IsGuiCreated()){
167 Q_ASSERT(Observer::IsModelAttached(
nullptr));
169 OnGuiModelAttached();
176template <
class Gui,
class Observer>
179 if (Observer::IsModelAttached(modelPtr)){
180 if (Gui::IsGuiCreated()){
181 if (!m_isReadOnly && !IsUpdateBlocked() && !m_isUpdatePending){
187 OnGuiModelDetached();
191 return Observer::OnModelDetached(modelPtr);
197template <
class Gui,
class Observer>
203template <
class Gui,
class Observer>
209template <
class Gui,
class Observer>
212 Q_ASSERT(Gui::IsGuiCreated());
213 Q_ASSERT(Observer::IsModelAttached(
nullptr));
216 UpdateEditor(initChangeSet);
220template <
class Gui,
class Observer>
223 if (!m_isReadOnly && Observer::IsModelAttached(
nullptr) && !IsUpdateBlocked() && !m_isUpdatePending){
231template <
class Gui,
class Observer>
234 return (m_ignoreUpdatesCounter > 0);
238template <
class Gui,
class Observer>
241 m_disableUiIfReadOnly = state;
247template <
class Gui,
class Observer>
250 if (!m_isReadOnly && !IsUpdateBlocked() && Observer::IsModelAttached()){
262template <
class Gui,
class Observer>
268template <
class Gui,
class Observer>
276template <
class Gui,
class Observer>
279 if (Gui::IsGuiShown()){
284 m_isUpdatePending =
true;
285 m_onShowChangeIds += changeSet;
290template <
class Gui,
class Observer>
293 if (!m_isReadOnly && !m_isUpdatePending){
301template <
class Gui,
class Observer>
306 if (Observer::IsModelAttached(
nullptr)){
307 if (m_isUpdatePending){
309 DoUpdate(m_onShowChangeIds);
311 m_onShowChangeIds.Reset();
313 m_isUpdatePending =
false;
321template <
class Gui,
class Observer>
326 if (Observer::IsModelAttached(
nullptr)){
332template <
class Gui,
class Observer>
337 Gui::OnGuiRetranslate();
341template <
class Gui,
class Observer>
346 if (m_disableUiIfReadOnly){
347 QWidget* widgetPtr = Gui::GetWidget();
348 Q_ASSERT(widgetPtr !=
nullptr);
350 widgetPtr->setEnabled(!m_isReadOnly);
353 if (Observer::IsModelAttached(
nullptr)){
354 OnGuiModelAttached();
359template <
class Gui,
class Observer>
362 if (Observer::IsModelAttached(
nullptr)){
363 OnGuiModelDetached();
366 Gui::OnGuiDestroyed();
372template <
class Gui,
class Observer>
375 Q_ASSERT(modelPtr !=
nullptr);
376 Q_ASSERT(Observer::IsModelAttached(modelPtr));
378 Observer::AfterModelChange(modelPtr, changeSet);
384 Gui::m_updateGuiCaller.DoCall([
this, changeSet]() { UpdateEditor(changeSet); });
390template <
class Gui,
class Observer>
397template <
class Gui,
class Observer>
400 m_isReadOnly = state;
402 if (m_disableUiIfReadOnly && Gui::IsGuiCreated()){
403 QWidget* widgetPtr = Gui::GetWidget();
404 Q_ASSERT(widgetPtr !=
nullptr);
406 widgetPtr->setEnabled(!m_isReadOnly);
413template <
class Gui,
class Observer>
416 if (changeSet.
IsEmpty() || IsUpdateBlocked() || !Gui::IsGuiCreated()){
420 UpdateBlocker updateBlocker(
this);
422 UpdateGui(changeSet);
428template <
class Gui,
class Observer>
430: m_parent(*parentPtr)
432 ++m_parent.m_ignoreUpdatesCounter;
436template <
class Gui,
class Observer>
439 --m_parent.m_ignoreUpdatesCounter;
Common interface for an model editor.
Common interface for model objects, that supports Model/Observer design pattern.
Set of change flags (its IDs).
bool IsEmpty() const
Check if there is any change in the set.
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.
UpdateBlocker(const TGuiObserverWrap< Gui, Observer > *parentPtr)
Join functionality of istdgui::IGuiObject interface and imod::IObserver.
virtual void OnGuiModelHidden()
Called when model is detached or GUI is hidden.
virtual void OnGuiModelDetached()
Called when model is detached or GUI is destroyed.
void UpdateEditor(const istd::IChangeable::ChangeSet &changeSet) override
Updates editor with model data.
void OnGuiCreated() override
void OnGuiShown() override
virtual void UpdateGui(const istd::IChangeable::ChangeSet &changeSet)
Do update of the GUI to reflect the state of model.
void OnGuiHidden() override
bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
bool OnModelDetached(imod::IModel *modelPtr) override
void SetReadOnly(bool state) override
Set flag that the model data can be changed.
virtual void UpdateModel() const
Do update of the model to reflect the current contents of GUI.
void OnGuiDestroyed() override
void UpdateModelFromEditor() const override
Updates model from editor.
bool IsReadOnly() const override
Returns true if the model data can be changed.
virtual void OnGuiModelShown()
Called when model is attached and GUI is shown.
virtual void OnGuiModelAttached()
Called when model is attached and GUI is created.
void OnGuiRetranslate() override
void AfterModelChange(imod::IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
bool DoUpdateModel() const
Secure update model.
void SetDisableUiIfReadOnly(bool state)
Control if GUI should be disaled for read-only editors.
bool IsUpdateBlocked() const
Check if GUI updating is blocked.
Standard GUI specific interfaces and components based on Qt.