mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #4745 from OPM/sync-tree-selection-with-field-value
Auto scroll to checked item
This commit is contained in:
commit
00eb02ccec
@ -99,7 +99,7 @@ void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
|
||||
QString indexAsString = stringList[1];
|
||||
|
||||
bool conversionOk = false;
|
||||
int index = indexAsString.toUInt( &conversionOk );
|
||||
auto index = indexAsString.toUInt( &conversionOk );
|
||||
|
||||
if ( conversionOk && index < sumCases.size() )
|
||||
{
|
||||
|
@ -40,9 +40,9 @@
|
||||
#include "RiuSummaryCurveDefinitionKeywords.h"
|
||||
#include "RiuSummaryVectorDescriptionMap.h"
|
||||
|
||||
#include "cafPdmUiTreeSelectionEditor.h"
|
||||
//#include "cafPdmObject.h"
|
||||
#include "cafPdmPointer.h"
|
||||
#include "cafPdmUiFieldHandle.h"
|
||||
#include "cafPdmUiTreeSelectionEditor.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -722,6 +722,37 @@ void RiuSummaryCurveDefSelection::fieldChangedByUi( const caf::PdmFieldHandle* c
|
||||
m_selectedSummaryCategories.v().push_back( currentCategory );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !newValue.toList().empty() )
|
||||
{
|
||||
auto identifierAndFieldList = m_identifierFieldsMap[currentCategory];
|
||||
for ( const auto identifierAndField : identifierAndFieldList )
|
||||
{
|
||||
if ( identifierAndField->summaryIdentifier() == RifEclipseSummaryAddress::INPUT_VECTOR_NAME )
|
||||
continue;
|
||||
|
||||
auto v = identifierAndField->pdmField()->value();
|
||||
if ( v.empty() )
|
||||
{
|
||||
auto field = identifierAndField->pdmField();
|
||||
|
||||
QList<caf::PdmOptionItemInfo> options;
|
||||
appendOptionItemsForSubCategoriesAndVectors( options, identifierAndField );
|
||||
|
||||
if ( !options.isEmpty() )
|
||||
{
|
||||
std::vector<QString> values;
|
||||
|
||||
auto firstOption = options.front();
|
||||
auto firstValue = firstOption.value();
|
||||
QString valueText = firstValue.toString();
|
||||
|
||||
values.push_back( valueText );
|
||||
field->setValue( values );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include <QPalette>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStyleOption>
|
||||
#include <QTimer>
|
||||
#include <QTreeView>
|
||||
|
||||
#include <algorithm>
|
||||
@ -374,6 +375,10 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// It is required to use a timer here, as the layout of the widgets are handled by events
|
||||
// Calling scrollTo() here has no effect, or scrolls to wrong location
|
||||
QTimer::singleShot(150, this, SLOT(slotScrollToFirstCheckedItem()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -647,6 +652,49 @@ void PdmUiTreeSelectionEditor::slotClicked(const QModelIndex& index)
|
||||
currentChanged(index);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeSelectionEditor::slotScrollToFirstCheckedItem()
|
||||
{
|
||||
auto firstVisibleIndex = m_treeView->indexAt(m_treeView->viewport()->rect().topLeft());
|
||||
auto lastVisibleIndex = m_treeView->indexAt(m_treeView->viewport()->rect().bottomRight());
|
||||
|
||||
if (!firstVisibleIndex.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!lastVisibleIndex.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = firstVisibleIndex.row(); i < lastVisibleIndex.row(); i++)
|
||||
{
|
||||
auto treeViewIndex = m_proxyModel->index(i, 0);
|
||||
|
||||
if (m_proxyModel->data(treeViewIndex, Qt::CheckStateRole).toBool())
|
||||
{
|
||||
// Do nothing if there is a checked and visible item in the view
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_proxyModel->rowCount(); i++)
|
||||
{
|
||||
auto treeViewIndex = m_proxyModel->index(i, 0);
|
||||
|
||||
if (m_proxyModel->data(treeViewIndex, Qt::CheckStateRole).toBool())
|
||||
{
|
||||
// Scroll to the first checked item if no checked items are visible
|
||||
m_treeView->scrollTo(treeViewIndex);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -115,6 +115,8 @@ private slots:
|
||||
|
||||
void slotClicked(const QModelIndex& index);
|
||||
|
||||
void slotScrollToFirstCheckedItem();
|
||||
|
||||
private:
|
||||
void currentChanged(const QModelIndex& current);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user