Skip to content

Commit

Permalink
#12020 Delay the call to updateConnectedEditors
Browse files Browse the repository at this point in the history
Move scheduler to AppFwk

Make sure the call to updateConnectedEditors happens after other slots have been processed. Also make sure that the call is done only once.

Add and use scheduler for updateConnectedEditors
  • Loading branch information
magnesj committed Jan 3, 2025
1 parent 45c8916 commit 756c1cb
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 85 deletions.
11 changes: 0 additions & 11 deletions ApplicationLibCode/Application/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaRftDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaDateTimeDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaPlotCollectionScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaSeismicDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaLasDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaOsduDefines.h
Expand Down Expand Up @@ -73,7 +72,6 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaRftDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaDateTimeDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaPlotCollectionScheduler.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaScheduler.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaSeismicDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaLasDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaOsduDefines.cpp
Expand All @@ -86,15 +84,6 @@ list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})

set(QT_MOC_HEADERS
${QT_MOC_HEADERS}
${CMAKE_CURRENT_LIST_DIR}/RiaConsoleApplication.h
${CMAKE_CURRENT_LIST_DIR}/RiaGuiApplication.h
${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.h
${CMAKE_CURRENT_LIST_DIR}/RiaScheduler.h
)

source_group(
"Application" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES}
${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

#pragma once

#include "RiaScheduler.h"

#include "cafPdmPointer.h"
#include "cafScheduler.h"

#include <vector>

Expand All @@ -29,7 +28,7 @@ class RimEclipseCase;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaCompletionTypeCalculationScheduler : public RiaScheduler
class RiaCompletionTypeCalculationScheduler : public caf::Scheduler
{
Q_OBJECT;

Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/Application/RiaPlotCollectionScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

#pragma once

#include "RiaScheduler.h"
#include "cafScheduler.h"

class RimPlotCollection;

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaPlotCollectionScheduler : public RiaScheduler
class RiaPlotCollectionScheduler : public caf::Scheduler
{
public:
RiaPlotCollectionScheduler();
Expand Down
5 changes: 3 additions & 2 deletions ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#pragma once

#include "RiaDefines.h"
#include "RiaScheduler.h"

#include "cafScheduler.h"

#include <QPointer>

Expand All @@ -29,7 +30,7 @@ class RiuMultiPlotPage;
class RiuMultiPlotBook;
class RiuPlotWidget;

class RiaPlotWindowRedrawScheduler : public RiaScheduler
class RiaPlotWindowRedrawScheduler : public caf::Scheduler
{
Q_OBJECT

Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/Application/RiaQuickAccessScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#pragma once

#include "RiaScheduler.h"
#include "cafScheduler.h"

class RiaQuickAccessScheduler : public RiaScheduler
class RiaQuickAccessScheduler : public caf::Scheduler
{
public:
RiaQuickAccessScheduler();
Expand Down
4 changes: 2 additions & 2 deletions ApplicationLibCode/Application/RiaViewRedrawScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

#pragma once

#include "RiaScheduler.h"
#include "cafScheduler.h"

#include "cafPdmPointer.h"

#include <vector>

class Rim3dView;

class RiaViewRedrawScheduler : public RiaScheduler
class RiaViewRedrawScheduler : public caf::Scheduler
{
public:
RiaViewRedrawScheduler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#include "cafPdmUiTreeOrdering.h"
#include "cafProgressInfo.h"
#include "cafTitledOverlayFrame.h"
#include "cafUpdateEditorsScheduler.h"

#include "cvfScalarMapper.h"

#include <QString>
Expand Down Expand Up @@ -1421,7 +1423,12 @@ void RimGridCrossPlotDataSet::triggerPlotNameUpdateAndReplot()
{
parent->updateCurveNamesAndPlotTitle();
parent->reattachAllCurves();
parent->updateConnectedEditors();

// updateConnectedEditors() causes the UI editor to be recreated (and the widgets contained in the UI editor). The function
// calling this function can in some cases comes from the widget to be destroyed, typically the tree view selection editor
// displaying available result properties. Using a scheduler will ensure that all other slots are processed before the
// updateConnectedEditors() is called.
caf::UpdateEditorsScheduler::instance()->scheduleUpdateConnectedEditors( parent );
}
}

Expand Down
5 changes: 0 additions & 5 deletions Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 5 additions & 46 deletions Fwk/AppFwk/cafUserInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,6 @@ if(MSVC)
add_definitions(-DNOMINMAX)
endif(MSVC)

# These headers need to go through Qt's MOC compiler
set(MOC_HEADER_FILES
cafPdmUiCheckBoxDelegate.h
cafPdmUiCheckBoxEditor.h
cafPdmUiCheckBoxTristateEditor.h
cafPdmUiColorEditor.h
cafPdmUiComboBoxEditor.h
cafPdmUiDateEditor.h
cafPdmUiTimeEditor.h
cafPdmUiDefaultObjectEditor.h
cafPdmUiDoubleSliderEditor.h
cafPdmUiFilePathEditor.h
cafPdmUiLineEditor.h
cafPdmUiListEditor.h
cafPdmUiListView.h
cafPdmUiListViewEditor.h
cafPdmUiPropertyView.h
cafPdmUiPushButtonEditor.h
cafPdmUiActionPushButtonEditor.h
cafPdmUiSliderEditor.h
cafPdmUiTableView.h
cafPdmUiTableViewDelegate.h
cafPdmUiTableViewEditor.h
cafPdmUiTableViewQModel.h
cafPdmUiTextEditor.h
cafPdmUiToolButtonEditor.h
cafPdmUiToolButtonCallbackEditor.h
cafPdmUiTreeView.h
cafPdmUiTreeViewQModel.h
cafPdmUiTreeViewEditor.h
cafUiProcess.h
QMinimizePanel.h
cafQStyledProgressBar.h
cafPdmUiTreeSelectionEditor.h
cafPdmUiTreeSelectionQModel.h
cafPdmUiFormLayoutObjectEditor.h
cafPdmUiDoubleValueEditor.h
cafPdmUniqueIdValidator.h
cafPdmDoubleStringValidator.h
cafPdmUiPickableLineEditor.h
cafPdmUiLabelEditor.h
cafPdmUiCheckBoxAndTextEditor.h
cafPdmUiValueRangeEditor.h
)

find_package(
Qt6
COMPONENTS
Expand Down Expand Up @@ -182,10 +137,14 @@ set(PROJECT_FILES
cafPdmUiSliderTools.cpp
cafPdmUiFieldLabelEditorHandle.h
cafPdmUiFieldLabelEditorHandle.cpp
cafScheduler.h
cafScheduler.cpp
cafUpdateEditorsScheduler.h
cafUpdateEditorsScheduler.cpp
)

add_library(
${PROJECT_NAME} ${PROJECT_FILES} ${MOC_SOURCE_FILES} ${QRC_FILES_CPP}
${PROJECT_NAME} ${PROJECT_FILES} ${QRC_FILES_CPP}
)

if(MSVC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
//
/////////////////////////////////////////////////////////////////////////////////

#include "RiaScheduler.h"

#include "cafScheduler.h"
#include "cafProgressState.h"

#include <QCoreApplication>
namespace caf
{

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaScheduler::RiaScheduler()
Scheduler::Scheduler()
: m_blockUpdate( false )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaScheduler::~RiaScheduler()
Scheduler::~Scheduler()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaScheduler::blockUpdate( bool blockUpdate )
void Scheduler::blockUpdate( bool blockUpdate )
{
m_blockUpdate = blockUpdate;
if ( !m_blockUpdate )
Expand All @@ -52,7 +52,7 @@ void RiaScheduler::blockUpdate( bool blockUpdate )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaScheduler::slotUpdateScheduledItemsWhenReady()
void Scheduler::slotUpdateScheduledItemsWhenReady()
{
if ( caf::ProgressState::isActive() )
{
Expand All @@ -66,7 +66,7 @@ void RiaScheduler::slotUpdateScheduledItemsWhenReady()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaScheduler::startTimer( int msecs )
void Scheduler::startTimer( int msecs )
{
if ( !m_updateTimer )
{
Expand All @@ -80,3 +80,4 @@ void RiaScheduler::startTimer( int msecs )
m_updateTimer->start( msecs );
}
}
} // namespace caf
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@
#include <QScopedPointer>
#include <QTimer>

namespace caf
{

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaScheduler : public QObject
class Scheduler : public QObject
{
Q_OBJECT

public:
RiaScheduler();
~RiaScheduler() override;
Scheduler();
~Scheduler() override;

virtual void performScheduledUpdates() = 0;

Expand All @@ -47,3 +50,4 @@ private slots:
QScopedPointer<QTimer> m_updateTimer;
bool m_blockUpdate;
};
} // namespace caf
68 changes: 68 additions & 0 deletions Fwk/AppFwk/cafUserInterface/cafUpdateEditorsScheduler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022- 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( 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
Loading

0 comments on commit 756c1cb

Please sign in to comment.