diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt index 72e9dea4a3..29b109f141 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt @@ -6,11 +6,6 @@ if(CAF_ENABLE_UNITY_BUILD) set(CMAKE_UNITY_BUILD true) endif() -# These headers need to go through Qt's MOC compiler -set(MOC_HEADER_FILES cafPdmUiEditorHandle.h cafPdmUiFieldEditorHandle.h - cafPdmUiSelection3dEditorVisualizer.h cafQShortenedLabel.h -) - find_package( Qt6 COMPONENTS @@ -67,6 +62,10 @@ set(PROJECT_FILES cafFontTools.h caf.h caf.cpp + cafScheduler.h + cafScheduler.cpp + cafUpdateEditorsScheduler.h + cafUpdateEditorsScheduler.cpp ) # NOTE! Resources in this subfolder appends to the variable QRC_FILES in parent diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp index e5b4d1b88b..53cf05144a 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp @@ -37,6 +37,7 @@ #include "cafPdmUiItem.h" #include "cafPdmUiEditorHandle.h" #include "cafPdmUiObjectEditorHandle.h" +#include "cafUpdateEditorsScheduler.h" namespace caf { @@ -662,6 +663,14 @@ void PdmUiItem::updateConnectedEditors() const } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiItem::scheduleUpdateConnectedEditors() const +{ + UpdateEditorsScheduler::instance()->scheduleUpdateConnectedEditors( this ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h index 9fdb143340..b1ccdbcb1f 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h @@ -295,6 +295,7 @@ public: /// Intended to be called when fields in an object has been changed void updateConnectedEditors() const; + void scheduleUpdateConnectedEditors() const; /// Intended to be called when an object has been created or deleted void updateAllRequiredEditors() const; diff --git a/ApplicationLibCode/Application/RiaScheduler.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafScheduler.cpp similarity index 87% rename from ApplicationLibCode/Application/RiaScheduler.cpp rename to Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafScheduler.cpp index 8d2e7a2adf..14cac7cbe7 100644 --- a/ApplicationLibCode/Application/RiaScheduler.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafScheduler.cpp @@ -16,16 +16,15 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include "RiaScheduler.h" +#include "cafScheduler.h" -#include "cafProgressState.h" - -#include +namespace caf +{ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiaScheduler::RiaScheduler() +Scheduler::Scheduler() : m_blockUpdate( false ) { } @@ -33,14 +32,14 @@ RiaScheduler::RiaScheduler() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiaScheduler::~RiaScheduler() +Scheduler::~Scheduler() { } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaScheduler::blockUpdate( bool blockUpdate ) +void Scheduler::blockUpdate( bool blockUpdate ) { m_blockUpdate = blockUpdate; if ( !m_blockUpdate ) @@ -52,9 +51,9 @@ void RiaScheduler::blockUpdate( bool blockUpdate ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaScheduler::slotUpdateScheduledItemsWhenReady() +void Scheduler::slotUpdateScheduledItemsWhenReady() { - if ( caf::ProgressState::isActive() ) + if ( SchedulerCallable::instance()->isScheduledTaskBlocked() ) { startTimer( 100 ); return; @@ -66,7 +65,7 @@ void RiaScheduler::slotUpdateScheduledItemsWhenReady() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaScheduler::startTimer( int msecs ) +void Scheduler::startTimer( int msecs ) { if ( !m_updateTimer ) { @@ -80,3 +79,4 @@ void RiaScheduler::startTimer( int msecs ) m_updateTimer->start( msecs ); } } +} // namespace caf diff --git a/ApplicationLibCode/Application/RiaScheduler.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafScheduler.h similarity index 58% rename from ApplicationLibCode/Application/RiaScheduler.h rename to Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafScheduler.h index 800a013c03..3e25d62923 100644 --- a/ApplicationLibCode/Application/RiaScheduler.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafScheduler.h @@ -22,16 +22,50 @@ #include #include +namespace caf +{ + +//-------------------------------------------------------------------------------------------------- +/// This class is used to block the scheduled task when a blocking operation is in ongoing. Currently this is used when +/// a progress dialog is visible. See ProgressInfoStatic::start() +//-------------------------------------------------------------------------------------------------- +class SchedulerCallable +{ +public: + void registerCallable( const std::function& func ) { m_callable = func; } + + static SchedulerCallable* instance() + { + static SchedulerCallable instance; + return &instance; + } + + bool isScheduledTaskBlocked() + { + if ( m_callable ) + { + return m_callable(); + } + else + { + return false; + } + } + +private: + std::function m_callable; +}; + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -class RiaScheduler : public QObject +class Scheduler : public QObject { Q_OBJECT public: - RiaScheduler(); - ~RiaScheduler() override; + Scheduler(); + ~Scheduler() override; virtual void performScheduledUpdates() = 0; @@ -47,3 +81,4 @@ private: QScopedPointer m_updateTimer; bool m_blockUpdate; }; +} // namespace caf diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafUpdateEditorsScheduler.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafUpdateEditorsScheduler.cpp new file mode 100644 index 0000000000..528ac12a7d --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafUpdateEditorsScheduler.cpp @@ -0,0 +1,68 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2025 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "cafUpdateEditorsScheduler.h" +#include "cafPdmUiItem.h" + +namespace caf +{ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +UpdateEditorsScheduler::UpdateEditorsScheduler() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +UpdateEditorsScheduler* UpdateEditorsScheduler::instance() +{ + static UpdateEditorsScheduler theInstance; + + return &theInstance; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void UpdateEditorsScheduler::scheduleUpdateConnectedEditors( const PdmUiItem* uiItem ) +{ + m_itemsToUpdate.insert( uiItem ); + + startTimer( 0 ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void UpdateEditorsScheduler::performScheduledUpdates() +{ + for ( auto uiItem : m_itemsToUpdate ) + { + if ( uiItem ) + { + uiItem->updateConnectedEditors(); + } + } + + m_itemsToUpdate.clear(); +} + +} //namespace caf diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafUpdateEditorsScheduler.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafUpdateEditorsScheduler.h new file mode 100644 index 0000000000..d16f93d486 --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafUpdateEditorsScheduler.h @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2025 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafScheduler.h" + +#include + +namespace caf +{ + +class PdmUiItem; + +class UpdateEditorsScheduler : public Scheduler +{ +public: + UpdateEditorsScheduler(); + + static UpdateEditorsScheduler* instance(); + + void scheduleUpdateConnectedEditors( const PdmUiItem* uiItem ); + void performScheduledUpdates() override; + +private: + std::set m_itemsToUpdate; +}; + +} // namespace caf