Add scheduler to AppFwk

Add scheduler to AppFwk
Make it possible to do a delayed call to updateConnectedEditors
This commit is contained in:
Magne Sjaastad 2025-01-04 09:12:13 +01:00
parent 8a55b4cd20
commit 207294c446
7 changed files with 174 additions and 18 deletions

View File

@ -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

View File

@ -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 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -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;

View File

@ -16,16 +16,15 @@
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaScheduler.h"
#include "cafScheduler.h"
#include "cafProgressState.h"
#include <QCoreApplication>
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

View File

@ -22,16 +22,50 @@
#include <QScopedPointer>
#include <QTimer>
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<bool()>& 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<bool()> 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<QTimer> m_updateTimer;
bool m_blockUpdate;
};
} // namespace caf

View File

@ -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 <http://www.gnu.org/licenses/gpl.html>
// 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

View File

@ -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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafScheduler.h"
#include <set>
namespace caf
{
class PdmUiItem;
class UpdateEditorsScheduler : public Scheduler
{
public:
UpdateEditorsScheduler();
static UpdateEditorsScheduler* instance();
void scheduleUpdateConnectedEditors( const PdmUiItem* uiItem );
void performScheduledUpdates() override;
private:
std::set<const PdmUiItem*> m_itemsToUpdate;
};
} // namespace caf