mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-11 07:56:08 -06:00
#4116 PdmUiListView: Scroll to the first selected item when activated
This solution does not always work, but scrolls to the first selected item in most cases
This commit is contained in:
parent
760fcaef43
commit
24bda0fda2
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "ManyGroups.h"
|
#include "ManyGroups.h"
|
||||||
#include "cafPdmUiTreeSelectionEditor.h"
|
#include "cafPdmUiTreeSelectionEditor.h"
|
||||||
|
#include "cafPdmUiListEditor.h"
|
||||||
|
|
||||||
CAF_PDM_SOURCE_INIT(ManyGroups, "LargeObject");
|
CAF_PDM_SOURCE_INIT(ManyGroups, "LargeObject");
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ ManyGroups::ManyGroups()
|
|||||||
m_multiSelectList.v().push_back("First");
|
m_multiSelectList.v().push_back("First");
|
||||||
m_multiSelectList.v().push_back("Second");
|
m_multiSelectList.v().push_back("Second");
|
||||||
m_multiSelectList.v().push_back("Third");
|
m_multiSelectList.v().push_back("Third");
|
||||||
|
|
||||||
|
CAF_PDM_InitField(&m_singleStringWithManySelectableItems, "m_singleStringWithManySelectableItems", QString(""), "Text with many items", "", "Text tooltip", "");
|
||||||
|
m_singleStringWithManySelectableItems.uiCapability()->setUiEditorTypeName(caf::PdmUiListEditor::uiEditorTypeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -62,6 +66,18 @@ QList<caf::PdmOptionItemInfo> ManyGroups::calculateValueOptions(const caf::PdmFi
|
|||||||
{
|
{
|
||||||
QList<caf::PdmOptionItemInfo> options;
|
QList<caf::PdmOptionItemInfo> options;
|
||||||
|
|
||||||
|
// Test code used to switch between two lists with different content, but same item count
|
||||||
|
if (fieldNeedingOptions == &m_singleStringWithManySelectableItems)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
QString text = QString("item %1").arg(i);
|
||||||
|
options.push_back(caf::PdmOptionItemInfo(text, text));
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
// Test code used to switch between two lists with different content, but same item count
|
// Test code used to switch between two lists with different content, but same item count
|
||||||
if (fieldNeedingOptions == &m_multiSelectList)
|
if (fieldNeedingOptions == &m_multiSelectList)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ public:
|
|||||||
caf::PdmProxyValueField<double> m_proxyDoubleField;
|
caf::PdmProxyValueField<double> m_proxyDoubleField;
|
||||||
|
|
||||||
caf::PdmField<std::vector<QString> > m_multiSelectList;
|
caf::PdmField<std::vector<QString> > m_multiSelectList;
|
||||||
|
caf::PdmField<QString> m_singleStringWithManySelectableItems;
|
||||||
|
|
||||||
caf::PdmField<bool> m_toggleField;
|
caf::PdmField<bool> m_toggleField;
|
||||||
caf::PdmFieldHandle* objectToggleField() override;
|
caf::PdmFieldHandle* objectToggleField() override;
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "cafPdmUiFieldEditorHandle.h"
|
#include "cafPdmUiFieldEditorHandle.h"
|
||||||
#include "cafPdmUiFieldEditorHelper.h"
|
#include "cafPdmUiFieldEditorHelper.h"
|
||||||
#include "cafPdmUiFieldHandle.h"
|
#include "cafPdmUiFieldHandle.h"
|
||||||
|
#include "cafPdmUiListEditor.h"
|
||||||
#include "cafPdmUiObjectHandle.h"
|
#include "cafPdmUiObjectHandle.h"
|
||||||
#include "cafPdmUiOrdering.h"
|
#include "cafPdmUiOrdering.h"
|
||||||
#include "cafPdmXmlObjectHandle.h"
|
#include "cafPdmXmlObjectHandle.h"
|
||||||
@ -49,8 +50,9 @@
|
|||||||
|
|
||||||
#include "QMinimizePanel.h"
|
#include "QMinimizePanel.h"
|
||||||
|
|
||||||
#include <QGridLayout>
|
#include <QCoreApplication>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
#include <QGridLayout>
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@ -468,6 +470,19 @@ void caf::PdmUiFormLayoutObjectEditor::configureAndUpdateUi(const QString& uiCon
|
|||||||
{
|
{
|
||||||
uiObject->onEditorWidgetsCreated();
|
uiObject->onEditorWidgetsCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process events to make sure the layout has completed before scrolling the list editor to current item
|
||||||
|
// If this step is omitted, the scrollTo method ends up at arbitrary positions
|
||||||
|
qApp->processEvents();
|
||||||
|
|
||||||
|
for (it = m_fieldViews.begin(); it != m_fieldViews.end(); ++it)
|
||||||
|
{
|
||||||
|
auto myObj = dynamic_cast<PdmUiListEditor*>(it->second);
|
||||||
|
if (myObj)
|
||||||
|
{
|
||||||
|
myObj->ensureCurrentItemIsVisible();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
//
|
//
|
||||||
//##################################################################################################
|
//##################################################################################################
|
||||||
|
|
||||||
|
|
||||||
#include "cafPdmUiListEditor.h"
|
#include "cafPdmUiListEditor.h"
|
||||||
|
|
||||||
#include "cafPdmUiDefaultObjectEditor.h"
|
#include "cafPdmUiDefaultObjectEditor.h"
|
||||||
@ -138,7 +137,8 @@ CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiListEditor);
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
PdmUiListEditor::PdmUiListEditor() :
|
PdmUiListEditor::PdmUiListEditor() :
|
||||||
m_isEditOperationsAvailable(true),
|
m_isEditOperationsAvailable(true),
|
||||||
m_optionItemCount(0)
|
m_optionItemCount(0),
|
||||||
|
m_isScrollToItemAllowed(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +149,21 @@ PdmUiListEditor::~PdmUiListEditor()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void PdmUiListEditor::ensureCurrentItemIsVisible()
|
||||||
|
{
|
||||||
|
if (m_isScrollToItemAllowed)
|
||||||
|
{
|
||||||
|
QModelIndex mi = m_listView->currentIndex();
|
||||||
|
if (mi.isValid())
|
||||||
|
{
|
||||||
|
m_listView->scrollTo(mi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -266,6 +281,8 @@ void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
|
|
||||||
m_listView->selectionModel()->blockSignals(false);
|
m_listView->selectionModel()->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ensureCurrentItemIsVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -306,6 +323,8 @@ void PdmUiListEditor::slotSelectionChanged(const QItemSelection & selected, cons
|
|||||||
{
|
{
|
||||||
if (m_optionItemCount == 0) return;
|
if (m_optionItemCount == 0) return;
|
||||||
|
|
||||||
|
m_isScrollToItemAllowed = false;
|
||||||
|
|
||||||
QVariant fieldValue = uiField()->uiValue();
|
QVariant fieldValue = uiField()->uiValue();
|
||||||
if (fieldValue.type() == QVariant::Int || fieldValue.type() == QVariant::UInt)
|
if (fieldValue.type() == QVariant::Int || fieldValue.type() == QVariant::UInt)
|
||||||
{
|
{
|
||||||
@ -359,6 +378,8 @@ void PdmUiListEditor::slotSelectionChanged(const QItemSelection & selected, cons
|
|||||||
|
|
||||||
this->setValueToField(valuesToSetInField);
|
this->setValueToField(valuesToSetInField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_isScrollToItemAllowed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -81,6 +81,8 @@ public:
|
|||||||
PdmUiListEditor();
|
PdmUiListEditor();
|
||||||
~PdmUiListEditor() override;
|
~PdmUiListEditor() override;
|
||||||
|
|
||||||
|
void ensureCurrentItemIsVisible();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QWidget* createEditorWidget(QWidget * parent) override;
|
QWidget* createEditorWidget(QWidget * parent) override;
|
||||||
QWidget* createLabelWidget(QWidget * parent) override;
|
QWidget* createLabelWidget(QWidget * parent) override;
|
||||||
@ -104,6 +106,7 @@ private:
|
|||||||
|
|
||||||
bool m_isEditOperationsAvailable;
|
bool m_isEditOperationsAvailable;
|
||||||
int m_optionItemCount;
|
int m_optionItemCount;
|
||||||
|
bool m_isScrollToItemAllowed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user