mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
#14167 Fix table dropdown needing two clicks when moving to another row
The table model shares one field editor handle per column across all rows. When an edit ends, the view schedules the editor widget for deletion with deleteLater(), but the handle's QPointer stays valid until the deferred deletion runs. Clicking a cell in the same column of another row reused that doomed widget as the new cell editor, so it was destroyed right after opening and the user had to click again. Moving horizontally was unaffected since a different column uses a different editor handle. Cancel the pending deferred deletion before handing the widget out again, and guard against a null editor widget.
This commit is contained in:
committed by
Magne Sjaastad
parent
417e515d3d
commit
ef815a79f8
@@ -45,6 +45,9 @@
|
||||
#include "cafPdmUiOrdering.h"
|
||||
#include "cafPdmUiTableRowEditor.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QEvent>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -541,6 +544,15 @@ QWidget* PdmUiTableViewQModel::getEditorWidgetAndTransferOwnership( QWidget* par
|
||||
// using QPointer
|
||||
editor->createWidgets( parent );
|
||||
QWidget* editorWidget = editor->editorWidget();
|
||||
if ( !editorWidget ) return nullptr;
|
||||
|
||||
// The editor handle is shared by every row in a column. When the edit on one cell ends, the view
|
||||
// schedules its editor widget for deletion via deleteLater(). Moving to another cell in the same
|
||||
// column reuses that very widget before the deferred deletion has run, so without this the widget
|
||||
// is destroyed moments after the new editor opens - silently cancelling the edit and forcing the
|
||||
// user to click a second time. Cancel the pending deletion so the reused widget stays alive.
|
||||
QCoreApplication::removePostedEvents( editorWidget, QEvent::DeferredDelete );
|
||||
|
||||
editorWidget->setParent( parent );
|
||||
|
||||
return editorWidget;
|
||||
|
||||
Reference in New Issue
Block a user