mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -05:00
#14104 Remember user-defined size of property and preferences dialogs
Persist the geometry of PdmUiPropertyViewDialog and RiuPropertyViewTabWidget to the application settings on close and restore it on the next show. Restoring is done in showEvent rather than the constructor so it is applied reliably for a modal dialog. The settings key includes the bound object class keyword so distinct dialogs that share a window title do not collide. This behaviour is gated behind a new "Remember Dialog Size" experimental feature, disabled by default. PdmUiPropertyViewDialog cannot access RiaPreferencesSystem, so the application pushes the current setting via the static enableGeometryPersistence(), following the existing pattern used for class-name display. RiuPropertyViewTabWidget queries the feature directly.
This commit is contained in:
1 parent
9c857288da
commit
8606fa002e
8 files changed
+299
-22
No files matched your search
@@ -33,6 +33,10 @@ const std::vector<RiaExperimentalFeatures::Feature>& RiaExperimentalFeatures::av
|
||||
{ "osdu-well-logs", "OSDU Well Logs", "Enable import of well logs from OSDU." },
|
||||
{ "undo-redo-view", "Undo/Redo View", "Show the command undo/redo history view." },
|
||||
{ "oil-volume-result", "Oil Volume Result", "Compute the derived oil volume cell result." },
|
||||
{ "remember-dialog-size",
|
||||
"Remember Dialog Size",
|
||||
"Remember the size of property and preferences dialogs between sessions and restore it the next time they "
|
||||
"open." },
|
||||
};
|
||||
|
||||
return features;
|
||||
|
||||
@@ -118,6 +118,7 @@
|
||||
#include "cafEffectGenerator.h"
|
||||
#include "cafFixedAtlasFont.h"
|
||||
#include "cafPdmUiModelChangeDetector.h"
|
||||
#include "cafPdmUiPropertyViewDialog.h"
|
||||
#include "cafPdmUiTreeView.h"
|
||||
#include "cafProgressInfo.h"
|
||||
#include "cafQTreeViewStateSerializer.h"
|
||||
@@ -1469,6 +1470,8 @@ void RiaGuiApplication::applyGuiPreferences( const RiaPreferences*
|
||||
caf::EffectGenerator::setRenderingMode( caf::EffectGenerator::FIXED_FUNCTION );
|
||||
}
|
||||
|
||||
caf::PdmUiPropertyViewDialog::enableGeometryPersistence( RiaPreferencesSystem::current()->isFeatureEnabled( "remember-dialog-size" ) );
|
||||
|
||||
if ( m_mainWindow )
|
||||
{
|
||||
for ( auto& tv : m_mainWindow->projectTreeViews() )
|
||||
|
||||
@@ -18,12 +18,16 @@
|
||||
|
||||
#include "RiuPropertyViewTabWidget.h"
|
||||
|
||||
#include "RiaPreferencesSystem.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiPropertyView.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QSettings>
|
||||
#include <QShowEvent>
|
||||
#include <QStringList>
|
||||
#include <QTabWidget>
|
||||
#include <QWidget>
|
||||
@@ -36,6 +40,8 @@ RiuPropertyViewTabWidget::RiuPropertyViewTabWidget( QWidget* parent,
|
||||
const QString& windowTitle,
|
||||
const QStringList& uiConfigNameForTabs )
|
||||
: QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
|
||||
, m_windowTitle( windowTitle )
|
||||
, m_objectClassKeyword( object ? object->classKeyword() : QString() )
|
||||
{
|
||||
setWindowTitle( windowTitle );
|
||||
|
||||
@@ -129,3 +135,68 @@ QDialogButtonBox* RiuPropertyViewTabWidget::dialogButtonBox()
|
||||
{
|
||||
return m_dialogButtonBox;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPropertyViewTabWidget::showEvent( QShowEvent* event )
|
||||
{
|
||||
// Restore the stored size on first show. Doing this here rather than in the constructor ensures
|
||||
// the geometry is applied reliably for a modal dialog and is not overridden by the initial sizing.
|
||||
// When no size is stored, the size is left to sizeHint()/minimumSizeHint().
|
||||
if ( RiaPreferencesSystem::current()->isFeatureEnabled( "remember-dialog-size" ) && !m_geometryRestored )
|
||||
{
|
||||
m_geometryRestored = true;
|
||||
restoreDialogGeometry();
|
||||
}
|
||||
|
||||
QDialog::showEvent( event );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPropertyViewTabWidget::done( int result )
|
||||
{
|
||||
if ( RiaPreferencesSystem::current()->isFeatureEnabled( "remember-dialog-size" ) )
|
||||
{
|
||||
saveDialogGeometry();
|
||||
}
|
||||
|
||||
QDialog::done( result );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuPropertyViewTabWidget::settingsKey() const
|
||||
{
|
||||
QString title = m_windowTitle;
|
||||
title.replace( '/', '_' );
|
||||
|
||||
return QString( "RiuPropertyViewTabWidget/%1/%2/geometry" ).arg( m_objectClassKeyword, title );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuPropertyViewTabWidget::restoreDialogGeometry()
|
||||
{
|
||||
QSettings settings;
|
||||
QVariant geometry = settings.value( settingsKey() );
|
||||
if ( geometry.isValid() )
|
||||
{
|
||||
return restoreGeometry( geometry.toByteArray() );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPropertyViewTabWidget::saveDialogGeometry()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue( settingsKey(), saveGeometry() );
|
||||
}
|
||||
@@ -41,7 +41,19 @@ public:
|
||||
QSize sizeHint() const override;
|
||||
QDialogButtonBox* dialogButtonBox();
|
||||
|
||||
protected:
|
||||
void showEvent( QShowEvent* event ) override;
|
||||
void done( int result ) override;
|
||||
|
||||
private:
|
||||
QString settingsKey() const;
|
||||
bool restoreDialogGeometry();
|
||||
void saveDialogGeometry();
|
||||
|
||||
private:
|
||||
QString m_windowTitle;
|
||||
QString m_objectClassKeyword;
|
||||
std::vector<caf::PdmUiPropertyView*> m_pageWidgets;
|
||||
QDialogButtonBox* m_dialogButtonBox;
|
||||
bool m_geometryRestored = false;
|
||||
};
|
||||
@@ -39,10 +39,30 @@
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiPropertyView.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QShowEvent>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
bool PdmUiPropertyViewDialog::sm_geometryPersistenceEnabled = false;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiPropertyViewDialog::enableGeometryPersistence( bool enable )
|
||||
{
|
||||
sm_geometryPersistenceEnabled = enable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiPropertyViewDialog::isGeometryPersistenceEnabled()
|
||||
{
|
||||
return sm_geometryPersistenceEnabled;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -88,28 +108,6 @@ QDialogButtonBox* PdmUiPropertyViewDialog::dialogButtonBox()
|
||||
return m_buttonBox;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize PdmUiPropertyViewDialog::sizeHint() const
|
||||
{
|
||||
// Ensure the preferred size is never degenerate, regardless of how the contained scroll area
|
||||
// reports its hints.
|
||||
return QDialog::sizeHint().expandedTo( QSize( 300, 200 ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize PdmUiPropertyViewDialog::minimumSizeHint() const
|
||||
{
|
||||
// The inner scroll area reports an artificially small minimum width, which lets some window
|
||||
// managers open the dialog collapsed (issue #14104). Provide a sensible floor, capped by the
|
||||
// content's preferred size so intentionally small dialogs are not enlarged.
|
||||
QSize floor = QSize( 300, 150 ).boundedTo( QDialog::sizeHint() );
|
||||
return QDialog::minimumSizeHint().expandedTo( floor );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -149,4 +147,94 @@ void PdmUiPropertyViewDialog::setupUi()
|
||||
dialogLayout->addWidget( m_buttonBox );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiPropertyViewDialog::showEvent( QShowEvent* event )
|
||||
{
|
||||
// Restore a previously stored size on first show. Restoring here rather than in the constructor
|
||||
// ensures the geometry is applied reliably for a modal dialog and is not overridden by the initial
|
||||
// sizing (see issue #14104). When no size is stored, the size is left to sizeHint()/minimumSizeHint()
|
||||
// and any explicit resize() done by the caller, so the default appearance is preserved.
|
||||
if ( sm_geometryPersistenceEnabled && !m_geometryRestored )
|
||||
{
|
||||
m_geometryRestored = true;
|
||||
restoreDialogGeometry();
|
||||
}
|
||||
|
||||
QDialog::showEvent( event );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize PdmUiPropertyViewDialog::sizeHint() const
|
||||
{
|
||||
// Ensure the preferred size is never degenerate, regardless of how the contained scroll area
|
||||
// reports its hints.
|
||||
return QDialog::sizeHint().expandedTo( QSize( 300, 200 ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize PdmUiPropertyViewDialog::minimumSizeHint() const
|
||||
{
|
||||
// The inner scroll area reports an artificially small minimum width, which lets some window
|
||||
// managers open the dialog collapsed (issue #14104). Provide a sensible floor, capped by the
|
||||
// content's preferred size so intentionally small dialogs are not enlarged.
|
||||
QSize floor = QSize( 300, 150 ).boundedTo( QDialog::sizeHint() );
|
||||
return QDialog::minimumSizeHint().expandedTo( floor );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiPropertyViewDialog::done( int result )
|
||||
{
|
||||
if ( sm_geometryPersistenceEnabled )
|
||||
{
|
||||
saveDialogGeometry();
|
||||
}
|
||||
|
||||
QDialog::done( result );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString PdmUiPropertyViewDialog::settingsKey() const
|
||||
{
|
||||
QString id = m_uiConfigName.isEmpty() ? m_windowTitle : m_uiConfigName;
|
||||
id.replace( '/', '_' );
|
||||
|
||||
QString classKeyword = m_pdmObject ? m_pdmObject->classKeyword() : QString();
|
||||
|
||||
return QString( "PdmUiPropertyViewDialog/%1/%2/geometry" ).arg( classKeyword, id );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiPropertyViewDialog::restoreDialogGeometry()
|
||||
{
|
||||
QSettings settings;
|
||||
QVariant geometry = settings.value( settingsKey() );
|
||||
if ( geometry.isValid() )
|
||||
{
|
||||
return restoreGeometry( geometry.toByteArray() );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiPropertyViewDialog::saveDialogGeometry()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue( settingsKey(), saveGeometry() );
|
||||
}
|
||||
|
||||
} // End of namespace caf
|
||||
@@ -60,16 +60,33 @@ public:
|
||||
QSize sizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
|
||||
// Persisting the dialog geometry to QSettings is gated behind an experimental feature. The
|
||||
// application pushes the current setting via enableGeometryPersistence(). The size floor in
|
||||
// sizeHint()/minimumSizeHint() is always applied, regardless of this setting.
|
||||
static void enableGeometryPersistence( bool enable );
|
||||
static bool isGeometryPersistenceEnabled();
|
||||
|
||||
protected:
|
||||
void showEvent( QShowEvent* event ) override;
|
||||
void done( int result ) override;
|
||||
|
||||
private:
|
||||
void initialize( PdmObject* object, const QString& windowTitle, const QString& uiConfigName );
|
||||
void setupUi();
|
||||
|
||||
QString settingsKey() const;
|
||||
bool restoreDialogGeometry();
|
||||
void saveDialogGeometry();
|
||||
|
||||
private:
|
||||
QString m_windowTitle;
|
||||
QString m_uiConfigName;
|
||||
PdmObject* m_pdmObject;
|
||||
PdmUiPropertyView* m_pdmUiPropertyView;
|
||||
QDialogButtonBox* m_buttonBox;
|
||||
bool m_geometryRestored = false;
|
||||
|
||||
static bool sm_geometryPersistenceEnabled;
|
||||
};
|
||||
|
||||
} // End of namespace caf
|
||||
@@ -19,6 +19,7 @@ set(PROJECT_FILES
|
||||
cafPdmUiTreeSelectionQModelTest.cpp
|
||||
cafPdmUiNumberFormatTest.cpp
|
||||
cafPdmUiCheckBoxAndTextEditorTest.cpp
|
||||
cafPdmUiPropertyViewDialogTest.cpp
|
||||
cafIconProviderTest.cpp
|
||||
gtest/gtest-all.cpp
|
||||
)
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiPropertyViewDialog.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
using namespace caf;
|
||||
|
||||
class GeometryTestObj : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
GeometryTestObj()
|
||||
{
|
||||
CAF_PDM_InitObject( "GeometryTestObj" );
|
||||
CAF_PDM_InitField( &m_value, "Value", 0, "Value" );
|
||||
}
|
||||
|
||||
caf::PdmField<int> m_value;
|
||||
};
|
||||
CAF_PDM_SOURCE_INIT( GeometryTestObj, "GeometryTestObj" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Verify that the dialog stores its geometry on close and restores it on the next show.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( PdmUiPropertyViewDialogTest, GeometryRoundTrip )
|
||||
{
|
||||
// Ensure QSettings has a defined, isolated location for the test.
|
||||
QCoreApplication::setOrganizationName( "ResInsightTest" );
|
||||
QCoreApplication::setApplicationName( "DialogGeometryTest" );
|
||||
QSettings().clear();
|
||||
|
||||
// Geometry persistence is gated behind an experimental feature and disabled by default. Enable it
|
||||
// explicitly for this test.
|
||||
PdmUiPropertyViewDialog::enableGeometryPersistence( true );
|
||||
|
||||
const QSize userSize( 742, 531 );
|
||||
|
||||
{
|
||||
GeometryTestObj obj;
|
||||
|
||||
PdmUiPropertyViewDialog dialog( nullptr, &obj, "Geometry Round Trip", "" );
|
||||
dialog.show();
|
||||
QApplication::processEvents();
|
||||
|
||||
dialog.resize( userSize );
|
||||
QApplication::processEvents();
|
||||
|
||||
// done() is what saves the geometry; reject() routes through done().
|
||||
dialog.reject();
|
||||
}
|
||||
|
||||
// The settings store should now contain a value for this dialog.
|
||||
{
|
||||
QSettings settings;
|
||||
bool anyKey = false;
|
||||
for ( const QString& key : settings.allKeys() )
|
||||
{
|
||||
if ( key.contains( "Geometry Round Trip" ) ) anyKey = true;
|
||||
}
|
||||
EXPECT_TRUE( anyKey ) << "No geometry was written to settings";
|
||||
}
|
||||
|
||||
{
|
||||
GeometryTestObj obj;
|
||||
|
||||
PdmUiPropertyViewDialog dialog( nullptr, &obj, "Geometry Round Trip", "" );
|
||||
dialog.show();
|
||||
QApplication::processEvents();
|
||||
|
||||
EXPECT_EQ( dialog.size().width(), userSize.width() );
|
||||
EXPECT_EQ( dialog.size().height(), userSize.height() );
|
||||
|
||||
dialog.reject();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user